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 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_MAC_H_ | |
| 6 #define CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_MAC_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/file_path.h" | |
| 11 #include "base/hash_tables.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/platform_file.h" | |
| 14 #include "base/sequenced_task_runner_helpers.h" | |
| 15 #include "base/synchronization/lock.h" | |
| 16 #include "base/synchronization/waitable_event.h" | |
| 17 #include "webkit/fileapi/file_system_file_util.h" | |
| 18 #include "webkit/fileapi/media/mtp_device_delegate.h" | |
| 19 | |
| 20 namespace base { | |
| 21 class SequencedTaskRunner; | |
| 22 } | |
| 23 | |
| 24 namespace chrome { | |
| 25 | |
| 26 // Delegate for presenting an Image Capture device through the filesystem | |
| 27 // API. The synthetic filesystem will be rooted at the constructed location, | |
| 28 // and names of all files notified through the ItemAdded call will be | |
| 29 // all appear as children of that directory. (ItemAdded calls with directories | |
| 30 // will be ignored.) | |
| 31 class MTPDeviceDelegateImplMac : public fileapi::MTPDeviceDelegate { | |
| 32 public: | |
| 33 MTPDeviceDelegateImplMac(const std::string& device_id, | |
| 34 const FilePath::StringType& synthetic_path, | |
| 35 base::SequencedTaskRunner* media_task_runner); | |
| 36 | |
| 37 // MTPDeviceDelegate: | |
| 38 virtual base::PlatformFileError GetFileInfo( | |
| 39 const FilePath& file_path, | |
| 40 base::PlatformFileInfo* file_info) OVERRIDE; | |
| 41 virtual scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> | |
| 42 CreateFileEnumerator(const FilePath& root, bool recursive) OVERRIDE; | |
| 43 virtual base::PlatformFileError CreateSnapshotFile( | |
| 44 const FilePath& device_file_path, | |
| 45 const FilePath& local_path, | |
| 46 base::PlatformFileInfo* file_info) OVERRIDE; | |
| 47 virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE; | |
| 48 | |
| 49 // Forward delegates for ImageCaptureDeviceListener | |
| 50 virtual void ItemAdded(const std::string& name, | |
| 51 const base::PlatformFileInfo& info); | |
| 52 virtual void NoMoreItems(); | |
| 53 virtual void DownloadedFile(const std::string& name, | |
| 54 base::PlatformFileError error); | |
| 55 | |
| 56 // Implementation returned by |CreateFileEnumerator()|. Must be deleted | |
| 57 // before CancelPendingTasksAndDeleteDelegate is called. | |
| 58 class Enumerator : | |
| 59 public fileapi::FileSystemFileUtil::AbstractFileEnumerator { | |
| 60 public: | |
| 61 explicit Enumerator(MTPDeviceDelegateImplMac* delegate); | |
| 62 virtual ~Enumerator(); | |
| 63 | |
| 64 virtual FilePath Next() OVERRIDE; | |
| 65 virtual int64 Size() OVERRIDE; | |
| 66 virtual base::Time LastModifiedTime() OVERRIDE; | |
| 67 virtual bool IsDirectory() OVERRIDE; | |
| 68 | |
| 69 // Called by the delegate to signal any waiters that the received items | |
| 70 // list has changed state. | |
| 71 void ItemsChanged(); | |
| 72 | |
| 73 private: | |
| 74 MTPDeviceDelegateImplMac* delegate_; | |
| 75 size_t position_; | |
| 76 bool done_; | |
| 77 base::WaitableEvent wait_for_items_; | |
| 78 }; | |
| 79 | |
| 80 // GetFile and HasAllFiles called by enumerators. | |
| 81 FilePath GetFile(size_t index); | |
| 82 bool ReceivedAllFiles(); | |
| 83 void RemoveEnumerator(Enumerator* enumerator); | |
| 84 | |
| 85 private: | |
| 86 friend class base::DeleteHelper<MTPDeviceDelegateImplMac>; | |
| 87 | |
| 88 class DeviceListener; | |
| 89 | |
| 90 virtual ~MTPDeviceDelegateImplMac(); | |
| 91 | |
| 92 std::string device_id_; | |
|
Lei Zhang
2013/01/25 23:51:20
|device_id_| and |root_path_| can be const.
Greg Billock
2013/01/26 01:29:44
Done.
| |
| 93 FilePath root_path_; | |
| 94 | |
| 95 // Stores a reference to worker pool thread. All requests and response of file | |
| 96 // operations are posted on |media_task_runner_|. All callbacks from the | |
| 97 // camera will come through this task runner as well. | |
| 98 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; | |
| 99 | |
| 100 // Interface object for the camera underlying this MTP session. | |
| 101 scoped_ptr<DeviceListener> camera_interface_; | |
| 102 | |
| 103 // This lock protects all subsequent state. While calling into the delegate | |
| 104 // from the FileSystem API happens in sequence, these calls may be | |
| 105 // interleaved with calls on other threads in the sequenced task runner | |
| 106 // forwarded from the device. | |
| 107 base::Lock mutex_; | |
| 108 | |
| 109 // Weak pointer to the enumerator which may be listening for files to come in. | |
| 110 Enumerator* enumerator_; | |
| 111 | |
| 112 // Stores a map from filename to file metadata received from the camera. | |
| 113 base::hash_map<FilePath::StringType, base::PlatformFileInfo> file_info_; | |
| 114 | |
| 115 // Notification for pending download. | |
| 116 base::WaitableEvent* file_download_event_; | |
| 117 | |
| 118 // Resulting error code for pending download. | |
| 119 base::PlatformFileError file_download_error_; | |
| 120 | |
| 121 // List of files received from the camera. | |
| 122 std::vector<FilePath> file_paths_; | |
| 123 | |
| 124 // Set to true when all file metadata has been received from the camera. | |
| 125 bool received_all_files_; | |
| 126 | |
| 127 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplMac); | |
| 128 }; | |
| 129 | |
| 130 } // namespace chrome | |
| 131 | |
| 132 #endif // CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_MAC_H_ | |
| OLD | NEW |