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. MTPDeviceMapService owns this object. | |
| 8 // This object is constructed and destructed on UI thread. All the device | |
| 9 // operations are performed on the blocking thread. A portable device can have | |
| 10 // multiple data partitions. A user can register each partition as a media | |
| 11 // file system. This class is instantitated per MTP device storage. | |
| 12 | |
| 13 #ifndef CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ | |
| 14 #define CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ | |
| 15 | |
| 16 #include <portabledeviceapi.h> | |
| 17 | |
| 18 #include "base/memory/ref_counted.h" | |
| 19 #include "base/platform_file.h" | |
| 20 #include "base/string16.h" | |
| 21 #include "base/win/scoped_comptr.h" | |
| 22 #include "content/public/browser/notification_observer.h" | |
| 23 #include "content/public/browser/notification_registrar.h" | |
| 24 #include "webkit/fileapi/file_system_file_util.h" | |
| 25 #include "webkit/fileapi/media/mtp_device_delegate.h" | |
| 26 | |
| 27 class FilePath; | |
| 28 | |
| 29 namespace base { | |
| 30 class SequencedTaskRunner; | |
| 31 } | |
| 32 | |
| 33 namespace chrome { | |
| 34 | |
| 35 // Helper class to communicate with MTP storage to complete isolated file system | |
| 36 // operations. This class contains platform specific code to communicate with | |
| 37 // the attached MTP storage. Instantiate this class per MTP storage. | |
| 38 // This class is ref-counted, because MtpDeviceDelegate is ref-counted. | |
| 39 class MTPDeviceDelegateImplWin : public fileapi::MtpDeviceDelegate, | |
| 40 public content::NotificationObserver { | |
| 41 public: | |
| 42 // Constructed on UI thread. Defer the device initializations until the first | |
| 43 // file operation request. Do all the initializations in LazyInit() function. | |
| 44 explicit MTPDeviceDelegateImplWin(const string16& pnp_device_id); | |
| 45 | |
| 46 // MtpDeviceDelegate: | |
| 47 virtual base::PlatformFileError GetFileInfo( | |
| 48 const FilePath& file_path, | |
| 49 base::PlatformFileInfo* file_info) OVERRIDE; | |
| 50 virtual fileapi::FileSystemFileUtil::AbstractFileEnumerator* | |
| 51 CreateFileEnumerator(const FilePath& root, bool recursive) OVERRIDE; | |
| 52 virtual base::PlatformFileError CreateSnapshotFile( | |
| 53 const FilePath& device_file_path, | |
| 54 const FilePath& local_path, | |
| 55 base::PlatformFileInfo* file_info) OVERRIDE; | |
| 56 virtual base::SequencedTaskRunner* media_task_runner() OVERRIDE; | |
| 57 virtual void DeleteOnCorrectThread() const OVERRIDE; | |
| 58 | |
| 59 private: | |
| 60 friend struct fileapi::MtpDeviceDelegateDeleter; | |
| 61 friend class base::DeleteHelper<MTPDeviceDelegateImplWin>; | |
| 62 | |
| 63 // Private because this class is ref-counted. | |
| 64 virtual ~MTPDeviceDelegateImplWin(); | |
| 65 | |
| 66 // content::NotificationObserver: | |
| 67 virtual void Observe(int type, | |
| 68 const content::NotificationSource& source, | |
| 69 const content::NotificationDetails& details) OVERRIDE; | |
| 70 | |
| 71 // Opens the device for communication. This function is called on the | |
| 72 // sequenced task runner. Returns true if the device is ready for | |
| 73 // communication, else false. | |
| 74 bool LazyInit(); | |
| 75 | |
| 76 // The Pnp Device Id, used to open the device for communication, | |
| 77 // e.g. "\\?\usb#vid_04a9&pid_3073#12#{6ac27878-a6fa-4155-ba85-f1d4f33}". | |
| 78 string16 pnp_device_id_; | |
| 79 | |
| 80 // The media file system root path, which is obtained during the registration | |
| 81 // of MTP device storage as a file system, | |
| 82 // e.g. "\\MTP:StorageSerial:SID-{10001,E,9823}:237483". | |
| 83 const string16 registered_device_path_; | |
| 84 | |
| 85 // The MTP device storage object identifier, used to enumerate the storage | |
| 86 // contents, e.g. "s10001". | |
| 87 string16 storage_object_id_; | |
| 88 | |
| 89 // The task runner used to execute tasks that may take a long time and thus | |
| 90 // should not be performed on the UI thread. | |
| 91 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; | |
| 92 | |
| 93 // The portable device. | |
| 94 base::win::ScopedComPtr<IPortableDevice> device_; | |
| 95 | |
| 96 // Used to listen for NOTIFICATION_APP_TERMINATING message. | |
|
Lei Zhang
2012/11/01 02:34:57
indentation
kmadhusu
2012/11/01 17:59:00
Done.
| |
| 97 content::NotificationRegistrar registrar_; | |
| 98 | |
| 99 // Used to notify the blocking tasks about the application termination | |
| 100 // message. | |
| 101 bool app_terminating_; | |
|
kmadhusu
2012/11/01 02:38:00
Just realized that I should have used cancellation
kmadhusu
2012/11/01 17:59:00
Fixed.
| |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplWin); | |
| 104 }; | |
| 105 | |
| 106 } // namespace chrome | |
| 107 | |
| 108 #endif // CHROME_BROWSER_MEDIA_GALLERY_WIN_MTP_DEVICE_DELEGATE_IMPL_WIN_H_ | |
| OLD | NEW |