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

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

Issue 562863002: Gardening: Revert "Use AudioStreamMonitor to control power save blocking." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « chrome/browser/media/OWNERS ('k') | chrome/browser/media/audio_stream_monitor.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media/audio_stream_monitor.h
diff --git a/content/browser/media/audio_stream_monitor.h b/chrome/browser/media/audio_stream_monitor.h
similarity index 58%
rename from content/browser/media/audio_stream_monitor.h
rename to chrome/browser/media/audio_stream_monitor.h
index d1a32d5f857b05925f884ef64d834e673c8c5f29..3282dbd8ba77edde54c6c35afb17bd4f49e5068e 100644
--- a/content/browser/media/audio_stream_monitor.h
+++ b/chrome/browser/media/audio_stream_monitor.h
@@ -2,28 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
-#define CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
+#ifndef CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
+#define CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
#include <map>
-#include <utility>
#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 "build/build_config.h"
-#include "content/common/content_export.h"
-#include "media/audio/audio_output_controller.h"
+#include "content/public/browser/web_contents_user_data.h"
namespace base {
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,45 +26,31 @@ class WebContents;
// to turn on/off repeatedly and annoy the user. AudioStreamMonitor sends UI
// update notifications only when needed, but may be queried at any time.
//
-// Each WebContentsImpl owns an AudioStreamMonitor.
-class CONTENT_EXPORT AudioStreamMonitor {
+// 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:
- explicit AudioStreamMonitor(WebContents* contents);
- ~AudioStreamMonitor();
-
- // Indicates if audio stream monitoring is available. It's only available if
- // AudioOutputController can and will monitor output power levels.
- 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;
- // Starts or stops audio level monitoring respectively for the stream owned by
- // the specified renderer. Safe to call from any thread.
- //
- // The callback returns the current power level (in dBFS units) and the clip
- // status (true if any part of the audio signal has clipped since the last
- // callback run). |stream_id| must be unique within a |render_process_id|.
+ // Starts polling the stream for audio stream power levels using |callback|.
typedef base::Callback<std::pair<float, bool>()> ReadPowerAndClipCallback;
- static void StartMonitoringStream(
- int render_process_id,
- int render_frame_id,
- int stream_id,
- const ReadPowerAndClipCallback& read_power_callback);
- 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;
- }
+ 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 {
@@ -82,26 +62,9 @@ class CONTENT_EXPORT AudioStreamMonitor {
kHoldOnMilliseconds = 2000
};
- // Helper methods for starting and stopping monitoring which lookup the
- // identified renderer and forward calls to the correct AudioStreamMonitor.
- static void StartMonitoringHelper(
- int render_process_id,
- int render_frame_id,
- int stream_id,
- const ReadPowerAndClipCallback& read_power_callback);
- static void StopMonitoringHelper(int render_process_id,
- int render_frame_id,
- int stream_id);
-
- // Starts polling the stream for audio stream power levels using |callback|.
- void StartMonitoringStreamOnUIThread(
- int render_process_id,
- int stream_id,
- const ReadPowerAndClipCallback& callback);
-
- // Stops polling the stream, discarding the internal copy of the |callback|
- // provided in the call to StartMonitoringStream().
- void StopMonitoringStreamOnUIThread(int render_process_id, int stream_id);
+ // 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.
@@ -115,7 +78,7 @@ class CONTENT_EXPORT AudioStreamMonitor {
// The WebContents instance instance to receive indicator toggle
// notifications. This pointer should be valid for the lifetime of
// AudioStreamMonitor.
- WebContents* const web_contents_;
+ content::WebContents* const web_contents_;
// Note: |clock_| is always |&default_tick_clock_|, except during unit
// testing.
@@ -127,8 +90,7 @@ class CONTENT_EXPORT AudioStreamMonitor {
// 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::pair<int, int> StreamID;
- typedef std::map<StreamID, ReadPowerAndClipCallback> StreamPollCallbackMap;
+ typedef std::map<int, ReadPowerAndClipCallback> StreamPollCallbackMap;
StreamPollCallbackMap poll_callbacks_;
// Records the last time at which sound was audible from any stream.
@@ -148,6 +110,4 @@ class CONTENT_EXPORT AudioStreamMonitor {
DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor);
};
-} // namespace content
-
-#endif // CONTENT_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
+#endif // CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_
« no previous file with comments | « chrome/browser/media/OWNERS ('k') | chrome/browser/media/audio_stream_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698