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

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: 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..12f6f5ed4b8102883acc0ac82bb134d418891bf4 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>
@@ -58,6 +59,20 @@ class BASE_EXPORT SystemMonitor {
DEVTYPE_UNKNOWN, // Other devices.
};
+ // The notification interfaces for storage free space.
+ class BASE_EXPORT StorageFreeSpaceNotification {
vandebo (ex-Chrome) 2012/09/11 22:49:27 This isn't a notification interface so much as a d
Hongbo Min 2012/09/12 09:24:31 Done.
+ public:
+ virtual ~StorageFreeSpaceNotification() {}
+
+ // Start watching the storage device identified by the |path| parameter.
+ // Return true if it succeeds to start, otherwise, false is returned.
+ // The |path| can be a drive path on Windows, or the mount point on Linux.
+ virtual bool StartWatchingStorage(const FilePath::StringType& path) = 0;
vandebo (ex-Chrome) 2012/09/11 22:49:27 Can you actually do anything if it fails to start?
Hongbo Min 2012/09/12 09:24:31 My initial thought is, if it failed to start watch
vandebo (ex-Chrome) 2012/09/12 17:54:47 I can think of two approaches to dealing with erro
+
+ // Stop watching the storage device identified by the |path| paramter.
+ virtual bool StopWatchingStorage(const FilePath::StringType& path) = 0;
vandebo (ex-Chrome) 2012/09/11 22:49:27 I doubt there's anything to do if it fails to stop
Hongbo Min 2012/09/12 09:24:31 Done. See comment above.
+ };
+
struct BASE_EXPORT RemovableStorageInfo {
RemovableStorageInfo();
RemovableStorageInfo(const std::string& id,
@@ -147,17 +162,27 @@ class BASE_EXPORT SystemMonitor {
virtual ~DevicesChangedObserver() {}
};
+ class BASE_EXPORT StorageFreeSpaceChangedObserver {
+ public:
+ // Triggered when the free space of the storage |path| is changed.
+ virtual void OnStorageFreeSpaceChanged(const FilePath::StringType& path) {}
vandebo (ex-Chrome) 2012/09/11 22:49:27 You've used FilePath::StringType throughout your c
Hongbo Min 2012/09/12 09:24:31 Now I use FilePath instead, but actually a FilePat
vandebo (ex-Chrome) 2012/09/12 17:54:47 An MTP device may not be a valid file path to read
Hongbo Min 2012/09/13 13:48:14 One more question, if we don't want to represent t
+ };
+
// 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::StringType& path,
+ StorageFreeSpaceChangedObserver* obs);
vandebo (ex-Chrome) 2012/09/11 22:49:27 nit: Stor... should line up with const on the prev
Hongbo Min 2012/09/12 09:24:31 Done.
// 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::StringType& path,
+ StorageFreeSpaceChangedObserver* obs);
vandebo (ex-Chrome) 2012/09/11 22:49:27 ditto
Hongbo Min 2012/09/12 09:24:31 Done.
#if defined(OS_WIN)
// Windows-specific handling of a WM_POWERBROADCAST message.
@@ -176,10 +201,26 @@ class BASE_EXPORT SystemMonitor {
const FilePath::StringType& location);
void ProcessRemovableStorageDetached(const std::string& id);
+ void ProcessStorageFreeSpaceChanged(const FilePath::StringType& path);
+
+ void set_storage_free_space_notification(
vandebo (ex-Chrome) 2012/09/11 22:49:27 notification -> delegate
Hongbo Min 2012/09/12 09:24:31 Done.
+ StorageFreeSpaceNotification* notification) {
+ free_space_notification_ = notification;
+ }
+
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::StringType,
+ scoped_refptr<StorageFreeSpaceChangedObserverList> >
+ StorageFreeSpaceChangedObserverMap;
+
+
#if defined(OS_MACOSX)
void PlatformInit();
void PlatformDestroy();
@@ -222,6 +263,13 @@ class BASE_EXPORT SystemMonitor {
// Map of all the attached removable storage devices.
RemovableStorageMap removable_storage_map_;
+ // The notification of storage free space change.
+ StorageFreeSpaceNotification* free_space_notification_;
+ // Map of the storage being watched to the observer list.
+ StorageFreeSpaceChangedObserverMap free_space_changed_observer_map_;
vandebo (ex-Chrome) 2012/09/11 22:49:27 Editing a std::map is not thread safe. This is ac
Hongbo Min 2012/09/12 09:24:31 Done.
Hongbo Min 2012/09/12 14:07:32 I try to fix it and the patch is uploaded to http:
vandebo (ex-Chrome) 2012/09/12 17:54:47 Thanks for doing this.
+ // The set of the storage path being watched.
+ std::multiset<FilePath::StringType> watching_storage_set_;
vandebo (ex-Chrome) 2012/09/11 22:49:27 You've be susceptible to misuse with a multiset.
Hongbo Min 2012/09/12 09:24:31 The multiset usage is to work around the limitatio
vandebo (ex-Chrome) 2012/09/12 17:54:47 Yea, I see why you're using the multiset. What I w
+
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