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

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 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 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20
21 namespace base {
22 class SequencedTaskRunner;
23 }
24
25 class FilePath;
26
27 namespace chrome {
28
29 // This class watches the portable device mount points and sends notifications
30 // to base::SystemMonitor about the attached/detached Mtp devices. This is a
31 // singleton class instantiated by RemovableDeviceNotificationsWindowWin. This
32 // class is created, destroyed and operates on the UI thread, except for long
33 // running tasks it spins off to a media task runner.
34 class PortableDeviceWatcherWin : public content::NotificationObserver {
35 public:
36 // Struct to store device storage information.
37 struct DeviceStorageObject {
38 // Storage object temporary identifier, e.g.: "s10001".
39 string16 object_temporary_id;
40
41 // Storage object persistent identifier,
42 // e.g.: "StorageSerial:<SID-{10001,D,31080448}>:<123456789>"
43 std::string object_persistent_id;
44 };
45
46 // Vector of media transfer protocol(mtp) device storage objects.
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
61 // Vector of media transfer protocol devices.
62 typedef std::vector<DeviceDetails> DeviceDetailsVector;
63
64 PortableDeviceWatcherWin();
65 virtual ~PortableDeviceWatcherWin();
66
67 // Must be called after the browser blocking pool is ready for use.
68 // RemovableDeviceNotificationsWindowsWin::Init() will call this function.
69 void Init();
70
71 // Processes DEV_BROADCAST_DEVICEINTERFACE messages and triggers a
72 // SystemMonitor notification if appropriate.
73 void OnWindowMessage(UINT event_type, LPARAM data);
74
75 private:
76 friend class TestPortableDeviceWatcherWin;
77
78 // Key: MTP device storage unique id.
79 // Value: Metadata for the given storage.
80 typedef std::map<std::string, base::SystemMonitor::RemovableStorageInfo>
81 MtpStorageMap;
82
83 // Key: Mtp device plug and play ID string.
84 // Value: Vector of device storage objects.
85 typedef std::map<string16, StorageObjects> MtpDeviceMap;
86
87 // Helpers to enumerate existing mtp storage devices.
88 virtual void EnumerateAttachedDevices();
89 virtual void OnDidEnumerateAttachedDevices(
90 const DeviceDetailsVector* device_details_vector);
91
92 // Helpers to handle device attach event.
93 virtual void HandleDeviceAttachEvent(const string16& pnp_device_id);
94 virtual void OnDidHandleDeviceAttachEvent(
95 const DeviceDetails* device_details);
96
97 // Handles the detach event of the device specified by |pnp_device_id|.
98 void HandleDeviceDetachEvent(const string16& pnp_device_id);
99
100 // content::NotificationObserver implementation.
101 virtual void Observe(int type,
102 const content::NotificationSource& source,
103 const content::NotificationDetails& details) OVERRIDE;
104
105
106 // Attached media transfer protocol device map.
107 MtpDeviceMap device_map_;
108
109 // Attached media transfer protocol device storage objects map.
110 MtpStorageMap storage_map_;
111
112 // The task runner used to execute tasks that may take a long time and thus
113 // should not be performed on the UI thread.
114 scoped_refptr<base::SequencedTaskRunner> media_task_runner_;
115
116 // Set to true if the application is terminating. If true, do not handle any
117 // device change messages.
118 bool app_terminating_;
119
120 // Used to listen for NOTIFICATION_APP_TERMINATING message. When the message
121 // is received, do not handle any window messages.
122 content::NotificationRegistrar registrar_;
123
124 // Used by |media_task_runner_| to create cancelable callbacks.
125 base::WeakPtrFactory<PortableDeviceWatcherWin> weak_ptr_factory_;
126
127 DISALLOW_COPY_AND_ASSIGN(PortableDeviceWatcherWin);
128 };
129
130 } // namespace chrome
131
132 #endif // CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698