Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / system_monitor / portable_device_watcher_win.h
blobdca68cba6faa050b4407208ae733d85b70923d1a
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.
5 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_
6 #define CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_
8 #include <portabledeviceapi.h>
10 #include <map>
11 #include <string>
12 #include <vector>
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"
19 namespace base {
20 class SequencedTaskRunner;
23 class FilePath;
25 namespace chrome {
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;
37 struct DeviceStorageObject {
38 DeviceStorageObject(const string16& temporary_id,
39 const std::string& persistent_id);
41 // Storage object temporary identifier, e.g. "s10001".
42 string16 object_temporary_id;
44 // Storage object persistent identifier,
45 // e.g. "StorageSerial:<SID-{10001,D,31080448}>:<123456789>".
46 std::string object_persistent_id;
48 typedef std::vector<DeviceStorageObject> StorageObjects;
50 // Struct to store attached MTP device details.
51 struct DeviceDetails {
52 // Device name.
53 string16 name;
55 // Device interface path.
56 string16 location;
58 // Device storage details. A device can have multiple data partitions.
59 StorageObjects storage_objects;
61 typedef std::vector<DeviceDetails> Devices;
63 PortableDeviceWatcherWin();
64 virtual ~PortableDeviceWatcherWin();
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);
70 // Processes DEV_BROADCAST_DEVICEINTERFACE messages and triggers a
71 // SystemMonitor notification if appropriate.
72 void OnWindowMessage(UINT event_type, LPARAM data);
74 private:
75 friend class TestPortableDeviceWatcherWin;
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;
82 // Key: MTP device plug and play ID string.
83 // Value: Vector of device storage objects.
84 typedef std::map<string16, StorageObjects> MTPDeviceMap;
86 // Helpers to enumerate existing MTP storage devices.
87 virtual void EnumerateAttachedDevices();
88 virtual void OnDidEnumerateAttachedDevices(const Devices* devices,
89 const bool result);
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);
96 // Handles the detach event of the device specified by |pnp_device_id|.
97 void HandleDeviceDetachEvent(const string16& pnp_device_id);
99 // The portable device notifications handle.
100 HDEVNOTIFY notifications_;
102 // Attached media transfer protocol device map.
103 MTPDeviceMap device_map_;
105 // Attached media transfer protocol device storage objects map.
106 MTPStorageMap storage_map_;
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_;
112 // Used by |media_task_runner_| to create cancelable callbacks.
113 base::WeakPtrFactory<PortableDeviceWatcherWin> weak_ptr_factory_;
115 DISALLOW_COPY_AND_ASSIGN(PortableDeviceWatcherWin);
118 } // namespace chrome
120 #endif // CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_