OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ | 5 #ifndef BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
6 #define BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ | 6 #define BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/base_export.h" | 9 #include "base/base_export.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/file_path.h" | |
Lei Zhang
2012/02/14 02:14:24
you can forward declare "class FilePath" and incli
vandebo (ex-Chrome)
2012/02/14 21:23:23
I tried that, but the observer code needs the full
vandebo (ex-Chrome)
2012/02/15 23:13:36
I think I was trying to declare it in the base nam
| |
11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
12 | 13 |
13 // Windows HiRes timers drain the battery faster so we need to know the battery | 14 // Windows HiRes timers drain the battery faster so we need to know the battery |
14 // status. This isn't true for other platforms. | 15 // status. This isn't true for other platforms. |
15 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
16 #define ENABLE_BATTERY_MONITORING 1 | 17 #define ENABLE_BATTERY_MONITORING 1 |
17 #else | 18 #else |
18 #undef ENABLE_BATTERY_MONITORING | 19 #undef ENABLE_BATTERY_MONITORING |
19 #endif // !OS_WIN | 20 #endif // !OS_WIN |
20 | 21 |
(...skipping 14 matching lines...) Expand all Loading... | |
35 // TODO(mbelshe): Add support beyond just power management. | 36 // TODO(mbelshe): Add support beyond just power management. |
36 class BASE_EXPORT SystemMonitor { | 37 class BASE_EXPORT SystemMonitor { |
37 public: | 38 public: |
38 // Normalized list of power events. | 39 // Normalized list of power events. |
39 enum PowerEvent { | 40 enum PowerEvent { |
40 POWER_STATE_EVENT, // The Power status of the system has changed. | 41 POWER_STATE_EVENT, // The Power status of the system has changed. |
41 SUSPEND_EVENT, // The system is being suspended. | 42 SUSPEND_EVENT, // The system is being suspended. |
42 RESUME_EVENT // The system is being resumed. | 43 RESUME_EVENT // The system is being resumed. |
43 }; | 44 }; |
44 | 45 |
46 typedef unsigned long DeviceIdType; | |
47 | |
45 // Create SystemMonitor. Only one SystemMonitor instance per application | 48 // Create SystemMonitor. Only one SystemMonitor instance per application |
46 // is allowed. | 49 // is allowed. |
47 SystemMonitor(); | 50 SystemMonitor(); |
48 ~SystemMonitor(); | 51 ~SystemMonitor(); |
49 | 52 |
50 // Get the application-wide SystemMonitor (if not present, returns NULL). | 53 // Get the application-wide SystemMonitor (if not present, returns NULL). |
51 static SystemMonitor* Get(); | 54 static SystemMonitor* Get(); |
52 | 55 |
53 #if defined(OS_MACOSX) | 56 #if defined(OS_MACOSX) |
54 // Allocate system resources needed by the SystemMonitor class. | 57 // Allocate system resources needed by the SystemMonitor class. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 // Notification that the system is resuming. | 89 // Notification that the system is resuming. |
87 virtual void OnResume() {} | 90 virtual void OnResume() {} |
88 | 91 |
89 protected: | 92 protected: |
90 virtual ~PowerObserver() {} | 93 virtual ~PowerObserver() {} |
91 }; | 94 }; |
92 | 95 |
93 class BASE_EXPORT DevicesChangedObserver { | 96 class BASE_EXPORT DevicesChangedObserver { |
94 public: | 97 public: |
95 // Notification that the devices connected to the system have changed. | 98 // Notification that the devices connected to the system have changed. |
99 // This is only implemented on Windows currently. | |
Lei Zhang
2012/02/14 02:14:24
Really? Is content::GamepadProvider() Windows-only
vandebo (ex-Chrome)
2012/02/14 21:23:23
The only caller of ProcessDevicesChanged is in the
| |
96 virtual void OnDevicesChanged() {} | 100 virtual void OnDevicesChanged() {} |
97 | 101 |
102 // When a media device is attached or detached, one of these two events | |
103 // if triggered. | |
104 // TODO(vandebo) Pass an appropriate device identifier or way to interact | |
105 // with the devices instead of FilePath. | |
106 virtual void OnMediaDeviceAttached(const DeviceIdType& id, | |
107 const std::string& name, | |
108 const FilePath& path) {} | |
109 | |
110 virtual void OnMediaDeviceDetached(const DeviceIdType& id) {} | |
111 | |
98 protected: | 112 protected: |
99 virtual ~DevicesChangedObserver() {} | 113 virtual ~DevicesChangedObserver() {} |
100 }; | 114 }; |
101 | 115 |
102 // Add a new observer. | 116 // Add a new observer. |
103 // Can be called from any thread. | 117 // Can be called from any thread. |
104 // Must not be called from within a notification callback. | 118 // Must not be called from within a notification callback. |
105 void AddPowerObserver(PowerObserver* obs); | 119 void AddPowerObserver(PowerObserver* obs); |
106 void AddDevicesChangedObserver(DevicesChangedObserver* obs); | 120 void AddDevicesChangedObserver(DevicesChangedObserver* obs); |
107 | 121 |
108 // Remove an existing observer. | 122 // Remove an existing observer. |
109 // Can be called from any thread. | 123 // Can be called from any thread. |
110 // Must not be called from within a notification callback. | 124 // Must not be called from within a notification callback. |
111 void RemovePowerObserver(PowerObserver* obs); | 125 void RemovePowerObserver(PowerObserver* obs); |
112 void RemoveDevicesChangedObserver(DevicesChangedObserver* obs); | 126 void RemoveDevicesChangedObserver(DevicesChangedObserver* obs); |
113 | 127 |
114 #if defined(OS_WIN) | 128 #if defined(OS_WIN) |
115 // Windows-specific handling of a WM_POWERBROADCAST message. | 129 // Windows-specific handling of a WM_POWERBROADCAST message. |
116 // Embedders of this API should hook their top-level window | 130 // Embedders of this API should hook their top-level window |
117 // message loop and forward WM_POWERBROADCAST through this call. | 131 // message loop and forward WM_POWERBROADCAST through this call. |
118 void ProcessWmPowerBroadcastMessage(int event_id); | 132 void ProcessWmPowerBroadcastMessage(int event_id); |
119 #endif | 133 #endif |
120 | 134 |
121 // Cross-platform handling of a power event. | 135 // Cross-platform handling of a power event. |
122 void ProcessPowerMessage(PowerEvent event_id); | 136 void ProcessPowerMessage(PowerEvent event_id); |
123 | 137 |
124 // Cross-platform handling of a device change event. | 138 // Cross-platform handling of a device change event. |
125 void ProcessDevicesChanged(); | 139 void ProcessDevicesChanged(); |
140 void ProcessMediaDeviceAttached(const DeviceIdType& id, | |
141 const std::string& name, | |
142 const FilePath& path); | |
143 void ProcessMediaDeviceDetached(const DeviceIdType& id); | |
126 | 144 |
127 private: | 145 private: |
128 #if defined(OS_MACOSX) | 146 #if defined(OS_MACOSX) |
129 void PlatformInit(); | 147 void PlatformInit(); |
130 void PlatformDestroy(); | 148 void PlatformDestroy(); |
131 #endif | 149 #endif |
132 | 150 |
133 // Platform-specific method to check whether the system is currently | 151 // Platform-specific method to check whether the system is currently |
134 // running on battery power. Returns true if running on batteries, | 152 // running on battery power. Returns true if running on batteries, |
135 // false otherwise. | 153 // false otherwise. |
136 bool IsBatteryPower(); | 154 bool IsBatteryPower(); |
137 | 155 |
138 // Checks the battery status and notifies observers if the battery | 156 // Checks the battery status and notifies observers if the battery |
139 // status has changed. | 157 // status has changed. |
140 void BatteryCheck(); | 158 void BatteryCheck(); |
141 | 159 |
142 // Functions to trigger notifications. | 160 // Functions to trigger notifications. |
143 void NotifyDevicesChanged(); | 161 void NotifyDevicesChanged(); |
162 void NotifyMediaDeviceAttached(const DeviceIdType& id, | |
163 const std::string& name, const FilePath& path); | |
willchan no longer on Chromium
2012/02/14 06:43:20
Move to the next line as per chromium style guide
vandebo (ex-Chrome)
2012/02/14 21:23:23
Done.
| |
164 void NotifyMediaDeviceDetached(const DeviceIdType& id); | |
144 void NotifyPowerStateChange(); | 165 void NotifyPowerStateChange(); |
145 void NotifySuspend(); | 166 void NotifySuspend(); |
146 void NotifyResume(); | 167 void NotifyResume(); |
147 | 168 |
148 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; | 169 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; |
149 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> > | 170 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> > |
150 devices_changed_observer_list_; | 171 devices_changed_observer_list_; |
151 bool battery_in_use_; | 172 bool battery_in_use_; |
152 bool suspended_; | 173 bool suspended_; |
153 | 174 |
154 #if defined(ENABLE_BATTERY_MONITORING) | 175 #if defined(ENABLE_BATTERY_MONITORING) |
155 base::OneShotTimer<SystemMonitor> delayed_battery_check_; | 176 base::OneShotTimer<SystemMonitor> delayed_battery_check_; |
156 #endif | 177 #endif |
157 | 178 |
158 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); | 179 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); |
159 }; | 180 }; |
160 | 181 |
161 } // namespace base | 182 } // namespace base |
162 | 183 |
163 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ | 184 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
OLD | NEW |