| 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..ba6b50fda48d9450b7551080c5dcd957c2d2a19c 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,45 +25,57 @@ 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;
|
| + api::experimental_system_info_storage::StorageUnitInfo> > StorageUnitList;
|
|
|
| -class StorageInfoProvider
|
| - : public SystemInfoProvider<StorageInfo>,
|
| - public chrome::RemovableStorageObserver {
|
| +class StorageInfoProvider : public SystemInfoProvider<StorageUnitList> {
|
| public:
|
| + StorageInfoProvider();
|
| +
|
| // Get the single shared instance of StorageInfoProvider.
|
| static StorageInfoProvider* Get();
|
|
|
| + // SystemInfoProvider implementations:
|
| + virtual void StartQueryInfoImpl() OVERRIDE;
|
| + virtual bool QueryInfo(StorageUnitList* info) OVERRIDE;
|
| +
|
| // 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 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);
|
| +
|
| + // 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();
|
|
|
| void SetWatchingIntervalForTesting(size_t ms) { watching_interval_ = ms; }
|
|
|
| private:
|
| - typedef std::map<std::string, double> StorageIDToSizeMap;
|
| + typedef std::map<base::FilePath, double> StorageLocationToSizeMap;
|
|
|
| - // chrome::RemovableStorageObserver implementation.
|
| - virtual void OnRemovableStorageAttached(
|
| - const chrome::StorageInfo& info) OVERRIDE;
|
| - virtual void OnRemovableStorageDetached(
|
| - const chrome::StorageInfo& info) OVERRIDE;
|
| + void QueryAvailableCapacityOnBlockingPool();
|
| + void QueryInfoImplOnUIThread();
|
|
|
| // Query the new attached removable storage info on the blocking pool.
|
| void QueryAttachedStorageInfoOnBlockingPool(const std::string& id);
|
| @@ -72,17 +84,15 @@ class StorageInfoProvider
|
| // 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();
|
| -
|
| - // Provides an explicit hook that tests can wait for to determine that the
|
| - // call to CheckWatchedStorages() has completed.
|
| - virtual void OnCheckWatchedStoragesFinishedForTesting() {}
|
| + // Check if the free space of |mount_path| is changed. If so, it will
|
| + // notify the observers about the change event.
|
| + void CheckWatchedStorageOnBlockingPool(const std::string& id,
|
| + const base::FilePath& mount_path);
|
|
|
| - // 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
|
| @@ -91,14 +101,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_;
|
| + 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.
|
|
|