Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1126)

Side by Side Diff: chrome/browser/system_monitor/portable_device_watcher_win.h

Issue 11088012: [Win, MediaGallery] Enumerate and handle mtp device attach/detach events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/sequenced_task_runner_helpers.h"
16 #include "base/string16.h"
17 #include "base/synchronization/waitable_event.h"
18 #include "base/system_monitor/system_monitor.h"
19 #include "base/win/scoped_comptr.h"
20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h"
23
24 namespace base {
25 class SequencedTaskRunner;
26 }
27
28 class FilePath;
29
30 namespace chrome {
31
32 // This class watches the portable device mount points and sends notifications
33 // to base::SystemMonitor about the attached/detached Mtp devices. This is a
34 // singleton class instantiated by RemovableDeviceNotificationsWindowWin.
35 class PortableDeviceWatcherWin
36 : public base::RefCountedThreadSafe<PortableDeviceWatcherWin,
37 content::BrowserThread::DeleteOnUIThread>,
Peter Kasting 2012/10/19 21:31:12 Except in extreme cases, refcounting implementatio
kmadhusu 2012/10/23 23:44:17 Thanks for the suggestion. Removed refcounting imp
38 public content::NotificationObserver {
39 public:
40 PortableDeviceWatcherWin();
41
42 // Must be called after the browser blocking pool is ready for use.
43 void Init();
44
45 // Gets the information about the mtp device specified by |device_path|.
46 // On success, returns true and fills in |location|, |unique_id|, |name| and
47 // |removable|.
48 virtual bool GetDeviceInfo(const FilePath& device_path,
49 string16* location,
50 std::string* unique_id,
51 string16* name,
52 bool* removable);
53
54 // Processes DEV_BROADCAST_DEVICEINTERFACE messages and triggers a
55 // SystemMonitor notification if appropriate.
56 void OnWindowMessage(UINT event_type, LPARAM data);
57
58 private:
59 friend struct content::BrowserThread::DeleteOnThread<
60 content::BrowserThread::UI>;
61 friend class base::DeleteHelper<PortableDeviceWatcherWin>;
62 friend class TestPortableDeviceWatcherWin;
63
64 // Struct to store temporary and persistent storage object identifiers.
65 struct DeviceStorageInfo {
66 // Temporary identifier that uniquely identifies the object on the device.
67 // This need not be persistent across sessions.
68 // E.g.: s10001
69 string16 storage_object_id;
70
71 // Stores the persistent id of the storage object.
72 // E.g.: StorageSerial:<SID-{10001,D,31080448}>:<123456789>
73 std::string unique_id;
74 };
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 // List of Mtp device storage details.
82 typedef std::vector<DeviceStorageInfo> StorageInfoList;
83
84 // Key: Mtp device plug and play ID string.
85 // Value: List of device storage objects.
86 typedef std::map<string16, StorageInfoList> MtpDeviceMap;
87
88 // PortableDeviceWatcherWin is refcounted.
89 virtual ~PortableDeviceWatcherWin();
90
91 // Initializes member variables on |media_task_runner_| thread.
92 virtual void InitOnBlockingThread();
93
94 // On success, returns the friendly name of the device.
95 // |pnp_device_id| specifies the plug and play device ID string.
96 virtual string16 GetDeviceName(const string16& pnp_device_id);
97
98 // On success, returns true and fills in |storages| with device
99 // storage details. |pnp_device_id| specifies the plug and play device ID
100 // string.
101 virtual bool GetStorages(const string16& pnp_device_id,
102 std::vector<DeviceStorageInfo>* storages);
Peter Kasting 2012/10/19 21:31:12 "Storages" is not a word (grammar: storage is a ma
kmadhusu 2012/10/23 23:44:17 Renamed GetStorages => GetDeviceStorageInfoList Re
103
104 // Enumerates existing mtp storage devices on |media_task_runner_| thread.
105 void EnumerateStoragesOnBlockingThread();
106
107 // Handles the new mtp device attach event on |media_task_runner_| thread.
108 // |pnp_device_id| specifies the plug and play device ID string.
109 void HandleDeviceAttachEventOnBlockingThread(const string16& pnp_device_id);
110
111 // Handles the detach event of the device specified by |pnp_device_id| on the
112 // UI thread.
113 void HandleDeviceDetachEventOnUIThread(const string16& pnp_device_id);
114
115 // Gets the device storage details (such as name, unique_id) on
116 // |media_task_runner_| thread.
117 void GetDeviceInfoOnBlockingThread(const string16& pnp_device_id);
118
119 // Adds the new mtp device details on UI thread.
120 void AddMtpDeviceOnUIThread(const StorageInfoList& storage_ids,
121 const string16& storage_name,
122 const string16& location);
123
124 // content::NotificationObserver implementation.
125 virtual void Observe(int type,
126 const content::NotificationSource& source,
127 const content::NotificationDetails& details) OVERRIDE;
128
129 // Map of all attached mtp device storages.
130 MtpStorageMap storage_map_;
131
132 // Map of all attached mtp devices.
133 MtpDeviceMap device_map_;
134
135 // Stores a reference to worker pool thread. Mtp device tasks are posted on
136 // this thread.
137 scoped_refptr<base::SequencedTaskRunner> media_task_runner_;
138
139 // Stores a reference to windows portable device manager.
140 base::win::ScopedComPtr<IPortableDeviceManager> portable_device_mgr_;
141
142 // Used to notify |media_task_runner_| pending tasks about the shutdown
143 // sequence.
144 base::WaitableEvent on_shutdown_event_;
145
146 // Handles registering notifications with the NotificationService.
147 // Used to listen for application termination message.
148 content::NotificationRegistrar registrar_;
149
150 DISALLOW_COPY_AND_ASSIGN(PortableDeviceWatcherWin);
151 };
152
153 } // namespace chrome
154
155 #endif // CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698