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> | |
|
sail
2012/12/26 21:30:43
newline after system includes
Greg Billock
2013/01/03 22:41:32
Done.
| |
| 9 #include "base/file_path.h" | |
| 10 #include "base/hash_tables.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/platform_file.h" | |
| 13 #include "base/synchronization/waitable_event.h" | |
| 14 #include "webkit/fileapi/file_system_file_util.h" | |
| 15 #include "webkit/fileapi/media/mtp_device_delegate.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class SequencedTaskRunner; | |
| 19 } | |
| 20 | |
| 21 namespace chrome { | |
| 22 | |
| 23 class CameraDeviceInterface; | |
|
sail
2012/12/26 21:30:43
make this an inner class? (you can still forward d
Greg Billock
2013/01/03 22:41:32
Could. Why do you think that's better?
On 2012/12
sail
2013/01/03 23:10:43
Currently this class is in the public name space.
Greg Billock
2013/01/04 18:05:05
It's in chrome namespace, but that's not a lot bet
sail
2013/01/08 20:16:41
I'd really like this not to be public.
Greg Billock
2013/01/16 01:15:29
Moved this and shortened the name.
On 2013/01/08
| |
| 24 | |
| 25 // Delegate for presenting an Image Capture device through the filesystem | |
| 26 // API. The synthetic filesystem will be rooted at the constructed location, | |
| 27 // and names of non-directories notified through the ItemAdded call will be | |
|
sail
2012/12/26 21:30:43
"non-directories notified through" is a bit confus
Greg Billock
2013/01/03 22:41:32
Done.
| |
| 28 // all appear as children of that directory. | |
| 29 class MTPDeviceDelegateImplMac : public fileapi::MTPDeviceDelegate { | |
| 30 public: | |
| 31 MTPDeviceDelegateImplMac(const FilePath::StringType& location, | |
| 32 base::SequencedTaskRunner* media_task_runner); | |
| 33 // Destructed via CancelPendingTasksAndDeleteDelegate. Do not call directly. | |
|
sail
2012/12/26 21:30:43
make the destructor private and remove comment?
Greg Billock
2013/01/03 22:41:32
Done.
| |
| 34 virtual ~MTPDeviceDelegateImplMac(); | |
| 35 | |
| 36 // MTPDeviceDelegate: | |
| 37 virtual base::PlatformFileError GetFileInfo( | |
| 38 const FilePath& file_path, | |
| 39 base::PlatformFileInfo* file_info) OVERRIDE; | |
| 40 virtual scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> | |
| 41 CreateFileEnumerator(const FilePath& root, bool recursive) OVERRIDE; | |
| 42 virtual base::PlatformFileError CreateSnapshotFile( | |
| 43 const FilePath& device_file_path, | |
| 44 const FilePath& local_path, | |
| 45 base::PlatformFileInfo* file_info) OVERRIDE; | |
| 46 virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE; | |
| 47 | |
| 48 // Forward delegates for ImageCaptureDeviceListener | |
| 49 virtual void ItemAdded(const std::string& name, | |
| 50 const base::PlatformFileInfo& info); | |
| 51 virtual void NoMoreItems(); | |
| 52 virtual void DownloadedFile(const std::string& name, | |
| 53 base::PlatformFileError error); | |
| 54 | |
| 55 // Implementation returned by |CreateFileEnumerator()|. Must be deleted | |
| 56 // before CancelPendingTasksAndDeleteDelegate is called. | |
| 57 class Enumerator : | |
| 58 public fileapi::FileSystemFileUtil::AbstractFileEnumerator { | |
| 59 public: | |
| 60 explicit Enumerator(MTPDeviceDelegateImplMac* delegate); | |
| 61 virtual ~Enumerator(); | |
| 62 | |
| 63 virtual FilePath Next() OVERRIDE; | |
| 64 virtual int64 Size() OVERRIDE; | |
| 65 virtual base::Time LastModifiedTime() OVERRIDE; | |
| 66 virtual bool IsDirectory() OVERRIDE; | |
| 67 | |
| 68 // Called by the delegate to signal any waiters that the received items | |
| 69 // list has changed state. | |
| 70 void ItemsChanged(); | |
| 71 | |
| 72 private: | |
| 73 MTPDeviceDelegateImplMac* delegate_; | |
| 74 size_t position_; | |
| 75 base::WaitableEvent wait_for_items_; | |
| 76 }; | |
| 77 | |
| 78 // GetFile and HasAllFiles called by enumerators. | |
| 79 FilePath GetFile(size_t index); | |
| 80 bool HasAllFiles(); | |
|
sail
2012/12/26 21:30:43
rename to received_all_files() ?
Greg Billock
2013/01/03 22:41:32
Done.
| |
| 81 void RemoveEnumerator(Enumerator* enumerator); | |
| 82 | |
| 83 private: | |
| 84 std::string device_id_; | |
| 85 FilePath root_path_; | |
| 86 | |
| 87 // Stores a reference to worker pool thread. All requests and response of file | |
| 88 // operations are posted on |media_task_runner_|. All callbacks from the | |
| 89 // camera will come through this task runner as well. | |
| 90 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; | |
| 91 | |
| 92 // Interface object for the camera underlying this MTP session. | |
| 93 scoped_ptr<CameraDeviceInterface> camera_interface_; | |
| 94 | |
| 95 // Stores a map from filename to file metadata received from the camera. | |
| 96 base::hash_map<FilePath::StringType, base::PlatformFileInfo> file_info_; | |
|
sail
2012/12/26 21:30:43
use std::map<> unless there's a reason to use hash
Greg Billock
2013/01/03 22:41:32
There could be tons of files.
sail
2013/01/03 23:10:43
Unless you can show a difference between hash_map
Greg Billock
2013/01/04 18:05:05
The difference is O(n) access vs O(1) access. Is t
sail
2013/01/08 20:16:41
Could you provide a reference for this?
Greg Billock
2013/01/16 01:15:29
log-n, so only a factor of 10 or so worse, not 100
| |
| 97 | |
| 98 // Notifications for all the files we're waiting on downloads for. | |
|
sail
2012/12/26 21:30:43
Events for pending downloads?
Greg Billock
2013/01/03 22:41:32
Done.
| |
| 99 base::hash_map<std::string, base::WaitableEvent*> download_events_; | |
| 100 | |
| 101 // Resulting error codes for downloads. | |
| 102 base::hash_map<std::string, base::PlatformFileError> download_errors_; | |
| 103 | |
| 104 // List of files received from the camera. | |
| 105 std::vector<FilePath::StringType> file_paths_; | |
|
sail
2012/12/26 21:30:43
can this be vector<FilePath> instead?
Greg Billock
2013/01/03 22:41:32
Done.
| |
| 106 | |
| 107 // Weak pointer to the enumerator which may be listening for files to come in. | |
| 108 Enumerator* enumerator_; | |
| 109 | |
| 110 // Set to true when all file metadata has been received from the camera. | |
| 111 bool received_all_files_; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplMac); | |
| 114 }; | |
| 115 | |
| 116 } // namespace chrome | |
| 117 | |
| 118 #endif // CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_MAC_H_ | |
| OLD | NEW |