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. A portable device can have multiple | |
| 8 // data partitions. A user can register each partition as a media file system. | |
| 9 // This class is instantiated per MTP device partition. | |
| 10 | |
| 11 #ifndef CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ | |
| 12 #define CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ | |
| 13 | |
| 14 #include <portabledeviceapi.h> | |
|
Peter Kasting
2012/12/19 20:17:58
Nit: In general can we avoid such #includes by for
kmadhusu
2012/12/20 20:37:29
How to forward declare this interface? There is no
Peter Kasting
2012/12/20 21:24:20
I was thinking we could just use "class IPortableD
kmadhusu
2012/12/21 01:45:23
Compiler is not happy when I specify "class IPorta
| |
| 15 #include <string> | |
| 16 | |
| 17 #include "base/platform_file.h" | |
| 18 #include "base/sequenced_task_runner_helpers.h" | |
| 19 #include "base/string16.h" | |
| 20 #include "base/synchronization/lock.h" | |
| 21 #include "base/win/scoped_comptr.h" | |
| 22 #include "chrome/browser/media_gallery/mtp_device_delegate_impl.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 the MTP device to complete isolated file system | |
| 35 // operations. This class contains platform specific code to communicate with | |
| 36 // the attached MTP device. Instantiate this class per MTP device storage | |
| 37 // partition using CreateMTPDeviceDelegate(). This object lives on a sequenced | |
| 38 // task runner thread, except for CancelPendingTasksAndDeleteDelegate() which | |
| 39 // happens on the UI thread. | |
| 40 class MTPDeviceDelegateImplWin : public fileapi::MTPDeviceDelegate { | |
| 41 private: | |
| 42 friend void CreateMTPDeviceDelegate(const string16&, | |
| 43 base::SequencedTaskRunner*, | |
| 44 const CreateMTPDeviceDelegateCallback&); | |
| 45 friend class base::DeleteHelper<MTPDeviceDelegateImplWin>; | |
| 46 | |
| 47 // Defer the device initializations until the first file operation request. | |
| 48 // Do all the initializations in LazyInit() function. | |
| 49 MTPDeviceDelegateImplWin(const string16& pnp_device_id, | |
| 50 base::SequencedTaskRunner* media_task_runner); | |
| 51 | |
| 52 // Destructed via CancelPendingTasksAndDeleteDelegate(). | |
| 53 virtual ~MTPDeviceDelegateImplWin(); | |
| 54 | |
| 55 // MTPDeviceDelegate: | |
| 56 virtual base::PlatformFileError GetFileInfo( | |
| 57 const FilePath& file_path, | |
| 58 base::PlatformFileInfo* file_info) OVERRIDE; | |
| 59 virtual scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> | |
| 60 CreateFileEnumerator(const FilePath& root, | |
| 61 bool recursive) OVERRIDE; | |
| 62 virtual base::PlatformFileError CreateSnapshotFile( | |
| 63 const FilePath& device_file_path, | |
| 64 const FilePath& local_path, | |
| 65 base::PlatformFileInfo* file_info) OVERRIDE; | |
| 66 virtual base::SequencedTaskRunner* GetMediaTaskRunner() OVERRIDE; | |
|
Peter Kasting
2012/12/19 20:17:58
It looks like in codesearch this isn't called anyw
kmadhusu
2012/12/20 20:37:29
Thanks for pointing this out. Removed this functio
| |
| 67 virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE; | |
| 68 | |
| 69 // Returns whether the device is ready for communication. | |
| 70 bool LazyInit(); | |
| 71 | |
| 72 // Returns the object id of the file object specified by the |file_path|, | |
| 73 // e.g. if the |file_path| is "\\MTP:StorageSerial:SID-{1001,,192}:125\DCIM" | |
| 74 // and |registered_device_path_| is "\\MTP:StorageSerial:SID-{1001,,192}:125", | |
| 75 // this function returns the identifier of the "DCIM" folder object. | |
| 76 // | |
| 77 // Returns an empty string if the device is detached while the request is in | |
| 78 // progress. | |
| 79 string16 GetFileObjectIdFromPath(const string16& file_path); | |
| 80 | |
| 81 // The Pnp Device Id, used to open the device for communication, | |
| 82 // e.g. "\\?\usb#vid_04a9&pid_3073#12#{6ac27878-a6fa-4155-ba85-f1d4f33}". | |
| 83 string16 pnp_device_id_; | |
| 84 | |
| 85 // The media file system root path, which is obtained during the registration | |
| 86 // of MTP device storage partition as a file system, | |
| 87 // e.g. "\\MTP:StorageSerial:SID-{10001,E,9823}:237483". | |
| 88 const string16 registered_device_path_; | |
| 89 | |
| 90 // The MTP device storage partition object identifier, used to enumerate the | |
| 91 // storage contents, e.g. "s10001". | |
| 92 string16 storage_object_id_; | |
| 93 | |
| 94 // The task runner used to execute tasks that may take a long time and thus | |
| 95 // should not be performed on the UI thread. | |
| 96 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; | |
|
Peter Kasting
2012/12/19 20:17:58
How come we actually need this anyway? It seems l
kmadhusu
2012/12/20 20:37:29
This comment is misleading. This reference pointer
Peter Kasting
2012/12/20 21:24:20
I talked to rsleevi a bunch about this so I could
kmadhusu
2012/12/21 01:45:23
Fixed the comment.
| |
| 97 | |
| 98 // The portable device. | |
| 99 base::win::ScopedComPtr<IPortableDevice> device_; | |
| 100 | |
| 101 // The lock to protect |cancel_pending_tasks_|. |cancel_pendings_tasks_| is | |
|
Peter Kasting
2012/12/19 20:17:58
Nit: Extra 's'
kmadhusu
2012/12/20 20:37:29
Fixed.
| |
| 102 // set on the UI thread when the | |
| 103 // (1) Browser application is in shutdown mode (or) | |
| 104 // (2) Last extension using this MTP device is destroyed (or) | |
| 105 // (3) Attached MTP device is removed (or) | |
| 106 // (4) User revoked the MTP device gallery permission. | |
| 107 base::Lock cancel_tasks_lock_; | |
| 108 bool cancel_pending_tasks_; | |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplWin); | |
| 111 }; | |
| 112 | |
| 113 } // namespace chrome | |
| 114 | |
| 115 #endif // CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ | |
| OLD | NEW |