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

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: updated patch 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..40a1e3e8126e089dc64010e0844f8bcbb5da8e42 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"
vandebo (ex-Chrome) 2012/09/13 19:57:34 Your other CL was committed, so you need to rebase
#include "build/build_config.h"
// Windows HiRes timers drain the battery faster so we need to know the battery
@@ -58,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
vandebo (ex-Chrome) 2012/09/13 19:57:34 I intended for you to save the thread id in delega
Hongbo Min 2012/09/14 06:04:36 Actually, the base code is not allowed to access B
vandebo (ex-Chrome) 2012/09/14 08:07:18 No, but it is allowed to look at the thread ID. L
+ // 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,
@@ -147,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) {}
vandebo (ex-Chrome) 2012/09/13 19:57:34 Shouldn't this be a uint64?
+
+ // Triggered when the free space delegate failed to start watching
+ // the given storage |path|.
+ virtual void OnFreeSpaceWatchingError(const FilePath& path) {}
vandebo (ex-Chrome) 2012/09/13 19:57:34 Maybe OnFreeSpaceChangeError()? What do you think
+ };
+
// 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);
#if defined(OS_WIN)
// Windows-specific handling of a WM_POWERBROADCAST message.
@@ -176,10 +214,32 @@ class BASE_EXPORT SystemMonitor {
const FilePath::StringType& location);
void ProcessRemovableStorageDetached(const std::string& id);
+ // Cross-platform handling of free space change event. The parameter
+ // |available_capacity| is valid only if the |error| is false.
+ void ProcessStorageFreeSpaceMessage(const FilePath& path,
vandebo (ex-Chrome) 2012/09/13 19:57:34 Because of the pattern for other things in the fil
+ int64 available_capacity,
+ bool error);
+
+ StorageFreeSpaceDelegate* storage_free_space_delegate() const {
vandebo (ex-Chrome) 2012/09/13 19:57:34 I don't think you really need this method.
+ return free_space_delegate_;
+ }
+
+ // Called on the thread that starts and stops watching storage paths.
+ void set_storage_free_space_delegate(StorageFreeSpaceDelegate* delegate);
willchan no longer on Chromium 2012/09/13 18:41:14 Ah, this is interesting. Please correct me if I'm
vandebo (ex-Chrome) 2012/09/13 20:08:41 Yes, the various parts of system monitor are imple
willchan no longer on Chromium 2012/09/13 20:24:33 Not needed. The setter is the constructor of Syste
+
private:
// Mapping of unique device id to device info tuple.
typedef std::map<std::string, RemovableStorageInfo> RemovableStorageMap;
+ typedef ObserverListThreadSafe<StorageFreeSpaceObserver>
+ StorageFreeSpaceObserverList;
+ // Mapping of the storage device path to the observer list.
+ typedef std::map<FilePath, scoped_refptr<StorageFreeSpaceObserverList> >
+ StorageFreeSpaceObserverListMap;
+ // Multi-mapping of the storage path to its observer.
+ typedef std::multimap<FilePath, StorageFreeSpaceObserver*>
vandebo (ex-Chrome) 2012/09/13 19:57:34 Using a multimap, you've almost accomplished what
Hongbo Min 2012/09/14 06:04:36 I don't think std::set can reduce the code complex
vandebo (ex-Chrome) 2012/09/14 08:07:18 Indeed, but using std::map<FilePath, std::set<Stor
+ StorageFreeSpaceObserverMap;
+
#if defined(OS_MACOSX)
void PlatformInit();
void PlatformDestroy();
@@ -204,6 +264,16 @@ class BASE_EXPORT SystemMonitor {
void NotifySuspend();
void NotifyResume();
+ // Notify the |observers| observing the given |path| for free space change
+ // event.
+ void NotifyStorageFreeSpaceChanged(
+ scoped_refptr<StorageFreeSpaceObserverList> observers,
+ const FilePath& path,
+ int64 available_capacity);
+ void NotifyStorageFreeSpaceWatchingError(
+ scoped_refptr<StorageFreeSpaceObserverList> observers,
+ const FilePath& path);
+
scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_;
scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> >
devices_changed_observer_list_;
@@ -222,6 +292,22 @@ 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_;
+
+ // Used to map the storage path and its associated observer. We use multimap
+ // because a path may be observed by more than one observer. It helps decide
+ // when to stop watching a storage path since we can't know when the thread
+ // safe observer list becomes empty.
+ StorageFreeSpaceObserverMap free_space_observer_map_;
+
+ // A lock used to synchronize access to |free_space_observer_list_map_| and
+ // |free_space_observer_map_| data.
+ 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