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 { |
Peter Kasting
2012/10/25 05:23:24
Should this stuff really be in a namespace? I tho
kmadhusu
2012/10/26 02:01:24
I thought the other way around. Since this file is
Peter Kasting
2012/10/26 02:14:49
Almost no code in chrome uses a chrome namespace.
kmadhusu
2012/10/26 22:23:26
As per brettw@ comment, I am leaving this as it is
Peter Kasting
2012/10/26 22:35:34
I assume you're saying all the other code in syste
|
+ |
+// 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 |
Peter Kasting
2012/10/25 05:23:24
Nit: Slightly clearer if you write this example in
kmadhusu
2012/10/26 02:01:24
Done.
|
+ string16 storage_object_id; |
+ |
+ // Stores the persistent id of the storage object. |
+ // E.g.: StorageSerial:<SID-{10001,D,31080448}>:<123456789> |
+ std::string unique_id; |
Peter Kasting
2012/10/25 05:23:24
Nit: It's confusing to have the first string comme
kmadhusu
2012/10/26 02:01:24
Rephrased the comments.
Renamed storage_object_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; |
Peter Kasting
2012/10/25 05:23:24
Tiny nit: Does it make sense to put this after the
kmadhusu
2012/10/26 02:01:24
Done.
|
+ |
+ // Device name. |
+ string16 name; |
+ |
+ // Device interface path. |
+ string16 location; |
+ }; |
+ |
+ PortableDeviceWatcherWin(); |
+ virtual ~PortableDeviceWatcherWin(); |
+ |
+ // Must be called after the browser blocking pool is ready for use. |
Peter Kasting
2012/10/25 05:23:24
Nit: Document who is supposed to call this.
kmadhusu
2012/10/26 02:01:24
Done.
|
+ 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|. |
Peter Kasting
2012/10/25 05:23:24
Nit: Say whether these are all left untouched on f
kmadhusu
2012/10/26 02:01:24
Done.
|
+ 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; |
Peter Kasting
2012/10/25 05:23:24
Nit: This should be public, and you should use it
kmadhusu
2012/10/26 02:01:24
Renamed DeviceStorageInfo => DeviceStorageObject
R
|
+ |
+ // 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); |
Peter Kasting
2012/10/25 05:23:24
Nit: const ref
kmadhusu
2012/10/26 02:01:24
Changed to const ptr. I couldn't pass const ref to
Peter Kasting
2012/10/26 02:14:49
Check with willchan, akalin, or some other knowled
kmadhusu
2012/10/26 22:23:26
Contacted willchan@ and akalin@. Looks like it is
|
+ |
+ // Helpers to handle device attach event. |
+ virtual void HandleDeviceAttachEvent(const string16& pnp_device_id); |
+ virtual void OnHandleDeviceAttachEvent(DeviceDetails device_details); |
Peter Kasting
2012/10/25 05:23:24
Nit: const ref
kmadhusu
2012/10/26 02:01:24
Changed to const ptr. I couldn't pass const ref to
|
+ |
+ // 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. |
Peter Kasting
2012/10/25 05:23:24
Nit: Don't say "stores" on data members.
kmadhusu
2012/10/26 02:01:24
Fixed.
|
+ MtpStorageMap storage_map_; |
Peter Kasting
2012/10/25 05:23:24
Tiny nit: Should this go after the device_map_?
kmadhusu
2012/10/26 02:01:24
Done.
|
+ |
+ // Stores attached mtp device details. |
+ MtpDeviceMap device_map_; |
+ |
+ // Stores a reference to worker pool thread. Mtp device tasks are posted on |
+ // this thread. |
Peter Kasting
2012/10/25 05:23:24
Nit: How about:
// The task runner used to exec
kmadhusu
2012/10/26 02:01:24
Done.
|
+ scoped_refptr<base::SequencedTaskRunner> media_task_runner_; |
+ |
+ // Used to notify PortableDeviceWatcherWin about the shutdown sequence. |
Peter Kasting
2012/10/25 05:23:24
Used by whom? And "the shutdown sequence" is vagu
kmadhusu
2012/10/26 02:01:24
Rephrased the comment. Removed cancellationFlag an
Peter Kasting
2012/10/26 02:14:49
But why does this class exist at all after app ter
vandebo (ex-Chrome)
2012/10/26 20:32:10
I'm with Peter here. On shutdown, the owner of th
kmadhusu
2012/10/26 22:23:26
Done. This class no longer listens for application
|
+ base::CancellationFlag app_terminating_flag_; |
+ |
+ // Handles registering notifications with the NotificationService. |
+ // Used to listen for application termination message. |
Peter Kasting
2012/10/25 05:23:24
Nit: First sentence is unnecessary. Second senten
kmadhusu
2012/10/26 02:01:24
Done.
|
+ content::NotificationRegistrar registrar_; |
+ |
+ // |media_task_runner_| tasks may take a longer time to complete the tasks. |
+ // Used for creating callbacks. |
Peter Kasting
2012/10/25 05:23:24
Nit: How about just:
// Used by |media_task_run
kmadhusu
2012/10/26 02:01:24
Done.
|
+ base::WeakPtrFactory<PortableDeviceWatcherWin> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PortableDeviceWatcherWin); |
+}; |
+ |
+} // namespace chrome |
+ |
+#endif // CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ |