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

Unified Diff: base/system_monitor/system_monitor.cc

Issue 10917166: Extend the capability of SystemMonitor to support watching storage free space change (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase and add available_capacity into the observer callback 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 side-by-side diff with in-line comments
Download patch
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..c48b44eac9359a59f69f4cb871a7f93660e5b75f 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_delegate_(NULL) {
DCHECK(!g_system_monitor);
g_system_monitor = this;
@@ -121,6 +122,17 @@ void SystemMonitor::ProcessRemovableStorageDetached(const std::string& id) {
NotifyRemovableStorageDetached(id);
}
+void SystemMonitor::ProcessStorageFreeSpaceChanged(const FilePath& path,
+ int64 available_capacity) {
+ DVLOG(1) << "Free Space Changing: " << path.value() << " "
+ << available_capacity << " bytes";
+ if (ContainsKey(free_space_changed_observer_map_, path) &&
vandebo (ex-Chrome) 2012/09/12 17:54:47 This needs to be locked.
vandebo (ex-Chrome) 2012/09/12 17:54:47 Use find so you only look up the path once. (else
Hongbo Min 2012/09/13 13:40:53 Done.
Hongbo Min 2012/09/13 13:40:53 Done.
+ free_space_changed_observer_map_[path].get())
+ free_space_changed_observer_map_[path]->Notify(
+ &StorageFreeSpaceChangedObserver::OnStorageFreeSpaceChanged,
+ path, available_capacity);
+}
+
std::vector<SystemMonitor::RemovableStorageInfo>
SystemMonitor::GetAttachedRemovableStorage() const {
std::vector<RemovableStorageInfo> results;
@@ -148,6 +160,42 @@ void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) {
devices_changed_observer_list_->RemoveObserver(obs);
}
+void SystemMonitor::AddStorageFreeSpaceChangedObserver(
+ const FilePath& path,
+ StorageFreeSpaceChangedObserver* obs) {
+ {
+ base::AutoLock lock(free_space_observers_lock_);
+ if (!ContainsKey(free_space_changed_observer_map_, path))
+ free_space_changed_observer_map_[path] =
+ new StorageFreeSpaceChangedObserverList();
vandebo (ex-Chrome) 2012/09/12 17:54:47 nit: Omit () when using new with a constructor tha
Hongbo Min 2012/09/13 13:40:53 Done.
+
+ watching_storage_set_.insert(path);
+ free_space_changed_observer_map_[path]->AddObserver(obs);
+ }
+
+ if (!free_space_delegate_->IsWatchingStorage(path))
+ free_space_delegate_->StartWatchingStorage(path);
vandebo (ex-Chrome) 2012/09/12 17:54:47 Hmm, consumers can call AddStorageFreeSpaceChanged
Hongbo Min 2012/09/13 13:40:53 Done. See the code comment of StorageFreeSpaceDele
+}
+
+void SystemMonitor::RemoveStorageFreeSpaceChangedObserver(
+ const FilePath& path,
+ StorageFreeSpaceChangedObserver* obs) {
+ base::AutoLock lock(free_space_observers_lock_);
+
+ std::multiset<FilePath>::iterator it = watching_storage_set_.find(path);
+ // Nobody is interested in the given |path|.
+ if (it == watching_storage_set_.end())
+ return;
+
+ free_space_changed_observer_map_[path]->RemoveObserver(obs);
+ watching_storage_set_.erase(it);
+
+ // Try to stop watching the storage if the last observer is removed.
+ if (!ContainsKey(watching_storage_set_, path) &&
+ free_space_delegate_->IsWatchingStorage(path))
+ free_space_delegate_->StopWatchingStorage(path);
+}
+
void SystemMonitor::NotifyDevicesChanged(DeviceType device_type) {
DVLOG(1) << "DevicesChanged with device type " << device_type;
devices_changed_observer_list_->Notify(

Powered by Google App Engine
This is Rietveld 408576698