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

Side by Side Diff: base/power_monitor/power_monitor.h

Issue 2310343002: Defer suspend events on Android when audio is active. (Closed)
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/power_monitor/power_monitor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 BASE_POWER_MONITOR_POWER_MONITOR_H_ 5 #ifndef BASE_POWER_MONITOR_POWER_MONITOR_H_
6 #define BASE_POWER_MONITOR_POWER_MONITOR_H_ 6 #define BASE_POWER_MONITOR_POWER_MONITOR_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/observer_list_threadsafe.h" 11 #include "base/observer_list_threadsafe.h"
12 #include "base/power_monitor/power_observer.h" 12 #include "base/power_monitor/power_observer.h"
13 #include "build/build_config.h"
14
15 #if defined(OS_ANDROID)
16 #include "base/synchronization/lock.h"
17 #endif
13 18
14 namespace base { 19 namespace base {
15 20
16 class PowerMonitorSource; 21 class PowerMonitorSource;
17 22
18 // A class used to monitor the power state change and notify the observers about 23 // A class used to monitor the power state change and notify the observers about
19 // the change event. 24 // the change event.
20 class BASE_EXPORT PowerMonitor { 25 class BASE_EXPORT PowerMonitor {
21 public: 26 public:
22 // Takes ownership of |source|. 27 // Takes ownership of |source|.
23 explicit PowerMonitor(std::unique_ptr<PowerMonitorSource> source); 28 explicit PowerMonitor(std::unique_ptr<PowerMonitorSource> source);
24 ~PowerMonitor(); 29 ~PowerMonitor();
25 30
26 // Get the process-wide PowerMonitor (if not present, returns NULL). 31 // Get the process-wide PowerMonitor (if not present, returns NULL).
27 static PowerMonitor* Get(); 32 static PowerMonitor* Get();
28 33
29 // Add and remove an observer. 34 // Add and remove an observer.
30 // Can be called from any thread. 35 // Can be called from any thread.
31 // Must not be called from within a notification callback. 36 // Must not be called from within a notification callback.
32 void AddObserver(PowerObserver* observer); 37 void AddObserver(PowerObserver* observer);
33 void RemoveObserver(PowerObserver* observer); 38 void RemoveObserver(PowerObserver* observer);
34 39
35 // Is the computer currently on battery power. 40 // Is the computer currently on battery power.
36 bool IsOnBatteryPower(); 41 bool IsOnBatteryPower();
37 42
43 #if defined(OS_ANDROID)
44 void DeferSuspendEvents(bool defer);
45 #endif
46
38 private: 47 private:
39 friend class PowerMonitorSource; 48 friend class PowerMonitorSource;
40 49
41 PowerMonitorSource* Source(); 50 PowerMonitorSource* Source();
42 51
43 void NotifyPowerStateChange(bool battery_in_use); 52 void NotifyPowerStateChange(bool battery_in_use);
44 void NotifySuspend(); 53 void NotifySuspend();
45 void NotifyResume(); 54 void NotifyResume();
46 55
47 scoped_refptr<ObserverListThreadSafe<PowerObserver> > observers_; 56 scoped_refptr<ObserverListThreadSafe<PowerObserver> > observers_;
48 std::unique_ptr<PowerMonitorSource> source_; 57 std::unique_ptr<PowerMonitorSource> source_;
49 58
59 base::Lock lock_;
60 bool is_suspended_ = false;
61 bool should_defer_suspend_ = false;
62
50 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); 63 DISALLOW_COPY_AND_ASSIGN(PowerMonitor);
51 }; 64 };
52 65
53 } // namespace base 66 } // namespace base
54 67
55 #endif // BASE_POWER_MONITOR_POWER_MONITOR_H_ 68 #endif // BASE_POWER_MONITOR_POWER_MONITOR_H_
OLDNEW
« no previous file with comments | « no previous file | base/power_monitor/power_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698