Index: content/browser/media/audio_stream_monitor.h |
diff --git a/content/browser/media/audio_stream_monitor.h b/content/browser/media/audio_stream_monitor.h |
index b3cbf16f4d3d63192d9acc60fc2072eb4be97beb..d1a32d5f857b05925f884ef64d834e673c8c5f29 100644 |
--- a/content/browser/media/audio_stream_monitor.h |
+++ b/content/browser/media/audio_stream_monitor.h |
@@ -14,7 +14,6 @@ |
#include "base/time/time.h" |
#include "base/timer/timer.h" |
#include "build/build_config.h" |
-#include "content/browser/media/audio_state_provider.h" |
#include "content/common/content_export.h" |
#include "media/audio/audio_output_controller.h" |
@@ -23,6 +22,7 @@ |
} |
namespace content { |
+class WebContents; |
// Repeatedly polls audio streams for their power levels, and "debounces" the |
// information into a simple, binary "was recently audible" result for the audio |
@@ -32,23 +32,23 @@ |
// to turn on/off repeatedly and annoy the user. AudioStreamMonitor sends UI |
// update notifications only when needed, but may be queried at any time. |
// |
-class CONTENT_EXPORT AudioStreamMonitor : public AudioStateProvider { |
+// Each WebContentsImpl owns an AudioStreamMonitor. |
+class CONTENT_EXPORT AudioStreamMonitor { |
public: |
explicit AudioStreamMonitor(WebContents* contents); |
- ~AudioStreamMonitor() override; |
+ ~AudioStreamMonitor(); |
// Indicates if audio stream monitoring is available. It's only available if |
// AudioOutputController can and will monitor output power levels. |
- bool IsAudioStateAvailable() const override; |
- |
- // This provider is a monitor, the method returns |this|. |
- AudioStreamMonitor* audio_stream_monitor() override; |
+ static bool monitoring_available() { |
+ return media::AudioOutputController::will_monitor_audio_levels(); |
+ } |
// 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 override; |
+ bool WasRecentlyAudible() const; |
// Starts or stops audio level monitoring respectively for the stream owned by |
// the specified renderer. Safe to call from any thread. |
@@ -65,6 +65,10 @@ |
static void StopMonitoringStream(int render_process_id, |
int render_frame_id, |
int stream_id); |
+ |
+ void set_was_recently_audible_for_testing(bool value) { |
+ was_recently_audible_ = value; |
+ } |
private: |
friend class AudioStreamMonitorTest; |
@@ -108,6 +112,11 @@ |
// 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. |
+ WebContents* const web_contents_; |
+ |
// Note: |clock_| is always |&default_tick_clock_|, except during unit |
// testing. |
base::DefaultTickClock default_tick_clock_; |
@@ -125,6 +134,10 @@ |
// 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_; |