| Index: base/system_monitor/system_monitor.h
|
| diff --git a/base/system_monitor/system_monitor.h b/base/system_monitor/system_monitor.h
|
| index ea95da89ccbe9fb6635b8ae905b6415ac977ca24..b1de861a89f5ad3dffd433b8a7bd0a809c94fb1e 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>
|
|
|
| @@ -59,6 +60,26 @@ class BASE_EXPORT SystemMonitor {
|
| DEVTYPE_UNKNOWN, // Other devices.
|
| };
|
|
|
| + // The delegate interfaces for storage free space change notification.
|
| + // Since the client code may call these interfaces from any thread, the
|
| + // implementation must take care to implement it, e.g. if it is not called
|
| + // from the thread on which the observation is working, you probably need
|
| + // to post a task to that thread for starting or stopping the watching
|
| + // operation.
|
| + class BASE_EXPORT StorageFreeSpaceDelegate {
|
| + public:
|
| + virtual ~StorageFreeSpaceDelegate() {}
|
| +
|
| + // Start watching the storage device identified by the |path| parameter.
|
| + // The |path| can be a drive path on Windows, or the mount point on Posix.
|
| + // It can be called from any thread.
|
| + virtual void StartWatchingStorage(const FilePath& path) = 0;
|
| +
|
| + // Stop watching the storage device identified by the |path| paramter. It
|
| + // can be called from any thread.
|
| + virtual void StopWatchingStorage(const FilePath& path) = 0;
|
| + };
|
| +
|
| struct BASE_EXPORT RemovableStorageInfo {
|
| RemovableStorageInfo();
|
| RemovableStorageInfo(const std::string& id,
|
| @@ -77,7 +98,7 @@ class BASE_EXPORT SystemMonitor {
|
|
|
| // Create SystemMonitor. Only one SystemMonitor instance per application
|
| // is allowed.
|
| - SystemMonitor();
|
| + SystemMonitor(StorageFreeSpaceDelegate* delegate = NULL);
|
| ~SystemMonitor();
|
|
|
| // Get the application-wide SystemMonitor (if not present, returns NULL).
|
| @@ -148,17 +169,33 @@ class BASE_EXPORT SystemMonitor {
|
| virtual ~DevicesChangedObserver() {}
|
| };
|
|
|
| + class BASE_EXPORT StorageFreeSpaceObserver {
|
| + public:
|
| + // Triggered when the free space of the storage |path| is changed. The
|
| + // |available_capacity| indicates the available capacity in bytes.
|
| + virtual void OnFreeSpaceChanged(const FilePath& path,
|
| + int64 available_capacity) {}
|
| +
|
| + // Triggered when the free space delegate failed to start watching
|
| + // the given storage |path|.
|
| + virtual void OnFreeSpaceChangeError(const FilePath& path) {}
|
| + };
|
| +
|
| // 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 AddStorageFreeSpaceObserver(const FilePath& path,
|
| + StorageFreeSpaceObserver* 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 RemoveStorageFreeSpaceObserver(const FilePath& path,
|
| + StorageFreeSpaceObserver* obs);
|
|
|
| // The ProcessFoo() style methods are a broken pattern and should not
|
| // be copied. Any significant addition to this class is blocked on
|
| @@ -181,10 +218,27 @@ class BASE_EXPORT SystemMonitor {
|
| const FilePath::StringType& location);
|
| void ProcessRemovableStorageDetached(const std::string& id);
|
|
|
| + // Cross-platform handling of free space change event.
|
| + void ProcessStorageFreeSpaceChanged(const FilePath& path,
|
| + int64 available_capacity);
|
| + void ProcessStorageFreeSpaceChangeError(const FilePath& path);
|
| +
|
| private:
|
| // Mapping of unique device id to device info tuple.
|
| typedef std::map<std::string, RemovableStorageInfo> RemovableStorageMap;
|
|
|
| + typedef ObserverListThreadSafe<StorageFreeSpaceObserver>
|
| + StorageFreeSpaceObserverList;
|
| + typedef std::set<StorageFreeSpaceObserver*> StorageFreeSpaceObserverSet;
|
| + struct PathObserverPair {
|
| + scoped_refptr<StorageFreeSpaceObserverList> observer_list;
|
| + // Used to help decide when to stop watching a storage path since we can't
|
| + // know when the thread safe observer list becomes empty.
|
| + StorageFreeSpaceObserverSet observer_set;
|
| + };
|
| + // Mapping of the storage device path to its observers.
|
| + typedef std::map<FilePath, PathObserverPair> StorageFreeSpaceObserverListMap;
|
| +
|
| #if defined(OS_MACOSX)
|
| void PlatformInit();
|
| void PlatformDestroy();
|
| @@ -229,6 +283,15 @@ class BASE_EXPORT SystemMonitor {
|
| // Map of all the attached removable storage devices.
|
| RemovableStorageMap removable_storage_map_;
|
|
|
| + // The delegate that implements free space change notification.
|
| + StorageFreeSpaceDelegate* free_space_delegate_;
|
| +
|
| + // Used to map the storage path being watched to its observer list.
|
| + StorageFreeSpaceObserverListMap free_space_observer_list_map_;
|
| +
|
| + // A lock used to synchronize access to |free_space_observer_list_map_|.
|
| + base::Lock free_space_observers_lock_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(SystemMonitor);
|
| };
|
|
|
|
|