Chromium Code Reviews| Index: content/browser/media/audio_stream_monitor.cc |
| diff --git a/chrome/browser/media/audio_stream_monitor.cc b/content/browser/media/audio_stream_monitor.cc |
| similarity index 38% |
| rename from chrome/browser/media/audio_stream_monitor.cc |
| rename to content/browser/media/audio_stream_monitor.cc |
| index 8633053d510684d1a69143590ec9d3047eb44194..62cbe46e2e1e0086f25c10fdab3771841804d477 100644 |
| --- a/chrome/browser/media/audio_stream_monitor.cc |
| +++ b/content/browser/media/audio_stream_monitor.cc |
| @@ -2,16 +2,48 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/media/audio_stream_monitor.h" |
| +#include "content/browser/media/audio_stream_monitor.h" |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/invalidate_type.h" |
| +#include "content/public/browser/render_frame_host.h" |
| #include "content/public/browser/web_contents.h" |
| -DEFINE_WEB_CONTENTS_USER_DATA_KEY(AudioStreamMonitor); |
| +namespace content { |
| -AudioStreamMonitor::AudioStreamMonitor(content::WebContents* contents) |
| +namespace { |
| + |
| +AudioStreamMonitor* AudioStreamMonitorFromRenderFrame(int render_process_id, |
| + int render_frame_id) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + WebContents* const web_contents = WebContents::FromRenderFrameHost( |
| + RenderFrameHost::FromID(render_process_id, render_frame_id)); |
| + if (!web_contents) |
| + return NULL; |
| + |
| + // Note: Calling CreateForWebContents() multiple times is valid (see usage |
| + // info for WebContentsUserData). |
| + AudioStreamMonitor::CreateForWebContents(web_contents); |
| + return AudioStreamMonitor::FromWebContents(web_contents); |
| +} |
| + |
| +} // namespace |
| + |
| +// TODO(dalecurtis): ???? DEFINE_WEB_CONTENTS_USER_DATA_KEY won't link, |
| +// kLocatorKey is created as a local symbol without the CONTENT_EXPORT |
| +// addition... without it, nm shows: |
| +// |
| +// $ nm content_unittests.audio_stream_monitor_unittest.o | grep kLocatorKey |
| +// U _ZN7content19...AudioStreamMonitorEE11kLocatorKeyE |
| +// $ nm libcontent.so | grep AudioStreamMonitor | grep kLocatorkey |
| +// 000000000139d8f0 b _ZN7content19...AudioStreamMonitorEE11kLocatorKeyE |
| +// |
| +template <> |
| +CONTENT_EXPORT int WebContentsUserData<AudioStreamMonitor>::kLocatorKey = 0; |
|
scherkus (not reviewing)
2014/09/09 21:07:41
as far as my code searching skills can tell, Audio
DaleCurtis
2014/09/10 00:51:14
Yeah, that's the only reason I can see this hasn't
|
| + |
| +AudioStreamMonitor::AudioStreamMonitor(WebContents* contents) |
| : web_contents_(contents), |
| clock_(&default_tick_clock_), |
| was_recently_audible_(false) { |
| @@ -25,12 +57,70 @@ bool AudioStreamMonitor::WasRecentlyAudible() const { |
| return was_recently_audible_; |
| } |
| +/* static */ |
|
scherkus (not reviewing)
2014/09/09 21:07:41
// static
here and below
DaleCurtis
2014/09/10 00:51:14
Done.
|
| void AudioStreamMonitor::StartMonitoringStream( |
| + int render_process_id, |
| + int render_frame_id, |
| + int stream_id, |
| + const ReadPowerAndClipCallback& read_power_callback) { |
| + if (!monitoring_available()) |
| + return; |
| + BrowserThread::PostTask(BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&StartMonitoringHelper, |
| + render_process_id, |
| + render_frame_id, |
| + stream_id, |
| + read_power_callback)); |
| +} |
| + |
| +/* static */ |
| +void AudioStreamMonitor::StopMonitoringStream(int render_process_id, |
| + int render_frame_id, |
| + int stream_id) { |
| + if (!monitoring_available()) |
| + return; |
| + BrowserThread::PostTask(BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&StopMonitoringHelper, |
| + render_process_id, |
| + render_frame_id, |
| + stream_id)); |
| +} |
| + |
| +/* static */ |
| +void AudioStreamMonitor::StartMonitoringHelper( |
| + int render_process_id, |
| + int render_frame_id, |
| + int stream_id, |
| + const ReadPowerAndClipCallback& read_power_callback) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + AudioStreamMonitor* const monitor = |
| + AudioStreamMonitorFromRenderFrame(render_process_id, render_frame_id); |
| + if (monitor) { |
| + monitor->StartMonitoringStreamOnUIThread( |
| + render_process_id, stream_id, read_power_callback); |
| + } |
| +} |
| + |
| +/* static */ |
| +void AudioStreamMonitor::StopMonitoringHelper(int render_process_id, |
| + int render_frame_id, |
| + int stream_id) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + AudioStreamMonitor* const monitor = |
| + AudioStreamMonitorFromRenderFrame(render_process_id, render_frame_id); |
| + if (monitor) |
| + monitor->StopMonitoringStreamOnUIThread(render_process_id, stream_id); |
| +} |
| + |
| +void AudioStreamMonitor::StartMonitoringStreamOnUIThread( |
| + int render_process_id, |
| int stream_id, |
| const ReadPowerAndClipCallback& read_power_callback) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(!read_power_callback.is_null()); |
| - poll_callbacks_[stream_id] = read_power_callback; |
| + poll_callbacks_[StreamID(render_process_id, stream_id)] = read_power_callback; |
| if (!poll_timer_.IsRunning()) { |
| poll_timer_.Start( |
| FROM_HERE, |
| @@ -39,9 +129,10 @@ void AudioStreamMonitor::StartMonitoringStream( |
| } |
| } |
| -void AudioStreamMonitor::StopMonitoringStream(int stream_id) { |
| +void AudioStreamMonitor::StopMonitoringStreamOnUIThread(int render_process_id, |
| + int stream_id) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - poll_callbacks_.erase(stream_id); |
| + poll_callbacks_.erase(StreamID(render_process_id, stream_id)); |
| if (poll_callbacks_.empty()) |
| poll_timer_.Stop(); |
| } |
| @@ -72,7 +163,7 @@ void AudioStreamMonitor::MaybeToggle() { |
| if (should_indicator_be_on != indicator_was_on) { |
| was_recently_audible_ = should_indicator_be_on; |
| - web_contents_->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
| + web_contents_->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| } |
| if (!should_indicator_be_on) { |
| @@ -84,3 +175,5 @@ void AudioStreamMonitor::MaybeToggle() { |
| base::Bind(&AudioStreamMonitor::MaybeToggle, base::Unretained(this))); |
| } |
| } |
| + |
| +} // namespace content |