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

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: Rename storage_iter => storage_map_iter 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
« no previous file with comments | « no previous file | chrome/browser/system_monitor/portable_device_watcher_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 media transfer protocol
29 // (MTP) devices. This is a singleton class instantiated by
30 // RemovableDeviceNotificationsWindowWin. This class is created, destroyed and
31 // operates on the UI thread, except for long running tasks it spins off to a
32 // SequencedTaskRunner.
33 class PortableDeviceWatcherWin {
34 public:
35 typedef std::vector<string16> StorageObjectIDs;
36
37 struct DeviceStorageObject {
38 DeviceStorageObject(const string16& temporary_id,
39 const std::string& persistent_id);
40
41 // Storage object temporary identifier, e.g. "s10001".
42 string16 object_temporary_id;
43
44 // Storage object persistent identifier,
45 // e.g. "StorageSerial:<SID-{10001,D,31080448}>:<123456789>".
46 std::string object_persistent_id;
47 };
48 typedef std::vector<DeviceStorageObject> StorageObjects;
49
50 // Struct to store attached MTP device details.
51 struct DeviceDetails {
52 // Device name.
53 string16 name;
54
55 // Device interface path.
56 string16 location;
57
58 // Device storage details. A device can have multiple data partitions.
59 StorageObjects storage_objects;
60 };
61 typedef std::vector<DeviceDetails> Devices;
62
63 PortableDeviceWatcherWin();
64 virtual ~PortableDeviceWatcherWin();
65
66 // Must be called after the browser blocking pool is ready for use.
67 // RemovableDeviceNotificationsWindowsWin::Init() will call this function.
68 void Init(HWND hwnd);
69
70 // Processes DEV_BROADCAST_DEVICEINTERFACE messages and triggers a
71 // SystemMonitor notification if appropriate.
72 void OnWindowMessage(UINT event_type, LPARAM data);
73
74 private:
75 friend class TestPortableDeviceWatcherWin;
76
77 // Key: MTP device storage unique id.
78 // Value: Metadata for the given storage.
79 typedef std::map<std::string, base::SystemMonitor::RemovableStorageInfo>
80 MTPStorageMap;
81
82 // Key: MTP device plug and play ID string.
83 // Value: Vector of device storage objects.
84 typedef std::map<string16, StorageObjects> MTPDeviceMap;
85
86 // Helpers to enumerate existing MTP storage devices.
87 virtual void EnumerateAttachedDevices();
88 virtual void OnDidEnumerateAttachedDevices(const Devices* devices,
89 const bool result);
90
91 // Helpers to handle device attach event.
92 virtual void HandleDeviceAttachEvent(const string16& pnp_device_id);
93 virtual void OnDidHandleDeviceAttachEvent(
94 const DeviceDetails* device_details, const bool result);
95
96 // Handles the detach event of the device specified by |pnp_device_id|.
97 void HandleDeviceDetachEvent(const string16& pnp_device_id);
98
99 // The portable device notifications handle.
100 HDEVNOTIFY notifications_;
101
102 // Attached media transfer protocol device map.
103 MTPDeviceMap device_map_;
104
105 // Attached media transfer protocol device storage objects map.
106 MTPStorageMap storage_map_;
107
108 // The task runner used to execute tasks that may take a long time and thus
109 // should not be performed on the UI thread.
110 scoped_refptr<base::SequencedTaskRunner> media_task_runner_;
111
112 // Used by |media_task_runner_| to create cancelable callbacks.
113 base::WeakPtrFactory<PortableDeviceWatcherWin> weak_ptr_factory_;
114
115 DISALLOW_COPY_AND_ASSIGN(PortableDeviceWatcherWin);
116 };
117
118 } // namespace chrome
119
120 #endif // CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/system_monitor/portable_device_watcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698