Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4780)

Unified Diff: chrome/browser/system_monitor/media_transfer_protocol_device_observer_win.h

Issue 11088012: [Win, MediaGallery] Enumerate and handle mtp device attach/detach events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/system_monitor/media_transfer_protocol_device_observer_win.h
diff --git a/chrome/browser/system_monitor/media_transfer_protocol_device_observer_win.h b/chrome/browser/system_monitor/media_transfer_protocol_device_observer_win.h
new file mode 100644
index 0000000000000000000000000000000000000000..6fa66842aa7fea623a4e2ac80bcc51558ba655c4
--- /dev/null
+++ b/chrome/browser/system_monitor/media_transfer_protocol_device_observer_win.h
@@ -0,0 +1,130 @@
+// 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_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_WIN_H_
+#define CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_WIN_H_
+
+#include <PortableDeviceApi.h>
+
+#include <map>
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/sequenced_task_runner_helpers.h"
+#include "base/string16.h"
+#include "base/system_monitor/system_monitor.h"
+#include "base/win/scoped_comptr.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace base {
+class SequencedTaskRunner;
+}
+
+namespace chrome {
+namespace mtp {
vandebo (ex-Chrome) 2012/10/16 17:42:36 I don't think the mtp namespace is needed
kmadhusu 2012/10/19 04:01:38 Done.
+
+// Helper class to send MTP storage attachment and detachment events to
+// base::SystemMonitor.
+class MediaTransferProtocolDeviceObserverWin
vandebo (ex-Chrome) 2012/10/16 17:42:36 I don't see any particular reason this should be a
kmadhusu 2012/10/19 04:01:38 This class has several portable device specific co
+ : public base::RefCountedThreadSafe<
+ MediaTransferProtocolDeviceObserverWin,
+ content::BrowserThread::DeleteOnUIThread> {
+ 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;
+ };
+
+ // Should only be called by browser start up code. Use GetInstance() instead.
+ MediaTransferProtocolDeviceObserverWin();
+
+ // Returns the instance of MediaTransferProtocolDeviceObserverWin.
+ static MediaTransferProtocolDeviceObserverWin* GetInstance();
+
+ // Should only be called by browser start up code. Do all initializations on
+ // InitOnBlockingThread().
+ void Init();
+
+ // Handles the mtp device event on UI thread. |pnp_device_id| specifies the
+ // plug and play device ID string.
+ void HandleMtpDeviceEventOnUIThread(bool is_attached,
+ const string16& pnp_device_id);
+
+ protected:
+ // MediaTransferProtocolDeviceObserverWin is refcounted.
+ virtual ~MediaTransferProtocolDeviceObserverWin();
+
+ // 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 GetStorageName(LPWSTR 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(LPWSTR pnp_device_id,
+ std::vector<DeviceStorageInfo>* storages);
+
+ private:
+ friend struct content::BrowserThread::DeleteOnThread<
+ content::BrowserThread::UI>;
+ friend class base::DeleteHelper<MediaTransferProtocolDeviceObserverWin>;
+
+ // Key: MTP device storage 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;
+
+ // 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);
+
+ // Gets the device storage details (such as name, unique_id) on
+ // |media_task_runner_| thread.
+ void GetDeviceInfoOnBlockingThread(const string16& storage_location);
+
+ // Adds the new mtp device details on UI thread.
+ void AddMtpDeviceOnUIThread(const StorageInfoList& storage_ids,
+ const string16& storage_name,
+ const string16& location);
+
+ // 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_;
+
+ DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDeviceObserverWin);
+};
+
+} // namespace mtp
+} // namespace chrome
+
+#endif // CHROME_BROWSER_SYSTEM_MONITOR_MEDIA_TRANSFER_PROTOCOL_DEVICE_OBSERVER_WIN_H_

Powered by Google App Engine
This is Rietveld 408576698