Chromium Code Reviews| Index: chrome/browser/media_gallery/win/mtp_device_delegate_impl_win.h |
| diff --git a/chrome/browser/media_gallery/win/mtp_device_delegate_impl_win.h b/chrome/browser/media_gallery/win/mtp_device_delegate_impl_win.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a845b9ba8627f712cfecbd82cb211644f58803a5 |
| --- /dev/null |
| +++ b/chrome/browser/media_gallery/win/mtp_device_delegate_impl_win.h |
| @@ -0,0 +1,124 @@ |
| +// 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. |
| +// |
| +// This class supports media transfer protocol (MTP) device file system |
| +// operations. This class communicates with the portable device and completes |
| +// the requested file system operation. A portable device can have multiple |
| +// data partitions. A user can register each partition as a media file system. |
| +// This class is instantiated per MTP device partition. |
|
Ryan Sleevi
2013/01/05 03:00:58
STYLE: You should be describing these comments as
kmadhusu
2013/01/08 03:19:40
rsleevi@: Moved some class detail comments from th
Ryan Sleevi
2013/01/09 00:20:36
My main concern was comments like "This class" rea
kmadhusu
2013/01/09 18:11:14
As we discussed, moved these class details to the
|
| + |
| +#ifndef CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ |
| +#define CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ |
| + |
| +#include <portabledeviceapi.h> |
| +#include <string> |
| + |
| +#include "base/platform_file.h" |
| +#include "base/sequenced_task_runner_helpers.h" |
| +#include "base/string16.h" |
| +#include "base/synchronization/lock.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "base/win/scoped_comptr.h" |
| +#include "chrome/browser/media_gallery/mtp_device_delegate_impl.h" |
| +#include "webkit/fileapi/file_system_file_util.h" |
| +#include "webkit/fileapi/media/mtp_device_delegate.h" |
| + |
| +class FilePath; |
| + |
| +namespace base { |
| +class SequencedTaskRunner; |
| +} |
| + |
| +namespace chrome { |
| + |
| +// This class communicates with the MTP device to complete isolated file system |
| +// operations. This class contains platform specific code to communicate with |
| +// the attached MTP device. Instantiate this class per MTP device storage |
| +// partition using CreateMTPDeviceDelegate(). This object lives on a sequenced |
| +// task runner thread, except for CancelPendingTasksAndDeleteDelegate() which |
| +// happens on the UI thread. |
| +class MTPDeviceDelegateImplWin : public fileapi::MTPDeviceDelegate { |
| + public: |
| + // Returns true to cancel the pending tasks if |this| object is scheduled to |
| + // be deleted. |
| + bool IsCancelTasksFlagSet(); |
| + |
| + private: |
| + friend void CreateMTPDeviceDelegate(const string16&, |
| + base::SequencedTaskRunner*, |
| + const CreateMTPDeviceDelegateCallback&); |
| + friend class base::DeleteHelper<MTPDeviceDelegateImplWin>; |
| + |
| + // Defer the device initializations until the first file operation request. |
| + // Do all the initializations in LazyInit() function. |
| + MTPDeviceDelegateImplWin(const string16& pnp_device_id, |
| + base::SequencedTaskRunner* media_task_runner); |
| + |
| + // Destructed via CancelPendingTasksAndDeleteDelegate(). |
| + virtual ~MTPDeviceDelegateImplWin(); |
| + |
| + // MTPDeviceDelegate: |
| + virtual base::PlatformFileError GetFileInfo( |
| + const FilePath& file_path, |
| + base::PlatformFileInfo* file_info) OVERRIDE; |
| + virtual scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> |
| + CreateFileEnumerator(const FilePath& root, |
| + bool recursive) OVERRIDE; |
| + virtual base::PlatformFileError CreateSnapshotFile( |
| + const FilePath& device_file_path, |
| + const FilePath& local_path, |
| + base::PlatformFileInfo* file_info) OVERRIDE; |
| + virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE; |
| + |
| + // Returns whether the device is ready for communication. |
| + bool LazyInit(); |
| + |
| + // Returns the object id of the file object specified by the |file_path|, |
| + // e.g. if the |file_path| is "\\MTP:StorageSerial:SID-{1001,,192}:125\DCIM" |
| + // and |registered_device_path_| is "\\MTP:StorageSerial:SID-{1001,,192}:125", |
| + // this function returns the identifier of the "DCIM" folder object. |
| + // |
| + // Returns an empty string if the device is detached while the request is in |
| + // progress. |
| + string16 GetFileObjectIdFromPath(const string16& file_path); |
| + |
| + // The Pnp Device Id, used to open the device for communication, |
| + // e.g. "\\?\usb#vid_04a9&pid_3073#12#{6ac27878-a6fa-4155-ba85-f1d4f33}". |
| + string16 pnp_device_id_; |
| + |
| + // The media file system root path, which is obtained during the registration |
| + // of MTP device storage partition as a file system, |
| + // e.g. "\\MTP:StorageSerial:SID-{10001,E,9823}:237483". |
| + const string16 registered_device_path_; |
| + |
| + // The MTP device storage partition object identifier, used to enumerate the |
| + // storage contents, e.g. "s10001". |
| + string16 storage_object_id_; |
| + |
| + // The task runner where most of the class lives and runs (save for |
| + // CancelPendingTasksAndDeleteDelegate). |
| + scoped_refptr<base::SequencedTaskRunner> media_task_runner_; |
| + |
| + // The portable device. |
| + base::win::ScopedComPtr<IPortableDevice> device_; |
| + |
| + // The lock to protect |cancel_pending_tasks_|. |cancel_pending_tasks_| is |
| + // set on the UI thread when the |
| + // (1) Browser application is in shutdown mode (or) |
| + // (2) Last extension using this MTP device is destroyed (or) |
| + // (3) Attached MTP device is removed (or) |
| + // (4) User revoked the MTP device gallery permission. |
| + base::Lock cancel_tasks_lock_; |
| + bool cancel_pending_tasks_; |
| + |
| + // The task runner can wait on this event until the device storage details |
| + // are fetched. |
| + base::WaitableEvent task_completed_event_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplWin); |
| +}; |
| + |
| +} // namespace chrome |
| + |
| +#endif // CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ |