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..2fa006be2eab842bff35bd7e159b74fc0b7e157a 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,80 +25,98 @@ 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< |
|
Greg Billock
2013/06/24 16:55:38
Can you add a TODO to see if we can get by without
Hongbo Min
2013/06/25 01:55:07
Since the type T generated by IDL parser disallows
Haojian Wu
2013/06/26 03:22:40
As hongbo@ said, the StorageUnitInfo class which i
|
| api::experimental_system_info_storage::StorageUnitInfo> > StorageInfo; |
| class StorageInfoProvider |
| - : public SystemInfoProvider<StorageInfo>, |
| - public chrome::RemovableStorageObserver { |
| + : public SystemInfoProvider<StorageInfo> { |
|
Lei Zhang
2013/06/25 04:49:55
fits on previous line
Haojian Wu
2013/06/26 03:22:40
Done.
|
| 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; |
| + |
| + // Return the amount of storage free space for |mount_path|, |
| + // or -1 on failure. |
| + virtual int64 GetStorageFreeSpace(const base::FilePath& mount_path); |
| 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<base::FilePath, double> StorageLocationToSizeMap; |
| + // Query the available capacity of all known storage devices on the blocking |
| + // pool, including fixed and removable.. |
|
Lei Zhang
2013/06/25 04:49:55
nit: double periods
Haojian Wu
2013/06/26 03:22:40
Done.
|
| + void QueryAvailableCapacityOnBlockingPool(); |
| // Query the new attached removable storage info on the blocking pool. |
| void QueryAttachedStorageInfoOnBlockingPool(const std::string& id); |
| + void QueryInfoImplOnUIThread(); |
|
Lei Zhang
2013/06/25 04:49:55
Add a comment. "Run the QueryInfo() implementation
Haojian Wu
2013/06/26 03:22:40
Done.
|
| + |
| // Posts a task to check for free space changes on the blocking pool. |
| // Should be called on the UI thread. |
| void CheckWatchedStorages(); |
| // 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(); |
| + // the |storage_location_to_size_map_|. It is called on blocking pool. |
| + void CheckWatchedStorageOnBlockingPool( |
| + const std::string& id, const base::FilePath& mount_path); |
| // 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. |
| - void AddWatchedStorageOnBlockingPool(const std::string& id); |
| - void RemoveWatchedStorageOnBlockingPool(const std::string& id); |
| + // Add the storage identified by |mount_path| into watching list. |
| + void AddWatchedStorageOnBlockingPool(const base::FilePath mount_path); |
| + // Remove the storage identified by |mount_path| from watching list. |
| + void RemoveWatchedStorageOnBlockingPool(const base::FilePath mount_path); |
| void StartWatchingTimerOnUIThread(); |
| // Force to stop the watching timer or there is no any one storage to be |
| // watched. It is called on UI thread. |
| void StopWatchingTimerOnUIThread(); |
| + // Get the storage mount path from |id|. The parameter |path| contains |
| + // the output value. Return false if no such storage |id| is found. |
| + virtual bool GetStoragePathFromId(const std::string& id, |
| + base::FilePath* path); |
| + |
| // 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_; |
| + StorageLocationToSizeMap storage_location_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. |