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 <set> | |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/base_export.h" | 13 #include "base/base_export.h" |
| 13 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 14 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 15 #include "base/string16.h" | 16 #include "base/string16.h" |
| 16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 17 | 18 |
| 18 // Windows HiRes timers drain the battery faster so we need to know the battery | 19 // Windows HiRes timers drain the battery faster so we need to know the battery |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 RESUME_EVENT // The system is being resumed. | 52 RESUME_EVENT // The system is being resumed. |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 // Type of devices whose change need to be monitored, such as add/remove. | 55 // Type of devices whose change need to be monitored, such as add/remove. |
| 55 enum DeviceType { | 56 enum DeviceType { |
| 56 DEVTYPE_AUDIO_CAPTURE, // Audio capture device, e.g., microphone. | 57 DEVTYPE_AUDIO_CAPTURE, // Audio capture device, e.g., microphone. |
| 57 DEVTYPE_VIDEO_CAPTURE, // Video capture device, e.g., webcam. | 58 DEVTYPE_VIDEO_CAPTURE, // Video capture device, e.g., webcam. |
| 58 DEVTYPE_UNKNOWN, // Other devices. | 59 DEVTYPE_UNKNOWN, // Other devices. |
| 59 }; | 60 }; |
| 60 | 61 |
| 62 // The delegate for watching the storage free space changes. If it starts | |
|
vandebo (ex-Chrome)
2012/09/10 21:52:49
This isn't for watching storage free space changes
| |
| 63 // watching a storage device, all DevicesChangedObserver added to the | |
| 64 // SystemMonitor will be received OnStorageFreeChanged notification in case | |
| 65 // of the free space of the storage being watched is changed. | |
| 66 class BASE_EXPORT StorageFreeSpaceDelegate { | |
| 67 public: | |
| 68 virtual ~StorageFreeSpaceDelegate() {} | |
| 69 | |
| 70 // Start watching the storage device identified by the |path| parameter. | |
| 71 // Return true if it succeeds to start, otherwise, false is returned. | |
| 72 virtual bool StartWatchingStorage(const FilePath::StringType& path) = 0; | |
| 73 | |
| 74 // Stop watching the storage device identified by the |path| paramter. | |
| 75 virtual bool StopWatchingStorage(const FilePath::StringType& path) = 0; | |
| 76 }; | |
| 77 | |
| 61 struct BASE_EXPORT RemovableStorageInfo { | 78 struct BASE_EXPORT RemovableStorageInfo { |
| 62 RemovableStorageInfo(); | 79 RemovableStorageInfo(); |
| 63 RemovableStorageInfo(const std::string& id, | 80 RemovableStorageInfo(const std::string& id, |
| 64 const string16& device_name, | 81 const string16& device_name, |
| 65 const FilePath::StringType& device_location); | 82 const FilePath::StringType& device_location); |
| 66 | 83 |
| 67 // Unique device id - persists between device attachments. | 84 // Unique device id - persists between device attachments. |
| 68 std::string device_id; | 85 std::string device_id; |
| 69 | 86 |
| 70 // Human readable removable storage device name. | 87 // Human readable removable storage device name. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 protected: | 145 protected: |
| 129 virtual ~PowerObserver() {} | 146 virtual ~PowerObserver() {} |
| 130 }; | 147 }; |
| 131 | 148 |
| 132 class BASE_EXPORT DevicesChangedObserver { | 149 class BASE_EXPORT DevicesChangedObserver { |
| 133 public: | 150 public: |
| 134 // Notification that the devices connected to the system have changed. | 151 // Notification that the devices connected to the system have changed. |
| 135 // This is only implemented on Windows currently. | 152 // This is only implemented on Windows currently. |
| 136 virtual void OnDevicesChanged(DeviceType device_type) {} | 153 virtual void OnDevicesChanged(DeviceType device_type) {} |
| 137 | 154 |
| 155 // Get triggered when the free space of the storage |path| is changed. | |
| 156 virtual void OnStorageFreeSpaceChanged(const FilePath::StringType& path) {} | |
| 157 | |
| 138 // When a removable storage device is attached or detached, one of these | 158 // When a removable storage device is attached or detached, one of these |
| 139 // two events is triggered. | 159 // two events is triggered. |
| 140 virtual void OnRemovableStorageAttached( | 160 virtual void OnRemovableStorageAttached( |
| 141 const std::string& id, | 161 const std::string& id, |
| 142 const string16& name, | 162 const string16& name, |
| 143 const FilePath::StringType& location) {} | 163 const FilePath::StringType& location) {} |
| 144 virtual void OnRemovableStorageDetached(const std::string& id) {} | 164 virtual void OnRemovableStorageDetached(const std::string& id) {} |
| 145 | 165 |
| 146 protected: | 166 protected: |
| 147 virtual ~DevicesChangedObserver() {} | 167 virtual ~DevicesChangedObserver() {} |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 169 // Cross-platform handling of a power event. | 189 // Cross-platform handling of a power event. |
| 170 void ProcessPowerMessage(PowerEvent event_id); | 190 void ProcessPowerMessage(PowerEvent event_id); |
| 171 | 191 |
| 172 // Cross-platform handling of a device change event. | 192 // Cross-platform handling of a device change event. |
| 173 void ProcessDevicesChanged(DeviceType device_type); | 193 void ProcessDevicesChanged(DeviceType device_type); |
| 174 void ProcessRemovableStorageAttached(const std::string& id, | 194 void ProcessRemovableStorageAttached(const std::string& id, |
| 175 const string16& name, | 195 const string16& name, |
| 176 const FilePath::StringType& location); | 196 const FilePath::StringType& location); |
| 177 void ProcessRemovableStorageDetached(const std::string& id); | 197 void ProcessRemovableStorageDetached(const std::string& id); |
| 178 | 198 |
| 199 void ProcessStorageFreeSpaceChanged(const FilePath::StringType& path); | |
| 200 | |
| 201 void set_storage_free_space_delegate(StorageFreeSpaceDelegate* delegate) { | |
| 202 free_space_delegate_ = delegate; | |
| 203 } | |
| 204 | |
|
Hongbo Min
2012/09/10 14:37:50
vandebo, here I add these two methods for the clie
vandebo (ex-Chrome)
2012/09/10 21:52:49
I guess that's a fair point, but there's a lot of
| |
| 205 bool StartWatchingStorage(const FilePath::StringType& path); | |
| 206 bool StopWatchingStorage(const FilePath::StringType& path); | |
| 207 | |
| 179 private: | 208 private: |
| 180 // Mapping of unique device id to device info tuple. | 209 // Mapping of unique device id to device info tuple. |
| 181 typedef std::map<std::string, RemovableStorageInfo> RemovableStorageMap; | 210 typedef std::map<std::string, RemovableStorageInfo> RemovableStorageMap; |
| 182 | 211 |
| 183 #if defined(OS_MACOSX) | 212 #if defined(OS_MACOSX) |
| 184 void PlatformInit(); | 213 void PlatformInit(); |
| 185 void PlatformDestroy(); | 214 void PlatformDestroy(); |
| 186 #endif | 215 #endif |
| 187 | 216 |
| 188 // Platform-specific method to check whether the system is currently | 217 // Platform-specific method to check whether the system is currently |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 215 #endif | 244 #endif |
| 216 | 245 |
| 217 #if defined(OS_IOS) | 246 #if defined(OS_IOS) |
| 218 // Holds pointers to system event notification observers. | 247 // Holds pointers to system event notification observers. |
| 219 std::vector<id> notification_observers_; | 248 std::vector<id> notification_observers_; |
| 220 #endif | 249 #endif |
| 221 | 250 |
| 222 // Map of all the attached removable storage devices. | 251 // Map of all the attached removable storage devices. |
| 223 RemovableStorageMap removable_storage_map_; | 252 RemovableStorageMap removable_storage_map_; |
| 224 | 253 |
| 254 // The delegate instance for watching storage free space changes. | |
| 255 StorageFreeSpaceDelegate* free_space_delegate_; | |
| 256 | |
| 257 // The set of the storage devices being watched. | |
| 258 std::multiset<FilePath::StringType> watched_storages_; | |
| 259 | |
| 225 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); | 260 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); |
| 226 }; | 261 }; |
| 227 | 262 |
| 228 } // namespace base | 263 } // namespace base |
| 229 | 264 |
| 230 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ | 265 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
| OLD | NEW |