| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_STORAGE_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_LINUX
_H_ | |
| 6 #define COMPONENTS_STORAGE_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_LINUX
_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/strings/string16.h" | |
| 13 #include "components/storage_monitor/storage_monitor.h" | |
| 14 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | |
| 15 | |
| 16 namespace base { | |
| 17 class FilePath; | |
| 18 } | |
| 19 | |
| 20 namespace storage_monitor { | |
| 21 | |
| 22 // Gets the mtp device information given a |storage_name|. On success, | |
| 23 // fills in |id|, |name|, |location|, |vendor_name|, and |product_name|. | |
| 24 typedef void (*GetStorageInfoFunc)( | |
| 25 const std::string& storage_name, | |
| 26 device::MediaTransferProtocolManager* mtp_manager, | |
| 27 std::string* id, | |
| 28 base::string16* name, | |
| 29 std::string* location, | |
| 30 base::string16* vendor_name, | |
| 31 base::string16* product_name); | |
| 32 | |
| 33 // Helper class to send MTP storage attachment and detachment events to | |
| 34 // StorageMonitor. | |
| 35 class MediaTransferProtocolDeviceObserverLinux | |
| 36 : public device::MediaTransferProtocolManager::Observer { | |
| 37 public: | |
| 38 MediaTransferProtocolDeviceObserverLinux( | |
| 39 StorageMonitor::Receiver* receiver, | |
| 40 device::MediaTransferProtocolManager* mtp_manager); | |
| 41 ~MediaTransferProtocolDeviceObserverLinux() override; | |
| 42 | |
| 43 // Finds the storage that contains |path| and populates |storage_info|. | |
| 44 // Returns false if unable to find the storage. | |
| 45 bool GetStorageInfoForPath(const base::FilePath& path, | |
| 46 StorageInfo* storage_info) const; | |
| 47 | |
| 48 void EjectDevice(const std::string& device_id, | |
| 49 base::Callback<void(StorageMonitor::EjectStatus)> callback); | |
| 50 | |
| 51 protected: | |
| 52 // Only used in unit tests. | |
| 53 MediaTransferProtocolDeviceObserverLinux( | |
| 54 StorageMonitor::Receiver* receiver, | |
| 55 device::MediaTransferProtocolManager* mtp_manager, | |
| 56 GetStorageInfoFunc get_storage_info_func); | |
| 57 | |
| 58 // device::MediaTransferProtocolManager::Observer implementation. | |
| 59 // Exposed for unit tests. | |
| 60 void StorageChanged(bool is_attached, | |
| 61 const std::string& storage_name) override; | |
| 62 | |
| 63 private: | |
| 64 // Mapping of storage location and mtp storage info object. | |
| 65 typedef std::map<std::string, StorageInfo> StorageLocationToInfoMap; | |
| 66 | |
| 67 // Enumerate existing mtp storage devices. | |
| 68 void EnumerateStorages(); | |
| 69 | |
| 70 // Find the |storage_map_| key for the record with this |device_id|. Returns | |
| 71 // true on success, false on failure. | |
| 72 bool GetLocationForDeviceId(const std::string& device_id, | |
| 73 std::string* location) const; | |
| 74 | |
| 75 // Pointer to the MTP manager. Not owned. Client must ensure the MTP | |
| 76 // manager outlives this object. | |
| 77 device::MediaTransferProtocolManager* mtp_manager_; | |
| 78 | |
| 79 // Map of all attached mtp devices. | |
| 80 StorageLocationToInfoMap storage_map_; | |
| 81 | |
| 82 // Function handler to get storage information. This is useful to set a mock | |
| 83 // handler for unit testing. | |
| 84 GetStorageInfoFunc get_storage_info_func_; | |
| 85 | |
| 86 // The notifications object to use to signal newly attached devices. | |
| 87 // Guaranteed to outlive this class. | |
| 88 StorageMonitor::Receiver* const notifications_; | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDeviceObserverLinux); | |
| 91 }; | |
| 92 | |
| 93 } // namespace storage_monitor | |
| 94 | |
| 95 #endif // COMPONENTS_STORAGE_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_LI
NUX_H_ | |
| OLD | NEW |