| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_STORAGE_STORAGE_INFO_PROVIDER_
H_ | 4 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_STORAGE_STORAGE_INFO_PROVIDER_H_ |
| 5 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_STORAGE_STORAGE_INFO_PROVIDER_
H_ | 5 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_STORAGE_STORAGE_INFO_PROVIDER_H_ |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/observer_list_threadsafe.h" | 10 #include "base/observer_list_threadsafe.h" |
| 11 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
| 12 #include "chrome/browser/extensions/api/system_info/system_info_provider.h" | 12 #include "chrome/browser/extensions/api/system_info/system_info_provider.h" |
| 13 #include "chrome/browser/extensions/api/system_info_storage/storage_free_space_o
bserver.h" | 13 #include "chrome/browser/extensions/api/system_storage/storage_free_space_observ
er.h" |
| 14 #include "chrome/browser/storage_monitor/removable_storage_observer.h" | 14 #include "chrome/browser/storage_monitor/removable_storage_observer.h" |
| 15 #include "chrome/browser/storage_monitor/storage_info.h" | 15 #include "chrome/browser/storage_monitor/storage_info.h" |
| 16 #include "chrome/common/extensions/api/experimental_system_info_storage.h" | 16 #include "chrome/common/extensions/api/system_storage.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 namespace systeminfo { | 22 namespace systeminfo { |
| 23 | 23 |
| 24 extern const char kStorageTypeUnknown[]; | 24 extern const char kStorageTypeUnknown[]; |
| 25 extern const char kStorageTypeFixed[]; | 25 extern const char kStorageTypeFixed[]; |
| 26 extern const char kStorageTypeRemovable[]; | 26 extern const char kStorageTypeRemovable[]; |
| 27 | 27 |
| 28 // Build StorageUnitInfo struct from chrome::StorageInfo instance. The |unit| | 28 // Build StorageUnitInfo struct from chrome::StorageInfo instance. The |unit| |
| 29 // parameter is the output value. | 29 // parameter is the output value. |
| 30 void BuildStorageUnitInfo(const chrome::StorageInfo& info, | 30 void BuildStorageUnitInfo(const chrome::StorageInfo& info, |
| 31 api::experimental_system_info_storage::StorageUnitInfo* unit); | 31 api::system_storage::StorageUnitInfo* unit); |
| 32 | 32 |
| 33 } // namespace systeminfo | 33 } // namespace systeminfo |
| 34 | 34 |
| 35 typedef std::vector<linked_ptr< | 35 typedef std::vector<linked_ptr< |
| 36 api::experimental_system_info_storage::StorageUnitInfo> > | 36 api::system_storage::StorageUnitInfo> > |
| 37 StorageUnitInfoList; | 37 StorageUnitInfoList; |
| 38 | 38 |
| 39 class StorageInfoProvider : public SystemInfoProvider<StorageUnitInfoList> { | 39 class StorageInfoProvider : public SystemInfoProvider<StorageUnitInfoList> { |
| 40 public: | 40 public: |
| 41 StorageInfoProvider(); | 41 StorageInfoProvider(); |
| 42 | 42 |
| 43 // Get the single shared instance of StorageInfoProvider. | 43 // Get the single shared instance of StorageInfoProvider. |
| 44 static StorageInfoProvider* Get(); | 44 static StorageInfoProvider* Get(); |
| 45 | 45 |
| 46 // Add and remove observer, both can be called from any thread. | 46 // Add and remove observer, both can be called from any thread. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // Put all available storages' information into |info_|. | 83 // Put all available storages' information into |info_|. |
| 84 virtual void GetAllStoragesIntoInfoList(); | 84 virtual void GetAllStoragesIntoInfoList(); |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 typedef std::map<std::string, double> StorageTransientIdToSizeMap; | 87 typedef std::map<std::string, double> StorageTransientIdToSizeMap; |
| 88 | 88 |
| 89 // SystemInfoProvider implementations. | 89 // SystemInfoProvider implementations. |
| 90 // Override to query the available capacity of all known storage devices on | 90 // Override to query the available capacity of all known storage devices on |
| 91 // the blocking pool, including fixed and removable devices. | 91 // the blocking pool, including fixed and removable devices. |
| 92 virtual bool QueryInfo() OVERRIDE; | 92 virtual bool QueryInfo() OVERRIDE; |
| 93 |
| 93 // Query the new attached removable storage info on the blocking pool. | 94 // Query the new attached removable storage info on the blocking pool. |
| 94 void QueryAttachedStorageInfoOnBlockingPool(const std::string& transient_id); | 95 void QueryAttachedStorageInfoOnBlockingPool(const std::string& transient_id); |
| 95 | 96 |
| 96 // Posts a task to check for free space changes on the blocking pool. | 97 // Posts a task to check for free space changes on the blocking pool. |
| 97 // Should be called on the UI thread. | 98 // Should be called on the UI thread. |
| 98 void CheckWatchedStorages(); | 99 void CheckWatchedStorages(); |
| 99 | 100 |
| 100 // Check if the free space changes for the watched storages by iterating over | 101 // Check if the free space changes for the watched storages by iterating over |
| 101 // the |storage_transient_id_to_size_map_|. It is called on blocking pool. | 102 // the |storage_transient_id_to_size_map_|. It is called on blocking pool. |
| 102 void CheckWatchedStorageOnBlockingPool(const std::string& transient_id); | 103 void CheckWatchedStorageOnBlockingPool(const std::string& transient_id); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 122 // storages. | 123 // storages. |
| 123 scoped_refptr<ObserverListThreadSafe<StorageFreeSpaceObserver> > observers_; | 124 scoped_refptr<ObserverListThreadSafe<StorageFreeSpaceObserver> > observers_; |
| 124 | 125 |
| 125 // The time interval for watching the free space change, in milliseconds. | 126 // The time interval for watching the free space change, in milliseconds. |
| 126 // Only changed for testing purposes. | 127 // Only changed for testing purposes. |
| 127 size_t watching_interval_; | 128 size_t watching_interval_; |
| 128 }; | 129 }; |
| 129 | 130 |
| 130 } // namespace extensions | 131 } // namespace extensions |
| 131 | 132 |
| 132 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_INFO_STORAGE_STORAGE_INFO_PROVID
ER_H_ | 133 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_STORAGE_STORAGE_INFO_PROVIDER_H_ |
| OLD | NEW |