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

Unified Diff: chrome/browser/extensions/api/system_info_storage/storage_info_provider.h

Issue 16707002: [SystemInfo API] Rewrite storage info provider using storage monitor impl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add explicit destructors in UnitTestStorageInfoProvider to avoid build error. Created 7 years, 6 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
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 88c147bc012f954ac77dc60ca5a9c023f183ffbd..cfa73970961acd7a87c1fdcefed95ce7a872b560 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/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,64 +25,77 @@ 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 |transient_id|.
+ virtual void StartWatching(const std::string& transient_id);
+ virtual void StopWatching(const std::string& transient_id);
+
+ // Returns all available storages, including fixed and removable.
+ virtual std::vector<chrome::StorageInfo> GetAllStorages() const;
- // Start and stop watching the given storage |id|.
- virtual void StartWatching(const std::string& id);
- virtual void StopWatching(const std::string& id);
+ // Get the amount of storage free space from |transient_id|, or -1 on failure.
+ virtual int64 GetStorageFreeSpaceFromTransientId(
+ const std::string& transient_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;
+ virtual std::string GetTransientIdForDeviceId(
+ const std::string& device_id) const;
+ virtual std::string GetDeviceIdForTransientId(
+ const std::string& transient_id) const;
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> StorageTransientIdToSizeMap;
+ // 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);
+ void QueryAttachedStorageInfoOnBlockingPool(const std::string& transient_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.
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() {}
+ // the |storage_transient_id_to_size_map_|. It is called on blocking pool.
+ void CheckWatchedStorageOnBlockingPool(const std::string& transient_id);
- // 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 |transient_id| into watching list.
+ void AddWatchedStorageOnBlockingPool(const std::string& transient_id);
+ // Remove the storage identified by |transient_id| from watching list.
+ void RemoveWatchedStorageOnBlockingPool(const std::string& transient_id);
void StartWatchingTimerOnUIThread();
// Force to stop the watching timer or there is no any one storage to be
@@ -91,14 +104,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_;
+ StorageTransientIdToSizeMap storage_transient_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.

Powered by Google App Engine
This is Rietveld 408576698