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

Unified Diff: base/system_monitor/system_monitor.h

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
« no previous file with comments | « no previous file | base/system_monitor/system_monitor.cc » ('j') | base/system_monitor/system_monitor.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/system_monitor/system_monitor.h
diff --git a/base/system_monitor/system_monitor.h b/base/system_monitor/system_monitor.h
index 48d512b708c11aa44368c05300dd9a38f29e00ed..9163db70e7a020a0a8b89e8308eebcb13540658b 100644
--- a/base/system_monitor/system_monitor.h
+++ b/base/system_monitor/system_monitor.h
@@ -6,6 +6,7 @@
#define BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_
#include <map>
+#include <set>
#include <string>
#include <vector>
@@ -13,6 +14,7 @@
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/string16.h"
+#include "base/synchronization/lock.h"
#include "build/build_config.h"
// Windows HiRes timers drain the battery faster so we need to know the battery
@@ -58,6 +60,22 @@ class BASE_EXPORT SystemMonitor {
DEVTYPE_UNKNOWN, // Other devices.
};
+ // The delegate interfaces for storage free space.
+ class BASE_EXPORT StorageFreeSpaceDelegate {
+ public:
+ virtual ~StorageFreeSpaceDelegate() {}
+
+ // Return true if the given storage |path| is already being watched.
+ virtual bool IsWatchingStorage(const FilePath& path) = 0;
vandebo (ex-Chrome) 2012/09/12 17:54:47 Not sure you need this.
Hongbo Min 2012/09/13 13:40:53 Removed it already.
+
+ // Start watching the storage device identified by the |path| parameter.
+ // The |path| can be a drive path on Windows, or the mount point on Linux.
vandebo (ex-Chrome) 2012/09/12 17:54:47 nit: Linux -> Posix
Hongbo Min 2012/09/13 13:40:53 Done.
+ virtual void StartWatchingStorage(const FilePath& path) = 0;
+
+ // Stop watching the storage device identified by the |path| paramter.
+ virtual void StopWatchingStorage(const FilePath& path) = 0;
+ };
+
struct BASE_EXPORT RemovableStorageInfo {
RemovableStorageInfo();
RemovableStorageInfo(const std::string& id,
@@ -147,17 +165,31 @@ class BASE_EXPORT SystemMonitor {
virtual ~DevicesChangedObserver() {}
};
+ class BASE_EXPORT StorageFreeSpaceChangedObserver {
+ public:
+ // Triggered when the free space of the storage |path| is changed. The
+ // |available_capacity| indicates the free space in bytes.
+ virtual void OnStorageFreeSpaceChanged(const FilePath& path,
+ int64 available_capacity) {}
+ };
+
// Add a new observer.
// Can be called from any thread.
// Must not be called from within a notification callback.
void AddPowerObserver(PowerObserver* obs);
void AddDevicesChangedObserver(DevicesChangedObserver* obs);
+ void AddStorageFreeSpaceChangedObserver(
+ const FilePath& path,
+ StorageFreeSpaceChangedObserver* obs);
// Remove an existing observer.
// Can be called from any thread.
// Must not be called from within a notification callback.
void RemovePowerObserver(PowerObserver* obs);
void RemoveDevicesChangedObserver(DevicesChangedObserver* obs);
+ void RemoveStorageFreeSpaceChangedObserver(
+ const FilePath& path,
+ StorageFreeSpaceChangedObserver* obs);
#if defined(OS_WIN)
// Windows-specific handling of a WM_POWERBROADCAST message.
@@ -176,10 +208,24 @@ class BASE_EXPORT SystemMonitor {
const FilePath::StringType& location);
void ProcessRemovableStorageDetached(const std::string& id);
+ void ProcessStorageFreeSpaceChanged(const FilePath& path,
+ int64 available_capacity);
+
+ void set_storage_free_space_delegate(StorageFreeSpaceDelegate* delegate) {
+ free_space_delegate_ = delegate;
vandebo (ex-Chrome) 2012/09/12 17:54:47 Add a DCHECK that free_sapce_delegate_ is NULL. W
Hongbo Min 2012/09/13 13:40:53 Done, but allow the free_space_delegate_ to be set
+ }
+
private:
// Mapping of unique device id to device info tuple.
typedef std::map<std::string, RemovableStorageInfo> RemovableStorageMap;
+ typedef ObserverListThreadSafe<StorageFreeSpaceChangedObserver>
+ StorageFreeSpaceChangedObserverList;
+
+ // Mapping of the storage device path to the observer list.
+ typedef std::map<FilePath, scoped_refptr<
+ StorageFreeSpaceChangedObserverList> > StorageFreeSpaceChangedObserverMap;
+
#if defined(OS_MACOSX)
void PlatformInit();
void PlatformDestroy();
@@ -222,6 +268,22 @@ class BASE_EXPORT SystemMonitor {
// Map of all the attached removable storage devices.
RemovableStorageMap removable_storage_map_;
+ // The delegate instance for storage free space change.
vandebo (ex-Chrome) 2012/09/12 17:54:47 nit: The delegate that implements free space-chang
Hongbo Min 2012/09/13 13:40:53 Done.
+ StorageFreeSpaceDelegate* free_space_delegate_;
+
+ // Map of the storage being watched to the observer list.
+ StorageFreeSpaceChangedObserverMap free_space_changed_observer_map_;
+
+ // The set of the storage path being watched. Since we can not know when
vandebo (ex-Chrome) 2012/09/12 17:54:47 nit: path -> paths, can not -> can't
Hongbo Min 2012/09/13 13:40:53 Done.
+ // the thread-safe observer list becomse empty, we have to use this set
+ // to decide to stop watching a storage path when its last observer has
+ // been removed.
+ std::multiset<FilePath> watching_storage_set_;
+
+ // The lock for manipulating free_space_changed_observer_map_
vandebo (ex-Chrome) 2012/09/12 17:54:47 nit: remove The: "Lock for..."
Hongbo Min 2012/09/13 13:40:53 Done.
+ // and watching_storage_set_.
+ base::Lock free_space_observers_lock_;
+
DISALLOW_COPY_AND_ASSIGN(SystemMonitor);
};
« no previous file with comments | « no previous file | base/system_monitor/system_monitor.cc » ('j') | base/system_monitor/system_monitor.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698