Commit a3cb5eee authored by Xiaohan Wang's avatar Xiaohan Wang Committed by Commit Bot

media: Simplify CdmService

- Restrict CdmService to only host library CDM. Previously CdmService
  is generic, but it's never used anywhere else, and that assumption
  has caused some unnecessary code complexity.
- As such, also remove ENABLE_STANDALONE_CDM_SERVICE and replace it
  with ENABLE_LIBRARY_CDMS where applicable.
- Remove the use of media::mojom::InterfaceFactory for the CdmService,
  and replace it with a dedicated media::mojom::CdmFactory.
- Remove the use of MojoMediaClient in CdmService, and replace it with
  CdmService::Client.

BUG=771791

Change-Id: I49e0fc4958b18e1b619e20ab4772245b256ab454
Reviewed-on: https://chromium-review.googlesource.com/852556
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Reviewed-by: default avatarJohn Rummell <jrummell@chromium.org>
Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531329}
parent e8ce3a42
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
#include "media/mojo/features.h"
#include "media/mojo/interfaces/constants.mojom.h" #include "media/mojo/interfaces/constants.mojom.h"
#include "media/mojo/interfaces/media_service.mojom.h" #include "media/mojo/interfaces/media_service.mojom.h"
#include "media/mojo/services/media_interface_provider.h" #include "media/mojo/services/media_interface_provider.h"
...@@ -36,16 +37,13 @@ ...@@ -36,16 +37,13 @@
#include "media/base/key_system_names.h" #include "media/base/key_system_names.h"
#include "mojo/public/cpp/bindings/interface_request.h" #include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
#if defined(OS_MACOSX)
#include "sandbox/mac/seatbelt_extension.h"
#endif // defined(OS_MACOSX)
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
#include "media/mojo/interfaces/cdm_service_mac.mojom.h" #include "media/mojo/interfaces/cdm_service_mac.mojom.h"
#include "sandbox/mac/seatbelt_extension.h"
#else #else
#include "media/mojo/interfaces/cdm_service.mojom.h" #include "media/mojo/interfaces/cdm_service.mojom.h"
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
namespace content { namespace content {
...@@ -123,8 +121,8 @@ MediaInterfaceProxy::MediaInterfaceProxy( ...@@ -123,8 +121,8 @@ MediaInterfaceProxy::MediaInterfaceProxy(
binding_.set_connection_error_handler(error_handler); binding_.set_connection_error_handler(error_handler);
// |interface_factory_ptr_| and |cdm_interface_factory_map_| will be lazily // |interface_factory_ptr_| and |cdm_factory_map_| will be lazily
// connected in GetMediaInterfaceFactory() and GetCdmInterfaceFactory(). // connected in GetMediaInterfaceFactory() and GetCdmFactory().
} }
MediaInterfaceProxy::~MediaInterfaceProxy() { MediaInterfaceProxy::~MediaInterfaceProxy() {
...@@ -161,16 +159,15 @@ void MediaInterfaceProxy::CreateCdm( ...@@ -161,16 +159,15 @@ void MediaInterfaceProxy::CreateCdm(
const std::string& key_system, const std::string& key_system,
media::mojom::ContentDecryptionModuleRequest request) { media::mojom::ContentDecryptionModuleRequest request) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
#if !BUILDFLAG(ENABLE_LIBRARY_CDMS)
InterfaceFactory* factory = auto* factory = GetMediaInterfaceFactory();
#if !BUILDFLAG(ENABLE_STANDALONE_CDM_SERVICE) if (factory)
GetMediaInterfaceFactory(); factory->CreateCdm(key_system, std::move(request));
#else #else
GetCdmInterfaceFactory(key_system); auto* factory = GetCdmFactory(key_system);
#endif
if (factory) if (factory)
factory->CreateCdm(key_system, std::move(request)); factory->CreateCdm(key_system, std::move(request));
#endif
} }
void MediaInterfaceProxy::CreateCdmProxy( void MediaInterfaceProxy::CreateCdmProxy(
...@@ -258,9 +255,9 @@ void MediaInterfaceProxy::OnMediaServiceConnectionError() { ...@@ -258,9 +255,9 @@ void MediaInterfaceProxy::OnMediaServiceConnectionError() {
interface_factory_ptr_.reset(); interface_factory_ptr_.reset();
} }
#if BUILDFLAG(ENABLE_STANDALONE_CDM_SERVICE) #if BUILDFLAG(ENABLE_LIBRARY_CDMS)
media::mojom::InterfaceFactory* MediaInterfaceProxy::GetCdmInterfaceFactory( media::mojom::CdmFactory* MediaInterfaceProxy::GetCdmFactory(
const std::string& key_system) { const std::string& key_system) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
...@@ -268,7 +265,6 @@ media::mojom::InterfaceFactory* MediaInterfaceProxy::GetCdmInterfaceFactory( ...@@ -268,7 +265,6 @@ media::mojom::InterfaceFactory* MediaInterfaceProxy::GetCdmInterfaceFactory(
base::FilePath cdm_path; base::FilePath cdm_path;
std::string cdm_file_system_id; std::string cdm_file_system_id;
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
std::unique_ptr<CdmInfo> cdm_info = std::unique_ptr<CdmInfo> cdm_info =
KeySystemSupportImpl::GetCdmInfoForKeySystem(key_system); KeySystemSupportImpl::GetCdmInfoForKeySystem(key_system);
if (!cdm_info) { if (!cdm_info) {
...@@ -290,22 +286,21 @@ media::mojom::InterfaceFactory* MediaInterfaceProxy::GetCdmInterfaceFactory( ...@@ -290,22 +286,21 @@ media::mojom::InterfaceFactory* MediaInterfaceProxy::GetCdmInterfaceFactory(
cdm_guid = cdm_info->guid; cdm_guid = cdm_info->guid;
cdm_path = cdm_info->path; cdm_path = cdm_info->path;
cdm_file_system_id = cdm_info->file_system_id; cdm_file_system_id = cdm_info->file_system_id;
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
auto found = cdm_interface_factory_map_.find(cdm_guid); auto found = cdm_factory_map_.find(cdm_guid);
if (found != cdm_interface_factory_map_.end()) if (found != cdm_factory_map_.end())
return found->second.get(); return found->second.get();
return ConnectToCdmService(cdm_guid, cdm_path, cdm_file_system_id); return ConnectToCdmService(cdm_guid, cdm_path, cdm_file_system_id);
} }
media::mojom::InterfaceFactory* MediaInterfaceProxy::ConnectToCdmService( media::mojom::CdmFactory* MediaInterfaceProxy::ConnectToCdmService(
const std::string& cdm_guid, const std::string& cdm_guid,
const base::FilePath& cdm_path, const base::FilePath& cdm_path,
const std::string& cdm_file_system_id) { const std::string& cdm_file_system_id) {
DVLOG(1) << __func__ << ": cdm_guid = " << cdm_guid; DVLOG(1) << __func__ << ": cdm_guid = " << cdm_guid;
DCHECK(!cdm_interface_factory_map_.count(cdm_guid)); DCHECK(!cdm_factory_map_.count(cdm_guid));
service_manager::Identity identity(media::mojom::kCdmServiceName, service_manager::Identity identity(media::mojom::kCdmServiceName,
service_manager::mojom::kInheritUserID, service_manager::mojom::kInheritUserID,
cdm_guid); cdm_guid);
...@@ -317,7 +312,6 @@ media::mojom::InterfaceFactory* MediaInterfaceProxy::ConnectToCdmService( ...@@ -317,7 +312,6 @@ media::mojom::InterfaceFactory* MediaInterfaceProxy::ConnectToCdmService(
media::mojom::CdmServicePtr cdm_service; media::mojom::CdmServicePtr cdm_service;
connector->BindInterface(identity, &cdm_service); connector->BindInterface(identity, &cdm_service);
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
// LoadCdm() should always be called before CreateInterfaceFactory(). // LoadCdm() should always be called before CreateInterfaceFactory().
media::mojom::SeatbeltExtensionTokenProviderPtr token_provider_ptr; media::mojom::SeatbeltExtensionTokenProviderPtr token_provider_ptr;
...@@ -329,20 +323,17 @@ media::mojom::InterfaceFactory* MediaInterfaceProxy::ConnectToCdmService( ...@@ -329,20 +323,17 @@ media::mojom::InterfaceFactory* MediaInterfaceProxy::ConnectToCdmService(
#else #else
cdm_service->LoadCdm(cdm_path); cdm_service->LoadCdm(cdm_path);
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
InterfaceFactoryPtr interface_factory_ptr; media::mojom::CdmFactoryPtr cdm_factory_ptr;
cdm_service->CreateInterfaceFactory( cdm_service->CreateCdmFactory(MakeRequest(&cdm_factory_ptr),
MakeRequest(&interface_factory_ptr), GetFrameServices(cdm_guid, cdm_file_system_id));
GetFrameServices(cdm_guid, cdm_file_system_id)); cdm_factory_ptr.set_connection_error_handler(
interface_factory_ptr.set_connection_error_handler(
base::BindOnce(&MediaInterfaceProxy::OnCdmServiceConnectionError, base::BindOnce(&MediaInterfaceProxy::OnCdmServiceConnectionError,
base::Unretained(this), cdm_guid)); base::Unretained(this), cdm_guid));
InterfaceFactory* cdm_interface_factory = interface_factory_ptr.get(); auto* cdm_factory = cdm_factory_ptr.get();
cdm_interface_factory_map_.emplace(cdm_guid, cdm_factory_map_.emplace(cdm_guid, std::move(cdm_factory_ptr));
std::move(interface_factory_ptr)); return cdm_factory;
return cdm_interface_factory;
} }
void MediaInterfaceProxy::OnCdmServiceConnectionError( void MediaInterfaceProxy::OnCdmServiceConnectionError(
...@@ -350,12 +341,10 @@ void MediaInterfaceProxy::OnCdmServiceConnectionError( ...@@ -350,12 +341,10 @@ void MediaInterfaceProxy::OnCdmServiceConnectionError(
DVLOG(1) << __func__; DVLOG(1) << __func__;
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(cdm_interface_factory_map_.count(cdm_guid)); DCHECK(cdm_factory_map_.count(cdm_guid));
cdm_interface_factory_map_.erase(cdm_guid); cdm_factory_map_.erase(cdm_guid);
} }
#endif // BUILDFLAG(ENABLE_STANDALONE_CDM_SERVICE)
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
void MediaInterfaceProxy::CreateCdmProxyInternal( void MediaInterfaceProxy::CreateCdmProxyInternal(
const std::string& cdm_guid, const std::string& cdm_guid,
media::mojom::CdmProxyRequest request) { media::mojom::CdmProxyRequest request) {
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "media/mojo/features.h" #include "media/media_features.h"
#include "media/mojo/interfaces/content_decryption_module.mojom.h"
#include "media/mojo/interfaces/interface_factory.mojom.h" #include "media/mojo/interfaces/interface_factory.mojom.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "services/service_manager/public/interfaces/interface_provider.mojom.h" #include "services/service_manager/public/interfaces/interface_provider.mojom.h"
...@@ -27,9 +28,9 @@ class RenderFrameHost; ...@@ -27,9 +28,9 @@ class RenderFrameHost;
// This implements the media::mojom::InterfaceFactory interface for a // This implements the media::mojom::InterfaceFactory interface for a
// RenderFrameHostImpl. Upon InterfaceFactory calls, it will // RenderFrameHostImpl. Upon InterfaceFactory calls, it will
// figure out where to forward to the interface requests. For example, // figure out where to forward to the interface requests. For example,
// - When |enable_standalone_cdm_service| is true, forward CDM request to a // - When |enable_library_cdms| is true, forward CDM request to the CdmService
// standalone CDM service rather than the general media service. // rather than the general media service.
// - Forward CDM requests to different CDM service instances based on library // - Forward CDM requests to different CdmService instances based on library
// CDM types. // CDM types.
class MediaInterfaceProxy : public media::mojom::InterfaceFactory { class MediaInterfaceProxy : public media::mojom::InterfaceFactory {
public: public:
...@@ -52,8 +53,6 @@ class MediaInterfaceProxy : public media::mojom::InterfaceFactory { ...@@ -52,8 +53,6 @@ class MediaInterfaceProxy : public media::mojom::InterfaceFactory {
media::mojom::CdmProxyRequest request) final; media::mojom::CdmProxyRequest request) final;
private: private:
using InterfaceFactoryPtr = media::mojom::InterfaceFactoryPtr;
// Gets services provided by the browser (at RenderFrameHost level) to the // Gets services provided by the browser (at RenderFrameHost level) to the
// mojo media (or CDM) service running remotely. |cdm_file_system_id| is // mojo media (or CDM) service running remotely. |cdm_file_system_id| is
// used to register the appropriate CdmStorage interface needed by the CDM. // used to register the appropriate CdmStorage interface needed by the CDM.
...@@ -70,27 +69,25 @@ class MediaInterfaceProxy : public media::mojom::InterfaceFactory { ...@@ -70,27 +69,25 @@ class MediaInterfaceProxy : public media::mojom::InterfaceFactory {
// Callback for connection error from |interface_factory_ptr_|. // Callback for connection error from |interface_factory_ptr_|.
void OnMediaServiceConnectionError(); void OnMediaServiceConnectionError();
#if BUILDFLAG(ENABLE_STANDALONE_CDM_SERVICE) #if BUILDFLAG(ENABLE_LIBRARY_CDMS)
// Gets a CDM InterfaceFactory pointer for |key_system|. Returns null if // Gets a CdmFactory pointer for |key_system|. Returns null if unexpected
// unexpected error happened. // error happened.
InterfaceFactory* GetCdmInterfaceFactory(const std::string& key_system); media::mojom::CdmFactory* GetCdmFactory(const std::string& key_system);
// Connects to the CDM service associated with |cdm_guid|, adds the new // Connects to the CDM service associated with |cdm_guid|, adds the new
// InterfaceFactoryPtr to the |cdm_interface_factory_map_|, and returns the // CdmFactoryPtr to the |cdm_factory_map_|, and returns the newly created
// newly created InterfaceFactory pointer. Returns nullptr if unexpected error // CdmFactory pointer. Returns nullptr if unexpected error happened.
// happened. |cdm_path| will be used to preload the CDM, if necessary. // |cdm_path| will be used to preload the CDM, if necessary.
// |cdm_file_system_id| is used when creating the matching storage // |cdm_file_system_id| is used when creating the matching storage interface.
// interface. media::mojom::CdmFactory* ConnectToCdmService(
InterfaceFactory* ConnectToCdmService(const std::string& cdm_guid, const std::string& cdm_guid,
const base::FilePath& cdm_path, const base::FilePath& cdm_path,
const std::string& cdm_file_system_id); const std::string& cdm_file_system_id);
// Callback for connection error from the InterfaceFactoryPtr in the // Callback for connection error from the CdmFactoryPtr in the
// |cdm_interface_factory_map_| associated with |cdm_guid|. // |cdm_factory_map_| associated with |cdm_guid|.
void OnCdmServiceConnectionError(const std::string& cdm_guid); void OnCdmServiceConnectionError(const std::string& cdm_guid);
#endif // BUILDFLAG(ENABLE_STANDALONE_CDM_SERVICE)
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
// Creates a CdmProxy for the CDM in CdmService. Not implemented in // Creates a CdmProxy for the CDM in CdmService. Not implemented in
// CreateCdmProxy() because we don't want any client to be able to create // CreateCdmProxy() because we don't want any client to be able to create
// a CdmProxy. // a CdmProxy.
...@@ -112,13 +109,13 @@ class MediaInterfaceProxy : public media::mojom::InterfaceFactory { ...@@ -112,13 +109,13 @@ class MediaInterfaceProxy : public media::mojom::InterfaceFactory {
// in the service named kMediaServiceName hosted in the process specified by // in the service named kMediaServiceName hosted in the process specified by
// the "mojo_media_host" gn argument. Available options are browser, GPU and // the "mojo_media_host" gn argument. Available options are browser, GPU and
// utility processes. // utility processes.
InterfaceFactoryPtr interface_factory_ptr_; media::mojom::InterfaceFactoryPtr interface_factory_ptr_;
#if BUILDFLAG(ENABLE_STANDALONE_CDM_SERVICE) #if BUILDFLAG(ENABLE_LIBRARY_CDMS)
// CDM GUID to CDM InterfaceFactoryPtr mapping, where the InterfaceFactory // CDM GUID to CDM InterfaceFactoryPtr mapping, where the InterfaceFactory
// instances live in the standalone kCdmServiceName service instances. // instances live in the standalone kCdmServiceName service instances.
std::map<std::string, InterfaceFactoryPtr> cdm_interface_factory_map_; std::map<std::string, media::mojom::CdmFactoryPtr> cdm_factory_map_;
#endif // BUILDFLAG(ENABLE_STANDALONE_CDM_SERVICE) #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
#include "content/public/common/service_names.mojom.h" #include "content/public/common/service_names.mojom.h"
#include "device/geolocation/geolocation_provider.h" #include "device/geolocation/geolocation_provider.h"
#include "media/media_features.h"
#include "media/mojo/features.h" #include "media/mojo/features.h"
#include "media/mojo/interfaces/constants.mojom.h" #include "media/mojo/interfaces/constants.mojom.h"
#include "mojo/edk/embedder/embedder.h" #include "mojo/edk/embedder/embedder.h"
...@@ -579,7 +580,7 @@ ServiceManagerContext::ServiceManagerContext() { ...@@ -579,7 +580,7 @@ ServiceManagerContext::ServiceManagerContext() {
base::ASCIIToUTF16("Media Service"); base::ASCIIToUTF16("Media Service");
#endif #endif
#if BUILDFLAG(ENABLE_STANDALONE_CDM_SERVICE) #if BUILDFLAG(ENABLE_LIBRARY_CDMS)
out_of_process_services[media::mojom::kCdmServiceName] = out_of_process_services[media::mojom::kCdmServiceName] =
base::ASCIIToUTF16("Content Decryption Module Service"); base::ASCIIToUTF16("Content Decryption Module Service");
#endif #endif
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#if BUILDFLAG(ENABLE_LIBRARY_CDMS) #if BUILDFLAG(ENABLE_LIBRARY_CDMS)
#include "media/cdm/cdm_adapter_factory.h" // nogncheck #include "media/cdm/cdm_adapter_factory.h" // nogncheck
#include "media/mojo/features.h" // nogncheck
#include "media/mojo/interfaces/constants.mojom.h" // nogncheck #include "media/mojo/interfaces/constants.mojom.h" // nogncheck
#include "media/mojo/services/cdm_service.h" // nogncheck #include "media/mojo/services/cdm_service.h" // nogncheck
#include "media/mojo/services/mojo_cdm_helper.h" // nogncheck #include "media/mojo/services/mojo_cdm_helper.h" // nogncheck
...@@ -62,18 +61,15 @@ namespace { ...@@ -62,18 +61,15 @@ namespace {
#if BUILDFLAG(ENABLE_LIBRARY_CDMS) #if BUILDFLAG(ENABLE_LIBRARY_CDMS)
static_assert(BUILDFLAG(ENABLE_STANDALONE_CDM_SERVICE), "");
static_assert(BUILDFLAG(ENABLE_MOJO_CDM), "");
std::unique_ptr<media::CdmAuxiliaryHelper> CreateCdmHelper( std::unique_ptr<media::CdmAuxiliaryHelper> CreateCdmHelper(
service_manager::mojom::InterfaceProvider* interface_provider) { service_manager::mojom::InterfaceProvider* interface_provider) {
return std::make_unique<media::MojoCdmHelper>(interface_provider); return std::make_unique<media::MojoCdmHelper>(interface_provider);
} }
class CdmMojoMediaClient final : public media::MojoMediaClient { class ContentCdmServiceClient final : public media::CdmService::Client {
public: public:
CdmMojoMediaClient() {} ContentCdmServiceClient() {}
~CdmMojoMediaClient() override {} ~ContentCdmServiceClient() override {}
void EnsureSandboxed() override { void EnsureSandboxed() override {
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -100,7 +96,7 @@ class CdmMojoMediaClient final : public media::MojoMediaClient { ...@@ -100,7 +96,7 @@ class CdmMojoMediaClient final : public media::MojoMediaClient {
std::unique_ptr<service_manager::Service> CreateCdmService() { std::unique_ptr<service_manager::Service> CreateCdmService() {
return std::unique_ptr<service_manager::Service>( return std::unique_ptr<service_manager::Service>(
new ::media::CdmService(std::make_unique<CdmMojoMediaClient>())); new ::media::CdmService(std::make_unique<ContentCdmServiceClient>()));
} }
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
......
...@@ -129,7 +129,8 @@ declare_args() { ...@@ -129,7 +129,8 @@ declare_args() {
} }
# Enables the use of library CDMs that implements the interface defined at # Enables the use of library CDMs that implements the interface defined at
# media/cdm/api/content_decryption_module.h # media/cdm/api/content_decryption_module.h. If true, the actually library CDM
# will be hosted in the mojo CDM service running in the CDM (utility) process.
# TODO(xhwang): Remove |enable_plugins| once pepper CDM support is removed. # TODO(xhwang): Remove |enable_plugins| once pepper CDM support is removed.
enable_library_cdms = enable_plugins && (is_linux || is_mac || is_win) enable_library_cdms = enable_plugins && (is_linux || is_mac || is_win)
...@@ -194,7 +195,12 @@ declare_args() { ...@@ -194,7 +195,12 @@ declare_args() {
# Renderer. Cannot be used with the mojo Renderer above. # Renderer. Cannot be used with the mojo Renderer above.
mojo_media_services = [] mojo_media_services = []
# The process to host the mojo media service. # The process that the mojo MediaService runs in. By default, all services
# registered in |mojo_media_services| are hosted in the MediaService, with the
# exception that when |enable_library_cdms| is true, the "cdm" service will
# run in a separate CdmService in the CDM (utility) process, while other
# |mojo_media_services| still run in the MediaService in the process specified
# by "mojo_media_host".
# Valid options are: # Valid options are:
# - "none": Do not use mojo media service. # - "none": Do not use mojo media service.
# - "browser": Use mojo media service hosted in the browser process. # - "browser": Use mojo media service hosted in the browser process.
...@@ -202,12 +208,6 @@ declare_args() { ...@@ -202,12 +208,6 @@ declare_args() {
# - "utility": Use mojo media service hosted in the utility process. # - "utility": Use mojo media service hosted in the utility process.
mojo_media_host = "none" mojo_media_host = "none"
# Force to host the CDM service in standalone "cdm" service instead of the
# "media" service hosted in the process specified by "mojo_media_host". Other
# mojo media services will not be affected. If true, the "cdm" service must
# also be included in "mojo_media_services".
enable_standalone_cdm_service = false
# Default mojo_media_services and mojo_media_host on various platforms. # Default mojo_media_services and mojo_media_host on various platforms.
# Can be overridden by gn build arguments from the --args command line flag # Can be overridden by gn build arguments from the --args command line flag
# for local testing. # for local testing.
...@@ -229,7 +229,6 @@ declare_args() { ...@@ -229,7 +229,6 @@ declare_args() {
} else if (enable_library_cdms) { } else if (enable_library_cdms) {
mojo_media_services = [ "cdm" ] mojo_media_services = [ "cdm" ]
mojo_media_host = "gpu" mojo_media_host = "gpu"
enable_standalone_cdm_service = true
} }
if (is_win) { if (is_win) {
......
...@@ -46,16 +46,11 @@ buildflag_header("features") { ...@@ -46,16 +46,11 @@ buildflag_header("features") {
enable_mojo_media_in_gpu_process = true enable_mojo_media_in_gpu_process = true
} else if (mojo_media_host == "utility") { } else if (mojo_media_host == "utility") {
enable_mojo_media_in_utility_process = true enable_mojo_media_in_utility_process = true
} else if (!enable_standalone_cdm_service) { } else {
assert(false, "Invalid mojo media host: $mojo_media_host") assert(false, "Invalid mojo media host: $mojo_media_host")
} }
} }
if (enable_standalone_cdm_service) {
assert(enable_mojo_cdm,
"Mojo CDM must be enabled to run in standalone CDM service.")
}
flags = [ flags = [
"ENABLE_MOJO_MEDIA=$enable_mojo_media", "ENABLE_MOJO_MEDIA=$enable_mojo_media",
"ENABLE_TEST_MOJO_MEDIA_CLIENT=$enable_test_mojo_media_client", "ENABLE_TEST_MOJO_MEDIA_CLIENT=$enable_test_mojo_media_client",
...@@ -66,7 +61,6 @@ buildflag_header("features") { ...@@ -66,7 +61,6 @@ buildflag_header("features") {
"ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS=$enable_mojo_media_in_browser_process", "ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS=$enable_mojo_media_in_browser_process",
"ENABLE_MOJO_MEDIA_IN_GPU_PROCESS=$enable_mojo_media_in_gpu_process", "ENABLE_MOJO_MEDIA_IN_GPU_PROCESS=$enable_mojo_media_in_gpu_process",
"ENABLE_MOJO_MEDIA_IN_UTILITY_PROCESS=$enable_mojo_media_in_utility_process", "ENABLE_MOJO_MEDIA_IN_UTILITY_PROCESS=$enable_mojo_media_in_utility_process",
"ENABLE_STANDALONE_CDM_SERVICE=$enable_standalone_cdm_service",
] ]
} }
......
...@@ -4,26 +4,25 @@ ...@@ -4,26 +4,25 @@
module media.mojom; module media.mojom;
import "media/mojo/interfaces/interface_factory.mojom"; import "media/mojo/interfaces/content_decryption_module.mojom";
import "mojo/common/file_path.mojom"; import "mojo/common/file_path.mojom";
import "services/service_manager/public/interfaces/interface_provider.mojom"; import "services/service_manager/public/interfaces/interface_provider.mojom";
// A service to provide media InterfaceFactory to provide CDM service, typically // A service to create a CdmFactory that can provide CDM service, typically
// to the media pipeline running in the renderer process. The service itself // to the media pipeline running in the renderer process. The service itself
// runs in the CDM (utility) process. The service is always connected from the // runs in the CDM (utility) process. The service is always connected from the
// browser process. // browser process.
interface CdmService { interface CdmService {
// Loads the CDM at |cdm_path| into the process. Must be called before // Loads the CDM at |cdm_path| into the process. Must be called before
// CreateInterfaceFactory(). Since the client will not know whether LoadCdm() // CreateCdmFactory(). Since the client will not know whether LoadCdm() has
// has been called by a previous CdmService instance, the client should always // been called by a previous CdmService instance, the client should always
// call it after service connection. If the CDM is already loaded, this will // call it after service connection. If the CDM is already loaded, this will
// be a no-op. // be a no-op.
LoadCdm(mojo.common.mojom.FilePath cdm_path); LoadCdm(mojo.common.mojom.FilePath cdm_path);
// Requests an InterfaceFactory. |host_interfaces| can optionally be used to // Requests an CdmFactory. |host_interfaces| can optionally be used to provide
// provide interfaces hosted by the caller to the remote InterfaceFactory // interfaces hosted by the caller to the remote CdmFactory implementation.
// implementation. CreateCdmFactory(
CreateInterfaceFactory( CdmFactory& factory,
InterfaceFactory& factory,
service_manager.mojom.InterfaceProvider? host_interfaces); service_manager.mojom.InterfaceProvider? host_interfaces);
}; };
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
module media.mojom; module media.mojom;
import "media/mojo/interfaces/interface_factory.mojom"; import "media/mojo/interfaces/content_decryption_module.mojom";
import "mojo/common/file_path.mojom"; import "mojo/common/file_path.mojom";
import "sandbox/mac/mojom/seatbelt_extension_token.mojom"; import "sandbox/mac/mojom/seatbelt_extension_token.mojom";
import "services/service_manager/public/interfaces/interface_provider.mojom"; import "services/service_manager/public/interfaces/interface_provider.mojom";
...@@ -12,14 +12,14 @@ import "services/service_manager/public/interfaces/interface_provider.mojom"; ...@@ -12,14 +12,14 @@ import "services/service_manager/public/interfaces/interface_provider.mojom";
// TODO(xhwang): Merge this file with media_service.mojom once EnabledIf // TODO(xhwang): Merge this file with media_service.mojom once EnabledIf
// attribute is supported in mojom files. See https://crbug.com/676224 // attribute is supported in mojom files. See https://crbug.com/676224
// A service to provide media InterfaceFactory to provide CDM service, typically // A service to create a CdmFactory that can provide CDM service, typically
// to the media pipeline running in the renderer process. The service itself // to the media pipeline running in the renderer process. The service itself
// runs in the CDM (utility) process. The service is always connected from the // runs in the CDM (utility) process. The service is always connected from the
// browser process. // browser process.
interface CdmService { interface CdmService {
// Loads the CDM at |cdm_path| into the process. Must be called before // Loads the CDM at |cdm_path| into the process. Must be called before
// CreateInterfaceFactory(). Since the client will not know whether LoadCdm() // CreateCdmFactory(). Since the client will not know whether LoadCdm() has
// has been called by a previous CdmService instance, the client should always // been called by a previous CdmService instance, the client should always
// call it after service connection. If the CDM is already loaded, this will // call it after service connection. If the CDM is already loaded, this will
// be a no-op. // be a no-op.
// |token_provider| can be used to get a sandbox seatbelt extension token // |token_provider| can be used to get a sandbox seatbelt extension token
...@@ -28,11 +28,10 @@ interface CdmService { ...@@ -28,11 +28,10 @@ interface CdmService {
LoadCdm(mojo.common.mojom.FilePath cdm_path, LoadCdm(mojo.common.mojom.FilePath cdm_path,
SeatbeltExtensionTokenProvider? token_provider); SeatbeltExtensionTokenProvider? token_provider);
// Requests an InterfaceFactory. |host_interfaces| can optionally be used to // Requests an CdmFactory. |host_interfaces| can optionally be used to provide
// provide interfaces hosted by the caller to the remote InterfaceFactory // interfaces hosted by the caller to the remote CdmFactory implementation.
// implementation. CreateCdmFactory(
CreateInterfaceFactory( CdmFactory& factory,
InterfaceFactory& factory,
service_manager.mojom.InterfaceProvider? host_interfaces); service_manager.mojom.InterfaceProvider? host_interfaces);
}; };
......
...@@ -130,3 +130,12 @@ interface ContentDecryptionModuleClient { ...@@ -130,3 +130,12 @@ interface ContentDecryptionModuleClient {
// |new_expiry_time_sec| is the number of seconds since epoch (Jan 1, 1970). // |new_expiry_time_sec| is the number of seconds since epoch (Jan 1, 1970).
OnSessionExpirationUpdate(string session_id, double new_expiry_time_sec); OnSessionExpirationUpdate(string session_id, double new_expiry_time_sec);
}; };
interface CdmFactory {
// Creates a CDM based on the |key_system| provided. A |key_system| is a
// generic term for a decryption mechanism and/or content protection provider.
// It should be a reverse domain name, e.g. "com.example.somesystem". However,
// this call may be initiated by an untrusted process (e.g. renderer), so the
// implementation must fully validate |key_system| before creating the CDM.
CreateCdm(string key_system, ContentDecryptionModule& cdm);
};
...@@ -12,8 +12,6 @@ import("//testing/test.gni") ...@@ -12,8 +12,6 @@ import("//testing/test.gni")
component("services") { component("services") {
output_name = "media_mojo_services" output_name = "media_mojo_services"
sources = [ sources = [
"cdm_service.cc",
"cdm_service.h",
"gpu_mojo_media_client.cc", "gpu_mojo_media_client.cc",
"gpu_mojo_media_client.h", "gpu_mojo_media_client.h",
"interface_factory_impl.cc", "interface_factory_impl.cc",
...@@ -117,6 +115,8 @@ component("services") { ...@@ -117,6 +115,8 @@ component("services") {
if (enable_library_cdms) { if (enable_library_cdms) {
sources += [ sources += [
"cdm_service.cc",
"cdm_service.h",
"mojo_cdm_allocator.cc", "mojo_cdm_allocator.cc",
"mojo_cdm_allocator.h", "mojo_cdm_allocator.h",
"mojo_cdm_file_io.cc", "mojo_cdm_file_io.cc",
......
...@@ -5,24 +5,112 @@ ...@@ -5,24 +5,112 @@
#include "media/mojo/services/cdm_service.h" #include "media/mojo/services/cdm_service.h"
#include "base/logging.h" #include "base/logging.h"
#include "media/base/cdm_factory.h"
#include "media/cdm/cdm_module.h"
#include "media/media_features.h" #include "media/media_features.h"
#include "media/mojo/services/interface_factory_impl.h" #include "media/mojo/services/mojo_cdm_service.h"
#include "media/mojo/services/mojo_media_client.h" #include "media/mojo/services/mojo_cdm_service_context.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/service_context.h"
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
#include "media/cdm/cdm_module.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
#include <vector> #include <vector>
#include "sandbox/mac/seatbelt_extension.h" #include "sandbox/mac/seatbelt_extension.h"
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
namespace media { namespace media {
CdmService::CdmService(std::unique_ptr<MojoMediaClient> mojo_media_client) namespace {
: mojo_media_client_(std::move(mojo_media_client)) {
DCHECK(mojo_media_client_); constexpr base::TimeDelta kServiceContextRefReleaseDelay =
base::TimeDelta::FromSeconds(5);
void DeleteServiceContextRef(service_manager::ServiceContextRef* ref) {
delete ref;
}
// Starting a new process and loading the library CDM could be expensive. This
// class helps delay the release of service_manager::ServiceContextRef by
// |kServiceContextRefReleaseDelay|, which will ultimately delay CdmService
// destruction by the same delay as well. This helps reduce the chance of
// destroying the CdmService and immediately creates it (in another process) in
// cases like navigation, which could cause long service connection delays.
class DelayedReleaseServiceContextRef {
public:
explicit DelayedReleaseServiceContextRef(
std::unique_ptr<service_manager::ServiceContextRef> ref)
: ref_(std::move(ref)),
task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
~DelayedReleaseServiceContextRef() {
service_manager::ServiceContextRef* ref_ptr = ref_.release();
if (!task_runner_->PostNonNestableDelayedTask(
FROM_HERE, base::BindOnce(&DeleteServiceContextRef, ref_ptr),
kServiceContextRefReleaseDelay)) {
DeleteServiceContextRef(ref_ptr);
}
}
private:
std::unique_ptr<service_manager::ServiceContextRef> ref_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
DISALLOW_COPY_AND_ASSIGN(DelayedReleaseServiceContextRef);
};
class CdmFactoryImpl : public mojom::CdmFactory {
public:
CdmFactoryImpl(
CdmService::Client* client,
service_manager::mojom::InterfaceProviderPtr interfaces,
std::unique_ptr<service_manager::ServiceContextRef> connection_ref)
: client_(client),
interfaces_(std::move(interfaces)),
connection_ref_(std::make_unique<DelayedReleaseServiceContextRef>(
std::move(connection_ref))) {}
~CdmFactoryImpl() final {}
// mojom::CdmFactory implementation.
void CreateCdm(const std::string& key_system,
mojom::ContentDecryptionModuleRequest request) final {
auto* cdm_factory = GetCdmFactory();
if (!cdm_factory)
return;
cdm_bindings_.AddBinding(
base::MakeUnique<MojoCdmService>(&cdm_service_context_, cdm_factory),
std::move(request));
}
private:
media::CdmFactory* GetCdmFactory() {
if (!cdm_factory_) {
cdm_factory_ = client_->CreateCdmFactory(interfaces_.get());
DLOG_IF(ERROR, !cdm_factory_) << "CdmFactory not available.";
}
return cdm_factory_.get();
}
// Must be declared before the bindings below because the bound objects might
// take a raw pointer of |cdm_service_context_| and assume it's always
// available.
MojoCdmServiceContext cdm_service_context_;
CdmService::Client* client_;
service_manager::mojom::InterfaceProviderPtr interfaces_;
mojo::StrongBindingSet<mojom::ContentDecryptionModule> cdm_bindings_;
std::unique_ptr<DelayedReleaseServiceContextRef> connection_ref_;
std::unique_ptr<media::CdmFactory> cdm_factory_;
DISALLOW_COPY_AND_ASSIGN(CdmFactoryImpl);
};
} // namespace
CdmService::CdmService(std::unique_ptr<Client> client)
: client_(std::move(client)) {
DCHECK(client_);
registry_.AddInterface<mojom::CdmService>( registry_.AddInterface<mojom::CdmService>(
base::BindRepeating(&CdmService::Create, base::Unretained(this))); base::BindRepeating(&CdmService::Create, base::Unretained(this)));
} }
...@@ -35,7 +123,6 @@ void CdmService::OnStart() { ...@@ -35,7 +123,6 @@ void CdmService::OnStart() {
ref_factory_.reset(new service_manager::ServiceContextRefFactory( ref_factory_.reset(new service_manager::ServiceContextRefFactory(
base::BindRepeating(&service_manager::ServiceContext::RequestQuit, base::BindRepeating(&service_manager::ServiceContext::RequestQuit,
base::Unretained(context())))); base::Unretained(context()))));
mojo_media_client_->Initialize(context()->connector());
} }
void CdmService::OnBindInterface( void CdmService::OnBindInterface(
...@@ -48,8 +135,8 @@ void CdmService::OnBindInterface( ...@@ -48,8 +135,8 @@ void CdmService::OnBindInterface(
} }
bool CdmService::OnServiceManagerConnectionLost() { bool CdmService::OnServiceManagerConnectionLost() {
interface_factory_bindings_.CloseAllBindings(); cdm_factory_bindings_.CloseAllBindings();
mojo_media_client_.reset(); client_.reset();
return true; return true;
} }
...@@ -67,10 +154,9 @@ void CdmService::LoadCdm(const base::FilePath& cdm_path) { ...@@ -67,10 +154,9 @@ void CdmService::LoadCdm(const base::FilePath& cdm_path) {
DVLOG(1) << __func__ << ": cdm_path = " << cdm_path.value(); DVLOG(1) << __func__ << ": cdm_path = " << cdm_path.value();
// Ignore request if service has already stopped. // Ignore request if service has already stopped.
if (!mojo_media_client_) if (!client_)
return; return;
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
CdmModule* instance = CdmModule::GetInstance(); CdmModule* instance = CdmModule::GetInstance();
if (instance->was_initialize_called()) { if (instance->was_initialize_called()) {
DCHECK_EQ(cdm_path, instance->GetCdmPath()); DCHECK_EQ(cdm_path, instance->GetCdmPath());
...@@ -87,7 +173,7 @@ void CdmService::LoadCdm(const base::FilePath& cdm_path) { ...@@ -87,7 +173,7 @@ void CdmService::LoadCdm(const base::FilePath& cdm_path) {
DVLOG(3) << "token: " << token.token(); DVLOG(3) << "token: " << token.token();
auto extension = sandbox::SeatbeltExtension::FromToken(std::move(token)); auto extension = sandbox::SeatbeltExtension::FromToken(std::move(token));
if (!extension->Consume()) { if (!extension->Consume()) {
DVLOG(1) << "Failed to comsume sandbox seatbelt extension. This could " DVLOG(1) << "Failed to consume sandbox seatbelt extension. This could "
"happen if --no-sandbox is specified."; "happen if --no-sandbox is specified.";
} }
extensions.push_back(std::move(extension)); extensions.push_back(std::move(extension));
...@@ -96,7 +182,7 @@ void CdmService::LoadCdm(const base::FilePath& cdm_path) { ...@@ -96,7 +182,7 @@ void CdmService::LoadCdm(const base::FilePath& cdm_path) {
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION) #if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
std::vector<CdmHostFilePath> cdm_host_file_paths; std::vector<CdmHostFilePath> cdm_host_file_paths;
mojo_media_client_->AddCdmHostFilePaths(&cdm_host_file_paths); client_->AddCdmHostFilePaths(&cdm_host_file_paths);
if (!instance->Initialize(cdm_path, cdm_host_file_paths)) if (!instance->Initialize(cdm_path, cdm_host_file_paths))
return; return;
#else #else
...@@ -105,7 +191,7 @@ void CdmService::LoadCdm(const base::FilePath& cdm_path) { ...@@ -105,7 +191,7 @@ void CdmService::LoadCdm(const base::FilePath& cdm_path) {
#endif // BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION) #endif // BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
// This may trigger the sandbox to be sealed. // This may trigger the sandbox to be sealed.
mojo_media_client_->EnsureSandboxed(); client_->EnsureSandboxed();
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
for (auto&& extension : extensions) for (auto&& extension : extensions)
...@@ -114,20 +200,18 @@ void CdmService::LoadCdm(const base::FilePath& cdm_path) { ...@@ -114,20 +200,18 @@ void CdmService::LoadCdm(const base::FilePath& cdm_path) {
// Always called within the sandbox. // Always called within the sandbox.
instance->InitializeCdmModule(); instance->InitializeCdmModule();
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
} }
void CdmService::CreateInterfaceFactory( void CdmService::CreateCdmFactory(
mojom::InterfaceFactoryRequest request, mojom::CdmFactoryRequest request,
service_manager::mojom::InterfaceProviderPtr host_interfaces) { service_manager::mojom::InterfaceProviderPtr host_interfaces) {
// Ignore request if service has already stopped. // Ignore request if service has already stopped.
if (!mojo_media_client_) if (!client_)
return; return;
interface_factory_bindings_.AddBinding( cdm_factory_bindings_.AddBinding(
std::make_unique<InterfaceFactoryImpl>( std::make_unique<CdmFactoryImpl>(
std::move(host_interfaces), &media_log_, ref_factory_->CreateRef(), client_.get(), std::move(host_interfaces), ref_factory_->CreateRef()),
mojo_media_client_.get()),
std::move(request)); std::move(request));
} }
......
...@@ -8,14 +8,12 @@ ...@@ -8,14 +8,12 @@
#include <memory> #include <memory>
#include "build/build_config.h" #include "build/build_config.h"
#include "media/base/media_log.h" #include "media/mojo/interfaces/content_decryption_module.mojom.h"
#include "media/mojo/interfaces/interface_factory.mojom.h"
#include "media/mojo/services/media_mojo_export.h" #include "media/mojo/services/media_mojo_export.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/strong_binding_set.h" #include "mojo/public/cpp/bindings/strong_binding_set.h"
#include "services/service_manager/public/cpp/binder_registry.h" #include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/service.h" #include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_context.h"
#include "services/service_manager/public/cpp/service_context_ref.h" #include "services/service_manager/public/cpp/service_context_ref.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
...@@ -26,12 +24,33 @@ ...@@ -26,12 +24,33 @@
namespace media { namespace media {
class MojoMediaClient; class CdmFactory;
class MEDIA_MOJO_EXPORT CdmService : public service_manager::Service, class MEDIA_MOJO_EXPORT CdmService : public service_manager::Service,
public mojom::CdmService { public mojom::CdmService {
public: public:
explicit CdmService(std::unique_ptr<MojoMediaClient> mojo_media_client); class Client {
public:
virtual ~Client() {}
// Called by the MediaService to ensure the process is sandboxed. It could
// be a no-op if the process is already sandboxed.
virtual void EnsureSandboxed() = 0;
// Returns the CdmFactory to be used by MojoCdmService. |host_interfaces|
// can be used to request interfaces provided remotely by the host. It may
// be a nullptr if the host chose not to bind the InterfacePtr.
virtual std::unique_ptr<CdmFactory> CreateCdmFactory(
service_manager::mojom::InterfaceProvider* host_interfaces) = 0;
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
// Gets a list of CDM host file paths and put them in |cdm_host_file_paths|.
virtual void AddCdmHostFilePaths(
std::vector<CdmHostFilePath>* cdm_host_file_paths) = 0;
#endif // BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
};
explicit CdmService(std::unique_ptr<Client> client);
~CdmService() final; ~CdmService() final;
private: private:
...@@ -52,25 +71,14 @@ class MEDIA_MOJO_EXPORT CdmService : public service_manager::Service, ...@@ -52,25 +71,14 @@ class MEDIA_MOJO_EXPORT CdmService : public service_manager::Service,
void LoadCdm(const base::FilePath& cdm_path) final; void LoadCdm(const base::FilePath& cdm_path) final;
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
void CreateInterfaceFactory( void CreateCdmFactory(
mojom::InterfaceFactoryRequest request, mojom::CdmFactoryRequest request,
service_manager::mojom::InterfaceProviderPtr host_interfaces) final; service_manager::mojom::InterfaceProviderPtr host_interfaces) final;
MediaLog media_log_;
std::unique_ptr<service_manager::ServiceContextRefFactory> ref_factory_; std::unique_ptr<service_manager::ServiceContextRefFactory> ref_factory_;
std::unique_ptr<Client> client_;
// Note: Since each instance runs on a different thread, do not share a common std::unique_ptr<CdmFactory> cdm_factory_;
// MojoMediaClient with other instances to avoid threading issues. Hence using mojo::StrongBindingSet<mojom::CdmFactory> cdm_factory_bindings_;
// a unique_ptr here.
//
// Note: Since |*ref_factory_| is passed to |mojo_media_client_|,
// |mojo_media_client_| must be destructed before |ref_factory_|.
std::unique_ptr<MojoMediaClient> mojo_media_client_;
// Note: Since |&media_log_| is passed to bindings, the bindings must be
// destructed first.
mojo::StrongBindingSet<mojom::InterfaceFactory> interface_factory_bindings_;
service_manager::BinderRegistry registry_; service_manager::BinderRegistry registry_;
mojo::BindingSet<mojom::CdmService> bindings_; mojo::BindingSet<mojom::CdmService> bindings_;
}; };
......
...@@ -42,44 +42,6 @@ ...@@ -42,44 +42,6 @@
namespace media { namespace media {
namespace {
constexpr base::TimeDelta kServiceContextRefReleaseDelay =
base::TimeDelta::FromSeconds(5);
void DeleteServiceContextRef(service_manager::ServiceContextRef* ref) {
delete ref;
}
} // namespace
// Helper class to help delay the release of service_manager::ServiceContextRef
// by |kServiceContextRefReleaseDelay|, which will ultimately delay MediaService
// destruction by the same delay as well. This helps reduce service connection
// time in cases like navigation.
class DelayedReleaseServiceContextRef {
public:
explicit DelayedReleaseServiceContextRef(
std::unique_ptr<service_manager::ServiceContextRef> ref)
: ref_(std::move(ref)),
task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
~DelayedReleaseServiceContextRef() {
service_manager::ServiceContextRef* ref_ptr = ref_.release();
if (!task_runner_->PostNonNestableDelayedTask(
FROM_HERE, base::BindOnce(&DeleteServiceContextRef, ref_ptr),
kServiceContextRefReleaseDelay)) {
DeleteServiceContextRef(ref_ptr);
}
}
private:
std::unique_ptr<service_manager::ServiceContextRef> ref_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
DISALLOW_COPY_AND_ASSIGN(DelayedReleaseServiceContextRef);
};
InterfaceFactoryImpl::InterfaceFactoryImpl( InterfaceFactoryImpl::InterfaceFactoryImpl(
service_manager::mojom::InterfaceProviderPtr interfaces, service_manager::mojom::InterfaceProviderPtr interfaces,
MediaLog* media_log, MediaLog* media_log,
...@@ -92,8 +54,7 @@ InterfaceFactoryImpl::InterfaceFactoryImpl( ...@@ -92,8 +54,7 @@ InterfaceFactoryImpl::InterfaceFactoryImpl(
#if BUILDFLAG(ENABLE_MOJO_CDM) #if BUILDFLAG(ENABLE_MOJO_CDM)
interfaces_(std::move(interfaces)), interfaces_(std::move(interfaces)),
#endif #endif
connection_ref_(std::make_unique<DelayedReleaseServiceContextRef>( connection_ref_(std::move(connection_ref)),
std::move(connection_ref))),
mojo_media_client_(mojo_media_client) { mojo_media_client_(mojo_media_client) {
DVLOG(1) << __func__; DVLOG(1) << __func__;
DCHECK(mojo_media_client_); DCHECK(mojo_media_client_);
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
namespace media { namespace media {
class CdmFactory; class CdmFactory;
class DelayedReleaseServiceContextRef;
class MediaLog; class MediaLog;
class MojoMediaClient; class MojoMediaClient;
class RendererFactory; class RendererFactory;
...@@ -80,7 +79,7 @@ class InterfaceFactoryImpl : public mojom::InterfaceFactory { ...@@ -80,7 +79,7 @@ class InterfaceFactoryImpl : public mojom::InterfaceFactory {
mojo::StrongBindingSet<mojom::CdmProxy> cdm_proxy_bindings_; mojo::StrongBindingSet<mojom::CdmProxy> cdm_proxy_bindings_;
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
std::unique_ptr<DelayedReleaseServiceContextRef> connection_ref_; std::unique_ptr<service_manager::ServiceContextRef> connection_ref_;
MojoMediaClient* mojo_media_client_; MojoMediaClient* mojo_media_client_;
DISALLOW_COPY_AND_ASSIGN(InterfaceFactoryImpl); DISALLOW_COPY_AND_ASSIGN(InterfaceFactoryImpl);
......
...@@ -25,8 +25,6 @@ MojoMediaClient::~MojoMediaClient() = default; ...@@ -25,8 +25,6 @@ MojoMediaClient::~MojoMediaClient() = default;
void MojoMediaClient::Initialize(service_manager::Connector* connector) {} void MojoMediaClient::Initialize(service_manager::Connector* connector) {}
void MojoMediaClient::EnsureSandboxed() {}
std::unique_ptr<AudioDecoder> MojoMediaClient::CreateAudioDecoder( std::unique_ptr<AudioDecoder> MojoMediaClient::CreateAudioDecoder(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
return nullptr; return nullptr;
...@@ -67,9 +65,4 @@ std::unique_ptr<CdmProxy> MojoMediaClient::CreateCdmProxy( ...@@ -67,9 +65,4 @@ std::unique_ptr<CdmProxy> MojoMediaClient::CreateCdmProxy(
} }
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
void MojoMediaClient::AddCdmHostFilePaths(
std::vector<media::CdmHostFilePath>* /* cdm_host_file_paths */) {}
#endif // BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
} // namespace media } // namespace media
...@@ -37,7 +37,6 @@ class MediaLog; ...@@ -37,7 +37,6 @@ class MediaLog;
class RendererFactory; class RendererFactory;
class VideoDecoder; class VideoDecoder;
class VideoRendererSink; class VideoRendererSink;
struct CdmHostFilePath;
class MEDIA_MOJO_EXPORT MojoMediaClient { class MEDIA_MOJO_EXPORT MojoMediaClient {
public: public:
...@@ -50,10 +49,6 @@ class MEDIA_MOJO_EXPORT MojoMediaClient { ...@@ -50,10 +49,6 @@ class MEDIA_MOJO_EXPORT MojoMediaClient {
// |this| to connect to other services. It is guaranteed to outlive |this|. // |this| to connect to other services. It is guaranteed to outlive |this|.
virtual void Initialize(service_manager::Connector* connector); virtual void Initialize(service_manager::Connector* connector);
// Called by the MediaService to ensure the process is sandboxed. It could be
// a no-op if the process is already sandboxed.
virtual void EnsureSandboxed();
virtual std::unique_ptr<AudioDecoder> CreateAudioDecoder( virtual std::unique_ptr<AudioDecoder> CreateAudioDecoder(
scoped_refptr<base::SingleThreadTaskRunner> task_runner); scoped_refptr<base::SingleThreadTaskRunner> task_runner);
...@@ -89,12 +84,6 @@ class MEDIA_MOJO_EXPORT MojoMediaClient { ...@@ -89,12 +84,6 @@ class MEDIA_MOJO_EXPORT MojoMediaClient {
virtual std::unique_ptr<CdmProxy> CreateCdmProxy(const std::string& cdm_guid); virtual std::unique_ptr<CdmProxy> CreateCdmProxy(const std::string& cdm_guid);
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
// Gets a list of CDM host file paths and put them in |cdm_host_file_paths|.
virtual void AddCdmHostFilePaths(
std::vector<CdmHostFilePath>* cdm_host_file_paths);
#endif // BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
protected: protected:
MojoMediaClient(); MojoMediaClient();
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment