Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: base/system_monitor/system_monitor.h

Issue 10893006: Extend system monitor capacity for watching the free space changes (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/system_monitor/system_monitor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 11
12 #include "base/base_export.h" 12 #include "base/base_export.h"
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/file_path.h" 14 #include "base/file_path.h"
15 #include "base/files/file_path_watcher.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
19 // status. This isn't true for other platforms. 20 // status. This isn't true for other platforms.
20 #if defined(OS_WIN) 21 #if defined(OS_WIN)
21 #define ENABLE_BATTERY_MONITORING 1 22 #define ENABLE_BATTERY_MONITORING 1
22 #else 23 #else
23 #undef ENABLE_BATTERY_MONITORING 24 #undef ENABLE_BATTERY_MONITORING
24 #endif // !OS_WIN 25 #endif // !OS_WIN
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 protected: 128 protected:
128 virtual ~PowerObserver() {} 129 virtual ~PowerObserver() {}
129 }; 130 };
130 131
131 class BASE_EXPORT DevicesChangedObserver { 132 class BASE_EXPORT DevicesChangedObserver {
132 public: 133 public:
133 // Notification that the devices connected to the system have changed. 134 // Notification that the devices connected to the system have changed.
134 // This is only implemented on Windows currently. 135 // This is only implemented on Windows currently.
135 virtual void OnDevicesChanged(DeviceType device_type) {} 136 virtual void OnDevicesChanged(DeviceType device_type) {}
136 137
138 // Called when the free space of the storage containing the |path| is
139 // changed.
140 virtual void OnStorageFreeSpaceChanged(const FilePath::StringType& path);
141
137 // When a removable storage device is attached or detached, one of these 142 // When a removable storage device is attached or detached, one of these
138 // two events is triggered. 143 // two events is triggered.
139 virtual void OnRemovableStorageAttached( 144 virtual void OnRemovableStorageAttached(
140 const std::string& id, 145 const std::string& id,
141 const string16& name, 146 const string16& name,
142 const FilePath::StringType& location) {} 147 const FilePath::StringType& location) {}
143 virtual void OnRemovableStorageDetached(const std::string& id) {} 148 virtual void OnRemovableStorageDetached(const std::string& id) {}
144 149
145 protected: 150 protected:
146 virtual ~DevicesChangedObserver() {} 151 virtual ~DevicesChangedObserver() {}
(...skipping 21 matching lines...) Expand all
168 // Cross-platform handling of a power event. 173 // Cross-platform handling of a power event.
169 void ProcessPowerMessage(PowerEvent event_id); 174 void ProcessPowerMessage(PowerEvent event_id);
170 175
171 // Cross-platform handling of a device change event. 176 // Cross-platform handling of a device change event.
172 void ProcessDevicesChanged(DeviceType device_type); 177 void ProcessDevicesChanged(DeviceType device_type);
173 void ProcessRemovableStorageAttached(const std::string& id, 178 void ProcessRemovableStorageAttached(const std::string& id,
174 const string16& name, 179 const string16& name,
175 const FilePath::StringType& location); 180 const FilePath::StringType& location);
176 void ProcessRemovableStorageDetached(const std::string& id); 181 void ProcessRemovableStorageDetached(const std::string& id);
177 182
183 // Start watching the storage device containing the |path| for its free
184 // space changes. The |path| can be a drive name on Windows, or a device
185 // name on Linux. Return true if succeeds to start watching.
186 bool StartWatchStorageDevice(const FilePath::StringType& path);
vandebo (ex-Chrome) 2012/08/28 23:56:30 nit: Watch -> Watching
187 // Stop watching the storage device containing the |path|.
188 bool StopWatchStorageDevice(const FilePath::StringType& path);
189
178 private: 190 private:
179 // Mapping of unique device id to device info tuple. 191 // Mapping of unique device id to device info tuple.
180 typedef std::map<std::string, RemovableStorageInfo> RemovableStorageMap; 192 typedef std::map<std::string, RemovableStorageInfo> RemovableStorageMap;
193 // Mapping of the storage path to watcher.
194 typedef std::map<FilePath::StringType,
195 scoped_refptr<FilePathWatcher::PlatformDelegate> > StorageDeviceWatcherMap;
181 196
182 #if defined(OS_MACOSX) 197 #if defined(OS_MACOSX)
183 void PlatformInit(); 198 void PlatformInit();
184 void PlatformDestroy(); 199 void PlatformDestroy();
185 #endif 200 #endif
186 201
187 // Platform-specific method to check whether the system is currently 202 // Platform-specific method to check whether the system is currently
188 // running on battery power. Returns true if running on batteries, 203 // running on battery power. Returns true if running on batteries,
189 // false otherwise. 204 // false otherwise.
190 bool IsBatteryPower(); 205 bool IsBatteryPower();
191 206
192 // Checks the battery status and notifies observers if the battery 207 // Checks the battery status and notifies observers if the battery
193 // status has changed. 208 // status has changed.
194 void BatteryCheck(); 209 void BatteryCheck();
195 210
196 // Functions to trigger notifications. 211 // Functions to trigger notifications.
197 void NotifyDevicesChanged(DeviceType device_type); 212 void NotifyDevicesChanged(DeviceType device_type);
213 void NotifyStorageFreeSpaceChanged(const FilePath::StringType& path,
214 double available_capacity);
198 void NotifyRemovableStorageAttached(const std::string& id, 215 void NotifyRemovableStorageAttached(const std::string& id,
199 const string16& name, 216 const string16& name,
200 const FilePath::StringType& location); 217 const FilePath::StringType& location);
201 void NotifyRemovableStorageDetached(const std::string& id); 218 void NotifyRemovableStorageDetached(const std::string& id);
202 void NotifyPowerStateChange(); 219 void NotifyPowerStateChange();
203 void NotifySuspend(); 220 void NotifySuspend();
204 void NotifyResume(); 221 void NotifyResume();
205 222
206 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; 223 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_;
207 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> > 224 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> >
208 devices_changed_observer_list_; 225 devices_changed_observer_list_;
209 bool battery_in_use_; 226 bool battery_in_use_;
210 bool suspended_; 227 bool suspended_;
211 228
212 #if defined(ENABLE_BATTERY_MONITORING) 229 #if defined(ENABLE_BATTERY_MONITORING)
213 base::OneShotTimer<SystemMonitor> delayed_battery_check_; 230 base::OneShotTimer<SystemMonitor> delayed_battery_check_;
214 #endif 231 #endif
215 232
216 #if defined(OS_IOS) 233 #if defined(OS_IOS)
217 // Holds pointers to system event notification observers. 234 // Holds pointers to system event notification observers.
218 std::vector<id> notification_observers_; 235 std::vector<id> notification_observers_;
219 #endif 236 #endif
220 237
221 // Map of all the attached removable storage devices. 238 // Map of all the attached removable storage devices.
222 RemovableStorageMap removable_storage_map_; 239 RemovableStorageMap removable_storage_map_;
223 240
241 // Map of all storage watchers.
242 StorageDeviceWatcherMap storage_watcher_map_;
243
224 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); 244 DISALLOW_COPY_AND_ASSIGN(SystemMonitor);
225 }; 245 };
226 246
227 } // namespace base 247 } // namespace base
228 248
229 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ 249 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_
OLDNEW
« no previous file with comments | « no previous file | base/system_monitor/system_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698