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 notification interfaces for storage free space. | |
| 63 class BASE_EXPORT StorageFreeSpaceNotification { | |
|
vandebo (ex-Chrome)
2012/09/11 22:49:27
This isn't a notification interface so much as a d
Hongbo Min
2012/09/12 09:24:31
Done.
| |
| 64 public: | |
| 65 virtual ~StorageFreeSpaceNotification() {} | |
| 66 | |
| 67 // Start watching the storage device identified by the |path| parameter. | |
| 68 // Return true if it succeeds to start, otherwise, false is returned. | |
| 69 // The |path| can be a drive path on Windows, or the mount point on Linux. | |
| 70 virtual bool StartWatchingStorage(const FilePath::StringType& path) = 0; | |
|
vandebo (ex-Chrome)
2012/09/11 22:49:27
Can you actually do anything if it fails to start?
Hongbo Min
2012/09/12 09:24:31
My initial thought is, if it failed to start watch
vandebo (ex-Chrome)
2012/09/12 17:54:47
I can think of two approaches to dealing with erro
| |
| 71 | |
| 72 // Stop watching the storage device identified by the |path| paramter. | |
| 73 virtual bool StopWatchingStorage(const FilePath::StringType& path) = 0; | |
|
vandebo (ex-Chrome)
2012/09/11 22:49:27
I doubt there's anything to do if it fails to stop
Hongbo Min
2012/09/12 09:24:31
Done. See comment above.
| |
| 74 }; | |
| 75 | |
| 61 struct BASE_EXPORT RemovableStorageInfo { | 76 struct BASE_EXPORT RemovableStorageInfo { |
| 62 RemovableStorageInfo(); | 77 RemovableStorageInfo(); |
| 63 RemovableStorageInfo(const std::string& id, | 78 RemovableStorageInfo(const std::string& id, |
| 64 const string16& device_name, | 79 const string16& device_name, |
| 65 const FilePath::StringType& device_location); | 80 const FilePath::StringType& device_location); |
| 66 | 81 |
| 67 // Unique device id - persists between device attachments. | 82 // Unique device id - persists between device attachments. |
| 68 std::string device_id; | 83 std::string device_id; |
| 69 | 84 |
| 70 // Human readable removable storage device name. | 85 // Human readable removable storage device name. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 virtual void OnRemovableStorageAttached( | 155 virtual void OnRemovableStorageAttached( |
| 141 const std::string& id, | 156 const std::string& id, |
| 142 const string16& name, | 157 const string16& name, |
| 143 const FilePath::StringType& location) {} | 158 const FilePath::StringType& location) {} |
| 144 virtual void OnRemovableStorageDetached(const std::string& id) {} | 159 virtual void OnRemovableStorageDetached(const std::string& id) {} |
| 145 | 160 |
| 146 protected: | 161 protected: |
| 147 virtual ~DevicesChangedObserver() {} | 162 virtual ~DevicesChangedObserver() {} |
| 148 }; | 163 }; |
| 149 | 164 |
| 165 class BASE_EXPORT StorageFreeSpaceChangedObserver { | |
| 166 public: | |
| 167 // Triggered when the free space of the storage |path| is changed. | |
| 168 virtual void OnStorageFreeSpaceChanged(const FilePath::StringType& path) {} | |
|
vandebo (ex-Chrome)
2012/09/11 22:49:27
You've used FilePath::StringType throughout your c
Hongbo Min
2012/09/12 09:24:31
Now I use FilePath instead, but actually a FilePat
vandebo (ex-Chrome)
2012/09/12 17:54:47
An MTP device may not be a valid file path to read
Hongbo Min
2012/09/13 13:48:14
One more question, if we don't want to represent t
| |
| 169 }; | |
| 170 | |
| 150 // Add a new observer. | 171 // Add a new observer. |
| 151 // Can be called from any thread. | 172 // Can be called from any thread. |
| 152 // Must not be called from within a notification callback. | 173 // Must not be called from within a notification callback. |
| 153 void AddPowerObserver(PowerObserver* obs); | 174 void AddPowerObserver(PowerObserver* obs); |
| 154 void AddDevicesChangedObserver(DevicesChangedObserver* obs); | 175 void AddDevicesChangedObserver(DevicesChangedObserver* obs); |
| 176 void AddStorageFreeSpaceChangedObserver(const FilePath::StringType& path, | |
| 177 StorageFreeSpaceChangedObserver* obs); | |
|
vandebo (ex-Chrome)
2012/09/11 22:49:27
nit: Stor... should line up with const on the prev
Hongbo Min
2012/09/12 09:24:31
Done.
| |
| 155 | 178 |
| 156 // Remove an existing observer. | 179 // Remove an existing observer. |
| 157 // Can be called from any thread. | 180 // Can be called from any thread. |
| 158 // Must not be called from within a notification callback. | 181 // Must not be called from within a notification callback. |
| 159 void RemovePowerObserver(PowerObserver* obs); | 182 void RemovePowerObserver(PowerObserver* obs); |
| 160 void RemoveDevicesChangedObserver(DevicesChangedObserver* obs); | 183 void RemoveDevicesChangedObserver(DevicesChangedObserver* obs); |
| 184 void RemoveStorageFreeSpaceChangedObserver(const FilePath::StringType& path, | |
| 185 StorageFreeSpaceChangedObserver* obs); | |
|
vandebo (ex-Chrome)
2012/09/11 22:49:27
ditto
Hongbo Min
2012/09/12 09:24:31
Done.
| |
| 161 | 186 |
| 162 #if defined(OS_WIN) | 187 #if defined(OS_WIN) |
| 163 // Windows-specific handling of a WM_POWERBROADCAST message. | 188 // Windows-specific handling of a WM_POWERBROADCAST message. |
| 164 // Embedders of this API should hook their top-level window | 189 // Embedders of this API should hook their top-level window |
| 165 // message loop and forward WM_POWERBROADCAST through this call. | 190 // message loop and forward WM_POWERBROADCAST through this call. |
| 166 void ProcessWmPowerBroadcastMessage(int event_id); | 191 void ProcessWmPowerBroadcastMessage(int event_id); |
| 167 #endif | 192 #endif |
| 168 | 193 |
| 169 // Cross-platform handling of a power event. | 194 // Cross-platform handling of a power event. |
| 170 void ProcessPowerMessage(PowerEvent event_id); | 195 void ProcessPowerMessage(PowerEvent event_id); |
| 171 | 196 |
| 172 // Cross-platform handling of a device change event. | 197 // Cross-platform handling of a device change event. |
| 173 void ProcessDevicesChanged(DeviceType device_type); | 198 void ProcessDevicesChanged(DeviceType device_type); |
| 174 void ProcessRemovableStorageAttached(const std::string& id, | 199 void ProcessRemovableStorageAttached(const std::string& id, |
| 175 const string16& name, | 200 const string16& name, |
| 176 const FilePath::StringType& location); | 201 const FilePath::StringType& location); |
| 177 void ProcessRemovableStorageDetached(const std::string& id); | 202 void ProcessRemovableStorageDetached(const std::string& id); |
| 178 | 203 |
| 204 void ProcessStorageFreeSpaceChanged(const FilePath::StringType& path); | |
| 205 | |
| 206 void set_storage_free_space_notification( | |
|
vandebo (ex-Chrome)
2012/09/11 22:49:27
notification -> delegate
Hongbo Min
2012/09/12 09:24:31
Done.
| |
| 207 StorageFreeSpaceNotification* notification) { | |
| 208 free_space_notification_ = notification; | |
| 209 } | |
| 210 | |
| 179 private: | 211 private: |
| 180 // Mapping of unique device id to device info tuple. | 212 // Mapping of unique device id to device info tuple. |
| 181 typedef std::map<std::string, RemovableStorageInfo> RemovableStorageMap; | 213 typedef std::map<std::string, RemovableStorageInfo> RemovableStorageMap; |
| 182 | 214 |
| 215 typedef ObserverListThreadSafe<StorageFreeSpaceChangedObserver> | |
| 216 StorageFreeSpaceChangedObserverList; | |
| 217 | |
| 218 // Mapping of the storage device path to the observer list. | |
| 219 typedef std::map<FilePath::StringType, | |
| 220 scoped_refptr<StorageFreeSpaceChangedObserverList> > | |
| 221 StorageFreeSpaceChangedObserverMap; | |
| 222 | |
| 223 | |
| 183 #if defined(OS_MACOSX) | 224 #if defined(OS_MACOSX) |
| 184 void PlatformInit(); | 225 void PlatformInit(); |
| 185 void PlatformDestroy(); | 226 void PlatformDestroy(); |
| 186 #endif | 227 #endif |
| 187 | 228 |
| 188 // Platform-specific method to check whether the system is currently | 229 // Platform-specific method to check whether the system is currently |
| 189 // running on battery power. Returns true if running on batteries, | 230 // running on battery power. Returns true if running on batteries, |
| 190 // false otherwise. | 231 // false otherwise. |
| 191 bool IsBatteryPower(); | 232 bool IsBatteryPower(); |
| 192 | 233 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 215 #endif | 256 #endif |
| 216 | 257 |
| 217 #if defined(OS_IOS) | 258 #if defined(OS_IOS) |
| 218 // Holds pointers to system event notification observers. | 259 // Holds pointers to system event notification observers. |
| 219 std::vector<id> notification_observers_; | 260 std::vector<id> notification_observers_; |
| 220 #endif | 261 #endif |
| 221 | 262 |
| 222 // Map of all the attached removable storage devices. | 263 // Map of all the attached removable storage devices. |
| 223 RemovableStorageMap removable_storage_map_; | 264 RemovableStorageMap removable_storage_map_; |
| 224 | 265 |
| 266 // The notification of storage free space change. | |
| 267 StorageFreeSpaceNotification* free_space_notification_; | |
| 268 // Map of the storage being watched to the observer list. | |
| 269 StorageFreeSpaceChangedObserverMap free_space_changed_observer_map_; | |
|
vandebo (ex-Chrome)
2012/09/11 22:49:27
Editing a std::map is not thread safe. This is ac
Hongbo Min
2012/09/12 09:24:31
Done.
Hongbo Min
2012/09/12 14:07:32
I try to fix it and the patch is uploaded to http:
vandebo (ex-Chrome)
2012/09/12 17:54:47
Thanks for doing this.
| |
| 270 // The set of the storage path being watched. | |
| 271 std::multiset<FilePath::StringType> watching_storage_set_; | |
|
vandebo (ex-Chrome)
2012/09/11 22:49:27
You've be susceptible to misuse with a multiset.
Hongbo Min
2012/09/12 09:24:31
The multiset usage is to work around the limitatio
vandebo (ex-Chrome)
2012/09/12 17:54:47
Yea, I see why you're using the multiset. What I w
| |
| 272 | |
| 225 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); | 273 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); |
| 226 }; | 274 }; |
| 227 | 275 |
| 228 } // namespace base | 276 } // namespace base |
| 229 | 277 |
| 230 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ | 278 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
| OLD | NEW |