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_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_WI N_H_ | |
6 #define CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_WI N_H_ | |
7 | |
8 #include <PortableDeviceApi.h> | |
9 | |
10 #include <map> | |
11 #include <string> | |
12 | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/sequenced_task_runner_helpers.h" | |
15 #include "base/string16.h" | |
16 #include "base/system_monitor/system_monitor.h" | |
17 #include "base/win/scoped_comptr.h" | |
18 #include "content/public/browser/browser_thread.h" | |
19 | |
20 namespace base { | |
21 class SequencedTaskRunner; | |
22 } | |
23 | |
24 namespace chrome { | |
25 namespace mtp { | |
vandebo (ex-Chrome)
2012/10/16 17:42:36
I don't think the mtp namespace is needed
kmadhusu
2012/10/19 04:01:38
Done.
| |
26 | |
27 // Helper class to send MTP storage attachment and detachment events to | |
28 // base::SystemMonitor. | |
29 class MediaTransferProtocolDeviceObserverWin | |
vandebo (ex-Chrome)
2012/10/16 17:42:36
I don't see any particular reason this should be a
kmadhusu
2012/10/19 04:01:38
This class has several portable device specific co
| |
30 : public base::RefCountedThreadSafe< | |
31 MediaTransferProtocolDeviceObserverWin, | |
32 content::BrowserThread::DeleteOnUIThread> { | |
33 public: | |
34 // Struct to store temporary and persistent storage object identifiers. | |
35 struct DeviceStorageInfo { | |
36 // Temporary identifier that uniquely identifies the object on the device. | |
37 // This need not be persistent across sessions. | |
38 // E.g.: s10001 | |
39 string16 storage_object_id; | |
40 | |
41 // Stores the persistent id of the storage object. | |
42 // E.g.: StorageSerial:<SID-{10001,D,31080448}>:<123456789> | |
43 std::string unique_id; | |
44 }; | |
45 | |
46 // Should only be called by browser start up code. Use GetInstance() instead. | |
47 MediaTransferProtocolDeviceObserverWin(); | |
48 | |
49 // Returns the instance of MediaTransferProtocolDeviceObserverWin. | |
50 static MediaTransferProtocolDeviceObserverWin* GetInstance(); | |
51 | |
52 // Should only be called by browser start up code. Do all initializations on | |
53 // InitOnBlockingThread(). | |
54 void Init(); | |
55 | |
56 // Handles the mtp device event on UI thread. |pnp_device_id| specifies the | |
57 // plug and play device ID string. | |
58 void HandleMtpDeviceEventOnUIThread(bool is_attached, | |
59 const string16& pnp_device_id); | |
60 | |
61 protected: | |
62 // MediaTransferProtocolDeviceObserverWin is refcounted. | |
63 virtual ~MediaTransferProtocolDeviceObserverWin(); | |
64 | |
65 // Initializes member variables on |media_task_runner_| thread. | |
66 virtual void InitOnBlockingThread(); | |
67 | |
68 // On success, returns the friendly name of the device. | |
69 // |pnp_device_id| specifies the plug and play device ID string. | |
70 virtual string16 GetStorageName(LPWSTR pnp_device_id); | |
71 | |
72 // On success, returns true and fills in |storages| with device | |
73 // storage details. |pnp_device_id| specifies the plug and play device ID | |
74 // string. | |
75 virtual bool GetStorages(LPWSTR pnp_device_id, | |
76 std::vector<DeviceStorageInfo>* storages); | |
77 | |
78 private: | |
79 friend struct content::BrowserThread::DeleteOnThread< | |
80 content::BrowserThread::UI>; | |
81 friend class base::DeleteHelper<MediaTransferProtocolDeviceObserverWin>; | |
82 | |
83 // Key: MTP device storage id. | |
84 // Value: Metadata for the given storage. | |
85 typedef std::map<std::string, base::SystemMonitor::RemovableStorageInfo> | |
86 MtpStorageMap; | |
87 | |
88 // List of Mtp device storage details. | |
89 typedef std::vector<DeviceStorageInfo> StorageInfoList; | |
90 | |
91 // Key: Mtp device plug and play ID string. | |
92 // Value: List of device storage objects. | |
93 typedef std::map<string16, StorageInfoList> MtpDeviceMap; | |
94 | |
95 // Enumerates existing mtp storage devices on |media_task_runner_| thread. | |
96 void EnumerateStoragesOnBlockingThread(); | |
97 | |
98 // Handles the new mtp device attach event on |media_task_runner_| thread. | |
99 // |pnp_device_id| specifies the plug and play device ID string. | |
100 void HandleDeviceAttachEventOnBlockingThread(const string16& pnp_device_id); | |
101 | |
102 // Gets the device storage details (such as name, unique_id) on | |
103 // |media_task_runner_| thread. | |
104 void GetDeviceInfoOnBlockingThread(const string16& storage_location); | |
105 | |
106 // Adds the new mtp device details on UI thread. | |
107 void AddMtpDeviceOnUIThread(const StorageInfoList& storage_ids, | |
108 const string16& storage_name, | |
109 const string16& location); | |
110 | |
111 // Map of all attached mtp device storages. | |
112 MtpStorageMap storage_map_; | |
113 | |
114 // Map of all attached mtp devices. | |
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 // Stores a reference to windows portable device manager. | |
122 base::win::ScopedComPtr<IPortableDeviceManager> portable_device_mgr_; | |
123 | |
124 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDeviceObserverWin); | |
125 }; | |
126 | |
127 } // namespace mtp | |
128 } // namespace chrome | |
129 | |
130 #endif // CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER _WIN_H_ | |
OLD | NEW |