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/synchronization/cancellation_flag.h" | |
| 18 #include "base/system_monitor/system_monitor.h" | |
| 19 #include "content/public/browser/notification_observer.h" | |
| 20 #include "content/public/browser/notification_registrar.h" | |
| 21 | |
| 22 namespace base { | |
| 23 class SequencedTaskRunner; | |
| 24 } | |
| 25 | |
| 26 class FilePath; | |
| 27 | |
| 28 namespace chrome { | |
| 29 | |
| 30 // This class watches the portable device mount points and sends notifications | |
| 31 // to base::SystemMonitor about the attached/detached Mtp devices. This is a | |
| 32 // singleton class instantiated by RemovableDeviceNotificationsWindowWin. | |
| 33 class PortableDeviceWatcherWin : public content::NotificationObserver { | |
| 34 public: | |
| 35 // Struct to store temporary and persistent storage object identifiers. | |
| 36 struct DeviceStorageInfo { | |
| 37 // Temporary identifier that uniquely identifies the object on the device. | |
| 38 // This need not be persistent across sessions. | |
| 39 // E.g.: s10001 | |
| 40 string16 storage_object_id; | |
| 41 | |
| 42 // Stores the persistent id of the storage object. | |
| 43 // E.g.: StorageSerial:<SID-{10001,D,31080448}>:<123456789> | |
| 44 std::string unique_id; | |
| 45 }; | |
| 46 | |
| 47 // Struct to store attached mtp device details. | |
| 48 struct DeviceDetails { | |
| 49 // Device can have multiple data partitions. Therefore, store a list of | |
| 50 // device storage details. | |
| 51 std::vector<DeviceStorageInfo> storage_info_list; | |
| 52 | |
| 53 // Device name. | |
| 54 string16 name; | |
| 55 | |
| 56 // Device interface path. | |
| 57 string16 location; | |
| 58 }; | |
| 59 | |
| 60 PortableDeviceWatcherWin(); | |
| 61 virtual ~PortableDeviceWatcherWin(); | |
| 62 | |
| 63 // Must be called after the browser blocking pool is ready for use. | |
| 64 void Init(); | |
| 65 | |
| 66 // Gets information about the mtp device specified by |device_path|. On | |
| 67 // success, returns true and fills in |location|, |unique_id|, |name| and | |
| 68 // |removable|. | |
| 69 bool GetDeviceInfo(const FilePath& device_path, | |
| 70 string16* location, | |
| 71 std::string* unique_id, | |
| 72 string16* name, | |
| 73 bool* removable); | |
| 74 | |
| 75 // Processes DEV_BROADCAST_DEVICEINTERFACE messages and triggers a | |
| 76 // SystemMonitor notification if appropriate. | |
| 77 void OnWindowMessage(UINT event_type, LPARAM data); | |
| 78 | |
| 79 private: | |
| 80 friend class TestPortableDeviceWatcherWin; | |
| 81 | |
| 82 // Key: MTP device storage unique id. | |
| 83 // Value: Metadata for the given storage. | |
| 84 typedef std::map<std::string, base::SystemMonitor::RemovableStorageInfo> | |
| 85 MtpStorageMap; | |
| 86 | |
| 87 // List of Mtp device storage details. | |
| 88 typedef std::vector<DeviceStorageInfo> StorageInfoList; | |
| 89 | |
| 90 // Key: Mtp device plug and play ID string. | |
| 91 // Value: List of device storage objects. | |
| 92 typedef std::map<string16, StorageInfoList> MtpDeviceMap; | |
| 93 | |
| 94 // Helpers to enumerate existing mtp storage devices. | |
| 95 virtual void EnumerateAttachedDevices(); | |
| 96 virtual void OnDidEnumerateAttachedDevices( | |
| 97 std::vector<DeviceDetails> device_details_list); | |
| 98 | |
| 99 // Helpers to handle device attach event. | |
| 100 virtual void HandleDeviceAttachEvent(const string16& pnp_device_id); | |
|
vandebo (ex-Chrome)
2012/10/25 19:24:47
The difference between these methods isn't clear f
kmadhusu
2012/10/26 02:01:24
Renamed OnHandleDeviceAttachEvent => OnDidHandleDe
| |
| 101 virtual void OnHandleDeviceAttachEvent(DeviceDetails device_details); | |
| 102 | |
| 103 // Handles the detach event of the device specified by |pnp_device_id|. | |
| 104 void HandleDeviceDetachEvent(const string16& pnp_device_id); | |
| 105 | |
| 106 // content::NotificationObserver implementation. | |
| 107 virtual void Observe(int type, | |
| 108 const content::NotificationSource& source, | |
| 109 const content::NotificationDetails& details) OVERRIDE; | |
| 110 | |
| 111 // Stores attached mtp device storage details. | |
| 112 MtpStorageMap storage_map_; | |
| 113 | |
| 114 // Stores attached mtp device details. | |
| 115 MtpDeviceMap device_map_; | |
| 116 | |
| 117 // Stores a reference to worker pool thread. Mtp device tasks are posted on | |
| 118 // this thread. | |
| 119 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; | |
| 120 | |
| 121 // Used to notify PortableDeviceWatcherWin about the shutdown sequence. | |
| 122 base::CancellationFlag app_terminating_flag_; | |
| 123 | |
| 124 // Handles registering notifications with the NotificationService. | |
| 125 // Used to listen for application termination message. | |
| 126 content::NotificationRegistrar registrar_; | |
| 127 | |
| 128 // |media_task_runner_| tasks may take a longer time to complete the tasks. | |
| 129 // Used for creating callbacks. | |
| 130 base::WeakPtrFactory<PortableDeviceWatcherWin> weak_ptr_factory_; | |
| 131 | |
| 132 DISALLOW_COPY_AND_ASSIGN(PortableDeviceWatcherWin); | |
| 133 }; | |
| 134 | |
| 135 } // namespace chrome | |
| 136 | |
| 137 #endif // CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ | |
| OLD | NEW |