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. | |
45 static void ProcessPowerEvent(PowerEvent event_id); | 43 static void ProcessPowerEvent(PowerEvent event_id); |
46 | 44 |
47 // Platform-specific method to check whether the system is currently | 45 // Platform-specific method to check whether the system is currently |
48 // running on battery power. Returns true if running on batteries, | 46 // running on battery power. Returns true if running on batteries, |
49 // false otherwise. | 47 // false otherwise. |
50 virtual bool IsOnBatteryPowerImpl() = 0; | 48 virtual bool IsOnBatteryPowerImpl() = 0; |
51 | 49 |
52 private: | 50 private: |
53 bool on_battery_power_; | 51 bool on_battery_power_; |
54 bool suspended_; | 52 bool suspended_; |
55 | 53 |
56 // This lock guards access to on_battery_power_, to ensure that | 54 // This lock guards access to on_battery_power_, to ensure that |
57 // IsOnBatteryPower can be called from any thread. | 55 // IsOnBatteryPower can be called from any thread. |
58 Lock battery_lock_; | 56 Lock battery_lock_; |
59 | 57 |
60 DISALLOW_COPY_AND_ASSIGN(PowerMonitorSource); | 58 DISALLOW_COPY_AND_ASSIGN(PowerMonitorSource); |
61 }; | 59 }; |
62 | 60 |
63 } // namespace base | 61 } // namespace base |
64 | 62 |
65 #endif // BASE_POWER_MONITOR_POWER_MONITOR_SOURCE_H_ | 63 #endif // BASE_POWER_MONITOR_POWER_MONITOR_SOURCE_H_ |
OLD | NEW |