Chromium Code Reviews| 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..acced4ad219a82493ed517e4cbd4745410b26530 |
| --- /dev/null |
| +++ b/chrome/browser/system_monitor/portable_device_watcher_win.h |
| @@ -0,0 +1,137 @@ |
| +// 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/synchronization/cancellation_flag.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. |
| +class PortableDeviceWatcherWin : public content::NotificationObserver { |
| + public: |
| + // Struct to store temporary and persistent storage object identifiers. |
| + struct DeviceStorageInfo { |
| + // Temporary identifier that uniquely identifies the object on the device. |
| + // This need not be persistent across sessions. |
| + // E.g.: s10001 |
| + string16 storage_object_id; |
| + |
| + // Stores the persistent id of the storage object. |
| + // E.g.: StorageSerial:<SID-{10001,D,31080448}>:<123456789> |
| + std::string unique_id; |
| + }; |
| + |
| + // Struct to store attached mtp device details. |
| + struct DeviceDetails { |
| + // Device can have multiple data partitions. Therefore, store a list of |
| + // device storage details. |
| + std::vector<DeviceStorageInfo> storage_info_list; |
| + |
| + // Device name. |
| + string16 name; |
| + |
| + // Device interface path. |
| + string16 location; |
| + }; |
| + |
| + PortableDeviceWatcherWin(); |
| + virtual ~PortableDeviceWatcherWin(); |
| + |
| + // Must be called after the browser blocking pool is ready for use. |
| + void Init(); |
| + |
| + // Gets information about the mtp device specified by |device_path|. On |
| + // success, returns true and fills in |location|, |unique_id|, |name| and |
| + // |removable|. |
| + bool GetDeviceInfo(const FilePath& device_path, |
| + string16* location, |
| + std::string* unique_id, |
| + string16* name, |
| + bool* removable); |
| + |
| + // 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; |
| + |
| + // List of Mtp device storage details. |
| + typedef std::vector<DeviceStorageInfo> StorageInfoList; |
| + |
| + // Key: Mtp device plug and play ID string. |
| + // Value: List of device storage objects. |
| + typedef std::map<string16, StorageInfoList> MtpDeviceMap; |
| + |
| + // Helpers to enumerate existing mtp storage devices. |
| + virtual void EnumerateAttachedDevices(); |
| + virtual void OnDidEnumerateAttachedDevices( |
| + std::vector<DeviceDetails> device_details_list); |
| + |
| + // Helpers to handle device attach event. |
| + virtual void HandleDeviceAttachEvent(const string16& pnp_device_id); |
|
vandebo (ex-Chrome)
2012/10/25 19:24:47
The difference between these methods isn't clear f
kmadhusu
2012/10/26 02:01:24
Renamed OnHandleDeviceAttachEvent => OnDidHandleDe
|
| + virtual void OnHandleDeviceAttachEvent(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; |
| + |
| + // Stores attached mtp device storage details. |
| + MtpStorageMap storage_map_; |
| + |
| + // Stores attached mtp device details. |
| + MtpDeviceMap device_map_; |
| + |
| + // Stores a reference to worker pool thread. Mtp device tasks are posted on |
| + // this thread. |
| + scoped_refptr<base::SequencedTaskRunner> media_task_runner_; |
| + |
| + // Used to notify PortableDeviceWatcherWin about the shutdown sequence. |
| + base::CancellationFlag app_terminating_flag_; |
| + |
| + // Handles registering notifications with the NotificationService. |
| + // Used to listen for application termination message. |
| + content::NotificationRegistrar registrar_; |
| + |
| + // |media_task_runner_| tasks may take a longer time to complete the tasks. |
| + // Used for creating callbacks. |
| + base::WeakPtrFactory<PortableDeviceWatcherWin> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PortableDeviceWatcherWin); |
| +}; |
| + |
| +} // namespace chrome |
| + |
| +#endif // CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ |