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

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, 1 month 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/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
Peter Kasting 2012/10/29 21:57:19 Nit: Mtp -> MTP (or "media transfer protocol (MTP)
kmadhusu 2012/10/30 01:29:24 Done.
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 SequencedTaskRunner.
32 class PortableDeviceWatcherWin {
33 public:
34 typedef std::vector<string16> StorageObjectIDs;
35
36 struct DeviceStorageObject {
37 DeviceStorageObject(const string16& temporary_id,
38 const std::string& persistent_id);
39
40 // Storage object temporary identifier, e.g. "s10001".
41 string16 object_temporary_id;
42
43 // Storage object persistent identifier,
44 // e.g. "StorageSerial:<SID-{10001,D,31080448}>:<123456789>"
Peter Kasting 2012/10/29 21:57:19 Nit: Trailing period
kmadhusu 2012/10/30 01:29:24 Done.
45 std::string object_persistent_id;
46 };
47 typedef std::vector<DeviceStorageObject> StorageObjects;
48
49 // Struct to store attached mtp device details.
50 struct DeviceDetails {
51 // Device name.
52 string16 name;
53
54 // Device interface path.
55 string16 location;
56
57 // Device storage details. A device can have multiple data partitions.
58 StorageObjects storage_objects;
59 };
60 typedef std::vector<DeviceDetails> Devices;
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;
Peter Kasting 2012/10/29 21:57:19 Nit: Style guide does not rule on this, but I thin
kmadhusu 2012/10/30 01:29:24 Done.
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(const Devices* devices,
88 const bool* result);
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, const bool* result);
94
95 // Handles the detach event of the device specified by |pnp_device_id|.
Peter Kasting 2012/10/29 21:57:19 Nit: Extra space
kmadhusu 2012/10/30 01:29:24 Done.
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698