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 // This class supports media transfer protocol (MTP) device file system | |
| 6 // operations. This class communicates with the portable device and completes | |
| 7 // the requested file system operation. ScopedMTPDeviceMapEntry class | |
| 8 // 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
| |
| 9 // 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.
| |
| 10 // performed on the blocking thread. A portable device can have multiple | |
| 11 // data partitions. A user can register each partition as a media file system. | |
| 12 // 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
| |
| 13 | |
| 14 #ifndef CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ | |
| 15 #define CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ | |
| 16 | |
| 17 #include <portabledeviceapi.h> | |
| 18 | |
| 19 #include "base/platform_file.h" | |
| 20 #include "base/string16.h" | |
| 21 #include "base/synchronization/lock.h" | |
| 22 #include "base/win/scoped_comptr.h" | |
| 23 #include "webkit/fileapi/file_system_file_util.h" | |
| 24 #include "webkit/fileapi/media/mtp_device_delegate.h" | |
| 25 | |
| 26 class FilePath; | |
| 27 | |
| 28 namespace base { | |
| 29 class SequencedTaskRunner; | |
| 30 } | |
| 31 | |
| 32 namespace chrome { | |
| 33 | |
| 34 // This class communicates with MTP storage to complete isolated file system | |
| 35 // operations. This class contains platform specific code to communicate with | |
| 36 // the attached MTP storage. This class supports weak pointers, because the | |
| 37 // base class supports weak pointers. | |
| 38 class MTPDeviceDelegateImplWin : public fileapi::MTPDeviceDelegate { | |
| 39 public: | |
| 40 // Constructed on UI thread. Defer the device initializations until the first | |
| 41 // file operation request. Do all the initializations in LazyInit() function. | |
| 42 explicit MTPDeviceDelegateImplWin(const string16& pnp_device_id); | |
| 43 | |
| 44 // MTPDeviceDelegate: | |
| 45 virtual base::PlatformFileError GetFileInfo( | |
| 46 const FilePath& file_path, | |
| 47 base::PlatformFileInfo* file_info) OVERRIDE; | |
| 48 virtual scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> | |
| 49 CreateFileEnumerator(const FilePath& root, bool recursive) OVERRIDE; | |
| 50 virtual base::PlatformFileError CreateSnapshotFile( | |
| 51 const FilePath& device_file_path, | |
| 52 const FilePath& local_path, | |
| 53 base::PlatformFileInfo* file_info) OVERRIDE; | |
| 54 virtual base::SequencedTaskRunner* GetMediaTaskRunner() OVERRIDE; | |
| 55 virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE; | |
| 56 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
| |
| 57 OVERRIDE; | |
| 58 | |
| 59 private: | |
| 60 // Destructed via DeleteDelegateOnTaskRunner(). Do all the clean up in | |
| 61 // DeleteDelegateOnTaskRunner(). | |
| 62 virtual ~MTPDeviceDelegateImplWin(); | |
| 63 | |
| 64 // Opens the device for communication. This function is called on the | |
| 65 // sequenced task runner. Returns true if the device is ready for | |
| 66 // 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.
| |
| 67 bool LazyInit(); | |
| 68 | |
| 69 // Returns the object id of the file object specified by the |file_path|, | |
| 70 // e.g. if the |file_path| is "\\MTP:StorageSerial:SID-{1001,,192}:125\DCIM" | |
| 71 // and |registered_device_path_| is "\\MTP:StorageSerial:SID-{1001,,192}:125", | |
| 72 // 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
| |
| 73 // | |
| 74 // 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.
| |
| 75 // progress. | |
| 76 string16 GetFileObjectIdFromPath(const string16& file_path); | |
| 77 | |
| 78 // 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.
| |
| 79 // CancelPendingTasksAndDeleteDelegate(). Performs clean up that needs to | |
| 80 // happen on the task runner thread. | |
| 81 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.
| |
| 82 | |
| 83 // The Pnp Device Id, used to open the device for communication, | |
| 84 // e.g. "\\?\usb#vid_04a9&pid_3073#12#{6ac27878-a6fa-4155-ba85-f1d4f33}". | |
| 85 string16 pnp_device_id_; | |
| 86 | |
| 87 // The media file system root path, which is obtained during the registration | |
| 88 // of MTP device storage as a file system, | |
| 89 // e.g. "\\MTP:StorageSerial:SID-{10001,E,9823}:237483". | |
| 90 const string16 registered_device_path_; | |
| 91 | |
| 92 // The MTP device storage object identifier, used to enumerate the storage | |
| 93 // contents, e.g. "s10001". | |
| 94 string16 storage_object_id_; | |
| 95 | |
| 96 // The task runner used to execute tasks that may take a long time and thus | |
| 97 // should not be performed on the UI thread. | |
| 98 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; | |
| 99 | |
| 100 // The portable device. | |
| 101 base::win::ScopedComPtr<IPortableDevice> device_; | |
| 102 | |
| 103 // The lock to protect |cancel_pending_tasks_|. |cancel_pendings_tasks_| is | |
| 104 // set on IO thread when the | |
| 105 // (1) Browser application is in shutdown mode (or) | |
| 106 // (2) Last extension using this MTP device is destroyed (or) | |
| 107 // (3) Attached MTP device is removed (or) | |
| 108 // (4) User revoked the MTP device gallery permission. | |
| 109 base::Lock cancel_tasks_lock_; | |
| 110 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
| |
| 111 | |
| 112 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplWin); | |
| 113 }; | |
| 114 | |
| 115 } // namespace chrome | |
| 116 | |
| 117 #endif // CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ | |
| OLD | NEW |