Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(707)

Unified Diff: content/browser/media/audio_stream_monitor.h

Issue 1215713021: Reverted the code for the non-interactive audible tab notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@notification
Patch Set: Rebased Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..bf5de689bb0866ce6dd0eccbcd922929834791d4 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"
@@ -24,6 +23,8 @@ class TickClock;
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
// indicators in the tab UI. The debouncing logic is to: 1) Turn on immediately
@@ -32,23 +33,23 @@ namespace content {
// 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.
@@ -66,6 +67,10 @@ class CONTENT_EXPORT AudioStreamMonitor : public AudioStateProvider {
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 +113,10 @@ class CONTENT_EXPORT AudioStreamMonitor : public AudioStateProvider {
// on, |off_timer_| is started to re-invoke this method in the future.
void MaybeToggle();
+ // The WebContents 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 @@ class CONTENT_EXPORT AudioStreamMonitor : public AudioStateProvider {
// 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_;

Powered by Google App Engine
This is Rietveld 408576698