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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_STORAGE_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_LINUX_H_
6 #define CHROME_BROWSER_STORAGE_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_LINUX_H_
11 #include "base/strings/string16.h"
12 #include "chrome/browser/storage_monitor/storage_monitor.h"
13 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
19 // Gets the mtp device information given a |storage_name|. On success,
20 // fills in |id|, |name| and |location|.
21 typedef void (*GetStorageInfoFunc)(
22 const std::string& storage_name,
23 device::MediaTransferProtocolManager* mtp_manager,
26 std::string* location);
28 // Helper class to send MTP storage attachment and detachment events to
30 class MediaTransferProtocolDeviceObserverLinux
31 : public device::MediaTransferProtocolManager::Observer {
33 MediaTransferProtocolDeviceObserverLinux(
34 StorageMonitor::Receiver* receiver,
35 device::MediaTransferProtocolManager* mtp_manager);
36 virtual ~MediaTransferProtocolDeviceObserverLinux();
38 // Finds the storage that contains |path| and populates |storage_info|.
39 // Returns false if unable to find the storage.
40 bool GetStorageInfoForPath(const base::FilePath& path,
41 StorageInfo* storage_info) const;
43 void EjectDevice(const std::string& device_id,
44 base::Callback<void(StorageMonitor::EjectStatus)> callback);
47 // Only used in unit tests.
48 MediaTransferProtocolDeviceObserverLinux(
49 StorageMonitor::Receiver* receiver,
50 device::MediaTransferProtocolManager* mtp_manager,
51 GetStorageInfoFunc get_storage_info_func);
53 // device::MediaTransferProtocolManager::Observer implementation.
54 // Exposed for unit tests.
55 virtual void StorageChanged(bool is_attached,
56 const std::string& storage_name) OVERRIDE;
59 // Mapping of storage location and mtp storage info object.
60 typedef std::map<std::string, StorageInfo> StorageLocationToInfoMap;
62 // Enumerate existing mtp storage devices.
63 void EnumerateStorages();
65 // Find the |storage_map_| key for the record with this |device_id|. Returns
66 // true on success, false on failure.
67 bool GetLocationForDeviceId(const std::string& device_id,
68 std::string* location) const;
70 // Pointer to the MTP manager. Not owned. Client must ensure the MTP
71 // manager outlives this object.
72 device::MediaTransferProtocolManager* mtp_manager_;
74 // Map of all attached mtp devices.
75 StorageLocationToInfoMap storage_map_;
77 // Function handler to get storage information. This is useful to set a mock
78 // handler for unit testing.
79 GetStorageInfoFunc get_storage_info_func_;
81 // The notifications object to use to signal newly attached devices.
82 // Guaranteed to outlive this class.
83 StorageMonitor::Receiver* const notifications_;
85 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDeviceObserverLinux);
88 #endif // CHROME_BROWSER_STORAGE_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_LINUX_H_