Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ | |
| 6 #define CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ | |
| 7 | |
| 8 #include <portabledeviceapi.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <string> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "base/string16.h" | |
| 17 #include "base/system_monitor/system_monitor.h" | |
| 18 | |
| 19 namespace base { | |
| 20 class SequencedTaskRunner; | |
| 21 } | |
| 22 | |
| 23 class FilePath; | |
| 24 | |
| 25 namespace chrome { | |
| 26 | |
| 27 // This class watches the portable device mount points and sends notifications | |
| 28 // to base::SystemMonitor about the attached/detached Mtp devices. This is a | |
| 29 // singleton class instantiated by RemovableDeviceNotificationsWindowWin. This | |
| 30 // class is created, destroyed and operates on the UI thread, except for long | |
| 31 // running tasks it spins off to a media task runner. | |
|
Peter Kasting
2012/10/26 23:46:23
Nit: media task runner -> SequencedTaskRunner
kmadhusu
2012/10/28 22:57:16
Done.
| |
| 32 class PortableDeviceWatcherWin { | |
| 33 public: | |
| 34 // Struct to store device storage information. | |
|
Peter Kasting
2012/10/26 23:46:23
Nit: This comment doesn't add anything, remove.
kmadhusu
2012/10/28 22:57:16
Done.
| |
| 35 struct DeviceStorageObject { | |
| 36 // Storage object temporary identifier, e.g.: "s10001". | |
|
Peter Kasting
2012/10/26 23:46:23
Tiny nit: ':' not necessary after "e.g." (2 places
kmadhusu
2012/10/28 22:57:16
Done.
| |
| 37 string16 object_temporary_id; | |
| 38 | |
| 39 // Storage object persistent identifier, | |
| 40 // e.g.: "StorageSerial:<SID-{10001,D,31080448}>:<123456789>" | |
| 41 std::string object_persistent_id; | |
| 42 }; | |
| 43 | |
| 44 // Vector of media transfer protocol(mtp) device storage objects. | |
|
Peter Kasting
2012/10/26 23:46:23
Nit: Comment doesn't add anything, remove. (Same
kmadhusu
2012/10/28 22:57:16
Done.
| |
| 45 typedef std::vector<DeviceStorageObject> StorageObjects; | |
| 46 | |
| 47 // Struct to store attached mtp device details. | |
| 48 struct DeviceDetails { | |
| 49 // Device name. | |
| 50 string16 name; | |
| 51 | |
| 52 // Device interface path. | |
| 53 string16 location; | |
| 54 | |
| 55 // Device storage details. A device can have multiple data partitions. | |
| 56 StorageObjects storage_objects; | |
| 57 }; | |
| 58 | |
| 59 // Vector of media transfer protocol devices. | |
| 60 typedef std::vector<DeviceDetails> DeviceDetailsVector; | |
|
Peter Kasting
2012/10/26 23:46:23
Nit: How about just "Devices" as the type name? (
kmadhusu
2012/10/28 22:57:16
Done.
| |
| 61 | |
| 62 PortableDeviceWatcherWin(); | |
| 63 virtual ~PortableDeviceWatcherWin(); | |
| 64 | |
| 65 // Must be called after the browser blocking pool is ready for use. | |
| 66 // RemovableDeviceNotificationsWindowsWin::Init() will call this function. | |
| 67 void Init(); | |
| 68 | |
| 69 // Processes DEV_BROADCAST_DEVICEINTERFACE messages and triggers a | |
| 70 // SystemMonitor notification if appropriate. | |
| 71 void OnWindowMessage(UINT event_type, LPARAM data); | |
| 72 | |
| 73 private: | |
| 74 friend class TestPortableDeviceWatcherWin; | |
| 75 | |
| 76 // Key: MTP device storage unique id. | |
| 77 // Value: Metadata for the given storage. | |
| 78 typedef std::map<std::string, base::SystemMonitor::RemovableStorageInfo> | |
| 79 MtpStorageMap; | |
| 80 | |
| 81 // Key: Mtp device plug and play ID string. | |
| 82 // Value: Vector of device storage objects. | |
| 83 typedef std::map<string16, StorageObjects> MtpDeviceMap; | |
| 84 | |
| 85 // Helpers to enumerate existing mtp storage devices. | |
| 86 virtual void EnumerateAttachedDevices(); | |
| 87 virtual void OnDidEnumerateAttachedDevices( | |
| 88 const DeviceDetailsVector* device_details_vector); | |
| 89 | |
| 90 // Helpers to handle device attach event. | |
| 91 virtual void HandleDeviceAttachEvent(const string16& pnp_device_id); | |
| 92 virtual void OnDidHandleDeviceAttachEvent( | |
| 93 const DeviceDetails* device_details); | |
| 94 | |
| 95 // Handles the detach event of the device specified by |pnp_device_id|. | |
| 96 void HandleDeviceDetachEvent(const string16& pnp_device_id); | |
| 97 | |
| 98 // Attached media transfer protocol device map. | |
| 99 MtpDeviceMap device_map_; | |
| 100 | |
| 101 // Attached media transfer protocol device storage objects map. | |
| 102 MtpStorageMap storage_map_; | |
| 103 | |
| 104 // The task runner used to execute tasks that may take a long time and thus | |
| 105 // should not be performed on the UI thread. | |
| 106 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; | |
| 107 | |
| 108 // Used by |media_task_runner_| to create cancelable callbacks. | |
| 109 base::WeakPtrFactory<PortableDeviceWatcherWin> weak_ptr_factory_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(PortableDeviceWatcherWin); | |
| 112 }; | |
| 113 | |
| 114 } // namespace chrome | |
| 115 | |
| 116 #endif // CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ | |
| OLD | NEW |