OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ |
6 #define CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ | 6 #define CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
12 #include "base/time/default_tick_clock.h" | 12 #include "base/time/default_tick_clock.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
15 #include "content/public/browser/web_contents_user_data.h" | 15 #include "content/public/browser/web_contents_user_data.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class TickClock; | 18 class TickClock; |
19 } | 19 } |
20 | 20 |
| 21 namespace content { |
| 22 class PowerSaveBlocker; |
| 23 } |
| 24 |
21 // Repeatedly polls audio streams for their power levels, and "debounces" the | 25 // Repeatedly polls audio streams for their power levels, and "debounces" the |
22 // information into a simple, binary "was recently audible" result for the audio | 26 // information into a simple, binary "was recently audible" result for the audio |
23 // indicators in the tab UI. The debouncing logic is to: 1) Turn on immediately | 27 // indicators in the tab UI. The debouncing logic is to: 1) Turn on immediately |
24 // when sound is audible; and 2) Hold on for X amount of time after sound has | 28 // when sound is audible; and 2) Hold on for X amount of time after sound has |
25 // gone silent, then turn off. Said another way, we don't want tab indicators | 29 // gone silent, then turn off. Said another way, we don't want tab indicators |
26 // to turn on/off repeatedly and annoy the user. AudioStreamMonitor sends UI | 30 // to turn on/off repeatedly and annoy the user. AudioStreamMonitor sends UI |
27 // update notifications only when needed, but may be queried at any time. | 31 // update notifications only when needed, but may be queried at any time. |
28 // | 32 // |
29 // There are zero or one instances of AudioStreamMonitor per | 33 // There are zero or one instances of AudioStreamMonitor per |
30 // content::WebContents instance (referred to as "the tab" in comments below). | 34 // content::WebContents instance (referred to as "the tab" in comments below). |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 // should be turned on. | 104 // should be turned on. |
101 bool was_recently_audible_; | 105 bool was_recently_audible_; |
102 | 106 |
103 // Calls Poll() at regular intervals while |poll_callbacks_| is non-empty. | 107 // Calls Poll() at regular intervals while |poll_callbacks_| is non-empty. |
104 base::RepeatingTimer<AudioStreamMonitor> poll_timer_; | 108 base::RepeatingTimer<AudioStreamMonitor> poll_timer_; |
105 | 109 |
106 // Started only when an indicator is toggled on, to turn it off again in the | 110 // Started only when an indicator is toggled on, to turn it off again in the |
107 // future. | 111 // future. |
108 base::OneShotTimer<AudioStreamMonitor> off_timer_; | 112 base::OneShotTimer<AudioStreamMonitor> off_timer_; |
109 | 113 |
| 114 // Prevent system sleep when audio is active. |
| 115 scoped_ptr<content::PowerSaveBlocker> blocker_; |
| 116 |
110 DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor); | 117 DISALLOW_COPY_AND_ASSIGN(AudioStreamMonitor); |
111 }; | 118 }; |
112 | 119 |
113 #endif // CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ | 120 #endif // CHROME_BROWSER_MEDIA_AUDIO_STREAM_MONITOR_H_ |
OLD | NEW |