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_SOURCE_H_ | 5 #ifndef BASE_POWER_MONITOR_POWER_MONITOR_SOURCE_H_ |
6 #define BASE_POWER_MONITOR_POWER_MONITOR_SOURCE_H_ | 6 #define BASE_POWER_MONITOR_POWER_MONITOR_SOURCE_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" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 protected: | 34 protected: |
35 friend class PowerMonitorTest; | 35 friend class PowerMonitorTest; |
36 | 36 |
37 // Friend function that is allowed to access the protected ProcessPowerEvent. | 37 // Friend function that is allowed to access the protected ProcessPowerEvent. |
38 friend void ProcessPowerEventHelper(PowerEvent); | 38 friend void ProcessPowerEventHelper(PowerEvent); |
39 | 39 |
40 // Get the process-wide PowerMonitorSource (if not present, returns NULL). | 40 // Get the process-wide PowerMonitorSource (if not present, returns NULL). |
41 static PowerMonitorSource* Get(); | 41 static PowerMonitorSource* Get(); |
42 | 42 |
| 43 // ProcessPowerEvent should only be called from a single thread, most likely |
| 44 // the UI thread or, in child processes, the IO thread. |
43 static void ProcessPowerEvent(PowerEvent event_id); | 45 static void ProcessPowerEvent(PowerEvent event_id); |
44 | 46 |
45 // Platform-specific method to check whether the system is currently | 47 // Platform-specific method to check whether the system is currently |
46 // running on battery power. Returns true if running on batteries, | 48 // running on battery power. Returns true if running on batteries, |
47 // false otherwise. | 49 // false otherwise. |
48 virtual bool IsOnBatteryPowerImpl() = 0; | 50 virtual bool IsOnBatteryPowerImpl() = 0; |
49 | 51 |
50 private: | 52 private: |
51 bool on_battery_power_; | 53 bool on_battery_power_; |
52 bool suspended_; | 54 bool suspended_; |
53 | 55 |
54 // This lock guards access to on_battery_power_, to ensure that | 56 // This lock guards access to on_battery_power_, to ensure that |
55 // IsOnBatteryPower can be called from any thread. | 57 // IsOnBatteryPower can be called from any thread. |
56 Lock battery_lock_; | 58 Lock battery_lock_; |
57 | 59 |
58 DISALLOW_COPY_AND_ASSIGN(PowerMonitorSource); | 60 DISALLOW_COPY_AND_ASSIGN(PowerMonitorSource); |
59 }; | 61 }; |
60 | 62 |
61 } // namespace base | 63 } // namespace base |
62 | 64 |
63 #endif // BASE_POWER_MONITOR_POWER_MONITOR_SOURCE_H_ | 65 #endif // BASE_POWER_MONITOR_POWER_MONITOR_SOURCE_H_ |
OLD | NEW |