| 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 42%
|
| rename from chrome/browser/media/audio_stream_monitor.cc
|
| rename to content/browser/media/audio_stream_monitor.cc
|
| index 8633053d510684d1a69143590ec9d3047eb44194..1d2f76f7f2c02f986f5b52122834363ff96be1e8 100644
|
| --- a/chrome/browser/media/audio_stream_monitor.cc
|
| +++ b/content/browser/media/audio_stream_monitor.cc
|
| @@ -2,16 +2,31 @@
|
| // 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/browser/web_contents/web_contents_impl.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/invalidate_type.h"
|
| -#include "content/public/browser/web_contents.h"
|
| +#include "content/public/browser/render_frame_host.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);
|
| + WebContentsImpl* const web_contents =
|
| + static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(
|
| + RenderFrameHost::FromID(render_process_id, render_frame_id)));
|
| + return web_contents ? web_contents->audio_stream_monitor() : NULL;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +AudioStreamMonitor::AudioStreamMonitor(WebContents* contents)
|
| : web_contents_(contents),
|
| clock_(&default_tick_clock_),
|
| was_recently_audible_(false) {
|
| @@ -25,12 +40,70 @@ bool AudioStreamMonitor::WasRecentlyAudible() const {
|
| return was_recently_audible_;
|
| }
|
|
|
| +// static
|
| 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 +112,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 +146,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 +158,5 @@ void AudioStreamMonitor::MaybeToggle() {
|
| base::Bind(&AudioStreamMonitor::MaybeToggle, base::Unretained(this)));
|
| }
|
| }
|
| +
|
| +} // namespace content
|
|
|