Chromium Code Reviews| Index: chrome/browser/extensions/api/system_info_storage/storage_info_provider.h |
| diff --git a/chrome/browser/extensions/api/system_info_storage/storage_info_provider.h b/chrome/browser/extensions/api/system_info_storage/storage_info_provider.h |
| index 5ed7b5a65ae242af641b25278e6550f7c2f2f76b..a4ce038eec1055a0a45f297dc072b0f4e4b4bfcf 100644 |
| --- a/chrome/browser/extensions/api/system_info_storage/storage_info_provider.h |
| +++ b/chrome/browser/extensions/api/system_info_storage/storage_info_provider.h |
| @@ -10,7 +10,7 @@ |
| #include "base/observer_list_threadsafe.h" |
| #include "base/timer.h" |
| #include "chrome/browser/extensions/api/system_info/system_info_provider.h" |
| -#include "chrome/browser/extensions/api/system_info_storage/storage_info_observer.h" |
| +#include "chrome/browser/extensions/api/system_info_storage/storage_free_space_observer.h" |
| #include "chrome/browser/storage_monitor/removable_storage_observer.h" |
| #include "chrome/browser/storage_monitor/storage_info.h" |
| #include "chrome/common/extensions/api/experimental_system_info_storage.h" |
| @@ -25,48 +25,59 @@ extern const char kStorageTypeUnknown[]; |
| extern const char kStorageTypeFixed[]; |
| extern const char kStorageTypeRemovable[]; |
| +// Build StorageUnitInfo struct from chrome::StorageInfo instance. The |unit| |
| +// parameter is the output value. |
| +void BuildStorageUnitInfo(const chrome::StorageInfo& info, |
| + api::experimental_system_info_storage::StorageUnitInfo* unit); |
| + |
| } // namespace systeminfo |
| typedef std::vector<linked_ptr< |
| api::experimental_system_info_storage::StorageUnitInfo> > StorageInfo; |
| -class StorageInfoProvider |
| - : public SystemInfoProvider<StorageInfo>, |
| - public chrome::RemovableStorageObserver { |
| +class StorageInfoProvider : public SystemInfoProvider<StorageInfo> { |
| public: |
| + StorageInfoProvider(); |
| + |
| // Get the single shared instance of StorageInfoProvider. |
| static StorageInfoProvider* Get(); |
| // Add and remove observer, both can be called from any thread. |
| - void AddObserver(StorageInfoObserver* obs); |
| - void RemoveObserver(StorageInfoObserver* obs); |
| + void AddObserver(StorageFreeSpaceObserver* obs); |
| + void RemoveObserver(StorageFreeSpaceObserver* obs); |
| // Start and stop watching the given storage |id|. |
| virtual void StartWatching(const std::string& id); |
| virtual void StopWatching(const std::string& id); |
| - // Get the information for the storage unit specified by the |id| parameter, |
| - // and output the result to the |info|. |
| - virtual bool QueryUnitInfo(const std::string& id, |
| - api::experimental_system_info_storage::StorageUnitInfo* info) = 0; |
| + // Returns all available storages, including fixed and removable. |
| + virtual std::vector<chrome::StorageInfo> GetAllStorages() const; |
| + |
| + // Get the amount of storage free space from |id|, |
|
Hongbo Min
2013/06/27 12:35:26
nits: no need 2 lines. append line 57 to line 56.
Haojian Wu
2013/06/28 14:51:05
Done.
|
| + // or -1 on failure. |
| + virtual int64 GetStorageFreeSpaceFromId(const std::string& id); |
| protected: |
| - StorageInfoProvider(); |
| virtual ~StorageInfoProvider(); |
| + // TODO(Haojian): Put this method in a testing subclass rather than here. |
| void SetWatchingIntervalForTesting(size_t ms) { watching_interval_ = ms; } |
| - private: |
| - typedef std::map<std::string, double> StorageIDToSizeMap; |
| + // SystemInfoProvider implementations. |
| + virtual bool QueryInfo(StorageInfo* info) OVERRIDE; |
| + virtual void StartQueryInfoImpl() OVERRIDE; |
| - // chrome::RemovableStorageObserver implementation. |
| - virtual void OnRemovableStorageAttached( |
| - const chrome::StorageInfo& info) OVERRIDE; |
| - virtual void OnRemovableStorageDetached( |
| - const chrome::StorageInfo& info) OVERRIDE; |
| + private: |
| + typedef std::map<std::string, double> StorageIdToSizeMap; |
| + // Query the available capacity of all known storage devices on the blocking |
| + // pool, including fixed and removable. |
| + void QueryAvailableCapacityOnBlockingPool(); |
| // Query the new attached removable storage info on the blocking pool. |
| void QueryAttachedStorageInfoOnBlockingPool(const std::string& id); |
| + // Run the QueryInfo() implementation after the StorageMonitor has been |
| + // initialized. |
| + void QueryInfoImplOnUIThread(); |
| // Posts a task to check for free space changes on the blocking pool. |
| // Should be called on the UI thread. |
| @@ -74,14 +85,15 @@ class StorageInfoProvider |
| // Check if the free space changes for the watched storages by iterating over |
| // the |storage_id_to_size_map_|. It is called on blocking pool. |
| - void CheckWatchedStoragesOnBlockingPool(); |
| + void CheckWatchedStorageOnBlockingPool(const std::string& id); |
| // Provides an explicit hook that tests can wait for to determine that the |
| // call to CheckWatchedStorages() has completed. |
| virtual void OnCheckWatchedStoragesFinishedForTesting() {} |
| - // Add and remove the storage to be watched. |
| + // Add the storage identified by |mount_path| into watching list. |
| void AddWatchedStorageOnBlockingPool(const std::string& id); |
| + // Remove the storage identified by |mount_path| from watching list. |
| void RemoveWatchedStorageOnBlockingPool(const std::string& id); |
| void StartWatchingTimerOnUIThread(); |
| @@ -91,14 +103,14 @@ class StorageInfoProvider |
| // Mapping of the storage being watched and the recent free space value. It |
| // is maintained on the blocking pool. |
| - StorageIDToSizeMap storage_id_to_size_map_; |
| + StorageIdToSizeMap storage_id_to_size_map_; |
| // The timer used for watching the storage free space changes periodically. |
| base::RepeatingTimer<StorageInfoProvider> watching_timer_; |
| // The thread-safe observer list that observe the changes happening on the |
| // storages. |
| - scoped_refptr<ObserverListThreadSafe<StorageInfoObserver> > observers_; |
| + scoped_refptr<ObserverListThreadSafe<StorageFreeSpaceObserver> > observers_; |
| // The time interval for watching the free space change, in milliseconds. |
| // Only changed for testing purposes. |