Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/basictypes.h" | 9 #include "base/basictypes.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 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 | 15 |
| 16 class PowerMonitorSource; | 16 class PowerMonitorSource; |
| 17 | 17 |
| 18 // A class used to monitor the power state change and notify the observers about | 18 // A class used to monitor the power state change and notify the observers about |
| 19 // the change event. | 19 // the change event. |
| 20 class BASE_EXPORT PowerMonitor { | 20 class BASE_EXPORT PowerMonitor { |
| 21 public: | 21 public: |
| 22 // Takes ownership of |source|. | 22 static PowerMonitor* Create(scoped_ptr<PowerMonitorSource> source); |
|
Ken Russell (switch to Gerrit)
2014/02/28 02:02:42
I find the pattern here confusing where PowerMonit
jam
2014/02/28 17:05:18
+1
| |
| 23 explicit PowerMonitor(scoped_ptr<PowerMonitorSource> source); | |
| 24 ~PowerMonitor(); | 23 ~PowerMonitor(); |
| 25 | 24 |
| 26 // Get the process-wide PowerMonitor (if not present, returns NULL). | 25 // Get the process-wide PowerMonitor (if not present, returns NULL). |
| 27 static PowerMonitor* Get(); | 26 static PowerMonitor* Get(); |
| 28 | 27 |
| 28 static bool AddObserverThreadSafe(PowerObserver* observer); | |
| 29 static bool RemoveObserverThreadSafe(PowerObserver* observer); | |
| 30 | |
| 31 // Is the computer currently on battery power. | |
| 32 bool IsOnBatteryPower(); | |
| 33 | |
| 34 private: | |
| 35 // Takes ownership of |source|. | |
| 36 explicit PowerMonitor(scoped_ptr<PowerMonitorSource> source); | |
| 37 friend class PowerMonitorSource; | |
| 38 | |
| 39 PowerMonitorSource* Source(); | |
| 40 | |
| 29 // Add and remove an observer. | 41 // Add and remove an observer. |
| 30 // Can be called from any thread. | 42 // Can be called from any thread. |
| 31 // Must not be called from within a notification callback. | 43 // Must not be called from within a notification callback. |
| 32 void AddObserver(PowerObserver* observer); | 44 void AddObserver(PowerObserver* observer); |
| 33 void RemoveObserver(PowerObserver* observer); | 45 void RemoveObserver(PowerObserver* observer); |
| 34 | 46 |
| 35 // Is the computer currently on battery power. | |
| 36 bool IsOnBatteryPower(); | |
| 37 | |
| 38 private: | |
| 39 friend class PowerMonitorSource; | |
| 40 | |
| 41 PowerMonitorSource* Source(); | |
| 42 | |
| 43 void NotifyPowerStateChange(bool battery_in_use); | 47 void NotifyPowerStateChange(bool battery_in_use); |
| 44 void NotifySuspend(); | 48 void NotifySuspend(); |
| 45 void NotifyResume(); | 49 void NotifyResume(); |
| 46 | 50 |
| 47 scoped_refptr<ObserverListThreadSafe<PowerObserver> > observers_; | 51 scoped_refptr<ObserverListThreadSafe<PowerObserver> > observers_; |
| 48 scoped_ptr<PowerMonitorSource> source_; | 52 scoped_ptr<PowerMonitorSource> source_; |
| 49 | 53 |
| 50 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); | 54 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); |
| 51 }; | 55 }; |
| 52 | 56 |
| 53 } // namespace base | 57 } // namespace base |
| 54 | 58 |
| 55 #endif // BASE_POWER_MONITOR_POWER_MONITOR_H_ | 59 #endif // BASE_POWER_MONITOR_POWER_MONITOR_H_ |
| OLD | NEW |