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..73a2086aa841bd0fced6cca86175360d983f07ca |
| --- /dev/null |
| +++ b/chrome/browser/media_gallery/win/mtp_device_delegate_impl_win.h |
| @@ -0,0 +1,117 @@ |
| +// 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. ScopedMTPDeviceMapEntry class |
| +// manages the lifetime of this object via MTPDeviceMapService class. |
|
Peter Kasting
2012/12/03 20:13:00
Nit: I'm not sure I understand this sentence... ma
kmadhusu
2012/12/15 02:34:56
This sentence is an implementation detail. This se
|
| +// This object is constructed on UI thread. All the device operations are |
|
Peter Kasting
2012/12/03 20:13:00
Nit: on UI -> on the UI
kmadhusu
2012/12/15 02:34:56
This sentence is no longer used.
|
| +// performed on the blocking thread. A portable device can have multiple |
| +// data partitions. A user can register each partition as a media file system. |
| +// This class is instantitated per MTP device storage. |
|
Peter Kasting
2012/12/03 20:13:00
Nit: instantitated -> instantiated
What does "per
kmadhusu
2012/12/15 02:34:56
Fixed.
instantitated -> instantiated
storage -> p
|
| + |
| +#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 "base/platform_file.h" |
| +#include "base/string16.h" |
| +#include "base/synchronization/lock.h" |
| +#include "base/win/scoped_comptr.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 MTP storage to complete isolated file system |
| +// operations. This class contains platform specific code to communicate with |
| +// the attached MTP storage. This class supports weak pointers, because the |
| +// base class supports weak pointers. |
| +class MTPDeviceDelegateImplWin : public fileapi::MTPDeviceDelegate { |
| + public: |
| + // Constructed on UI thread. Defer the device initializations until the first |
| + // file operation request. Do all the initializations in LazyInit() function. |
| + explicit MTPDeviceDelegateImplWin(const string16& pnp_device_id); |
| + |
| + // 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 base::SequencedTaskRunner* GetMediaTaskRunner() OVERRIDE; |
| + virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE; |
| + virtual base::WeakPtr<fileapi::MTPDeviceDelegate> GetAsWeakPtrOnIOThread() |
|
Peter Kasting
2012/12/03 20:13:00
You're vending a weak pointer on a different threa
kmadhusu
2012/12/15 02:34:56
This class no longer supports weak pointers. This
|
| + OVERRIDE; |
| + |
| + private: |
| + // Destructed via DeleteDelegateOnTaskRunner(). Do all the clean up in |
| + // DeleteDelegateOnTaskRunner(). |
| + virtual ~MTPDeviceDelegateImplWin(); |
| + |
| + // Opens the device for communication. This function is called on the |
| + // sequenced task runner. Returns true if the device is ready for |
| + // communication, else false. |
|
Peter Kasting
2012/12/03 20:13:00
Nit: "Returns whether the device is ready for comm
kmadhusu
2012/12/15 02:34:56
Done.
|
| + 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 object id of "DCIM" folder. |
|
Peter Kasting
2012/12/03 20:13:00
Nit: of -> of the
Is the object ID "DCIM"? Or is
kmadhusu
2012/12/15 02:34:56
DCIM is the folder object name. Based on the state
|
| + // |
| + // Returns an empty string, if the device is detached while the request is in |
|
Peter Kasting
2012/12/03 20:13:00
Nit: Remove comma
kmadhusu
2012/12/15 02:34:56
Done.
|
| + // progress. |
| + string16 GetFileObjectIdFromPath(const string16& file_path); |
| + |
| + // Deletes the delegate on the task runner thread. Called by |
|
Peter Kasting
2012/12/03 20:13:00
!! Objects should be created and destroyed on the
kmadhusu
2012/12/15 02:34:56
Removed DeleteDelegateOnTaskRunner() function.
|
| + // CancelPendingTasksAndDeleteDelegate(). Performs clean up that needs to |
| + // happen on the task runner thread. |
| + void DeleteDelegateOnTaskRunner(); |
|
Peter Kasting
2012/12/03 20:13:00
Nit: I suggest adding "Thread" to the end of this
kmadhusu
2012/12/15 02:34:56
This function is no longer used.
|
| + |
| + // 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 as a file system, |
| + // e.g. "\\MTP:StorageSerial:SID-{10001,E,9823}:237483". |
| + const string16 registered_device_path_; |
| + |
| + // The MTP device storage object identifier, used to enumerate the storage |
| + // contents, e.g. "s10001". |
| + string16 storage_object_id_; |
| + |
| + // The task runner used to execute tasks that may take a long time and thus |
| + // should not be performed on the UI thread. |
| + scoped_refptr<base::SequencedTaskRunner> media_task_runner_; |
| + |
| + // The portable device. |
| + base::win::ScopedComPtr<IPortableDevice> device_; |
| + |
| + // The lock to protect |cancel_pending_tasks_|. |cancel_pendings_tasks_| is |
| + // set on IO 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_; |
|
Peter Kasting
2012/12/03 20:13:00
This seems like a job for a CancellationFlag.
kmadhusu
2012/12/15 02:34:56
CancellationFlag can only be set on the thread it
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplWin); |
| +}; |
| + |
| +} // namespace chrome |
| + |
| +#endif // CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ |