Chromium Code Reviews| Index: base/system_monitor/system_monitor.cc |
| diff --git a/base/system_monitor/system_monitor.cc b/base/system_monitor/system_monitor.cc |
| index f30c8935c9a999b38382f78e879c9319a4eba13f..acc82ff3b722e942bff8b1a274128570e57ffc45 100644 |
| --- a/base/system_monitor/system_monitor.cc |
| +++ b/base/system_monitor/system_monitor.cc |
| @@ -39,7 +39,8 @@ SystemMonitor::SystemMonitor() |
| devices_changed_observer_list_( |
| new ObserverListThreadSafe<DevicesChangedObserver>()), |
| battery_in_use_(false), |
| - suspended_(false) { |
| + suspended_(false), |
| + free_space_notification_(NULL) { |
| DCHECK(!g_system_monitor); |
| g_system_monitor = this; |
| @@ -121,6 +122,14 @@ void SystemMonitor::ProcessRemovableStorageDetached(const std::string& id) { |
| NotifyRemovableStorageDetached(id); |
| } |
| +void SystemMonitor::ProcessStorageFreeSpaceChanged( |
| + const FilePath::StringType& path) { |
| + DVLOG(1) << "Free Space Changing: " << path; |
| + if (free_space_changed_observer_map_[path].get()) |
|
vandebo (ex-Chrome)
2012/09/11 22:49:27
Use find(path) so that you don't add something to
Hongbo Min
2012/09/12 09:24:31
Done.
|
| + free_space_changed_observer_map_[path]->Notify( |
| + &StorageFreeSpaceChangedObserver::OnStorageFreeSpaceChanged, path); |
| +} |
| + |
| std::vector<SystemMonitor::RemovableStorageInfo> |
| SystemMonitor::GetAttachedRemovableStorage() const { |
| std::vector<RemovableStorageInfo> results; |
| @@ -148,6 +157,38 @@ void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) { |
| devices_changed_observer_list_->RemoveObserver(obs); |
| } |
| +void SystemMonitor::AddStorageFreeSpaceChangedObserver( |
| + const FilePath::StringType& path, |
| + StorageFreeSpaceChangedObserver* obs) { |
| + |
| + // Try to start watching the storage. |
| + if (watching_storage_set_.find(path) == watching_storage_set_.end() && |
| + !free_space_notification_->StartWatchingStorage(path)) |
|
vandebo (ex-Chrome)
2012/09/11 22:49:27
Make this two different if's to make it more reada
Hongbo Min
2012/09/12 09:24:31
Done.
|
| + return; |
| + |
| + watching_storage_set_.insert(path); |
| + if (!free_space_changed_observer_map_[path].get()) |
| + free_space_changed_observer_map_[path] = |
| + new StorageFreeSpaceChangedObserverList(); |
| + |
| + free_space_changed_observer_map_[path]->AddObserver(obs); |
|
vandebo (ex-Chrome)
2012/09/11 22:49:27
Once you have a lock, I think you'll want to add t
Hongbo Min
2012/09/12 09:24:31
It can avoid the lock occupied too much time in ca
|
| +} |
| + |
| +void SystemMonitor::RemoveStorageFreeSpaceChangedObserver( |
| + const FilePath::StringType& path, |
| + StorageFreeSpaceChangedObserver* obs) { |
| + size_t count = watching_storage_set_.count(path); |
| + if (count == 0) |
| + return; |
| + |
| + // Stop watching the storage in case of the last observer is removed. |
| + if (count == 1) |
| + free_space_notification_->StopWatchingStorage(path); |
| + |
| + free_space_changed_observer_map_[path]->RemoveObserver(obs); |
| + watching_storage_set_.erase(path); |
| +} |
| + |
| void SystemMonitor::NotifyDevicesChanged(DeviceType device_type) { |
| DVLOG(1) << "DevicesChanged with device type " << device_type; |
| devices_changed_observer_list_->Notify( |