Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 // TODO(mbelshe): Add support beyond just power management. | 44 // TODO(mbelshe): Add support beyond just power management. |
| 45 class BASE_EXPORT SystemMonitor { | 45 class BASE_EXPORT SystemMonitor { |
| 46 public: | 46 public: |
| 47 // Normalized list of power events. | 47 // Normalized list of power events. |
| 48 enum PowerEvent { | 48 enum PowerEvent { |
| 49 POWER_STATE_EVENT, // The Power status of the system has changed. | 49 POWER_STATE_EVENT, // The Power status of the system has changed. |
| 50 SUSPEND_EVENT, // The system is being suspended. | 50 SUSPEND_EVENT, // The system is being suspended. |
| 51 RESUME_EVENT // The system is being resumed. | 51 RESUME_EVENT // The system is being resumed. |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 // Type of devices whose change need to be monitored, such as add/remove. | |
| 55 enum DeviceType { | |
|
tommi (sloooow) - chröme
2012/07/30 10:02:28
MediaDeviceType and DeviceType sound very similar.
| |
| 56 DEVTYPE_AUDIO_CAPTURE, // Audio capture device, e.g., microphone. | |
| 57 DEVTYPE_VIDEO_CAPTURE, // Video capture device, e.g., webcam. | |
| 58 DEVTYPE_UNKNOWN, // Other devices. | |
| 59 }; | |
| 60 | |
| 54 // Type of location data to identify a currently attached media device. | 61 // Type of location data to identify a currently attached media device. |
| 55 enum MediaDeviceType { | 62 enum MediaDeviceType { |
| 56 TYPE_PATH, // FilePath::StringType, e.g. a mount point. | 63 TYPE_PATH, // FilePath::StringType, e.g. a mount point. |
| 57 TYPE_MTP, // (W)string to locate a MTP device, e.g. its usb bus/port. | 64 TYPE_MTP, // (W)string to locate a MTP device, e.g. its usb bus/port. |
| 58 }; | 65 }; |
| 59 | 66 |
| 60 struct MediaDeviceInfo { | 67 struct MediaDeviceInfo { |
| 61 MediaDeviceInfo(const std::string& id, | 68 MediaDeviceInfo(const std::string& id, |
| 62 const string16& device_name, | 69 const string16& device_name, |
| 63 MediaDeviceType device_type, | 70 MediaDeviceType device_type, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 virtual void OnResume() {} | 140 virtual void OnResume() {} |
| 134 | 141 |
| 135 protected: | 142 protected: |
| 136 virtual ~PowerObserver() {} | 143 virtual ~PowerObserver() {} |
| 137 }; | 144 }; |
| 138 | 145 |
| 139 class BASE_EXPORT DevicesChangedObserver { | 146 class BASE_EXPORT DevicesChangedObserver { |
| 140 public: | 147 public: |
| 141 // Notification that the devices connected to the system have changed. | 148 // Notification that the devices connected to the system have changed. |
| 142 // This is only implemented on Windows currently. | 149 // This is only implemented on Windows currently. |
| 143 virtual void OnDevicesChanged() {} | 150 virtual void OnDevicesChanged(DeviceType device_type) {} |
| 144 | 151 |
| 145 // When a media device is attached or detached, one of these two events | 152 // When a media device is attached or detached, one of these two events |
| 146 // is triggered. | 153 // is triggered. |
| 147 virtual void OnMediaDeviceAttached(const std::string& id, | 154 virtual void OnMediaDeviceAttached(const std::string& id, |
| 148 const string16& name, | 155 const string16& name, |
| 149 MediaDeviceType type, | 156 MediaDeviceType type, |
| 150 const FilePath::StringType& location) {} | 157 const FilePath::StringType& location) {} |
| 151 | 158 |
| 152 virtual void OnMediaDeviceDetached(const std::string& id) {} | 159 virtual void OnMediaDeviceDetached(const std::string& id) {} |
| 153 | 160 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 171 // Windows-specific handling of a WM_POWERBROADCAST message. | 178 // Windows-specific handling of a WM_POWERBROADCAST message. |
| 172 // Embedders of this API should hook their top-level window | 179 // Embedders of this API should hook their top-level window |
| 173 // message loop and forward WM_POWERBROADCAST through this call. | 180 // message loop and forward WM_POWERBROADCAST through this call. |
| 174 void ProcessWmPowerBroadcastMessage(int event_id); | 181 void ProcessWmPowerBroadcastMessage(int event_id); |
| 175 #endif | 182 #endif |
| 176 | 183 |
| 177 // Cross-platform handling of a power event. | 184 // Cross-platform handling of a power event. |
| 178 void ProcessPowerMessage(PowerEvent event_id); | 185 void ProcessPowerMessage(PowerEvent event_id); |
| 179 | 186 |
| 180 // Cross-platform handling of a device change event. | 187 // Cross-platform handling of a device change event. |
| 181 void ProcessDevicesChanged(); | 188 void ProcessDevicesChanged(DeviceType device_type); |
| 182 void ProcessMediaDeviceAttached(const std::string& id, | 189 void ProcessMediaDeviceAttached(const std::string& id, |
| 183 const string16& name, | 190 const string16& name, |
| 184 MediaDeviceType type, | 191 MediaDeviceType type, |
| 185 const FilePath::StringType& location); | 192 const FilePath::StringType& location); |
| 186 void ProcessMediaDeviceDetached(const std::string& id); | 193 void ProcessMediaDeviceDetached(const std::string& id); |
| 187 | 194 |
| 188 private: | 195 private: |
| 189 // Mapping of unique device id to device info tuple. | 196 // Mapping of unique device id to device info tuple. |
| 190 typedef std::map<std::string, MediaDeviceInfo> MediaDeviceMap; | 197 typedef std::map<std::string, MediaDeviceInfo> MediaDeviceMap; |
| 191 | 198 |
| 192 #if defined(OS_MACOSX) | 199 #if defined(OS_MACOSX) |
| 193 void PlatformInit(); | 200 void PlatformInit(); |
| 194 void PlatformDestroy(); | 201 void PlatformDestroy(); |
| 195 #endif | 202 #endif |
| 196 | 203 |
| 197 // Platform-specific method to check whether the system is currently | 204 // Platform-specific method to check whether the system is currently |
| 198 // running on battery power. Returns true if running on batteries, | 205 // running on battery power. Returns true if running on batteries, |
| 199 // false otherwise. | 206 // false otherwise. |
| 200 bool IsBatteryPower(); | 207 bool IsBatteryPower(); |
| 201 | 208 |
| 202 // Checks the battery status and notifies observers if the battery | 209 // Checks the battery status and notifies observers if the battery |
| 203 // status has changed. | 210 // status has changed. |
| 204 void BatteryCheck(); | 211 void BatteryCheck(); |
| 205 | 212 |
| 206 // Functions to trigger notifications. | 213 // Functions to trigger notifications. |
| 207 void NotifyDevicesChanged(); | 214 void NotifyDevicesChanged(DeviceType device_type); |
| 208 void NotifyMediaDeviceAttached(const std::string& id, | 215 void NotifyMediaDeviceAttached(const std::string& id, |
| 209 const string16& name, | 216 const string16& name, |
| 210 MediaDeviceType type, | 217 MediaDeviceType type, |
| 211 const FilePath::StringType& data); | 218 const FilePath::StringType& data); |
| 212 void NotifyMediaDeviceDetached(const std::string& id); | 219 void NotifyMediaDeviceDetached(const std::string& id); |
| 213 void NotifyPowerStateChange(); | 220 void NotifyPowerStateChange(); |
| 214 void NotifySuspend(); | 221 void NotifySuspend(); |
| 215 void NotifyResume(); | 222 void NotifyResume(); |
| 216 | 223 |
| 217 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; | 224 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 231 | 238 |
| 232 // Map of all the attached media devices. | 239 // Map of all the attached media devices. |
| 233 MediaDeviceMap media_device_map_; | 240 MediaDeviceMap media_device_map_; |
| 234 | 241 |
| 235 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); | 242 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); |
| 236 }; | 243 }; |
| 237 | 244 |
| 238 } // namespace base | 245 } // namespace base |
| 239 | 246 |
| 240 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ | 247 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
| OLD | NEW |