Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ | |
| 6 #define CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ | |
| 7 | |
| 8 #include <portabledeviceapi.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <string> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "base/string16.h" | |
| 17 #include "base/synchronization/cancellation_flag.h" | |
| 18 #include "base/system_monitor/system_monitor.h" | |
| 19 #include "content/public/browser/notification_observer.h" | |
| 20 #include "content/public/browser/notification_registrar.h" | |
| 21 | |
| 22 namespace base { | |
| 23 class SequencedTaskRunner; | |
| 24 } | |
| 25 | |
| 26 class FilePath; | |
| 27 | |
| 28 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
| |
| 29 | |
| 30 // This class watches the portable device mount points and sends notifications | |
| 31 // to base::SystemMonitor about the attached/detached Mtp devices. This is a | |
| 32 // singleton class instantiated by RemovableDeviceNotificationsWindowWin. | |
| 33 class PortableDeviceWatcherWin : public content::NotificationObserver { | |
| 34 public: | |
| 35 // Struct to store temporary and persistent storage object identifiers. | |
| 36 struct DeviceStorageInfo { | |
| 37 // Temporary identifier that uniquely identifies the object on the device. | |
| 38 // This need not be persistent across sessions. | |
| 39 // 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.
| |
| 40 string16 storage_object_id; | |
| 41 | |
| 42 // Stores the persistent id of the storage object. | |
| 43 // E.g.: StorageSerial:<SID-{10001,D,31080448}>:<123456789> | |
| 44 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
| |
| 45 }; | |
| 46 | |
| 47 // Struct to store attached mtp device details. | |
| 48 struct DeviceDetails { | |
| 49 // Device can have multiple data partitions. Therefore, store a list of | |
| 50 // device storage details. | |
| 51 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.
| |
| 52 | |
| 53 // Device name. | |
| 54 string16 name; | |
| 55 | |
| 56 // Device interface path. | |
| 57 string16 location; | |
| 58 }; | |
| 59 | |
| 60 PortableDeviceWatcherWin(); | |
| 61 virtual ~PortableDeviceWatcherWin(); | |
| 62 | |
| 63 // 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.
| |
| 64 void Init(); | |
| 65 | |
| 66 // Gets information about the mtp device specified by |device_path|. On | |
| 67 // success, returns true and fills in |location|, |unique_id|, |name| and | |
| 68 // |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.
| |
| 69 bool GetDeviceInfo(const FilePath& device_path, | |
| 70 string16* location, | |
| 71 std::string* unique_id, | |
| 72 string16* name, | |
| 73 bool* removable); | |
| 74 | |
| 75 // Processes DEV_BROADCAST_DEVICEINTERFACE messages and triggers a | |
| 76 // SystemMonitor notification if appropriate. | |
| 77 void OnWindowMessage(UINT event_type, LPARAM data); | |
| 78 | |
| 79 private: | |
| 80 friend class TestPortableDeviceWatcherWin; | |
| 81 | |
| 82 // Key: MTP device storage unique id. | |
| 83 // Value: Metadata for the given storage. | |
| 84 typedef std::map<std::string, base::SystemMonitor::RemovableStorageInfo> | |
| 85 MtpStorageMap; | |
| 86 | |
| 87 // List of Mtp device storage details. | |
| 88 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
| |
| 89 | |
| 90 // Key: Mtp device plug and play ID string. | |
| 91 // Value: List of device storage objects. | |
| 92 typedef std::map<string16, StorageInfoList> MtpDeviceMap; | |
| 93 | |
| 94 // Helpers to enumerate existing mtp storage devices. | |
| 95 virtual void EnumerateAttachedDevices(); | |
| 96 virtual void OnDidEnumerateAttachedDevices( | |
| 97 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
| |
| 98 | |
| 99 // Helpers to handle device attach event. | |
| 100 virtual void HandleDeviceAttachEvent(const string16& pnp_device_id); | |
| 101 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
| |
| 102 | |
| 103 // Handles the detach event of the device specified by |pnp_device_id|. | |
| 104 void HandleDeviceDetachEvent(const string16& pnp_device_id); | |
| 105 | |
| 106 // content::NotificationObserver implementation. | |
| 107 virtual void Observe(int type, | |
| 108 const content::NotificationSource& source, | |
| 109 const content::NotificationDetails& details) OVERRIDE; | |
| 110 | |
| 111 // 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.
| |
| 112 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.
| |
| 113 | |
| 114 // Stores attached mtp device details. | |
| 115 MtpDeviceMap device_map_; | |
| 116 | |
| 117 // Stores a reference to worker pool thread. Mtp device tasks are posted on | |
| 118 // 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.
| |
| 119 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; | |
| 120 | |
| 121 // 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
| |
| 122 base::CancellationFlag app_terminating_flag_; | |
| 123 | |
| 124 // Handles registering notifications with the NotificationService. | |
| 125 // 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.
| |
| 126 content::NotificationRegistrar registrar_; | |
| 127 | |
| 128 // |media_task_runner_| tasks may take a longer time to complete the tasks. | |
| 129 // 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.
| |
| 130 base::WeakPtrFactory<PortableDeviceWatcherWin> weak_ptr_factory_; | |
| 131 | |
| 132 DISALLOW_COPY_AND_ASSIGN(PortableDeviceWatcherWin); | |
| 133 }; | |
| 134 | |
| 135 } // namespace chrome | |
| 136 | |
| 137 #endif // CHROME_BROWSER_SYSTEM_MONITOR_PORTABLE_DEVICE_WATCHER_WIN_H_ | |
| OLD | NEW |