#include "content/utility/services.h"
#include <utility>
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/lazy_instance.h"
#include "base/task/single_thread_task_runner.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "components/services/storage/public/mojom/storage_service.mojom.h"
#include "components/services/storage/storage_service_impl.h"
#include "content/child/child_process.h"
#include "content/public/common/content_switches.h"
#include "content/public/utility/content_utility_client.h"
#include "content/public/utility/utility_thread.h"
#include "content/services/auction_worklet/auction_worklet_service_impl.h"
#include "content/services/auction_worklet/public/mojom/auction_worklet_service.mojom.h"
#include "device/vr/buildflags/buildflags.h"
#include "media/base/media_switches.h"
#include "media/gpu/buildflags.h"
#include "media/media_buildflags.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "mojo/public/cpp/bindings/service_factory.h"
#include "services/accessibility/buildflags.h"
#include "services/audio/service_factory.h"
#include "services/data_decoder/data_decoder_service.h"
#include "services/network/network_service.h"
#include "services/on_device_model/on_device_model_service.h"
#include "services/tracing/public/mojom/tracing_service.mojom.h"
#include "services/tracing/tracing_service.h"
#include "services/video_capture/public/mojom/video_capture_service.mojom.h"
#include "services/video_capture/video_capture_service_impl.h"
#include "services/video_effects/public/cpp/buildflags.h"
#if BUILDFLAG(ENABLE_VIDEO_EFFECTS)
#include "services/video_effects/public/mojom/video_effects_service.mojom.h"
#include "services/video_effects/video_effects_service_impl.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "base/apple/mach_logging.h"
#include "sandbox/mac/system_services.h"
#include "sandbox/policy/sandbox.h"
#endif
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
#include "media/cdm/cdm_adapter_factory.h"
#include "media/mojo/mojom/cdm_service.mojom.h"
#include "media/mojo/mojom/frame_interface_factory.mojom.h"
#include "media/mojo/services/cdm_service.h"
#include "media/mojo/services/cdm_service_broker.h"
#include "media/mojo/services/mojo_cdm_helper.h"
#include "media/mojo/services/mojo_media_client.h"
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
#include "media/cdm/cdm_host_file.h"
#endif
#endif
#if BUILDFLAG(ENABLE_VR) && !BUILDFLAG(IS_ANDROID)
#include "content/services/isolated_xr_device/xr_device_service.h"
#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "base/win/scoped_com_initializer.h"
#include "sandbox/win/src/sandbox.h"
extern sandbox::TargetServices* g_utility_target_services;
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "media/mojo/services/mojo_video_encode_accelerator_provider_factory.h"
#include "sandbox/linux/services/libc_interceptor.h"
#include "sandbox/policy/mojom/sandbox.mojom.h"
#include "sandbox/policy/sandbox_type.h"
#endif
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) && BUILDFLAG(IS_CHROMEOS)
#include "services/shape_detection/public/mojom/shape_detection_service.mojom.h"
#include "services/shape_detection/shape_detection_service.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "media/mojo/mojom/media_foundation_service.mojom.h"
#include "media/mojo/services/media_foundation_service_broker.h"
#endif
#if BUILDFLAG(IS_ANDROID)
#include "media/mojo/mojom/mediadrm_support.mojom.h"
#include "media/mojo/services/mediadrm_support_service.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH) && \
(BUILDFLAG(USE_VAAPI) || BUILDFLAG(USE_V4L2_CODEC))
#include "ash/components/arc/video_accelerator/oop_arc_video_accelerator_factory.h"
#endif
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_ASH)) && \
(BUILDFLAG(USE_VAAPI) || BUILDFLAG(USE_V4L2_CODEC))
#include "content/common/features.h"
#include "media/mojo/services/stable_video_decoder_factory_process_service.h"
#endif
#if BUILDFLAG(ENABLE_ACCESSIBILITY_SERVICE)
#if BUILDFLAG(SUPPORTS_OS_ACCESSIBILITY_SERVICE)
#include "services/accessibility/os_accessibility_service.h"
#else
#include "services/accessibility/browser_accessibility_service.h"
#endif
#include "services/accessibility/public/mojom/accessibility_service.mojom.h"
#include "ui/accessibility/accessibility_features.h"
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS_ASH) || \
BUILDFLAG(ENABLE_VIDEO_EFFECTS)
#include "services/viz/public/cpp/gpu/gpu.h"
#include "services/viz/public/mojom/gpu.mojom.h"
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS_ASH)
#include "media/capture/capture_switches.h"
#endif
namespace content {
base::LazyInstance<NetworkBinderCreationCallback>::Leaky
g_network_binder_creation_callback_for_testing = …;
namespace {
#if BUILDFLAG(IS_WIN)
void EnsureSandboxedWin() {
if (g_utility_target_services)
g_utility_target_services->LowerToken();
}
#endif
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
std::unique_ptr<media::CdmAuxiliaryHelper> CreateCdmHelper(
media::mojom::FrameInterfaceFactory* interface_provider) { … }
class ContentCdmServiceClient final : public media::CdmService::Client { … };
#endif
class UtilityThreadVideoCaptureServiceImpl final
: public video_capture::VideoCaptureServiceImpl { … };
auto RunNetworkService(
mojo::PendingReceiver<network::mojom::NetworkService> receiver) { … }
auto RunAuctionWorkletService(
mojo::PendingReceiver<auction_worklet::mojom::AuctionWorkletService>
receiver) { … }
auto RunAudio(mojo::PendingReceiver<audio::mojom::AudioService> receiver) { … }
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) && BUILDFLAG(IS_CHROMEOS)
auto RunShapeDetectionService(
mojo::PendingReceiver<shape_detection::mojom::ShapeDetectionService>
receiver) {
return std::make_unique<shape_detection::ShapeDetectionService>(
std::move(receiver));
}
#endif
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
auto RunCdmServiceBroker(
mojo::PendingReceiver<media::mojom::CdmServiceBroker> receiver) { … }
#endif
auto RunDataDecoder(
mojo::PendingReceiver<data_decoder::mojom::DataDecoderService> receiver) { … }
#if BUILDFLAG(ENABLE_ACCESSIBILITY_SERVICE)
auto RunAccessibilityService(
mojo::PendingReceiver<ax::mojom::AccessibilityService> receiver) {
#if BUILDFLAG(SUPPORTS_OS_ACCESSIBILITY_SERVICE)
return std::make_unique<ax::OSAccessibilityService>(std::move(receiver));
#else
return std::make_unique<ax::BrowserAccessibilityService>(std::move(receiver));
#endif
}
#endif
#if BUILDFLAG(IS_WIN)
std::unique_ptr<media::MediaFoundationServiceBroker>
RunMediaFoundationServiceBroker(
mojo::PendingReceiver<media::mojom::MediaFoundationServiceBroker>
receiver) {
return std::make_unique<media::MediaFoundationServiceBroker>(
std::move(receiver), base::BindOnce(&EnsureSandboxedWin));
}
#endif
#if BUILDFLAG(IS_ANDROID)
auto RunMediaDrmSupportService(
mojo::PendingReceiver<media::mojom::MediaDrmSupport> receiver) {
return std::make_unique<media::MediaDrmSupportService>(std::move(receiver));
}
#endif
auto RunStorageService(
mojo::PendingReceiver<storage::mojom::StorageService> receiver) { … }
auto RunTracing(
mojo::PendingReceiver<tracing::mojom::TracingService> receiver) { … }
auto RunVideoCapture(
mojo::PendingReceiver<video_capture::mojom::VideoCaptureService> receiver) { … }
#if BUILDFLAG(ENABLE_VIDEO_EFFECTS)
auto RunVideoEffects(
mojo::PendingReceiver<video_effects::mojom::VideoEffectsService> receiver) { … }
#endif
auto RunOnDeviceModel(
mojo::PendingReceiver<on_device_model::mojom::OnDeviceModelService>
receiver) { … }
#if BUILDFLAG(ENABLE_VR) && !BUILDFLAG(IS_ANDROID)
auto RunXrDeviceService(
mojo::PendingReceiver<device::mojom::XRDeviceService> receiver) { … }
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH) && \
(BUILDFLAG(USE_VAAPI) || BUILDFLAG(USE_V4L2_CODEC))
auto RunOOPArcVideoAcceleratorFactoryService(
mojo::PendingReceiver<arc::mojom::VideoAcceleratorFactory> receiver) {
return std::make_unique<arc::OOPArcVideoAcceleratorFactory>(
std::move(receiver));
}
#endif
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_ASH)) && \
(BUILDFLAG(USE_VAAPI) || BUILDFLAG(USE_V4L2_CODEC))
auto RunStableVideoDecoderFactoryProcessService(
mojo::PendingReceiver<
media::stable::mojom::StableVideoDecoderFactoryProcess> receiver) { … }
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
auto RunVideoEncodeAcceleratorProviderFactory(
mojo::PendingReceiver<media::mojom::VideoEncodeAcceleratorProviderFactory>
receiver) { … }
#endif
}
void SetNetworkBinderCreationCallbackForTesting(
NetworkBinderCreationCallback callback) { … }
void RegisterIOThreadServices(mojo::ServiceFactory& services) { … }
void RegisterMainThreadServices(mojo::ServiceFactory& services) { … }
}