diff options
28 files changed, 101 insertions, 124 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 1915f6b..4d91175d 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -36,6 +36,7 @@ #include "chrome/browser/geolocation/chrome_access_token_store.h" #include "chrome/browser/google/google_util.h" #include "chrome/browser/infobars/infobar_tab_helper.h" +#include "chrome/browser/media/media_internals.h" #include "chrome/browser/net/chrome_net_log.h" #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/notifications/desktop_notification_service_factory.h" @@ -1162,6 +1163,10 @@ void ChromeContentBrowserClient::RequestMediaAccessPermission( #endif // TOOLKIT_VIEWS || OS_LINUX } +content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { + return MediaInternals::GetInstance(); +} + void ChromeContentBrowserClient::RequestDesktopNotificationPermission( const GURL& source_origin, int callback_context, diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h index 79278fc..f0ff699 100644 --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -121,6 +121,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { virtual void RequestMediaAccessPermission( const content::MediaStreamRequest* request, const content::MediaResponseCallback& callback) OVERRIDE; + virtual content::MediaObserver* GetMediaObserver() OVERRIDE; virtual void RequestDesktopNotificationPermission( const GURL& source_origin, int callback_context, diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index c539860..3229f7c 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -20,7 +20,6 @@ #include "build/build_config.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/extension_event_router_forwarder.h" -#include "chrome/browser/media/media_internals.h" #include "chrome/browser/net/chrome_net_log.h" #include "chrome/browser/net/chrome_network_delegate.h" #include "chrome/browser/net/chrome_url_request_context.h" @@ -287,10 +286,6 @@ IOThread::Globals::Globals() {} IOThread::Globals::~Globals() {} -IOThread::Globals::MediaGlobals::MediaGlobals() {} - -IOThread::Globals::MediaGlobals::~MediaGlobals() {} - // |local_state| is passed in explicitly in order to (1) reduce implicit // dependencies and (2) make IOThread more flexible for testing. IOThread::IOThread( @@ -374,8 +369,6 @@ void IOThread::Init() { DCHECK(!globals_); globals_ = new Globals; - globals_->media.media_internals.reset(new MediaInternals()); - // Add an observer that will emit network change events to the ChromeNetLog. // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be // logging the network change before other IO thread consumers respond to it. diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h index d651faa..2cffacf 100644 --- a/chrome/browser/io_thread.h +++ b/chrome/browser/io_thread.h @@ -21,7 +21,6 @@ class ChromeNetLog; class ExtensionEventRouterForwarder; -class MediaInternals; class PrefProxyConfigTrackerImpl; class PrefService; class SystemURLRequestContextGetter; @@ -58,13 +57,6 @@ class IOThread : public content::BrowserThreadDelegate { Globals(); ~Globals(); - struct MediaGlobals { - MediaGlobals(); - ~MediaGlobals(); - // MediaInternals singleton used to aggregate media information. - scoped_ptr<MediaInternals> media_internals; - } media; - // The "system" NetworkDelegate, used for Profile-agnostic network events. scoped_ptr<net::NetworkDelegate> system_network_delegate; scoped_ptr<net::HostResolver> host_resolver; diff --git a/chrome/browser/media/media_internals.cc b/chrome/browser/media/media_internals.cc index b85369b..1564283 100644 --- a/chrome/browser/media/media_internals.cc +++ b/chrome/browser/media/media_internals.cc @@ -13,10 +13,16 @@ #include "media/base/media_log.h" #include "media/base/media_log_event.h" +using content::BrowserThread; + +MediaInternals* MediaInternals::GetInstance() { + return Singleton<MediaInternals>::get(); +} + MediaInternals::~MediaInternals() {} void MediaInternals::OnDeleteAudioStream(void* host, int stream_id) { - DCHECK(CalledOnValidThread()); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); std::string stream = base::StringPrintf("audio_streams.%p:%d", host, stream_id); DeleteItem(stream); @@ -24,28 +30,28 @@ void MediaInternals::OnDeleteAudioStream(void* host, int stream_id) { void MediaInternals::OnSetAudioStreamPlaying( void* host, int stream_id, bool playing) { - DCHECK(CalledOnValidThread()); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); UpdateAudioStream(host, stream_id, "playing", Value::CreateBooleanValue(playing)); } void MediaInternals::OnSetAudioStreamStatus( void* host, int stream_id, const std::string& status) { - DCHECK(CalledOnValidThread()); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); UpdateAudioStream(host, stream_id, "status", Value::CreateStringValue(status)); } void MediaInternals::OnSetAudioStreamVolume( void* host, int stream_id, double volume) { - DCHECK(CalledOnValidThread()); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); UpdateAudioStream(host, stream_id, "volume", Value::CreateDoubleValue(volume)); } void MediaInternals::OnMediaEvent( int render_process_id, const media::MediaLogEvent& event) { - DCHECK(CalledOnValidThread()); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); // Notify observers that |event| has occured. DictionaryValue dict; @@ -58,17 +64,17 @@ void MediaInternals::OnMediaEvent( } void MediaInternals::AddObserver(MediaInternalsObserver* observer) { - DCHECK(CalledOnValidThread()); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); observers_.AddObserver(observer); } void MediaInternals::RemoveObserver(MediaInternalsObserver* observer) { - DCHECK(CalledOnValidThread()); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); observers_.RemoveObserver(observer); } void MediaInternals::SendEverything() { - DCHECK(CalledOnValidThread()); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); SendUpdate("media.onReceiveEverything", &data_); } diff --git a/chrome/browser/media/media_internals.h b/chrome/browser/media/media_internals.h index 825925b..4a8fb7c 100644 --- a/chrome/browser/media/media_internals.h +++ b/chrome/browser/media/media_internals.h @@ -7,8 +7,8 @@ #pragma once #include "base/memory/ref_counted.h" +#include "base/memory/singleton.h" #include "base/observer_list.h" -#include "base/threading/non_thread_safe.h" #include "base/values.h" #include "content/public/browser/media_observer.h" @@ -19,12 +19,14 @@ struct MediaLogEvent; } // This class stores information about currently active media. -// All of its methods are called on the IO thread. -class MediaInternals : public content::MediaObserver, - public base::NonThreadSafe { +// It's constructed on the UI thread but all of its methods are called on the IO +// thread. +class MediaInternals : public content::MediaObserver { public: virtual ~MediaInternals(); + static MediaInternals* GetInstance(); + // Overridden from content::MediaObserver: virtual void OnDeleteAudioStream(void* host, int stream_id) OVERRIDE; virtual void OnSetAudioStreamPlaying(void* host, @@ -47,8 +49,8 @@ class MediaInternals : public content::MediaObserver, void SendEverything(); private: - friend class IOThread; friend class MediaInternalsTest; + friend struct DefaultSingletonTraits<MediaInternals>; MediaInternals(); diff --git a/chrome/browser/media/media_internals_unittest.cc b/chrome/browser/media/media_internals_unittest.cc index 9e6ce59c128..da38490 100644 --- a/chrome/browser/media/media_internals_unittest.cc +++ b/chrome/browser/media/media_internals_unittest.cc @@ -5,7 +5,9 @@ #include "chrome/browser/media/media_internals.h" #include "base/memory/scoped_ptr.h" +#include "base/message_loop.h" #include "chrome/browser/media/media_internals_observer.h" +#include "content/test/test_browser_thread.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -16,6 +18,7 @@ class MockMediaInternalsObserver : public MediaInternalsObserver { class MediaInternalsTest : public testing::Test { public: + MediaInternalsTest() : io_thread_(content::BrowserThread::IO, &loop_) {} DictionaryValue* data() { return &internals_->data_; } @@ -37,6 +40,9 @@ class MediaInternalsTest : public testing::Test { virtual void SetUp() { internals_.reset(new MediaInternals()); } + + MessageLoop loop_; + content::TestBrowserThread io_thread_; scoped_ptr<MediaInternals> internals_; }; diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc index 1556ad8..a029925 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -25,7 +25,6 @@ #include "chrome/browser/extensions/extension_info_map.h" #include "chrome/browser/extensions/extension_protocols.h" #include "chrome/browser/io_thread.h" -#include "chrome/browser/media/media_internals.h" #include "chrome/browser/net/chrome_cookie_notification_details.h" #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" #include "chrome/browser/net/chrome_net_log.h" @@ -391,12 +390,6 @@ net::URLRequestContext* ProfileIOData::ResourceContext::GetRequestContext() { return request_context_; } -content::MediaObserver* ProfileIOData::ResourceContext::GetMediaObserver() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - EnsureInitialized(); - return media_observer_; -} - // static std::string ProfileIOData::GetSSLSessionCacheShard() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); @@ -495,8 +488,6 @@ void ProfileIOData::LazyInitialize() const { resource_context_.host_resolver_ = io_thread_globals->host_resolver.get(); resource_context_.request_context_ = main_request_context_; - resource_context_.media_observer_ = - io_thread_globals->media.media_internals.get(); LazyInitializeInternal(profile_params_.get()); diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h index b6ff4c8..4cafe09 100644 --- a/chrome/browser/profiles/profile_io_data.h +++ b/chrome/browser/profiles/profile_io_data.h @@ -219,15 +219,12 @@ class ProfileIOData { // ResourceContext implementation: virtual net::HostResolver* GetHostResolver() OVERRIDE; virtual net::URLRequestContext* GetRequestContext() OVERRIDE; - virtual content::MediaObserver* GetMediaObserver() OVERRIDE; - void EnsureInitialized(); ProfileIOData* const io_data_; net::HostResolver* host_resolver_; net::URLRequestContext* request_context_; - content::MediaObserver* media_observer_; }; typedef base::hash_map<std::string, scoped_refptr<ChromeURLRequestContext> > diff --git a/chrome/browser/ui/webui/media/media_internals_proxy.cc b/chrome/browser/ui/webui/media/media_internals_proxy.cc index 6b1bc17..792c0ac 100644 --- a/chrome/browser/ui/webui/media/media_internals_proxy.cc +++ b/chrome/browser/ui/webui/media/media_internals_proxy.cc @@ -126,20 +126,20 @@ Value* MediaInternalsProxy::GetConstants() { void MediaInternalsProxy::ObserveMediaInternalsOnIOThread() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - io_thread_->globals()->media.media_internals->AddObserver(this); + MediaInternals::GetInstance()->AddObserver(this); io_thread_->net_log()->AddThreadSafeObserver(this, net::NetLog::LOG_ALL_BUT_BYTES); } void MediaInternalsProxy::StopObservingMediaInternalsOnIOThread() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - io_thread_->globals()->media.media_internals->RemoveObserver(this); + MediaInternals::GetInstance()->RemoveObserver(this); io_thread_->net_log()->RemoveThreadSafeObserver(this); } void MediaInternalsProxy::GetEverythingOnIOThread() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - io_thread_->globals()->media.media_internals->SendEverything(); + MediaInternals::GetInstance()->SendEverything(); } void MediaInternalsProxy::UpdateUIOnUIThread(const string16& update) { diff --git a/content/browser/mock_content_browser_client.cc b/content/browser/mock_content_browser_client.cc index 0eb60d7..8456785 100644 --- a/content/browser/mock_content_browser_client.cc +++ b/content/browser/mock_content_browser_client.cc @@ -211,6 +211,10 @@ void MockContentBrowserClient::RequestMediaAccessPermission( const MediaResponseCallback& callback) { } +MediaObserver* MockContentBrowserClient::GetMediaObserver() { + return NULL; +} + void MockContentBrowserClient::RequestDesktopNotificationPermission( const GURL& source_origin, int callback_context, diff --git a/content/browser/mock_content_browser_client.h b/content/browser/mock_content_browser_client.h index e143f3d..5d68787 100644 --- a/content/browser/mock_content_browser_client.h +++ b/content/browser/mock_content_browser_client.h @@ -113,6 +113,7 @@ class MockContentBrowserClient : public ContentBrowserClient { virtual void RequestMediaAccessPermission( const MediaStreamRequest* request, const MediaResponseCallback& callback) OVERRIDE; + virtual MediaObserver* GetMediaObserver() OVERRIDE; virtual void RequestDesktopNotificationPermission( const GURL& source_origin, int callback_context, diff --git a/content/browser/renderer_host/media/audio_renderer_host.cc b/content/browser/renderer_host/media/audio_renderer_host.cc index 041ba30..76691e1 100644 --- a/content/browser/renderer_host/media/audio_renderer_host.cc +++ b/content/browser/renderer_host/media/audio_renderer_host.cc @@ -12,7 +12,6 @@ #include "content/browser/renderer_host/media/audio_sync_reader.h" #include "content/common/media/audio_messages.h" #include "content/public/browser/media_observer.h" -#include "content/public/browser/resource_context.h" #include "media/audio/audio_util.h" using content::BrowserMessageFilter; @@ -28,10 +27,10 @@ AudioRendererHost::AudioEntry::~AudioEntry() {} /////////////////////////////////////////////////////////////////////////////// // AudioRendererHost implementations. AudioRendererHost::AudioRendererHost( - content::ResourceContext* resource_context, - AudioManager* audio_manager) - : resource_context_(resource_context), - audio_manager_(audio_manager) { + AudioManager* audio_manager, + content::MediaObserver* media_observer) + : audio_manager_(audio_manager), + media_observer_(media_observer) { } AudioRendererHost::~AudioRendererHost() { @@ -41,9 +40,6 @@ AudioRendererHost::~AudioRendererHost() { void AudioRendererHost::OnChannelClosing() { BrowserMessageFilter::OnChannelClosing(); - // Channel is closing, so |resource_context_| is about to become invalid. - resource_context_ = NULL; - // Since the IPC channel is gone, close all requested audio streams. DeleteEntries(); } @@ -240,8 +236,8 @@ void AudioRendererHost::OnCreateStream( // to the map. entry->stream_id = stream_id; audio_entries_.insert(std::make_pair(stream_id, entry.release())); - if (GetMediaObserver()) - GetMediaObserver()->OnSetAudioStreamStatus(this, stream_id, "created"); + if (media_observer_) + media_observer_->OnSetAudioStreamStatus(this, stream_id, "created"); } void AudioRendererHost::OnPlayStream(int stream_id) { @@ -254,8 +250,8 @@ void AudioRendererHost::OnPlayStream(int stream_id) { } entry->controller->Play(); - if (GetMediaObserver()) - GetMediaObserver()->OnSetAudioStreamPlaying(this, stream_id, true); + if (media_observer_) + media_observer_->OnSetAudioStreamPlaying(this, stream_id, true); } void AudioRendererHost::OnPauseStream(int stream_id) { @@ -268,8 +264,8 @@ void AudioRendererHost::OnPauseStream(int stream_id) { } entry->controller->Pause(); - if (GetMediaObserver()) - GetMediaObserver()->OnSetAudioStreamPlaying(this, stream_id, false); + if (media_observer_) + media_observer_->OnSetAudioStreamPlaying(this, stream_id, false); } void AudioRendererHost::OnFlushStream(int stream_id) { @@ -282,15 +278,15 @@ void AudioRendererHost::OnFlushStream(int stream_id) { } entry->controller->Flush(); - if (GetMediaObserver()) - GetMediaObserver()->OnSetAudioStreamStatus(this, stream_id, "flushed"); + if (media_observer_) + media_observer_->OnSetAudioStreamStatus(this, stream_id, "flushed"); } void AudioRendererHost::OnCloseStream(int stream_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (GetMediaObserver()) - GetMediaObserver()->OnSetAudioStreamStatus(this, stream_id, "closed"); + if (media_observer_) + media_observer_->OnSetAudioStreamStatus(this, stream_id, "closed"); AudioEntry* entry = LookupById(stream_id); @@ -311,8 +307,8 @@ void AudioRendererHost::OnSetVolume(int stream_id, double volume) { if (volume < 0 || volume > 1.0) return; entry->controller->SetVolume(volume); - if (GetMediaObserver()) - GetMediaObserver()->OnSetAudioStreamVolume(this, stream_id, volume); + if (media_observer_) + media_observer_->OnSetAudioStreamVolume(this, stream_id, volume); } void AudioRendererHost::SendErrorMessage(int32 stream_id) { @@ -356,8 +352,8 @@ void AudioRendererHost::DeleteEntry(AudioEntry* entry) { audio_entries_.erase(entry->stream_id); // Notify the media observer. - if (GetMediaObserver()) - GetMediaObserver()->OnDeleteAudioStream(this, entry->stream_id); + if (media_observer_) + media_observer_->OnDeleteAudioStream(this, entry->stream_id); } void AudioRendererHost::DeleteEntryOnError(AudioEntry* entry) { @@ -367,8 +363,8 @@ void AudioRendererHost::DeleteEntryOnError(AudioEntry* entry) { // |entry| is destroyed in DeleteEntry(). SendErrorMessage(entry->stream_id); - if (GetMediaObserver()) - GetMediaObserver()->OnSetAudioStreamStatus(this, entry->stream_id, "error"); + if (media_observer_) + media_observer_->OnSetAudioStreamStatus(this, entry->stream_id, "error"); CloseAndDeleteStream(entry); } @@ -394,10 +390,3 @@ AudioRendererHost::AudioEntry* AudioRendererHost::LookupByController( } return NULL; } - -content::MediaObserver* AudioRendererHost::GetMediaObserver() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (resource_context_) - return resource_context_->GetMediaObserver(); - return NULL; -} diff --git a/content/browser/renderer_host/media/audio_renderer_host.h b/content/browser/renderer_host/media/audio_renderer_host.h index 0880e3b..a9ca80f 100644 --- a/content/browser/renderer_host/media/audio_renderer_host.h +++ b/content/browser/renderer_host/media/audio_renderer_host.h @@ -89,8 +89,8 @@ class CONTENT_EXPORT AudioRendererHost typedef std::map<int, AudioEntry*> AudioEntryMap; // Called from UI thread from the owner of this object. - AudioRendererHost(content::ResourceContext* resource_context, - AudioManager* audio_manager); + AudioRendererHost(AudioManager* audio_manager, + content::MediaObserver* media_observer); // content::BrowserMessageFilter implementation. virtual void OnChannelClosing() OVERRIDE; @@ -178,14 +178,11 @@ class CONTENT_EXPORT AudioRendererHost // event is received. AudioEntry* LookupByController(media::AudioOutputController* controller); - // Returns the MediaObserver from |resource_context_| or NULL if none exists. - content::MediaObserver* GetMediaObserver(); - // A map of stream IDs to audio sources. AudioEntryMap audio_entries_; - content::ResourceContext* resource_context_; AudioManager* audio_manager_; + content::MediaObserver* media_observer_; DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); }; diff --git a/content/browser/renderer_host/media/audio_renderer_host_unittest.cc b/content/browser/renderer_host/media/audio_renderer_host_unittest.cc index 46a841f..71a5063 100644 --- a/content/browser/renderer_host/media/audio_renderer_host_unittest.cc +++ b/content/browser/renderer_host/media/audio_renderer_host_unittest.cc @@ -12,7 +12,6 @@ #include "content/browser/renderer_host/media/audio_renderer_host.h" #include "content/browser/renderer_host/media/mock_media_observer.h" #include "content/common/media/audio_messages.h" -#include "content/test/mock_resource_context.h" #include "ipc/ipc_message_utils.h" #include "media/audio/audio_manager.h" #include "media/audio/fake_audio_output_stream.h" @@ -44,9 +43,9 @@ static bool IsRunningHeadless() { class MockAudioRendererHost : public AudioRendererHost { public: explicit MockAudioRendererHost( - content::ResourceContext* resource_context, - AudioManager* audio_manager) - : AudioRendererHost(resource_context, audio_manager), + AudioManager* audio_manager, + content::MediaObserver* media_observer) + : AudioRendererHost(audio_manager, media_observer), shared_memory_length_(0) { } @@ -164,8 +163,7 @@ class AudioRendererHostTest : public testing::Test { message_loop_.get())); audio_manager_.reset(AudioManager::Create()); observer_.reset(new MockMediaObserver()); - resource_context_.set_media_observer(observer_.get()); - host_ = new MockAudioRendererHost(&resource_context_, audio_manager_.get()); + host_ = new MockAudioRendererHost(audio_manager_.get(), observer_.get()); // Simulate IPC channel connected. host_->OnChannelConnected(base::GetCurrentProcId()); @@ -313,7 +311,6 @@ class AudioRendererHostTest : public testing::Test { scoped_ptr<BrowserThreadImpl> io_thread_; scoped_ptr<BrowserThreadImpl> ui_thread_; scoped_ptr<AudioManager> audio_manager_; - content::MockResourceContext resource_context_; DISALLOW_COPY_AND_ASSIGN(AudioRendererHostTest); }; diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc index b4b10d2..fbbff99 100644 --- a/content/browser/renderer_host/render_message_filter.cc +++ b/content/browser/renderer_host/render_message_filter.cc @@ -269,7 +269,8 @@ RenderMessageFilter::RenderMessageFilter( PluginServiceImpl* plugin_service, content::BrowserContext* browser_context, net::URLRequestContextGetter* request_context, - RenderWidgetHelper* render_widget_helper) + RenderWidgetHelper* render_widget_helper, + content::MediaObserver* media_observer) : resource_dispatcher_host_(ResourceDispatcherHostImpl::Get()), plugin_service_(plugin_service), browser_context_(browser_context), @@ -280,7 +281,8 @@ RenderMessageFilter::RenderMessageFilter( dom_storage_context_(static_cast<DOMStorageContextImpl*>( BrowserContext::GetDOMStorageContext(browser_context))), render_process_id_(render_process_id), - cpu_usage_(0) { + cpu_usage_(0), + media_observer_(media_observer) { DCHECK(request_context_); render_widget_helper_->Init(render_process_id_, resource_dispatcher_host_); @@ -881,10 +883,8 @@ void RenderMessageFilter::AsyncOpenFileOnFileThread(const FilePath& path, } void RenderMessageFilter::OnMediaLogEvent(const media::MediaLogEvent& event) { - if (!resource_context_->GetMediaObserver()) - return; - resource_context_->GetMediaObserver()->OnMediaEvent( - render_process_id_, event); + if (media_observer_) + media_observer_->OnMediaEvent(render_process_id_, event); } void RenderMessageFilter::CheckPolicyForCookies( diff --git a/content/browser/renderer_host/render_message_filter.h b/content/browser/renderer_host/render_message_filter.h index fff1963..710db73 100644 --- a/content/browser/renderer_host/render_message_filter.h +++ b/content/browser/renderer_host/render_message_filter.h @@ -38,6 +38,7 @@ struct WebScreenInfo; namespace content { class BrowserContext; +class MediaObserver; class ResourceContext; class ResourceDispatcherHostImpl; } @@ -73,7 +74,8 @@ class RenderMessageFilter : public content::BrowserMessageFilter { PluginServiceImpl * plugin_service, content::BrowserContext* browser_context, net::URLRequestContextGetter* request_context, - RenderWidgetHelper* render_widget_helper); + RenderWidgetHelper* render_widget_helper, + content::MediaObserver* media_observer); // IPC::ChannelProxy::MessageFilter methods: virtual void OnChannelClosing() OVERRIDE; @@ -266,6 +268,8 @@ class RenderMessageFilter : public content::BrowserMessageFilter { // Used for sampling CPU usage of the renderer process. scoped_ptr<base::ProcessMetrics> process_metrics_; + content::MediaObserver* media_observer_; + DISALLOW_COPY_AND_ASSIGN(RenderMessageFilter); }; diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index f88fd08..ce8115c 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -448,13 +448,16 @@ bool RenderProcessHostImpl::Init(bool is_accessibility_enabled) { } void RenderProcessHostImpl::CreateMessageFilters() { + content::MediaObserver* media_observer = + content::GetContentClient()->browser()->GetMediaObserver(); scoped_refptr<RenderMessageFilter> render_message_filter( new RenderMessageFilter( GetID(), PluginServiceImpl::GetInstance(), GetBrowserContext(), GetBrowserContext()->GetRequestContextForRenderProcess(GetID()), - widget_helper_)); + widget_helper_, + media_observer)); channel_->AddFilter(render_message_filter); content::BrowserContext* browser_context = GetBrowserContext(); content::ResourceContext* resource_context = @@ -471,7 +474,7 @@ void RenderProcessHostImpl::CreateMessageFilters() { AudioManager* audio_manager = content::BrowserMainLoop::GetAudioManager(); channel_->AddFilter(new AudioInputRendererHost( resource_context, audio_manager)); - channel_->AddFilter(new AudioRendererHost(resource_context, audio_manager)); + channel_->AddFilter(new AudioRendererHost(audio_manager, media_observer)); channel_->AddFilter(new VideoCaptureHost(resource_context, audio_manager)); #endif channel_->AddFilter(new AppCacheDispatcherHost( diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h index c9303d9..9a3c5a5 100644 --- a/content/public/browser/content_browser_client.h +++ b/content/public/browser/content_browser_client.h @@ -63,10 +63,11 @@ class AccessTokenStore; class BrowserChildProcessHost; class BrowserContext; class BrowserMainParts; -class RenderProcessHost; +class MediaObserver; class QuotaPermissionContext; -class ResourceContext; +class RenderProcessHost; class RenderViewHost; +class ResourceContext; class SiteInstance; class SpeechInputManagerDelegate; class WebContents; @@ -292,6 +293,10 @@ class ContentBrowserClient { int render_process_id, int render_view_id) = 0; + // Returns a a class to get notifications about media event. The embedder can + // return NULL if they're not interested. + virtual MediaObserver* GetMediaObserver() = 0; + // Asks permission to use the camera and/or microphone. If permission is // granted, a call should be made to |callback| with the devices. If the // request is denied, a call should be made to |callback| with an empty list diff --git a/content/public/browser/media_observer.h b/content/public/browser/media_observer.h index 0b0a6b7..c938b1c 100644 --- a/content/public/browser/media_observer.h +++ b/content/public/browser/media_observer.h @@ -12,8 +12,8 @@ struct MediaLogEvent; namespace content { -// A class may implement MediaObserver and register itself with ResourceContext -// to receive callbacks as media events occur. +// An embedder may implement MediaObserver and return it from +// ContentBrowserClient to receive callbacks as media events occur. class MediaObserver { public: // Called when an audio stream is deleted. diff --git a/content/public/browser/resource_context.h b/content/public/browser/resource_context.h index 817578f..e52cdeb 100644 --- a/content/public/browser/resource_context.h +++ b/content/public/browser/resource_context.h @@ -19,8 +19,6 @@ class URLRequestContext; namespace content { -class MediaObserver; - // ResourceContext contains the relevant context information required for // resource loading. It lives on the IO thread, although it is constructed on // the UI thread. @@ -32,7 +30,6 @@ class CONTENT_EXPORT ResourceContext : public base::SupportsUserData { virtual ~ResourceContext() {} virtual net::HostResolver* GetHostResolver() = 0; virtual net::URLRequestContext* GetRequestContext() = 0; - virtual MediaObserver* GetMediaObserver() = 0; }; } // namespace content diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index cdc5d3e..901c572 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -230,6 +230,10 @@ void ShellContentBrowserClient::RequestMediaAccessPermission( const content::MediaResponseCallback& callback) { } +MediaObserver* ShellContentBrowserClient::GetMediaObserver() { + return NULL; +} + void ShellContentBrowserClient::RequestDesktopNotificationPermission( const GURL& source_origin, int callback_context, diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h index 03b389d..8b25e16 100644 --- a/content/shell/shell_content_browser_client.h +++ b/content/shell/shell_content_browser_client.h @@ -121,6 +121,7 @@ class ShellContentBrowserClient : public ContentBrowserClient { virtual void RequestMediaAccessPermission( const content::MediaStreamRequest* request, const content::MediaResponseCallback& callback) OVERRIDE; + virtual MediaObserver* GetMediaObserver() OVERRIDE; virtual void RequestDesktopNotificationPermission( const GURL& source_origin, int callback_context, diff --git a/content/shell/shell_resource_context.cc b/content/shell/shell_resource_context.cc index dbe20e8..4d247e4 100644 --- a/content/shell/shell_resource_context.cc +++ b/content/shell/shell_resource_context.cc @@ -23,8 +23,4 @@ net::URLRequestContext* ShellResourceContext::GetRequestContext() { return getter_->GetURLRequestContext(); } -MediaObserver* ShellResourceContext::GetMediaObserver() { - return NULL; -} - } // namespace content diff --git a/content/shell/shell_resource_context.h b/content/shell/shell_resource_context.h index 2f3aa1c..a084e61 100644 --- a/content/shell/shell_resource_context.h +++ b/content/shell/shell_resource_context.h @@ -23,7 +23,6 @@ class ShellResourceContext : public content::ResourceContext { // ResourceContext implementation: virtual net::HostResolver* GetHostResolver() OVERRIDE; virtual net::URLRequestContext* GetRequestContext() OVERRIDE; - virtual MediaObserver* GetMediaObserver() OVERRIDE; scoped_refptr<ShellURLRequestContextGetter> getter_; diff --git a/content/test/mock_resource_context.cc b/content/test/mock_resource_context.cc index ec64c69..ee9a6f1 100644 --- a/content/test/mock_resource_context.cc +++ b/content/test/mock_resource_context.cc @@ -10,13 +10,11 @@ namespace content { MockResourceContext::MockResourceContext() - : test_request_context_(new TestURLRequestContext), - media_observer_(NULL) { + : test_request_context_(new TestURLRequestContext) { } MockResourceContext::MockResourceContext(net::URLRequestContext* context) - : test_request_context_(context), - media_observer_(NULL) { + : test_request_context_(context) { } MockResourceContext::~MockResourceContext() {} @@ -29,8 +27,4 @@ net::URLRequestContext* MockResourceContext::GetRequestContext() { return test_request_context_; } -MediaObserver* MockResourceContext::GetMediaObserver() { - return media_observer_; -} - } // namespace content diff --git a/content/test/mock_resource_context.h b/content/test/mock_resource_context.h index 5e6d213..d25bcd6 100644 --- a/content/test/mock_resource_context.h +++ b/content/test/mock_resource_context.h @@ -23,18 +23,12 @@ class MockResourceContext : public ResourceContext { test_request_context_ = context; } - void set_media_observer(MediaObserver* observer) { - media_observer_ = observer; - } - // ResourceContext implementation: virtual net::HostResolver* GetHostResolver() OVERRIDE; virtual net::URLRequestContext* GetRequestContext() OVERRIDE; - virtual MediaObserver* GetMediaObserver() OVERRIDE; private: scoped_refptr<net::URLRequestContext> test_request_context_; - MediaObserver* media_observer_; DISALLOW_COPY_AND_ASSIGN(MockResourceContext); }; diff --git a/content/test/webrtc_audio_device_test.cc b/content/test/webrtc_audio_device_test.cc index d13f79ca..cb37584 100644 --- a/content/test/webrtc_audio_device_test.cc +++ b/content/test/webrtc_audio_device_test.cc @@ -170,7 +170,6 @@ void WebRTCAudioDeviceTest::InitializeIOThread(const char* thread_name) { test_request_context_ = new TestURLRequestContext(); resource_context_->set_request_context(test_request_context_.get()); media_observer_.reset(new MockMediaObserver()); - resource_context_->set_media_observer(media_observer_.get()); // Create an IPC channel that handles incoming messages on the IO thread. CreateChannel(thread_name); @@ -187,7 +186,7 @@ void WebRTCAudioDeviceTest::UninitializeIOThread() { void WebRTCAudioDeviceTest::CreateChannel(const char* name) { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); audio_render_host_ = new AudioRendererHost( - resource_context_.get(), audio_manager_.get()); + audio_manager_.get(), media_observer_.get()); audio_render_host_->OnChannelConnected(base::GetCurrentProcId()); audio_input_renderer_host_ = new AudioInputRendererHost( |