Index: chrome/browser/system_monitor/portable_device_watcher_win.h |
diff --git a/chrome/browser/system_monitor/portable_device_watcher_win.h b/chrome/browser/system_monitor/portable_device_watcher_win.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b96b00f3b85905fb55f1d44218411aaa5130cf33 |
--- /dev/null |
+++ b/chrome/browser/system_monitor/portable_device_watcher_win.h |
@@ -0,0 +1,132 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ |
+#define CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ |
+ |
+#include <portabledeviceapi.h> |
+ |
+#include <map> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/string16.h" |
+#include "base/system_monitor/system_monitor.h" |
+#include "content/public/browser/notification_observer.h" |
+#include "content/public/browser/notification_registrar.h" |
+ |
+namespace base { |
+class SequencedTaskRunner; |
+} |
+ |
+class FilePath; |
+ |
+namespace chrome { |
+ |
+// This class watches the portable device mount points and sends notifications |
+// to base::SystemMonitor about the attached/detached Mtp devices. This is a |
+// singleton class instantiated by RemovableDeviceNotificationsWindowWin. This |
+// class is created, destroyed and operates on the UI thread, except for long |
+// running tasks it spins off to a media task runner. |
+class PortableDeviceWatcherWin : public content::NotificationObserver { |
+ public: |
+ // Struct to store device storage information. |
+ struct DeviceStorageObject { |
+ // Storage object temporary identifier, e.g.: "s10001". |
+ string16 object_temporary_id; |
+ |
+ // Storage object persistent identifier, |
+ // e.g.: "StorageSerial:<SID-{10001,D,31080448}>:<123456789>" |
+ std::string object_persistent_id; |
+ }; |
+ |
+ // Vector of media transfer protocol(mtp) device storage objects. |
+ typedef std::vector<DeviceStorageObject> StorageObjects; |
+ |
+ // Struct to store attached mtp device details. |
+ struct DeviceDetails { |
+ // Device name. |
+ string16 name; |
+ |
+ // Device interface path. |
+ string16 location; |
+ |
+ // Device storage details. A device can have multiple data partitions. |
+ StorageObjects storage_objects; |
+ }; |
+ |
+ // Vector of media transfer protocol devices. |
+ typedef std::vector<DeviceDetails> DeviceDetailsVector; |
+ |
+ PortableDeviceWatcherWin(); |
+ virtual ~PortableDeviceWatcherWin(); |
+ |
+ // Must be called after the browser blocking pool is ready for use. |
+ // RemovableDeviceNotificationsWindowsWin::Init() will call this function. |
+ void Init(); |
+ |
+ // Processes DEV_BROADCAST_DEVICEINTERFACE messages and triggers a |
+ // SystemMonitor notification if appropriate. |
+ void OnWindowMessage(UINT event_type, LPARAM data); |
+ |
+ private: |
+ friend class TestPortableDeviceWatcherWin; |
+ |
+ // Key: MTP device storage unique id. |
+ // Value: Metadata for the given storage. |
+ typedef std::map<std::string, base::SystemMonitor::RemovableStorageInfo> |
+ MtpStorageMap; |
+ |
+ // Key: Mtp device plug and play ID string. |
+ // Value: Vector of device storage objects. |
+ typedef std::map<string16, StorageObjects> MtpDeviceMap; |
+ |
+ // Helpers to enumerate existing mtp storage devices. |
+ virtual void EnumerateAttachedDevices(); |
+ virtual void OnDidEnumerateAttachedDevices( |
+ const DeviceDetailsVector* device_details_vector); |
+ |
+ // Helpers to handle device attach event. |
+ virtual void HandleDeviceAttachEvent(const string16& pnp_device_id); |
+ virtual void OnDidHandleDeviceAttachEvent( |
+ const DeviceDetails* device_details); |
+ |
+ // Handles the detach event of the device specified by |pnp_device_id|. |
+ void HandleDeviceDetachEvent(const string16& pnp_device_id); |
+ |
+ // content::NotificationObserver implementation. |
+ virtual void Observe(int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) OVERRIDE; |
+ |
+ |
+ // Attached media transfer protocol device map. |
+ MtpDeviceMap device_map_; |
+ |
+ // Attached media transfer protocol device storage objects map. |
+ MtpStorageMap storage_map_; |
+ |
+ // The task runner used to execute tasks that may take a long time and thus |
+ // should not be performed on the UI thread. |
+ scoped_refptr<base::SequencedTaskRunner> media_task_runner_; |
+ |
+ // Set to true if the application is terminating. If true, do not handle any |
+ // device change messages. |
+ bool app_terminating_; |
+ |
+ // Used to listen for NOTIFICATION_APP_TERMINATING message. When the message |
+ // is received, do not handle any window messages. |
+ content::NotificationRegistrar registrar_; |
+ |
+ // Used by |media_task_runner_| to create cancelable callbacks. |
+ base::WeakPtrFactory<PortableDeviceWatcherWin> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PortableDeviceWatcherWin); |
+}; |
+ |
+} // namespace chrome |
+ |
+#endif // CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ |