| 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_DEVICE_SOURCE_H_ | 5 #ifndef BASE_POWER_MONITOR_POWER_MONITOR_DEVICE_SOURCE_H_ |
| 6 #define BASE_POWER_MONITOR_POWER_MONITOR_DEVICE_SOURCE_H_ | 6 #define BASE_POWER_MONITOR_POWER_MONITOR_DEVICE_SOURCE_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_monitor_source.h" | 12 #include "base/power_monitor/power_monitor_source.h" |
| 13 #include "base/power_monitor/power_observer.h" | 13 #include "base/power_monitor/power_observer.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 | 15 |
| 16 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
| 17 #include <windows.h> | 17 #include <windows.h> |
| 18 | |
| 19 // Windows HiRes timers drain the battery faster so we need to know the battery | |
| 20 // status. This isn't true for other platforms. | |
| 21 #define ENABLE_BATTERY_MONITORING 1 | |
| 22 #else | |
| 23 #undef ENABLE_BATTERY_MONITORING | |
| 24 #endif // !OS_WIN | 18 #endif // !OS_WIN |
| 25 | 19 |
| 26 #if defined(ENABLE_BATTERY_MONITORING) | |
| 27 #include "base/timer/timer.h" | |
| 28 #endif // defined(ENABLE_BATTERY_MONITORING) | |
| 29 | |
| 30 #if defined(OS_IOS) | 20 #if defined(OS_IOS) |
| 31 #include <objc/runtime.h> | 21 #include <objc/runtime.h> |
| 32 #endif // OS_IOS | 22 #endif // OS_IOS |
| 33 | 23 |
| 34 namespace base { | 24 namespace base { |
| 35 | 25 |
| 36 // A class used to monitor the power state change and notify the observers about | 26 // A class used to monitor the power state change and notify the observers about |
| 37 // the change event. | 27 // the change event. |
| 38 class BASE_EXPORT PowerMonitorDeviceSource : public PowerMonitorSource { | 28 class BASE_EXPORT PowerMonitorDeviceSource : public PowerMonitorSource { |
| 39 public: | 29 public: |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 #if defined(OS_MACOSX) | 76 #if defined(OS_MACOSX) |
| 87 void PlatformInit(); | 77 void PlatformInit(); |
| 88 void PlatformDestroy(); | 78 void PlatformDestroy(); |
| 89 #endif | 79 #endif |
| 90 | 80 |
| 91 // Platform-specific method to check whether the system is currently | 81 // Platform-specific method to check whether the system is currently |
| 92 // running on battery power. Returns true if running on batteries, | 82 // running on battery power. Returns true if running on batteries, |
| 93 // false otherwise. | 83 // false otherwise. |
| 94 bool IsOnBatteryPowerImpl() override; | 84 bool IsOnBatteryPowerImpl() override; |
| 95 | 85 |
| 96 // Checks the battery status and notifies observers if the battery | |
| 97 // status has changed. | |
| 98 void BatteryCheck(); | |
| 99 | |
| 100 #if defined(OS_IOS) | 86 #if defined(OS_IOS) |
| 101 // Holds pointers to system event notification observers. | 87 // Holds pointers to system event notification observers. |
| 102 std::vector<id> notification_observers_; | 88 std::vector<id> notification_observers_; |
| 103 #endif | 89 #endif |
| 104 | 90 |
| 105 #if defined(ENABLE_BATTERY_MONITORING) | |
| 106 base::OneShotTimer delayed_battery_check_; | |
| 107 #endif | |
| 108 | |
| 109 #if defined(OS_WIN) | 91 #if defined(OS_WIN) |
| 110 PowerMessageWindow power_message_window_; | 92 PowerMessageWindow power_message_window_; |
| 111 #endif | 93 #endif |
| 112 | 94 |
| 113 DISALLOW_COPY_AND_ASSIGN(PowerMonitorDeviceSource); | 95 DISALLOW_COPY_AND_ASSIGN(PowerMonitorDeviceSource); |
| 114 }; | 96 }; |
| 115 | 97 |
| 116 } // namespace base | 98 } // namespace base |
| 117 | 99 |
| 118 #endif // BASE_POWER_MONITOR_POWER_MONITOR_DEVICE_SOURCE_H_ | 100 #endif // BASE_POWER_MONITOR_POWER_MONITOR_DEVICE_SOURCE_H_ |
| OLD | NEW |