diff options
author | xhwang <xhwang@chromium.org> | 2015-04-02 22:38:15 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-03 05:38:52 +0000 |
commit | d7180836244cfbc01e551ee9f482df798503a142 (patch) | |
tree | ae9f74c5fa0d9705016928ea2dd7d680ad9e2167 /content/renderer | |
parent | 68924b69bdf1a943162467cc1cd1de37c0beec7c (diff) | |
download | chromium_src-d7180836244cfbc01e551ee9f482df798503a142.zip chromium_src-d7180836244cfbc01e551ee9f482df798503a142.tar.gz chromium_src-d7180836244cfbc01e551ee9f482df798503a142.tar.bz2 |
media: Make RenderCdmFactory a RenderFrameObserver.
This makes ownership cleaner and simplifies a lot of code. Also it's consistent
with other code in RenderFrameImpl.
Since RenderCdmFactory is owned by RenderFrameImpl, pass raw pointer of
CdmFactory around instead of a scopted pointer.
Review URL: https://codereview.chromium.org/1054873002
Cr-Commit-Position: refs/heads/master@{#323644}
Diffstat (limited to 'content/renderer')
-rw-r--r-- | content/renderer/media/android/webmediaplayer_android.cc | 9 | ||||
-rw-r--r-- | content/renderer/media/android/webmediaplayer_android.h | 8 | ||||
-rw-r--r-- | content/renderer/media/crypto/render_cdm_factory.cc | 24 | ||||
-rw-r--r-- | content/renderer/media/crypto/render_cdm_factory.h | 16 | ||||
-rw-r--r-- | content/renderer/render_frame_impl.cc | 70 | ||||
-rw-r--r-- | content/renderer/render_frame_impl.h | 10 |
6 files changed, 68 insertions, 69 deletions
diff --git a/content/renderer/media/android/webmediaplayer_android.cc b/content/renderer/media/android/webmediaplayer_android.cc index 235f357..a8188bd 100644 --- a/content/renderer/media/android/webmediaplayer_android.cc +++ b/content/renderer/media/android/webmediaplayer_android.cc @@ -149,7 +149,7 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid( blink::WebMediaPlayerClient* client, base::WeakPtr<media::WebMediaPlayerDelegate> delegate, RendererMediaPlayerManager* player_manager, - RendererCdmManager* cdm_manager, + media::CdmFactory* cdm_factory, media::MediaPermission* media_permission, blink::WebContentDecryptionModule* initial_cdm, scoped_refptr<StreamTextureFactory> factory, @@ -166,7 +166,7 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid( seeking_(false), did_loading_progress_(false), player_manager_(player_manager), - cdm_manager_(cdm_manager), + cdm_factory_(cdm_factory), media_permission_(media_permission), network_state_(WebMediaPlayer::NetworkStateEmpty), ready_state_(WebMediaPlayer::ReadyStateHaveNothing), @@ -195,7 +195,7 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid( interpolator_(&default_tick_clock_), weak_factory_(this) { DCHECK(player_manager_); - DCHECK(cdm_manager_); + DCHECK(cdm_factory_); DCHECK(main_thread_checker_.CalledOnValidThread()); stream_texture_factory_->AddObserver(this); @@ -1541,8 +1541,7 @@ WebMediaPlayerAndroid::GenerateKeyRequestInternal( } GURL security_origin(frame_->document().securityOrigin().toString()); - RenderCdmFactory cdm_factory(cdm_manager_); - if (!proxy_decryptor_->InitializeCDM(&cdm_factory, key_system, + if (!proxy_decryptor_->InitializeCDM(cdm_factory_, key_system, security_origin)) { return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; } diff --git a/content/renderer/media/android/webmediaplayer_android.h b/content/renderer/media/android/webmediaplayer_android.h index 8c19b04..2294b7c 100644 --- a/content/renderer/media/android/webmediaplayer_android.h +++ b/content/renderer/media/android/webmediaplayer_android.h @@ -58,6 +58,7 @@ struct MailboxHolder; namespace media { class CdmContext; +class CdmFactory; class MediaLog; class MediaPermission; class WebContentDecryptionModuleImpl; @@ -89,7 +90,7 @@ class WebMediaPlayerAndroid : public blink::WebMediaPlayer, blink::WebMediaPlayerClient* client, base::WeakPtr<media::WebMediaPlayerDelegate> delegate, RendererMediaPlayerManager* player_manager, - RendererCdmManager* cdm_manager, + media::CdmFactory* cdm_factory, media::MediaPermission* media_permission, blink::WebContentDecryptionModule* initial_cdm, scoped_refptr<StreamTextureFactory> factory, @@ -396,10 +397,9 @@ class WebMediaPlayerAndroid : public blink::WebMediaPlayer, // Owned by RenderFrameImpl. RendererMediaPlayerManager* const player_manager_; - // Delegates EME calls to the browser process. Owned by RenderFrameImpl. - // TODO(xhwang): Remove |cdm_manager_| when prefixed EME is deprecated. See + // TODO(xhwang): Remove |cdm_factory_| when prefixed EME is deprecated. See // http://crbug.com/249976 - RendererCdmManager* const cdm_manager_; + media::CdmFactory* const cdm_factory_; media::MediaPermission* media_permission_; diff --git a/content/renderer/media/crypto/render_cdm_factory.cc b/content/renderer/media/crypto/render_cdm_factory.cc index 01d9a27..fab62f9 100644 --- a/content/renderer/media/crypto/render_cdm_factory.cc +++ b/content/renderer/media/crypto/render_cdm_factory.cc @@ -17,21 +17,24 @@ namespace content { -#if defined(ENABLE_PEPPER_CDMS) RenderCdmFactory::RenderCdmFactory( - const CreatePepperCdmCB& create_pepper_cdm_cb) - : create_pepper_cdm_cb_(create_pepper_cdm_cb) { -} +#if defined(ENABLE_PEPPER_CDMS) + const CreatePepperCdmCB& create_pepper_cdm_cb, #elif defined(ENABLE_BROWSER_CDMS) -RenderCdmFactory::RenderCdmFactory(RendererCdmManager* manager) - : manager_(manager) { -} -#else -RenderCdmFactory::RenderCdmFactory() { -} + RendererCdmManager* manager, #endif // defined(ENABLE_PEPPER_CDMS) + RenderFrame* render_frame) + : RenderFrameObserver(render_frame) +#if defined(ENABLE_PEPPER_CDMS) + , create_pepper_cdm_cb_(create_pepper_cdm_cb) +#elif defined(ENABLE_BROWSER_CDMS) + , manager_(manager) +#endif // defined(ENABLE_PEPPER_CDMS) +{ +} RenderCdmFactory::~RenderCdmFactory() { + DCHECK(thread_checker_.CalledOnValidThread()); } scoped_ptr<media::MediaKeys> RenderCdmFactory::Create( @@ -44,6 +47,7 @@ scoped_ptr<media::MediaKeys> RenderCdmFactory::Create( const media::LegacySessionErrorCB& legacy_session_error_cb, const media::SessionKeysChangeCB& session_keys_change_cb, const media::SessionExpirationUpdateCB& session_expiration_update_cb) { + DCHECK(thread_checker_.CalledOnValidThread()); // TODO(jrummell): Pass |security_origin| to all constructors. // TODO(jrummell): Enable the following line once blink code updated to // check the security origin before calling. diff --git a/content/renderer/media/crypto/render_cdm_factory.h b/content/renderer/media/crypto/render_cdm_factory.h index 50e1422..f15bfe8 100644 --- a/content/renderer/media/crypto/render_cdm_factory.h +++ b/content/renderer/media/crypto/render_cdm_factory.h @@ -8,6 +8,8 @@ #include <string> #include "base/memory/scoped_ptr.h" +#include "base/threading/thread_checker.h" +#include "content/public/renderer/render_frame_observer.h" #include "media/base/cdm_factory.h" #include "media/base/media_keys.h" @@ -23,15 +25,17 @@ namespace content { class RendererCdmManager; #endif -class RenderCdmFactory : public media::CdmFactory { +// CdmFactory implementation in content/renderer. This class is not thread safe +// and should only be used on one thread. +class RenderCdmFactory : public media::CdmFactory, public RenderFrameObserver { public: + RenderCdmFactory( #if defined(ENABLE_PEPPER_CDMS) - explicit RenderCdmFactory(const CreatePepperCdmCB& create_pepper_cdm_cb); + const CreatePepperCdmCB& create_pepper_cdm_cb, #elif defined(ENABLE_BROWSER_CDMS) - explicit RenderCdmFactory(RendererCdmManager* manager); -#else - RenderCdmFactory(); + RendererCdmManager* manager, #endif // defined(ENABLE_PEPPER_CDMS) + RenderFrame* render_frame); ~RenderCdmFactory() override; @@ -55,6 +59,8 @@ class RenderCdmFactory : public media::CdmFactory { RendererCdmManager* manager_; #endif + base::ThreadChecker thread_checker_; + DISALLOW_COPY_AND_ASSIGN(RenderCdmFactory); }; diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc index cb43d46..88b26d2 100644 --- a/content/renderer/render_frame_impl.cc +++ b/content/renderer/render_frame_impl.cc @@ -672,6 +672,7 @@ RenderFrameImpl::RenderFrameImpl(RenderViewImpl* render_view, int routing_id) #if defined(ENABLE_BROWSER_CDMS) cdm_manager_(NULL), #endif + cdm_factory_(NULL), #if defined(VIDEO_HOLE) contains_media_player_(false), #endif @@ -1944,16 +1945,12 @@ blink::WebMediaPlayer* RenderFrameImpl::createMediaPlayer( if (!web_stream.isNull()) return CreateWebMediaPlayerForMediaStream(url, client); - if (!media_permission_dispatcher_) - media_permission_dispatcher_ = new MediaPermissionDispatcher(this); - #if defined(OS_ANDROID) - return CreateAndroidWebMediaPlayer(url, client, media_permission_dispatcher_, + return CreateAndroidWebMediaPlayer(url, client, GetMediaPermission(), initial_cdm); #else scoped_refptr<media::MediaLog> media_log(new RenderMediaLog()); - RenderThreadImpl* render_thread = RenderThreadImpl::current(); media::WebMediaPlayerParams params( base::Bind(&ContentRendererClient::DeferMediaLoad, @@ -1962,19 +1959,9 @@ blink::WebMediaPlayer* RenderFrameImpl::createMediaPlayer( render_thread->GetAudioRendererMixerManager()->CreateInput(routing_id_), media_log, render_thread->GetMediaThreadTaskRunner(), render_thread->compositor_message_loop_proxy(), - base::Bind(&GetSharedMainThreadContext3D), media_permission_dispatcher_, + base::Bind(&GetSharedMainThreadContext3D), GetMediaPermission(), initial_cdm); -#if defined(ENABLE_PEPPER_CDMS) - scoped_ptr<media::CdmFactory> cdm_factory( - new RenderCdmFactory(base::Bind(&PepperCdmWrapperImpl::Create, frame))); -#elif defined(ENABLE_BROWSER_CDMS) - scoped_ptr<media::CdmFactory> cdm_factory( - new RenderCdmFactory(GetCdmManager())); -#else - scoped_ptr<media::CdmFactory> cdm_factory(new RenderCdmFactory()); -#endif - #if defined(ENABLE_MEDIA_MOJO_RENDERER) scoped_ptr<media::RendererFactory> media_renderer_factory( new media::MojoRendererFactory(make_scoped_ptr( @@ -1993,7 +1980,7 @@ blink::WebMediaPlayer* RenderFrameImpl::createMediaPlayer( return new media::WebMediaPlayerImpl( frame, client, weak_factory_.GetWeakPtr(), media_renderer_factory.Pass(), - cdm_factory.Pass(), params); + GetCdmFactory(), params); #endif // defined(OS_ANDROID) } @@ -3565,21 +3552,8 @@ blink::WebUserMediaClient* RenderFrameImpl::userMediaClient() { blink::WebEncryptedMediaClient* RenderFrameImpl::encryptedMediaClient() { if (!web_encrypted_media_client_) { -#if defined(ENABLE_PEPPER_CDMS) - scoped_ptr<media::CdmFactory> cdm_factory( - new RenderCdmFactory(base::Bind(PepperCdmWrapperImpl::Create, frame_))); -#elif defined(ENABLE_BROWSER_CDMS) - scoped_ptr<media::CdmFactory> cdm_factory( - new RenderCdmFactory(GetCdmManager())); -#else - scoped_ptr<media::CdmFactory> cdm_factory(new RenderCdmFactory()); -#endif - - if (!media_permission_dispatcher_) - media_permission_dispatcher_ = new MediaPermissionDispatcher(this); - web_encrypted_media_client_.reset(new media::WebEncryptedMediaClientImpl( - cdm_factory.Pass(), media_permission_dispatcher_)); + GetCdmFactory(), GetMediaPermission())); } return web_encrypted_media_client_.get(); } @@ -4693,14 +4667,8 @@ WebMediaPlayer* RenderFrameImpl::CreateAndroidWebMediaPlayer( } return new WebMediaPlayerAndroid( - frame_, - client, - weak_factory_.GetWeakPtr(), - GetMediaPlayerManager(), - GetCdmManager(), - media_permission, - initial_cdm, - stream_texture_factory, + frame_, client, weak_factory_.GetWeakPtr(), GetMediaPlayerManager(), + GetCdmFactory(), media_permission, initial_cdm, stream_texture_factory, RenderThreadImpl::current()->GetMediaThreadTaskRunner(), new RenderMediaLog()); } @@ -4713,12 +4681,30 @@ RendererMediaPlayerManager* RenderFrameImpl::GetMediaPlayerManager() { #endif // defined(OS_ANDROID) +media::MediaPermission* RenderFrameImpl::GetMediaPermission() { + if (!media_permission_dispatcher_) + media_permission_dispatcher_ = new MediaPermissionDispatcher(this); + return media_permission_dispatcher_; +} + +media::CdmFactory* RenderFrameImpl::GetCdmFactory() { #if defined(ENABLE_BROWSER_CDMS) -RendererCdmManager* RenderFrameImpl::GetCdmManager() { if (!cdm_manager_) cdm_manager_ = new RendererCdmManager(this); - return cdm_manager_; -} #endif // defined(ENABLE_BROWSER_CDMS) + if (!cdm_factory_) { + DCHECK(frame_); + cdm_factory_ = new RenderCdmFactory( +#if defined(ENABLE_PEPPER_CDMS) + base::Bind(&PepperCdmWrapperImpl::Create, frame_), +#elif defined(ENABLE_BROWSER_CDMS) + cdm_manager_, +#endif + this); + } + + return cdm_factory_; +} + } // namespace content diff --git a/content/renderer/render_frame_impl.h b/content/renderer/render_frame_impl.h index 70413d2..beeff55 100644 --- a/content/renderer/render_frame_impl.h +++ b/content/renderer/render_frame_impl.h @@ -67,6 +67,7 @@ class Rect; } namespace media { +class CdmFactory; class MediaPermission; class WebEncryptedMediaClientImpl; } @@ -91,6 +92,7 @@ class PepperPluginInstanceImpl; class PermissionDispatcher; class PresentationDispatcher; class PushMessagingDispatcher; +class RenderCdmFactory; class RendererAccessibility; class RendererCdmManager; class RendererMediaPlayerManager; @@ -752,9 +754,8 @@ class CONTENT_EXPORT RenderFrameImpl RendererMediaPlayerManager* GetMediaPlayerManager(); #endif -#if defined(ENABLE_BROWSER_CDMS) - RendererCdmManager* GetCdmManager(); -#endif + media::MediaPermission* GetMediaPermission(); + media::CdmFactory* GetCdmFactory(); // Stores the WebLocalFrame we are associated with. This is null from the // constructor until SetWebFrame is called, and it is null after @@ -872,6 +873,9 @@ class CONTENT_EXPORT RenderFrameImpl RendererCdmManager* cdm_manager_; #endif + // The CDM factory attached to this frame, lazily initialized. + RenderCdmFactory* cdm_factory_; + #if defined(VIDEO_HOLE) // Whether or not this RenderFrameImpl contains a media player. Used to // register as an observer for video-hole-specific events. |