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..354be9aae01b944c3f0cfb78dcdf8705baabc83c |
| --- /dev/null |
| +++ b/chrome/browser/system_monitor/portable_device_watcher_win.h |
| @@ -0,0 +1,155 @@ |
| +// 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/sequenced_task_runner_helpers.h" |
| +#include "base/string16.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "base/system_monitor/system_monitor.h" |
| +#include "base/win/scoped_comptr.h" |
| +#include "content/public/browser/browser_thread.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 base::RefCountedThreadSafe<PortableDeviceWatcherWin, |
| + content::BrowserThread::DeleteOnUIThread>, |
|
Peter Kasting
2012/10/19 21:31:12
Except in extreme cases, refcounting implementatio
kmadhusu
2012/10/23 23:44:17
Thanks for the suggestion. Removed refcounting imp
|
| + public content::NotificationObserver { |
| + public: |
| + PortableDeviceWatcherWin(); |
| + |
| + // Must be called after the browser blocking pool is ready for use. |
| + void Init(); |
| + |
| + // Gets the information about the mtp device specified by |device_path|. |
| + // On success, returns true and fills in |location|, |unique_id|, |name| and |
| + // |removable|. |
| + virtual 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 struct content::BrowserThread::DeleteOnThread< |
| + content::BrowserThread::UI>; |
| + friend class base::DeleteHelper<PortableDeviceWatcherWin>; |
| + friend class TestPortableDeviceWatcherWin; |
| + |
| + // 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; |
| + }; |
| + |
| + // 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; |
| + |
| + // PortableDeviceWatcherWin is refcounted. |
| + virtual ~PortableDeviceWatcherWin(); |
| + |
| + // Initializes member variables on |media_task_runner_| thread. |
| + virtual void InitOnBlockingThread(); |
| + |
| + // On success, returns the friendly name of the device. |
| + // |pnp_device_id| specifies the plug and play device ID string. |
| + virtual string16 GetDeviceName(const string16& pnp_device_id); |
| + |
| + // On success, returns true and fills in |storages| with device |
| + // storage details. |pnp_device_id| specifies the plug and play device ID |
| + // string. |
| + virtual bool GetStorages(const string16& pnp_device_id, |
| + std::vector<DeviceStorageInfo>* storages); |
|
Peter Kasting
2012/10/19 21:31:12
"Storages" is not a word (grammar: storage is a ma
kmadhusu
2012/10/23 23:44:17
Renamed GetStorages => GetDeviceStorageInfoList
Re
|
| + |
| + // Enumerates existing mtp storage devices on |media_task_runner_| thread. |
| + void EnumerateStoragesOnBlockingThread(); |
| + |
| + // Handles the new mtp device attach event on |media_task_runner_| thread. |
| + // |pnp_device_id| specifies the plug and play device ID string. |
| + void HandleDeviceAttachEventOnBlockingThread(const string16& pnp_device_id); |
| + |
| + // Handles the detach event of the device specified by |pnp_device_id| on the |
| + // UI thread. |
| + void HandleDeviceDetachEventOnUIThread(const string16& pnp_device_id); |
| + |
| + // Gets the device storage details (such as name, unique_id) on |
| + // |media_task_runner_| thread. |
| + void GetDeviceInfoOnBlockingThread(const string16& pnp_device_id); |
| + |
| + // Adds the new mtp device details on UI thread. |
| + void AddMtpDeviceOnUIThread(const StorageInfoList& storage_ids, |
| + const string16& storage_name, |
| + const string16& location); |
| + |
| + // content::NotificationObserver implementation. |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| + // Map of all attached mtp device storages. |
| + MtpStorageMap storage_map_; |
| + |
| + // Map of all attached mtp devices. |
| + 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_; |
| + |
| + // Stores a reference to windows portable device manager. |
| + base::win::ScopedComPtr<IPortableDeviceManager> portable_device_mgr_; |
| + |
| + // Used to notify |media_task_runner_| pending tasks about the shutdown |
| + // sequence. |
| + base::WaitableEvent on_shutdown_event_; |
| + |
| + // Handles registering notifications with the NotificationService. |
| + // Used to listen for application termination message. |
| + content::NotificationRegistrar registrar_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PortableDeviceWatcherWin); |
| +}; |
| + |
| +} // namespace chrome |
| + |
| +#endif // CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ |