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

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

Issue 2351593004: Implement base::PowerMonitor::IsOnBatteryPower() for OSX. (Closed)
Patch Set: Invert setter. Created 4 years, 2 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
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_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 {
Robert Sesek 2016/09/26 22:21:19 This class has kind of a weird design with all the
39 public: 29 public:
40 PowerMonitorDeviceSource(); 30 PowerMonitorDeviceSource();
41 ~PowerMonitorDeviceSource() override; 31 ~PowerMonitorDeviceSource() override;
42 32
43 #if defined(OS_MACOSX) 33 #if defined(OS_MACOSX)
44 // Allocate system resources needed by the PowerMonitor class. 34 // Allocate system resources needed by the PowerMonitor class.
45 // 35 //
46 // This function must be called before instantiating an instance of the class 36 // This function must be called before instantiating an instance of the class
47 // and before the Sandbox is initialized. 37 // and before the Sandbox is initialized.
48 #if !defined(OS_IOS) 38 #if !defined(OS_IOS)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 #endif // OS_WIN 74 #endif // OS_WIN
85 75
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;
Nico 2016/09/27 20:59:33 Ah, because this is in the vtable. But what refere
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698