| Index: content/browser/media/audio_stream_monitor.cc
|
| diff --git a/content/browser/media/audio_stream_monitor.cc b/content/browser/media/audio_stream_monitor.cc
|
| index 1d2f76f7f2c02f986f5b52122834363ff96be1e8..4c0bc0a5d720c6ce0debbadd6587ac96b8a0fa75 100644
|
| --- a/content/browser/media/audio_stream_monitor.cc
|
| +++ b/content/browser/media/audio_stream_monitor.cc
|
| @@ -21,23 +21,36 @@ AudioStreamMonitor* AudioStreamMonitorFromRenderFrame(int render_process_id,
|
| 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;
|
| +
|
| + if (!web_contents)
|
| + return nullptr;
|
| +
|
| + AudioStateProvider* audio_provider = web_contents->audio_state_provider();
|
| + return audio_provider ? audio_provider->audio_stream_monitor() : nullptr;
|
| }
|
|
|
| } // namespace
|
|
|
| AudioStreamMonitor::AudioStreamMonitor(WebContents* contents)
|
| - : web_contents_(contents),
|
| - clock_(&default_tick_clock_),
|
| - was_recently_audible_(false) {
|
| - DCHECK(web_contents_);
|
| + : AudioStateProvider(contents),
|
| + clock_(&default_tick_clock_)
|
| +{
|
| }
|
|
|
| AudioStreamMonitor::~AudioStreamMonitor() {}
|
|
|
| +bool AudioStreamMonitor::IsAudioStateAvailable() const {
|
| + return media::AudioOutputController::will_monitor_audio_levels();
|
| +}
|
| +
|
| +// This provider is the monitor.
|
| +AudioStreamMonitor* AudioStreamMonitor::audio_stream_monitor() {
|
| + return this;
|
| +}
|
| +
|
| bool AudioStreamMonitor::WasRecentlyAudible() const {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| - return was_recently_audible_;
|
| + return AudioStateProvider::WasRecentlyAudible();
|
| }
|
|
|
| // static
|
| @@ -46,7 +59,7 @@ void AudioStreamMonitor::StartMonitoringStream(
|
| int render_frame_id,
|
| int stream_id,
|
| const ReadPowerAndClipCallback& read_power_callback) {
|
| - if (!monitoring_available())
|
| + if (!media::AudioOutputController::will_monitor_audio_levels())
|
| return;
|
| BrowserThread::PostTask(BrowserThread::UI,
|
| FROM_HERE,
|
| @@ -61,7 +74,7 @@ void AudioStreamMonitor::StartMonitoringStream(
|
| void AudioStreamMonitor::StopMonitoringStream(int render_process_id,
|
| int render_frame_id,
|
| int stream_id) {
|
| - if (!monitoring_available())
|
| + if (!media::AudioOutputController::will_monitor_audio_levels())
|
| return;
|
| BrowserThread::PostTask(BrowserThread::UI,
|
| FROM_HERE,
|
| @@ -138,16 +151,12 @@ void AudioStreamMonitor::Poll() {
|
| }
|
|
|
| void AudioStreamMonitor::MaybeToggle() {
|
| - const bool indicator_was_on = was_recently_audible_;
|
| const base::TimeTicks off_time =
|
| last_blurt_time_ + base::TimeDelta::FromMilliseconds(kHoldOnMilliseconds);
|
| const base::TimeTicks now = clock_->NowTicks();
|
| const bool should_indicator_be_on = now < off_time;
|
|
|
| - if (should_indicator_be_on != indicator_was_on) {
|
| - was_recently_audible_ = should_indicator_be_on;
|
| - web_contents_->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
|
| - }
|
| + Notify(should_indicator_be_on);
|
|
|
| if (!should_indicator_be_on) {
|
| off_timer_.Stop();
|
|
|