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_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_LI
NUX_H_ | 5 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_LI
NUX_H_ |
6 #define CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_LI
NUX_H_ | 6 #define CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_LI
NUX_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "base/system_monitor/system_monitor.h" | 12 #include "base/system_monitor/system_monitor.h" |
13 #include "chrome/browser/media_transfer_protocol/media_transfer_protocol_manager
.h" | 13 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
14 | 14 |
15 class FilePath; | 15 class FilePath; |
16 | 16 |
17 namespace chrome { | 17 namespace chrome { |
18 | 18 |
19 // Gets the mtp device information given a |storage_name|. On success, | 19 // Gets the mtp device information given a |storage_name|. On success, |
20 // fills in |id|, |name| and |location|. | 20 // fills in |id|, |name| and |location|. |
21 typedef void (*GetStorageInfoFunc)(const std::string& storage_name, | 21 typedef void (*GetStorageInfoFunc)(const std::string& storage_name, |
22 std::string* id, | 22 std::string* id, |
23 string16* name, | 23 string16* name, |
24 std::string* location); | 24 std::string* location); |
25 | 25 |
26 // Helper class to send MTP storage attachment and detachment events to | 26 // Helper class to send MTP storage attachment and detachment events to |
27 // SystemMonitor. | 27 // SystemMonitor. |
28 class MediaTransferProtocolDeviceObserverLinux | 28 class MediaTransferProtocolDeviceObserverLinux |
29 : public MediaTransferProtocolManager::Observer { | 29 : public device::MediaTransferProtocolManager::Observer { |
30 public: | 30 public: |
31 // Should only be called by browser start up code. Use GetInstance() instead. | 31 // Should only be called by browser start up code. Use GetInstance() instead. |
32 MediaTransferProtocolDeviceObserverLinux(); | 32 MediaTransferProtocolDeviceObserverLinux(); |
33 virtual ~MediaTransferProtocolDeviceObserverLinux(); | 33 virtual ~MediaTransferProtocolDeviceObserverLinux(); |
34 | 34 |
35 static MediaTransferProtocolDeviceObserverLinux* GetInstance(); | 35 static MediaTransferProtocolDeviceObserverLinux* GetInstance(); |
36 | 36 |
37 // Finds the storage that contains |path| and populates |storage_info|. | 37 // Finds the storage that contains |path| and populates |storage_info|. |
38 // Returns false if unable to find the storage. | 38 // Returns false if unable to find the storage. |
39 bool GetStorageInfoForPath( | 39 bool GetStorageInfoForPath( |
40 const FilePath& path, | 40 const FilePath& path, |
41 base::SystemMonitor::RemovableStorageInfo* storage_info) const; | 41 base::SystemMonitor::RemovableStorageInfo* storage_info) const; |
42 | 42 |
43 protected: | 43 protected: |
44 // Only used in unit tests. | 44 // Only used in unit tests. |
45 explicit MediaTransferProtocolDeviceObserverLinux( | 45 explicit MediaTransferProtocolDeviceObserverLinux( |
46 GetStorageInfoFunc get_storage_info_func); | 46 GetStorageInfoFunc get_storage_info_func); |
47 | 47 |
48 // MediaTransferProtocolManager::Observer implementation. | 48 // device::MediaTransferProtocolManager::Observer implementation. |
49 // Exposed for unit tests. | 49 // Exposed for unit tests. |
50 virtual void StorageChanged(bool is_attached, | 50 virtual void StorageChanged(bool is_attached, |
51 const std::string& storage_name) OVERRIDE; | 51 const std::string& storage_name) OVERRIDE; |
52 | 52 |
53 private: | 53 private: |
54 // Mapping of storage location and mtp storage info object. | 54 // Mapping of storage location and mtp storage info object. |
55 typedef std::map<std::string, base::SystemMonitor::RemovableStorageInfo> | 55 typedef std::map<std::string, base::SystemMonitor::RemovableStorageInfo> |
56 StorageLocationToInfoMap; | 56 StorageLocationToInfoMap; |
57 | 57 |
58 // Enumerate existing mtp storage devices. | 58 // Enumerate existing mtp storage devices. |
59 void EnumerateStorages(); | 59 void EnumerateStorages(); |
60 | 60 |
61 // Map of all attached mtp devices. | 61 // Map of all attached mtp devices. |
62 StorageLocationToInfoMap storage_map_; | 62 StorageLocationToInfoMap storage_map_; |
63 | 63 |
64 // Function handler to get storage information. This is useful to set a mock | 64 // Function handler to get storage information. This is useful to set a mock |
65 // handler for unit testing. | 65 // handler for unit testing. |
66 GetStorageInfoFunc get_storage_info_func_; | 66 GetStorageInfoFunc get_storage_info_func_; |
67 | 67 |
68 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDeviceObserverLinux); | 68 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDeviceObserverLinux); |
69 }; | 69 }; |
70 | 70 |
71 } // namespace chrome | 71 } // namespace chrome |
72 | 72 |
73 #endif // CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER
_LINUX_H_ | 73 #endif // CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER
_LINUX_H_ |
OLD | NEW |