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" | |
tpayne
2012/02/08 16:20:30
I thought forward declarations are preferred over
vandebo (ex-Chrome)
2012/02/08 18:37:01
Right, but the bind code, which is used by the obs
| |
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 | 89 |
89 protected: | 90 protected: |
90 virtual ~PowerObserver() {} | 91 virtual ~PowerObserver() {} |
91 }; | 92 }; |
92 | 93 |
93 class BASE_EXPORT DevicesChangedObserver { | 94 class BASE_EXPORT DevicesChangedObserver { |
94 public: | 95 public: |
95 // Notification that the devices connected to the system have changed. | 96 // Notification that the devices connected to the system have changed. |
96 virtual void OnDevicesChanged() {} | 97 virtual void OnDevicesChanged() {} |
97 | 98 |
99 // When a media device is attached or detached, we also fire one of these | |
100 // two events. | |
101 // TODO(vandebo) Pass an appropriate device identifier instead of FilePath. | |
102 virtual void OnMediaDeviceAttached(const std::string& name, | |
103 const FilePath& path) {} | |
104 | |
105 virtual void OnMediaDeviceDetached(const std::string& name) {} | |
106 | |
98 protected: | 107 protected: |
99 virtual ~DevicesChangedObserver() {} | 108 virtual ~DevicesChangedObserver() {} |
100 }; | 109 }; |
101 | 110 |
102 // Add a new observer. | 111 // Add a new observer. |
103 // Can be called from any thread. | 112 // Can be called from any thread. |
104 // Must not be called from within a notification callback. | 113 // Must not be called from within a notification callback. |
105 void AddPowerObserver(PowerObserver* obs); | 114 void AddPowerObserver(PowerObserver* obs); |
106 void AddDevicesChangedObserver(DevicesChangedObserver* obs); | 115 void AddDevicesChangedObserver(DevicesChangedObserver* obs); |
107 | 116 |
108 // Remove an existing observer. | 117 // Remove an existing observer. |
109 // Can be called from any thread. | 118 // Can be called from any thread. |
110 // Must not be called from within a notification callback. | 119 // Must not be called from within a notification callback. |
111 void RemovePowerObserver(PowerObserver* obs); | 120 void RemovePowerObserver(PowerObserver* obs); |
112 void RemoveDevicesChangedObserver(DevicesChangedObserver* obs); | 121 void RemoveDevicesChangedObserver(DevicesChangedObserver* obs); |
113 | 122 |
114 #if defined(OS_WIN) | 123 #if defined(OS_WIN) |
115 // Windows-specific handling of a WM_POWERBROADCAST message. | 124 // Windows-specific handling of a WM_POWERBROADCAST message. |
116 // Embedders of this API should hook their top-level window | 125 // Embedders of this API should hook their top-level window |
117 // message loop and forward WM_POWERBROADCAST through this call. | 126 // message loop and forward WM_POWERBROADCAST through this call. |
118 void ProcessWmPowerBroadcastMessage(int event_id); | 127 void ProcessWmPowerBroadcastMessage(int event_id); |
119 #endif | 128 #endif |
120 | 129 |
121 // Cross-platform handling of a power event. | 130 // Cross-platform handling of a power event. |
122 void ProcessPowerMessage(PowerEvent event_id); | 131 void ProcessPowerMessage(PowerEvent event_id); |
123 | 132 |
124 // Cross-platform handling of a device change event. | 133 // Cross-platform handling of a device change event. |
125 void ProcessDevicesChanged(); | 134 void ProcessDevicesChanged(); |
135 void ProcessMediaDeviceAttached(const std::string& name, | |
136 const FilePath& path); | |
137 void ProcessMediaDeviceDetached(const std::string& name); | |
126 | 138 |
127 private: | 139 private: |
128 #if defined(OS_MACOSX) | 140 #if defined(OS_MACOSX) |
129 void PlatformInit(); | 141 void PlatformInit(); |
130 void PlatformDestroy(); | 142 void PlatformDestroy(); |
131 #endif | 143 #endif |
132 | 144 |
133 // Platform-specific method to check whether the system is currently | 145 // Platform-specific method to check whether the system is currently |
134 // running on battery power. Returns true if running on batteries, | 146 // running on battery power. Returns true if running on batteries, |
135 // false otherwise. | 147 // false otherwise. |
136 bool IsBatteryPower(); | 148 bool IsBatteryPower(); |
137 | 149 |
138 // Checks the battery status and notifies observers if the battery | 150 // Checks the battery status and notifies observers if the battery |
139 // status has changed. | 151 // status has changed. |
140 void BatteryCheck(); | 152 void BatteryCheck(); |
141 | 153 |
142 // Functions to trigger notifications. | 154 // Functions to trigger notifications. |
143 void NotifyDevicesChanged(); | 155 void NotifyDevicesChanged(); |
156 void NotifyMediaDeviceAttached(const std::string& name, const FilePath& path); | |
157 void NotifyMediaDeviceDetached(const std::string& name); | |
144 void NotifyPowerStateChange(); | 158 void NotifyPowerStateChange(); |
145 void NotifySuspend(); | 159 void NotifySuspend(); |
146 void NotifyResume(); | 160 void NotifyResume(); |
147 | 161 |
148 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; | 162 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; |
149 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> > | 163 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> > |
150 devices_changed_observer_list_; | 164 devices_changed_observer_list_; |
151 bool battery_in_use_; | 165 bool battery_in_use_; |
152 bool suspended_; | 166 bool suspended_; |
153 | 167 |
154 #if defined(ENABLE_BATTERY_MONITORING) | 168 #if defined(ENABLE_BATTERY_MONITORING) |
155 base::OneShotTimer<SystemMonitor> delayed_battery_check_; | 169 base::OneShotTimer<SystemMonitor> delayed_battery_check_; |
156 #endif | 170 #endif |
157 | 171 |
158 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); | 172 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); |
159 }; | 173 }; |
160 | 174 |
161 } // namespace base | 175 } // namespace base |
162 | 176 |
163 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ | 177 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
OLD | NEW |