Chromium Code Reviews| 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 | 4 |
| 5 #ifndef CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_H_ | 5 #ifndef CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_H_ |
| 6 #define CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_H_ | 6 #define CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 EJECT_FAILURE | 60 EJECT_FAILURE |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 // Returns a pointer to an object owned by the BrowserMainParts, with lifetime | 63 // Returns a pointer to an object owned by the BrowserMainParts, with lifetime |
| 64 // somewhat shorter than a process Singleton. | 64 // somewhat shorter than a process Singleton. |
| 65 static StorageMonitor* GetInstance(); | 65 static StorageMonitor* GetInstance(); |
| 66 | 66 |
| 67 // Initialize the storage monitor. The provided callback, if non-null, | 67 // Initialize the storage monitor. The provided callback, if non-null, |
| 68 // will be called when initialization is complete. If initialization has | 68 // will be called when initialization is complete. If initialization has |
| 69 // already completed, this callback will be invoked within the calling stack. | 69 // already completed, this callback will be invoked within the calling stack. |
| 70 // Before the callback is run, calls to |GetAttachedStorage| and | 70 // Before the callback is run, calls to |GetAllAvailableStorages| and |
| 71 // |GetStorageInfoForPath| may not return the correct results. In addition, | 71 // |GetStorageInfoForPath| may not return the correct results. In addition, |
| 72 // registered observers will not be notified on device attachment/detachment. | 72 // registered observers will not be notified on device attachment/detachment. |
| 73 // Should be invoked on the UI thread; callbacks will be run on the UI thread. | 73 // Should be invoked on the UI thread; callbacks will be run on the UI thread. |
| 74 void Initialize(base::Closure callback); | 74 void Initialize(base::Closure callback); |
| 75 | 75 |
| 76 // Return true if the storage monitor has already been initialized. | 76 // Return true if the storage monitor has already been initialized. |
| 77 bool IsInitialized(); | 77 bool IsInitialized(); |
| 78 | 78 |
| 79 // Finds the device that contains |path| and populates |device_info|. | 79 // Finds the device that contains |path| and populates |device_info|. |
| 80 // Should be able to handle any path on the local system, not just removable | 80 // Should be able to handle any path on the local system, not just removable |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 95 const std::string& storage_device_id, | 95 const std::string& storage_device_id, |
| 96 string16* device_location, | 96 string16* device_location, |
| 97 string16* storage_object_id) const = 0; | 97 string16* storage_object_id) const = 0; |
| 98 #endif | 98 #endif |
| 99 | 99 |
| 100 #if defined(OS_LINUX) | 100 #if defined(OS_LINUX) |
| 101 virtual device::MediaTransferProtocolManager* | 101 virtual device::MediaTransferProtocolManager* |
| 102 media_transfer_protocol_manager() = 0; | 102 media_transfer_protocol_manager() = 0; |
| 103 #endif | 103 #endif |
| 104 | 104 |
| 105 // Returns information for attached removable storage. | 105 // Returns information for all known storages on the system, |
| 106 std::vector<StorageInfo> GetAttachedStorage() const; | 106 // including fixed and removable storages. |
| 107 std::vector<StorageInfo> GetAllAvailableStorages() const; | |
| 107 | 108 |
| 108 void AddObserver(RemovableStorageObserver* obs); | 109 void AddObserver(RemovableStorageObserver* obs); |
| 109 void RemoveObserver(RemovableStorageObserver* obs); | 110 void RemoveObserver(RemovableStorageObserver* obs); |
| 110 | 111 |
| 111 std::string GetTransientIdForDeviceId(const std::string& device_id); | 112 std::string GetTransientIdForDeviceId(const std::string& device_id); |
| 112 std::string GetDeviceIdForTransientId(const std::string& transient_id) const; | 113 std::string GetDeviceIdForTransientId(const std::string& transient_id) const; |
| 113 | 114 |
| 114 virtual void EjectDevice( | 115 virtual void EjectDevice( |
| 115 const std::string& device_id, | 116 const std::string& device_id, |
| 116 base::Callback<void(EjectStatus)> callback); | 117 base::Callback<void(EjectStatus)> callback); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 136 | 137 |
| 137 // Called by subclasses to mark the storage monitor as | 138 // Called by subclasses to mark the storage monitor as |
| 138 // fully initialized. Must be called on the UI thread. | 139 // fully initialized. Must be called on the UI thread. |
| 139 void MarkInitialized(); | 140 void MarkInitialized(); |
| 140 | 141 |
| 141 private: | 142 private: |
| 142 class ReceiverImpl; | 143 class ReceiverImpl; |
| 143 friend class ReceiverImpl; | 144 friend class ReceiverImpl; |
| 144 | 145 |
| 145 // Key: device id. | 146 // Key: device id. |
| 146 typedef std::map<std::string, StorageInfo> RemovableStorageMap; | 147 typedef std::map<std::string, StorageInfo> AllAvailableStorageMap; |
|
Hongbo Min
2013/06/04 02:52:29
StorageMap might be a better name.
Haojian Wu
2013/06/04 03:52:09
Done.
| |
| 147 | 148 |
| 148 void ProcessAttach(const StorageInfo& storage); | 149 void ProcessAttach(const StorageInfo& storage); |
| 149 void ProcessDetach(const std::string& id); | 150 void ProcessDetach(const std::string& id); |
| 150 | 151 |
| 151 scoped_ptr<Receiver> receiver_; | 152 scoped_ptr<Receiver> receiver_; |
| 152 | 153 |
| 153 scoped_refptr<ObserverListThreadSafe<RemovableStorageObserver> > | 154 scoped_refptr<ObserverListThreadSafe<RemovableStorageObserver> > |
| 154 observer_list_; | 155 observer_list_; |
| 155 | 156 |
| 156 bool initialized_; | 157 bool initialized_; |
| 157 std::vector<base::Closure> on_initialize_callbacks_; | 158 std::vector<base::Closure> on_initialize_callbacks_; |
| 158 | 159 |
| 159 // For manipulating removable_storage_map_ structure. | 160 // For manipulating removable_storage_map_ structure. |
| 160 mutable base::Lock storage_lock_; | 161 mutable base::Lock storage_lock_; |
| 161 | 162 |
| 162 // Map of all the attached removable storage devices. | 163 // Map of all the attached removable storage devices. |
| 163 RemovableStorageMap storage_map_; | 164 AllAvailableStorageMap storage_map_; |
| 164 | 165 |
| 165 scoped_ptr<TransientDeviceIds> transient_device_ids_; | 166 scoped_ptr<TransientDeviceIds> transient_device_ids_; |
| 166 }; | 167 }; |
| 167 | 168 |
| 168 } // namespace chrome | 169 } // namespace chrome |
| 169 | 170 |
| 170 #endif // CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_H_ | 171 #endif // CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_H_ |
| OLD | NEW |