| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013 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 #ifndef CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ |
| 7 |
| 8 #include <portabledeviceapi.h> |
| 9 |
| 10 #include <string> |
| 11 |
| 12 #include "base/platform_file.h" |
| 13 #include "base/sequenced_task_runner_helpers.h" |
| 14 #include "base/string16.h" |
| 15 #include "base/synchronization/lock.h" |
| 16 #include "base/win/scoped_comptr.h" |
| 17 #include "chrome/browser/media_gallery/mtp_device_delegate_impl.h" |
| 18 #include "webkit/fileapi/file_system_file_util.h" |
| 19 #include "webkit/fileapi/media/mtp_device_delegate.h" |
| 20 |
| 21 class FilePath; |
| 22 |
| 23 namespace base { |
| 24 class SequencedTaskRunner; |
| 25 } |
| 26 |
| 27 namespace chrome { |
| 28 |
| 29 // MTPDeviceDelegateImplWin is used to communicate with the media transfer |
| 30 // protocol (MTP) device to complete isolated file system operations. MTP |
| 31 // device can have multiple data storage partitions. MTPDeviceDelegateImplWin |
| 32 // is instantiated per MTP device storage partition using |
| 33 // CreateMTPDeviceDelegate(). MTPDeviceDelegateImplWin lives on a sequenced |
| 34 // task runner thread, except for CancelPendingTasksAndDeleteDelegate() which |
| 35 // happens on the UI thread. |
| 36 class MTPDeviceDelegateImplWin : public fileapi::MTPDeviceDelegate { |
| 37 private: |
| 38 friend void OnGotStorageInfoCreateDelegate( |
| 39 const string16& device_location, |
| 40 base::SequencedTaskRunner* media_task_runner, |
| 41 const CreateMTPDeviceDelegateCallback& callback, |
| 42 const string16& pnp_device_id, |
| 43 const string16& storage_object_id); |
| 44 |
| 45 friend class base::DeleteHelper<MTPDeviceDelegateImplWin>; |
| 46 |
| 47 // Defers the device initializations until the first file operation request. |
| 48 // Do all the initializations in LazyInit() function. |
| 49 MTPDeviceDelegateImplWin(const string16& fs_root_path, |
| 50 const string16& pnp_device_id, |
| 51 const string16& storage_object_id, |
| 52 base::SequencedTaskRunner* media_task_runner); |
| 53 |
| 54 // Destructed via CancelPendingTasksAndDeleteDelegate(). |
| 55 virtual ~MTPDeviceDelegateImplWin(); |
| 56 |
| 57 // MTPDeviceDelegate: |
| 58 virtual base::PlatformFileError GetFileInfo( |
| 59 const FilePath& file_path, |
| 60 base::PlatformFileInfo* file_info) OVERRIDE; |
| 61 virtual scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> |
| 62 CreateFileEnumerator(const FilePath& root, |
| 63 bool recursive) OVERRIDE; |
| 64 virtual base::PlatformFileError CreateSnapshotFile( |
| 65 const FilePath& device_file_path, |
| 66 const FilePath& local_path, |
| 67 base::PlatformFileInfo* file_info) OVERRIDE; |
| 68 virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE; |
| 69 |
| 70 // Returns whether the device is ready for communication. |
| 71 bool LazyInit(); |
| 72 |
| 73 // Returns the object id of the file object specified by the |file_path|, |
| 74 // e.g. if the |file_path| is "\\MTP:StorageSerial:SID-{1001,,192}:125\DCIM" |
| 75 // and |registered_device_path_| is "\\MTP:StorageSerial:SID-{1001,,192}:125", |
| 76 // this function returns the identifier of the "DCIM" folder object. |
| 77 // |
| 78 // Returns an empty string if the device is detached while the request is in |
| 79 // progress. |
| 80 string16 GetFileObjectIdFromPath(const string16& file_path); |
| 81 |
| 82 // The PnP Device Id, used to open the device for communication, |
| 83 // e.g. "\\?\usb#vid_04a9&pid_3073#12#{6ac27878-a6fa-4155-ba85-f1d4f33}". |
| 84 const string16 pnp_device_id_; |
| 85 |
| 86 // The media file system root path, which is obtained during the registration |
| 87 // of MTP device storage partition as a file system, |
| 88 // e.g. "\\MTP:StorageSerial:SID-{10001,E,9823}:237483". |
| 89 const string16 registered_device_path_; |
| 90 |
| 91 // The MTP device storage partition object identifier, used to enumerate the |
| 92 // storage contents, e.g. "s10001". |
| 93 const string16 storage_object_id_; |
| 94 |
| 95 // The task runner where most of the class lives and runs (save for |
| 96 // CancelPendingTasksAndDeleteDelegate). |
| 97 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; |
| 98 |
| 99 // The portable device. |
| 100 base::win::ScopedComPtr<IPortableDevice> device_; |
| 101 |
| 102 // The lock to protect |cancel_pending_tasks_|. |cancel_pending_tasks_| is |
| 103 // set on the UI thread when the |
| 104 // (1) Browser application is in shutdown mode (or) |
| 105 // (2) Last extension using this MTP device is destroyed (or) |
| 106 // (3) Attached MTP device is removed (or) |
| 107 // (4) User revoked the MTP device gallery permission. |
| 108 base::Lock cancel_tasks_lock_; |
| 109 bool cancel_pending_tasks_; |
| 110 |
| 111 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplWin); |
| 112 }; |
| 113 |
| 114 } // namespace chrome |
| 115 |
| 116 #endif // CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ |
| OLD | NEW |