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

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: 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..29937d8bced3818f78f57fb09f8774e446437a94 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,43 @@ void SystemMonitor::ProcessRemovableStorageDetached(const std::string& id) {
NotifyRemovableStorageDetached(id);
}
+void SystemMonitor::ProcessStorageFreeSpaceChanged(
+ const FilePath::StringType& path) {
+ DVLOG(1) << "Free Space Changing";
+ devices_changed_observer_list_->Notify(
+ &DevicesChangedObserver::OnStorageFreeSpaceChanged, path);
+}
+
+bool SystemMonitor::StartWatchingStorage(const FilePath::StringType& path) {
+ if (!free_space_delegate_)
+ return false;
+
+ // Try to start watching if the first one is requested.
+ if (watched_storages_.find(path) == watched_storages_.end() &&
+ !free_space_delegate_->StartWatchingStorage(path)) {
+ return false;
+ }
+
+ // The free space watcher has been started for the storage identifed by
+ // |path|.
+ watched_storages_.insert(path);
+ return true;
+}
+
+bool SystemMonitor::StopWatchingStorage(const FilePath::StringType& path) {
+ if (!free_space_delegate_)
+ return false;
+
+ watched_storages_.erase(path);
+
+ // Try to stop watching when the last one is erased.
+ if (watched_storages_.find(path) == watched_storages_.end() &&
+ !free_space_delegate_->StopWatchingStorage(path))
+ return false;
+
+ return true;
+}
+
std::vector<SystemMonitor::RemovableStorageInfo>
SystemMonitor::GetAttachedRemovableStorage() const {
std::vector<RemovableStorageInfo> results;

Powered by Google App Engine
This is Rietveld 408576698