| 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_PORTABLE_DEVICE_WATCHER_WIN_H_ | 5 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ |
| 6 #define CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ | 6 #define CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ |
| 7 | 7 |
| 8 #include <portabledeviceapi.h> | 8 #include <portabledeviceapi.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "base/system_monitor/system_monitor.h" | 17 #include "chrome/browser/system_monitor/removable_storage_notifications.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class SequencedTaskRunner; | 20 class SequencedTaskRunner; |
| 21 } | 21 } |
| 22 | 22 |
| 23 class FilePath; | 23 class FilePath; |
| 24 | 24 |
| 25 namespace chrome { | 25 namespace chrome { |
| 26 | 26 |
| 27 namespace test { | 27 namespace test { |
| 28 class TestPortableDeviceWatcherWin; | 28 class TestPortableDeviceWatcherWin; |
| 29 } | 29 } |
| 30 | 30 |
| 31 // This class watches the portable device mount points and sends notifications | 31 // This class watches the portable device mount points and sends notifications |
| 32 // to base::SystemMonitor about the attached/detached media transfer protocol | 32 // about the attached/detached media transfer protocol (MTP) devices. |
| 33 // (MTP) devices. This is a singleton class instantiated by | 33 // This is a singleton class instantiated by |
| 34 // RemovableDeviceNotificationsWindowWin. This class is created, destroyed and | 34 // RemovableDeviceNotificationsWindowWin. This class is created, destroyed and |
| 35 // operates on the UI thread, except for long running tasks it spins off to a | 35 // operates on the UI thread, except for long running tasks it spins off to a |
| 36 // SequencedTaskRunner. | 36 // SequencedTaskRunner. |
| 37 class PortableDeviceWatcherWin { | 37 class PortableDeviceWatcherWin { |
| 38 public: | 38 public: |
| 39 typedef std::vector<string16> StorageObjectIDs; | 39 typedef std::vector<string16> StorageObjectIDs; |
| 40 | 40 |
| 41 struct DeviceStorageObject { | 41 struct DeviceStorageObject { |
| 42 DeviceStorageObject(const string16& temporary_id, | 42 DeviceStorageObject(const string16& temporary_id, |
| 43 const std::string& persistent_id); | 43 const std::string& persistent_id); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 60 string16 name; | 60 string16 name; |
| 61 | 61 |
| 62 // Device interface path. | 62 // Device interface path. |
| 63 string16 location; | 63 string16 location; |
| 64 | 64 |
| 65 // Device storage details. A device can have multiple data partitions. | 65 // Device storage details. A device can have multiple data partitions. |
| 66 StorageObjects storage_objects; | 66 StorageObjects storage_objects; |
| 67 }; | 67 }; |
| 68 typedef std::vector<DeviceDetails> Devices; | 68 typedef std::vector<DeviceDetails> Devices; |
| 69 | 69 |
| 70 // TODO(gbillock): Change to take the device notifications object as |
| 71 // an argument. |
| 70 PortableDeviceWatcherWin(); | 72 PortableDeviceWatcherWin(); |
| 71 virtual ~PortableDeviceWatcherWin(); | 73 virtual ~PortableDeviceWatcherWin(); |
| 72 | 74 |
| 73 // Must be called after the browser blocking pool is ready for use. | 75 // Must be called after the browser blocking pool is ready for use. |
| 74 // RemovableDeviceNotificationsWindowsWin::Init() will call this function. | 76 // RemovableDeviceNotificationsWindowsWin::Init() will call this function. |
| 75 void Init(HWND hwnd); | 77 void Init(HWND hwnd); |
| 76 | 78 |
| 77 // Processes DEV_BROADCAST_DEVICEINTERFACE messages and triggers a | 79 // Processes DEV_BROADCAST_DEVICEINTERFACE messages and triggers a |
| 78 // SystemMonitor notification if appropriate. | 80 // notification if appropriate. |
| 79 void OnWindowMessage(UINT event_type, LPARAM data); | 81 void OnWindowMessage(UINT event_type, LPARAM data); |
| 80 | 82 |
| 81 // Gets the information of the MTP storage specified by |storage_device_id|. | 83 // Gets the information of the MTP storage specified by |storage_device_id|. |
| 82 // On success, returns true and fills in |device_location| with device | 84 // On success, returns true and fills in |device_location| with device |
| 83 // interface details and |storage_object_id| with storage object temporary | 85 // interface details and |storage_object_id| with storage object temporary |
| 84 // identifier. | 86 // identifier. |
| 85 bool GetMTPStorageInfoFromDeviceId(const std::string& storage_device_id, | 87 bool GetMTPStorageInfoFromDeviceId(const std::string& storage_device_id, |
| 86 string16* device_location, | 88 string16* device_location, |
| 87 string16* storage_object_id); | 89 string16* storage_object_id); |
| 88 | 90 |
| 89 private: | 91 private: |
| 90 friend class test::TestPortableDeviceWatcherWin; | 92 friend class test::TestPortableDeviceWatcherWin; |
| 91 | 93 |
| 92 // Key: MTP device storage unique id. | 94 // Key: MTP device storage unique id. |
| 93 // Value: Metadata for the given storage. | 95 // Value: Metadata for the given storage. |
| 94 typedef std::map<std::string, base::SystemMonitor::RemovableStorageInfo> | 96 typedef std::map<std::string, RemovableStorageNotifications::StorageInfo> |
| 95 MTPStorageMap; | 97 MTPStorageMap; |
| 96 | 98 |
| 97 // Key: MTP device plug and play ID string. | 99 // Key: MTP device plug and play ID string. |
| 98 // Value: Vector of device storage objects. | 100 // Value: Vector of device storage objects. |
| 99 typedef std::map<string16, StorageObjects> MTPDeviceMap; | 101 typedef std::map<string16, StorageObjects> MTPDeviceMap; |
| 100 | 102 |
| 101 // Helpers to enumerate existing MTP storage devices. | 103 // Helpers to enumerate existing MTP storage devices. |
| 102 virtual void EnumerateAttachedDevices(); | 104 virtual void EnumerateAttachedDevices(); |
| 103 void OnDidEnumerateAttachedDevices(const Devices* devices, | 105 void OnDidEnumerateAttachedDevices(const Devices* devices, |
| 104 const bool result); | 106 const bool result); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 126 | 128 |
| 127 // Used by |media_task_runner_| to create cancelable callbacks. | 129 // Used by |media_task_runner_| to create cancelable callbacks. |
| 128 base::WeakPtrFactory<PortableDeviceWatcherWin> weak_ptr_factory_; | 130 base::WeakPtrFactory<PortableDeviceWatcherWin> weak_ptr_factory_; |
| 129 | 131 |
| 130 DISALLOW_COPY_AND_ASSIGN(PortableDeviceWatcherWin); | 132 DISALLOW_COPY_AND_ASSIGN(PortableDeviceWatcherWin); |
| 131 }; | 133 }; |
| 132 | 134 |
| 133 } // namespace chrome | 135 } // namespace chrome |
| 134 | 136 |
| 135 #endif // CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ | 137 #endif // CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ |
| OLD | NEW |