diff options
author | dalecurtis <dalecurtis@chromium.org> | 2014-09-10 19:51:40 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-11 03:07:16 +0000 |
commit | 484d29dcb45ca362fc9049c37dd3a51e11492f14 (patch) | |
tree | cec6b893a679431117b957c975ada3f7e0a946fa /chrome | |
parent | e6492dbcddf1845779da22d0de309bb9e496dd2c (diff) | |
download | chromium_src-484d29dcb45ca362fc9049c37dd3a51e11492f14.zip chromium_src-484d29dcb45ca362fc9049c37dd3a51e11492f14.tar.gz chromium_src-484d29dcb45ca362fc9049c37dd3a51e11492f14.tar.bz2 |
Use AudioStreamMonitor to control power save blocking.
Prevents looping, soundless videos from preventing system sleep if they're
in a background tab. We don't want soundless videos in the main tab to
allow sleeping as they'll impact the muted video + captions use case.
Reworks WebContentsImpl to track active media players and whether the
attached WebContents is visible. When visible and there's an active video
player, it will create a power save blocker. One blocker is shared for all
active media players for simplicity.
Reworks AudioStreamMonitor to handle the PowerSaveBlocker for audio
such that one is only created when non-silent audio is present.
To prevent splitting power blocking duties across chrome/ and content/,
AudioStreamMonitor now lives in content/. WebContents exposes a
WasRecentlyAudible() method for the existing tab audio indicator.
BUG=43667,367785
TEST=manual.
Review URL: https://codereview.chromium.org/478543003
Cr-Commit-Position: refs/heads/master@{#294303}
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/media/OWNERS | 1 | ||||
-rw-r--r-- | chrome/browser/media/audio_stream_monitor.cc | 86 | ||||
-rw-r--r-- | chrome/browser/media/audio_stream_monitor.h | 113 | ||||
-rw-r--r-- | chrome/browser/media/audio_stream_monitor_unittest.cc | 278 | ||||
-rw-r--r-- | chrome/browser/media/media_capture_devices_dispatcher.cc | 88 | ||||
-rw-r--r-- | chrome/browser/media/media_capture_devices_dispatcher.h | 9 | ||||
-rw-r--r-- | chrome/browser/ui/tabs/tab_utils.cc | 6 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_tests_unit.gypi | 1 |
9 files changed, 2 insertions, 582 deletions
diff --git a/chrome/browser/media/OWNERS b/chrome/browser/media/OWNERS index cbda62f..b146f03 100644 --- a/chrome/browser/media/OWNERS +++ b/chrome/browser/media/OWNERS @@ -15,5 +15,4 @@ per-file cast_*=mikhal@chromium.org per-file cast_*=pwestin@google.com # For changes related to the tab media indicators. -per-file audio_stream_monitor*=miu@chromium.org per-file media_stream_capture_indicator*=miu@chromium.org diff --git a/chrome/browser/media/audio_stream_monitor.cc b/chrome/browser/media/audio_stream_monitor.cc deleted file mode 100644 index 8633053..0000000 --- a/chrome/browser/media/audio_stream_monitor.cc +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// 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 "base/bind.h" -#include "base/bind_helpers.h" -#include "content/public/browser/invalidate_type.h" -#include "content/public/browser/web_contents.h" - -DEFINE_WEB_CONTENTS_USER_DATA_KEY(AudioStreamMonitor); - -AudioStreamMonitor::AudioStreamMonitor(content::WebContents* contents) - : web_contents_(contents), - clock_(&default_tick_clock_), - was_recently_audible_(false) { - DCHECK(web_contents_); -} - -AudioStreamMonitor::~AudioStreamMonitor() {} - -bool AudioStreamMonitor::WasRecentlyAudible() const { - DCHECK(thread_checker_.CalledOnValidThread()); - return was_recently_audible_; -} - -void AudioStreamMonitor::StartMonitoringStream( - 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; - if (!poll_timer_.IsRunning()) { - poll_timer_.Start( - FROM_HERE, - base::TimeDelta::FromSeconds(1) / kPowerMeasurementsPerSecond, - base::Bind(&AudioStreamMonitor::Poll, base::Unretained(this))); - } -} - -void AudioStreamMonitor::StopMonitoringStream(int stream_id) { - DCHECK(thread_checker_.CalledOnValidThread()); - poll_callbacks_.erase(stream_id); - if (poll_callbacks_.empty()) - poll_timer_.Stop(); -} - -void AudioStreamMonitor::Poll() { - for (StreamPollCallbackMap::const_iterator it = poll_callbacks_.begin(); - it != poll_callbacks_.end(); - ++it) { - // TODO(miu): A new UI for delivering specific power level and clipping - // information is still in the works. For now, we throw away all - // information except for "is it audible?" - const float power_dbfs = it->second.Run().first; - const float kSilenceThresholdDBFS = -72.24719896f; - if (power_dbfs >= kSilenceThresholdDBFS) { - last_blurt_time_ = clock_->NowTicks(); - MaybeToggle(); - break; // No need to poll remaining streams. - } - } -} - -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(content::INVALIDATE_TYPE_TAB); - } - - if (!should_indicator_be_on) { - off_timer_.Stop(); - } else if (!off_timer_.IsRunning()) { - off_timer_.Start( - FROM_HERE, - off_time - now, - base::Bind(&AudioStreamMonitor::MaybeToggle, base::Unretained(this))); - } -} diff --git a/chrome/browser/media/audio_stream_monitor.h b/chrome/browser/media/audio_stream_monitor.h deleted file mode 100644 index 3282dbd..0000000 --- a/chrome/browser/media/audio_stream_monitor.h +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ -#define CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ - -#include <map> - -#include "base/callback_forward.h" -#include "base/threading/thread_checker.h" -#include "base/time/default_tick_clock.h" -#include "base/time/time.h" -#include "base/timer/timer.h" -#include "content/public/browser/web_contents_user_data.h" - -namespace base { -class TickClock; -} - -// Repeatedly polls audio streams for their power levels, and "debounces" the -// information into a simple, binary "was recently audible" result for the audio -// indicators in the tab UI. The debouncing logic is to: 1) Turn on immediately -// when sound is audible; and 2) Hold on for X amount of time after sound has -// gone silent, then turn off. Said another way, we don't want tab indicators -// to turn on/off repeatedly and annoy the user. AudioStreamMonitor sends UI -// update notifications only when needed, but may be queried at any time. -// -// There are zero or one instances of AudioStreamMonitor per -// content::WebContents instance (referred to as "the tab" in comments below). -// AudioStreamMonitor is created on-demand, and automatically destroyed when its -// associated WebContents is destroyed. See content::WebContentsUserData for -// usage. -class AudioStreamMonitor - : public content::WebContentsUserData<AudioStreamMonitor> { - public: - // Returns true if audio has recently been audible from the tab. This is - // usually called whenever the tab data model is refreshed; but there are - // other use cases as well (e.g., the OOM killer uses this to de-prioritize - // the killing of tabs making sounds). - bool WasRecentlyAudible() const; - - // Starts polling the stream for audio stream power levels using |callback|. - typedef base::Callback<std::pair<float, bool>()> ReadPowerAndClipCallback; - void StartMonitoringStream(int stream_id, - const ReadPowerAndClipCallback& callback); - - // Stops polling the stream, discarding the internal copy of the |callback| - // provided in the call to StartMonitoringStream(). - void StopMonitoringStream(int stream_id); - - private: - friend class content::WebContentsUserData<AudioStreamMonitor>; - friend class AudioStreamMonitorTest; - - enum { - // Desired polling frequency. Note: If this is set too low, short-duration - // "blip" sounds won't be detected. http://crbug.com/339133#c4 - kPowerMeasurementsPerSecond = 15, - - // Amount of time to hold a tab indicator on after its last blurt. - kHoldOnMilliseconds = 2000 - }; - - // Invoked by content::WebContentsUserData only. - explicit AudioStreamMonitor(content::WebContents* contents); - virtual ~AudioStreamMonitor(); - - // Called by |poll_timer_| to sample the power levels from each of the streams - // playing in the tab. - void Poll(); - - // Compares last known indicator state with what it should be, and triggers UI - // updates through |web_contents_| if needed. When the indicator is turned - // on, |off_timer_| is started to re-invoke this method in the future. - void MaybeToggle(); - - // The WebContents instance instance to receive indicator toggle - // notifications. This pointer should be valid for the lifetime of - // AudioStreamMonitor. - content::WebContents* const web_contents_; - - // Note: |clock_| is always |&default_tick_clock_|, except during unit - // testing. - base::DefaultTickClock default_tick_clock_; - base::TickClock* const clock_; - - // Confirms single-threaded access in debug builds. - base::ThreadChecker thread_checker_; - - // The callbacks to read power levels for each stream. Only playing (i.e., - // not paused) streams will have an entry in this map. - typedef std::map<int, ReadPowerAndClipCallback> StreamPollCallbackMap; - StreamPollCallbackMap poll_callbacks_; - - // Records the last time at which sound was audible from any stream. - base::TimeTicks last_blurt_time_; - - // Set to true if the last call to MaybeToggle() determined the indicator - // should be turned on. - bool was_recently_audible_; - - // Calls Poll() at regular intervals while |poll_callbacks_| is non-empty. - base::RepeatingTimer<AudioStreamMonitor> poll_timer_; - - // Started only when an indicator is toggled on, to turn it off again in the - // future. - base::OneShotTimer<AudioStreamMonitor> off_timer_; - - DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor); -}; - -#endif // CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ diff --git a/chrome/browser/media/audio_stream_monitor_unittest.cc b/chrome/browser/media/audio_stream_monitor_unittest.cc deleted file mode 100644 index 58c4adb..0000000 --- a/chrome/browser/media/audio_stream_monitor_unittest.cc +++ /dev/null @@ -1,278 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// 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 <map> -#include <utility> - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/memory/scoped_ptr.h" -#include "base/test/simple_test_tick_clock.h" -#include "chrome/test/base/testing_profile.h" -#include "content/public/browser/invalidate_type.h" -#include "content/public/browser/web_contents.h" -#include "content/public/browser/web_contents_delegate.h" -#include "content/public/test/test_browser_thread_bundle.h" -#include "media/audio/audio_power_monitor.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" - -using ::testing::InvokeWithoutArgs; - -namespace { - -const int kStreamId = 3; -const int kAnotherStreamId = 6; - -// Used to confirm audio indicator state changes occur at the correct times. -class MockWebContentsDelegate : public content::WebContentsDelegate { - public: - MOCK_METHOD2(NavigationStateChanged, - void(const content::WebContents* source, - content::InvalidateTypes changed_flags)); -}; - -} // namespace - -class AudioStreamMonitorTest : public testing::Test { - public: - AudioStreamMonitorTest() { - // Start |clock_| at non-zero. - clock_.Advance(base::TimeDelta::FromSeconds(1000000)); - - // Create a WebContents instance and set it to use our mock delegate. - web_contents_.reset(content::WebContents::Create( - content::WebContents::CreateParams(&profile_, NULL))); - web_contents_->SetDelegate(&mock_web_contents_delegate_); - - // Create an AudioStreamMonitor instance whose lifecycle is tied to that of - // |web_contents_|, and override its clock with the test clock. - AudioStreamMonitor::CreateForWebContents(web_contents_.get()); - CHECK(audio_stream_monitor()); - const_cast<base::TickClock*&>(audio_stream_monitor()->clock_) = &clock_; - } - - AudioStreamMonitor* audio_stream_monitor() { - return AudioStreamMonitor::FromWebContents(web_contents_.get()); - } - - base::TimeTicks GetTestClockTime() { return clock_.NowTicks(); } - - void AdvanceClock(const base::TimeDelta& delta) { clock_.Advance(delta); } - - AudioStreamMonitor::ReadPowerAndClipCallback CreatePollCallback( - int stream_id) { - return base::Bind( - &AudioStreamMonitorTest::ReadPower, base::Unretained(this), stream_id); - } - - void SetStreamPower(int stream_id, float power) { - current_power_[stream_id] = power; - } - - void SimulatePollTimerFired() { audio_stream_monitor()->Poll(); } - - void SimulateOffTimerFired() { audio_stream_monitor()->MaybeToggle(); } - - void ExpectIsPolling(int stream_id, bool is_polling) { - AudioStreamMonitor* const monitor = audio_stream_monitor(); - EXPECT_EQ(is_polling, - monitor->poll_callbacks_.find(stream_id) != - monitor->poll_callbacks_.end()); - EXPECT_EQ(!monitor->poll_callbacks_.empty(), - monitor->poll_timer_.IsRunning()); - } - - void ExpectTabWasRecentlyAudible(bool was_audible, - const base::TimeTicks& last_blurt_time) { - AudioStreamMonitor* const monitor = audio_stream_monitor(); - EXPECT_EQ(was_audible, monitor->was_recently_audible_); - EXPECT_EQ(last_blurt_time, monitor->last_blurt_time_); - EXPECT_EQ(monitor->was_recently_audible_, monitor->off_timer_.IsRunning()); - } - - void ExpectWebContentsWillBeNotifiedOnce(bool should_be_audible) { - EXPECT_CALL(mock_web_contents_delegate_, - NavigationStateChanged(web_contents_.get(), - content::INVALIDATE_TYPE_TAB)) - .WillOnce(InvokeWithoutArgs( - this, - should_be_audible - ? &AudioStreamMonitorTest::ExpectIsNotifyingForToggleOn - : &AudioStreamMonitorTest::ExpectIsNotifyingForToggleOff)) - .RetiresOnSaturation(); - } - - static base::TimeDelta one_polling_interval() { - return base::TimeDelta::FromSeconds(1) / - AudioStreamMonitor::kPowerMeasurementsPerSecond; - } - - static base::TimeDelta holding_period() { - return base::TimeDelta::FromMilliseconds( - AudioStreamMonitor::kHoldOnMilliseconds); - } - - private: - std::pair<float, bool> ReadPower(int stream_id) { - return std::make_pair(current_power_[stream_id], false); - } - - void ExpectIsNotifyingForToggleOn() { - EXPECT_TRUE(audio_stream_monitor()->WasRecentlyAudible()); - } - - void ExpectIsNotifyingForToggleOff() { - EXPECT_FALSE(audio_stream_monitor()->WasRecentlyAudible()); - } - - content::TestBrowserThreadBundle browser_thread_bundle_; - TestingProfile profile_; - MockWebContentsDelegate mock_web_contents_delegate_; - base::SimpleTestTickClock clock_; - std::map<int, float> current_power_; - scoped_ptr<content::WebContents> web_contents_; - - DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitorTest); -}; - -// Tests that AudioStreamMonitor is polling while it has a -// ReadPowerAndClipCallback, and is not polling at other times. -TEST_F(AudioStreamMonitorTest, PollsWhenProvidedACallback) { - EXPECT_FALSE(audio_stream_monitor()->WasRecentlyAudible()); - ExpectIsPolling(kStreamId, false); - - audio_stream_monitor()->StartMonitoringStream(kStreamId, - CreatePollCallback(kStreamId)); - EXPECT_FALSE(audio_stream_monitor()->WasRecentlyAudible()); - ExpectIsPolling(kStreamId, true); - - audio_stream_monitor()->StopMonitoringStream(kStreamId); - EXPECT_FALSE(audio_stream_monitor()->WasRecentlyAudible()); - ExpectIsPolling(kStreamId, false); -} - -// Tests that AudioStreamMonitor debounces the power level readings it's taking, -// which could be fluctuating rapidly between the audible versus silence -// threshold. See comments in audio_stream_monitor.h for expected behavior. -TEST_F(AudioStreamMonitorTest, - ImpulsesKeepIndicatorOnUntilHoldingPeriodHasPassed) { - audio_stream_monitor()->StartMonitoringStream(kStreamId, - CreatePollCallback(kStreamId)); - - // Expect WebContents will get one call form AudioStreamMonitor to toggle the - // indicator on upon the very first poll. - ExpectWebContentsWillBeNotifiedOnce(true); - - // Loop, each time testing a slightly longer period of polled silence. The - // indicator should remain on throughout. - int num_silence_polls = 0; - base::TimeTicks last_blurt_time; - do { - // Poll an audible signal, and expect tab indicator state is on. - SetStreamPower(kStreamId, media::AudioPowerMonitor::max_power()); - last_blurt_time = GetTestClockTime(); - SimulatePollTimerFired(); - ExpectTabWasRecentlyAudible(true, last_blurt_time); - AdvanceClock(one_polling_interval()); - - // Poll a silent signal repeatedly, ensuring that the indicator is being - // held on during the holding period. - SetStreamPower(kStreamId, media::AudioPowerMonitor::zero_power()); - for (int i = 0; i < num_silence_polls; ++i) { - SimulatePollTimerFired(); - ExpectTabWasRecentlyAudible(true, last_blurt_time); - // Note: Redundant off timer firings should not have any effect. - SimulateOffTimerFired(); - ExpectTabWasRecentlyAudible(true, last_blurt_time); - AdvanceClock(one_polling_interval()); - } - - ++num_silence_polls; - } while (GetTestClockTime() < last_blurt_time + holding_period()); - - // At this point, the clock has just advanced to beyond the holding period, so - // the next firing of the off timer should turn off the tab indicator. Also, - // make sure it stays off for several cycles thereafter. - ExpectWebContentsWillBeNotifiedOnce(false); - for (int i = 0; i < 10; ++i) { - SimulateOffTimerFired(); - ExpectTabWasRecentlyAudible(false, last_blurt_time); - AdvanceClock(one_polling_interval()); - } -} - -// Tests that the AudioStreamMonitor correctly processes the blurts from two -// different streams in the same tab. -TEST_F(AudioStreamMonitorTest, HandlesMultipleStreamsBlurting) { - audio_stream_monitor()->StartMonitoringStream(kStreamId, - CreatePollCallback(kStreamId)); - audio_stream_monitor()->StartMonitoringStream( - kAnotherStreamId, - CreatePollCallback(kAnotherStreamId)); - - base::TimeTicks last_blurt_time; - ExpectTabWasRecentlyAudible(false, last_blurt_time); - - // Measure audible sound from the first stream and silence from the second. - // The indicator turns on (i.e., tab was recently audible). - ExpectWebContentsWillBeNotifiedOnce(true); - SetStreamPower(kStreamId, media::AudioPowerMonitor::max_power()); - SetStreamPower(kAnotherStreamId, media::AudioPowerMonitor::zero_power()); - last_blurt_time = GetTestClockTime(); - SimulatePollTimerFired(); - ExpectTabWasRecentlyAudible(true, last_blurt_time); - - // Halfway through the holding period, the second stream joins in. The - // indicator stays on. - AdvanceClock(holding_period() / 2); - SimulateOffTimerFired(); - SetStreamPower(kAnotherStreamId, media::AudioPowerMonitor::max_power()); - last_blurt_time = GetTestClockTime(); - SimulatePollTimerFired(); // Restarts holding period. - ExpectTabWasRecentlyAudible(true, last_blurt_time); - - // Now, measure silence from both streams. After an entire holding period - // has passed (since the second stream joined in), the indicator should turn - // off. - ExpectWebContentsWillBeNotifiedOnce(false); - AdvanceClock(holding_period()); - SimulateOffTimerFired(); - SetStreamPower(kStreamId, media::AudioPowerMonitor::zero_power()); - SetStreamPower(kAnotherStreamId, media::AudioPowerMonitor::zero_power()); - SimulatePollTimerFired(); - ExpectTabWasRecentlyAudible(false, last_blurt_time); - - // Now, measure silence from the first stream and audible sound from the - // second. The indicator turns back on. - ExpectWebContentsWillBeNotifiedOnce(true); - SetStreamPower(kAnotherStreamId, media::AudioPowerMonitor::max_power()); - last_blurt_time = GetTestClockTime(); - SimulatePollTimerFired(); - ExpectTabWasRecentlyAudible(true, last_blurt_time); - - // From here onwards, both streams are silent. Halfway through the holding - // period, the indicator should not have changed. - SetStreamPower(kAnotherStreamId, media::AudioPowerMonitor::zero_power()); - AdvanceClock(holding_period() / 2); - SimulatePollTimerFired(); - SimulateOffTimerFired(); - ExpectTabWasRecentlyAudible(true, last_blurt_time); - - // Just past the holding period, the indicator should be turned off. - ExpectWebContentsWillBeNotifiedOnce(false); - AdvanceClock(holding_period() - (GetTestClockTime() - last_blurt_time)); - SimulateOffTimerFired(); - ExpectTabWasRecentlyAudible(false, last_blurt_time); - - // Polling should not turn the indicator back while both streams are remaining - // silent. - for (int i = 0; i < 100; ++i) { - AdvanceClock(one_polling_interval()); - SimulatePollTimerFired(); - ExpectTabWasRecentlyAudible(false, last_blurt_time); - } -} diff --git a/chrome/browser/media/media_capture_devices_dispatcher.cc b/chrome/browser/media/media_capture_devices_dispatcher.cc index 2d0a7989..a3a1ddc 100644 --- a/chrome/browser/media/media_capture_devices_dispatcher.cc +++ b/chrome/browser/media/media_capture_devices_dispatcher.cc @@ -54,12 +54,6 @@ #include "ash/shell.h" #endif // defined(OS_CHROMEOS) -// Only do audio stream monitoring for platforms that use it for the tab media -// indicator UI or the OOM killer. -#if !defined(OS_ANDROID) && !defined(OS_IOS) -#define AUDIO_STREAM_MONITORING -#include "chrome/browser/media/audio_stream_monitor.h" -#endif // !defined(OS_ANDROID) && !defined(OS_IOS) #if defined(ENABLE_EXTENSIONS) #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" @@ -196,43 +190,6 @@ scoped_ptr<content::MediaStreamUI> GetDevicesForDesktopCapture( return ui.Pass(); } -#if defined(AUDIO_STREAM_MONITORING) - -AudioStreamMonitor* AudioStreamMonitorFromRenderFrame( - int render_process_id, - int render_frame_id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - content::WebContents* const web_contents = - content::WebContents::FromRenderFrameHost( - content::RenderFrameHost::FromID(render_process_id, render_frame_id)); - if (!web_contents) - return NULL; - return AudioStreamMonitor::FromWebContents(web_contents); -} - -void StartAudioStreamMonitoringOnUIThread( - int render_process_id, - int render_frame_id, - int stream_id, - const AudioStreamMonitor::ReadPowerAndClipCallback& read_power_callback) { - AudioStreamMonitor* const audio_stream_monitor = - AudioStreamMonitorFromRenderFrame(render_process_id, render_frame_id); - if (audio_stream_monitor) - audio_stream_monitor->StartMonitoringStream(stream_id, read_power_callback); -} - -void StopAudioStreamMonitoringOnUIThread( - int render_process_id, - int render_frame_id, - int stream_id) { - AudioStreamMonitor* const audio_stream_monitor = - AudioStreamMonitorFromRenderFrame(render_process_id, render_frame_id); - if (audio_stream_monitor) - audio_stream_monitor->StopMonitoringStream(stream_id); -} - -#endif // defined(AUDIO_STREAM_MONITORING) - #if !defined(OS_ANDROID) // Find browser or app window from a given |web_contents|. gfx::NativeWindow FindParentWindowForWebContents( @@ -937,40 +894,6 @@ void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged( page_request_id, security_origin, stream_type, state)); } -void MediaCaptureDevicesDispatcher::OnAudioStreamPlaying( - int render_process_id, - int render_frame_id, - int stream_id, - const ReadPowerAndClipCallback& read_power_callback) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); -#if defined(AUDIO_STREAM_MONITORING) - BrowserThread::PostTask( - BrowserThread::UI, - FROM_HERE, - base::Bind(&StartAudioStreamMonitoringOnUIThread, - render_process_id, - render_frame_id, - stream_id, - read_power_callback)); -#endif -} - -void MediaCaptureDevicesDispatcher::OnAudioStreamStopped( - int render_process_id, - int render_frame_id, - int stream_id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); -#if defined(AUDIO_STREAM_MONITORING) - BrowserThread::PostTask( - BrowserThread::UI, - FROM_HERE, - base::Bind(&StopAudioStreamMonitoringOnUIThread, - render_process_id, - render_frame_id, - stream_id)); -#endif -} - void MediaCaptureDevicesDispatcher::OnCreatingAudioStream( int render_process_id, int render_frame_id) { @@ -1069,16 +992,6 @@ void MediaCaptureDevicesDispatcher::OnCreatingAudioStreamOnUIThread( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); FOR_EACH_OBSERVER(Observer, observers_, OnCreatingAudioStream(render_process_id, render_frame_id)); -#if defined(AUDIO_STREAM_MONITORING) - content::WebContents* const web_contents = - content::WebContents::FromRenderFrameHost( - content::RenderFrameHost::FromID(render_process_id, render_frame_id)); - if (web_contents) { - // Note: Calling CreateForWebContents() multiple times is valid (see usage - // info for content::WebContentsUserData). - AudioStreamMonitor::CreateForWebContents(web_contents); - } -#endif } bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() { @@ -1086,7 +999,6 @@ bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() { return desktop_capture_sessions_.size() > 0; } - void MediaCaptureDevicesDispatcher::SetTestAudioCaptureDevices( const MediaStreamDevices& devices) { test_audio_devices_ = devices; diff --git a/chrome/browser/media/media_capture_devices_dispatcher.h b/chrome/browser/media/media_capture_devices_dispatcher.h index dcef644..162c654 100644 --- a/chrome/browser/media/media_capture_devices_dispatcher.h +++ b/chrome/browser/media/media_capture_devices_dispatcher.h @@ -129,15 +129,6 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver, content::MediaRequestState state) OVERRIDE; virtual void OnCreatingAudioStream(int render_process_id, int render_frame_id) OVERRIDE; - virtual void OnAudioStreamPlaying( - int render_process_id, - int render_frame_id, - int stream_id, - const ReadPowerAndClipCallback& power_read_callback) OVERRIDE; - virtual void OnAudioStreamStopped( - int render_process_id, - int render_frame_id, - int stream_id) OVERRIDE; scoped_refptr<MediaStreamCaptureIndicator> GetMediaStreamCaptureIndicator(); diff --git a/chrome/browser/ui/tabs/tab_utils.cc b/chrome/browser/ui/tabs/tab_utils.cc index e11df6cd..84956d1 100644 --- a/chrome/browser/ui/tabs/tab_utils.cc +++ b/chrome/browser/ui/tabs/tab_utils.cc @@ -5,10 +5,10 @@ #include "chrome/browser/ui/tabs/tab_utils.h" #include "base/strings/string16.h" -#include "chrome/browser/media/audio_stream_monitor.h" #include "chrome/browser/media/media_capture_devices_dispatcher.h" #include "chrome/browser/media/media_stream_capture_indicator.h" #include "chrome/grit/generated_resources.h" +#include "content/public/browser/web_contents.h" #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" @@ -117,9 +117,7 @@ bool ShouldTabShowCloseButton(int capacity, } bool IsPlayingAudio(content::WebContents* contents) { - AudioStreamMonitor* const audio_stream_monitor = - AudioStreamMonitor::FromWebContents(contents); - return audio_stream_monitor && audio_stream_monitor->WasRecentlyAudible(); + return contents->WasRecentlyAudible(); } TabMediaState GetTabMediaStateForContents(content::WebContents* contents) { diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 59f24a1..a873dec 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -631,8 +631,6 @@ 'browser/mac/relauncher.h', 'browser/mac/security_wrappers.cc', 'browser/mac/security_wrappers.h', - 'browser/media/audio_stream_monitor.cc', - 'browser/media/audio_stream_monitor.h', 'browser/media/cast_transport_host_filter.cc', 'browser/media/cast_transport_host_filter.h', 'browser/media/desktop_media_list.h', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 53c4a28..6430c48 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -1026,7 +1026,6 @@ 'browser/io_thread_unittest.cc', 'browser/logging_chrome_unittest.cc', 'browser/mac/keystone_glue_unittest.mm', - 'browser/media/audio_stream_monitor_unittest.cc', 'browser/media/cast_transport_host_filter_unittest.cc', 'browser/media/desktop_media_list_ash_unittest.cc', 'browser/media/native_desktop_media_list_unittest.cc', |