Merge from Chromium at DEPS revision r212014

This commit was generated by merge_to_master.py.

Change-Id: Ie0f261e9682cd8abea1eea1e51beab83d5eea21a
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 88c147b..a6138dd 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,86 @@
 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> >
+        StorageUnitInfoList;
 
-class StorageInfoProvider
-    : public SystemInfoProvider<StorageInfo>,
-      public chrome::RemovableStorageObserver {
+class StorageInfoProvider : public SystemInfoProvider<StorageUnitInfoList> {
  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);
+  // Start and stop watching the given storage |transient_id|.
+  void StartWatching(const std::string& transient_id);
+  void StopWatching(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;
+  // Start and stop watching all available storages.
+  void StartWatchingAllStorages();
+  void StopWatchingAllStorages();
+
+  // Returns all available storages, including fixed and removable.
+  virtual std::vector<chrome::StorageInfo> GetAllStorages() const;
+
+  // SystemInfoProvider implementations
+  virtual void PrepareQueryOnUIThread() OVERRIDE;
+  virtual void InitializeProvider(const base::Closure& do_query_info_callback)
+      OVERRIDE;
+
+  // Get the amount of storage free space from |transient_id|, or -1 on failure.
+  virtual int64 GetStorageFreeSpaceFromTransientId(
+      const std::string& transient_id);
+
+  virtual std::string GetTransientIdForDeviceId(
+      const std::string& device_id) const;
+  virtual std::string GetDeviceIdForTransientId(
+      const std::string& transient_id) const;
+
+  const StorageUnitInfoList& storage_unit_info_list() 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; }
 
+  // Put all available storages' information into |info_|.
+  virtual void GetAllStoragesIntoInfoList();
+
  private:
-  typedef std::map<std::string, double> StorageIDToSizeMap;
+  typedef std::map<std::string, double> StorageTransientIdToSizeMap;
 
-  // chrome::RemovableStorageObserver implementation.
-  virtual void OnRemovableStorageAttached(
-      const chrome::StorageInfo& info) OVERRIDE;
-  virtual void OnRemovableStorageDetached(
-      const chrome::StorageInfo& info) OVERRIDE;
-
+  // SystemInfoProvider implementations.
+  // Override to query the available capacity of all known storage devices on
+  // the blocking pool, including fixed and removable devices.
+  virtual bool QueryInfo() OVERRIDE;
   // Query the new attached removable storage info on the blocking pool.
-  void QueryAttachedStorageInfoOnBlockingPool(const std::string& id);
+  void QueryAttachedStorageInfoOnBlockingPool(const std::string& transient_id);
 
   // 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_transient_id_to_size_map_|. It is called on blocking pool.
+  void CheckWatchedStorageOnBlockingPool(const std::string& transient_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.
-  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 +113,14 @@
 
   // 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.