Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/browser/media_gallery/mac/mtp_device_delegate_impl_mac.h

Issue 12255023: [Media Galleries] Switch Mac MTP delegate to async interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: No log lines Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_MAC_H_ 5 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_MAC_H_
6 #define CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_MAC_H_ 6 #define CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_MAC_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/hash_tables.h" 11 #include "base/hash_tables.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/platform_file.h" 13 #include "base/platform_file.h"
14 #include "base/sequenced_task_runner_helpers.h" 14 #include "base/sequenced_task_runner_helpers.h"
kmadhusu 2013/02/26 17:59:15 This header file is not required.
Greg Billock 2013/02/26 22:02:09 Done.
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
kmadhusu 2013/02/26 17:59:15 Remove this include statement.
Greg Billock 2013/02/26 22:02:09 Done.
16 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
kmadhusu 2013/02/26 17:59:15 Remove this include statement.
Greg Billock 2013/02/26 22:02:09 Done.
17 #include "webkit/fileapi/file_system_file_util.h" 17 #include "webkit/fileapi/file_system_file_util.h"
kmadhusu 2013/02/26 17:59:15 Can you include this header file in .cc file?
Greg Billock 2013/02/26 22:02:09 Dropped.
18 #include "webkit/fileapi/media/mtp_device_delegate.h" 18 #include "webkit/fileapi/media/mtp_device_async_delegate.h"
19 19
20 namespace base { 20 namespace base {
21 class SequencedTaskRunner; 21 class SequencedTaskRunner;
kmadhusu 2013/02/26 17:59:15 No longer used.
Greg Billock 2013/02/26 22:02:09 Done.
22 } 22 }
23 23
24 namespace chrome { 24 namespace chrome {
25 25
26 // Delegate for presenting an Image Capture device through the filesystem 26 // Delegate for presenting an Image Capture device through the filesystem
27 // API. The synthetic filesystem will be rooted at the constructed location, 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 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 29 // all appear as children of that directory. (ItemAdded calls with directories
30 // will be ignored.) 30 // will be ignored.)
31 class MTPDeviceDelegateImplMac : public fileapi::MTPDeviceDelegate { 31 class MTPDeviceDelegateImplMac : public fileapi::MTPDeviceAsyncDelegate {
32 public: 32 public:
33 MTPDeviceDelegateImplMac(const std::string& device_id, 33 MTPDeviceDelegateImplMac(const std::string& device_id,
kmadhusu 2013/02/26 17:59:15 This can be in private section.
Greg Billock 2013/02/26 22:02:09 Create method needs to call it. It'd require more
34 const base::FilePath::StringType& synthetic_path, 34 const base::FilePath::StringType& synthetic_path);
35 base::SequencedTaskRunner* media_task_runner);
36 35
37 // MTPDeviceDelegate: 36 // MTPDeviceAsyncDelegate:
kmadhusu 2013/02/26 17:59:15 You can declare these virtual functions in the pri
Greg Billock 2013/02/26 22:02:09 Technically, yes, but since the interface makes th
38 virtual base::PlatformFileError GetFileInfo( 37 virtual void GetFileInfo(
39 const base::FilePath& file_path, 38 const base::FilePath& file_path,
40 base::PlatformFileInfo* file_info) OVERRIDE; 39 const GetFileInfoSuccessCallback& success_callback,
41 virtual scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> 40 const ErrorCallback& error_callback) OVERRIDE;
42 CreateFileEnumerator(const base::FilePath& root, bool recursive) OVERRIDE; 41 virtual void ReadDirectory(
43 virtual base::PlatformFileError CreateSnapshotFile( 42 const base::FilePath& root,
43 const ReadDirectorySuccessCallback& success_callback,
44 const ErrorCallback& error_callback) OVERRIDE;
45 virtual void CreateSnapshotFile(
44 const base::FilePath& device_file_path, 46 const base::FilePath& device_file_path,
45 const base::FilePath& local_path, 47 const base::FilePath& local_path,
46 base::PlatformFileInfo* file_info) OVERRIDE; 48 const CreateSnapshotFileSuccessCallback& success_callback,
49 const ErrorCallback& error_callback) OVERRIDE;
47 virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE; 50 virtual void CancelPendingTasksAndDeleteDelegate() OVERRIDE;
48 51
49 // Forward delegates for ImageCaptureDeviceListener 52 // Forward delegates for ImageCaptureDeviceListener
50 virtual void ItemAdded(const std::string& name, 53 virtual void ItemAdded(const std::string& name,
51 const base::PlatformFileInfo& info); 54 const base::PlatformFileInfo& info);
52 virtual void NoMoreItems(); 55 virtual void NoMoreItems();
53 virtual void DownloadedFile(const std::string& name, 56 virtual void DownloadedFile(const std::string& name,
54 base::PlatformFileError error); 57 base::PlatformFileError error);
55 58
56 // Implementation returned by |CreateFileEnumerator()|. Must be deleted 59 // Public for closures; should not be called except by
57 // before CancelPendingTasksAndDeleteDelegate is called. 60 // CancelTasksAndDeleteDelegate.
58 class Enumerator : 61 void CancelAndDelete();
59 public fileapi::FileSystemFileUtil::AbstractFileEnumerator {
60 public:
61 explicit Enumerator(MTPDeviceDelegateImplMac* delegate);
62 virtual ~Enumerator();
63
64 virtual base::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 base::WaitableEvent wait_for_items_;
77 };
78
79 // GetFile and HasAllFiles called by enumerators.
80 base::FilePath GetFile(size_t index);
81 bool ReceivedAllFiles();
82 void RemoveEnumerator(Enumerator* enumerator);
83 62
84 private: 63 private:
85 friend class base::DeleteHelper<MTPDeviceDelegateImplMac>; 64 friend class base::DeleteHelper<MTPDeviceDelegateImplMac>;
kmadhusu 2013/02/26 17:59:15 This is no longer required.
Greg Billock 2013/02/26 22:02:09 Done.
86 65
87 class DeviceListener; 66 class DeviceListener;
88 67
89 virtual ~MTPDeviceDelegateImplMac(); 68 virtual ~MTPDeviceDelegateImplMac();
90 69
70 void GetFileInfoImpl(const base::FilePath& file_path,
71 base::PlatformFileInfo* file_info,
72 base::PlatformFileError* error);
73
74 void ReadDirectoryImpl(
75 const base::FilePath& root,
76 const ReadDirectorySuccessCallback& success_callback,
77 const ErrorCallback& error_callback);
78
79 void DownloadFile(
kmadhusu 2013/02/26 17:59:15 Please document the new member functions.
Greg Billock 2013/02/26 22:02:09 Done.
80 const base::FilePath& device_file_path,
81 const base::FilePath& local_path,
82 const CreateSnapshotFileSuccessCallback& success_callback,
83 const ErrorCallback& error_callback);
84
85 void CancelDownloads();
86
87 void NotifyReadDir();
88
91 std::string device_id_; 89 std::string device_id_;
92 base::FilePath root_path_; 90 base::FilePath root_path_;
93 91
94 // Stores a reference to worker pool thread. All requests and response of file
95 // operations are posted on |media_task_runner_|. All callbacks from the
96 // camera will come through this task runner as well.
97 scoped_refptr<base::SequencedTaskRunner> media_task_runner_;
98
99 // Interface object for the camera underlying this MTP session. 92 // Interface object for the camera underlying this MTP session.
100 scoped_ptr<DeviceListener> camera_interface_; 93 scoped_ptr<DeviceListener> camera_interface_;
101 94
102 // This lock protects all subsequent state. While calling into the delegate
103 // from the FileSystem API happens in sequence, these calls may be
104 // interleaved with calls on other threads in the sequenced task runner
105 // forwarded from the device.
106 base::Lock mutex_;
107
108 // Weak pointer to the enumerator which may be listening for files to come in.
109 Enumerator* enumerator_;
110
111 // Stores a map from filename to file metadata received from the camera. 95 // Stores a map from filename to file metadata received from the camera.
112 base::hash_map<base::FilePath::StringType, base::PlatformFileInfo> file_info_; 96 base::hash_map<base::FilePath::StringType, base::PlatformFileInfo> file_info_;
113 97
114 // Notification for pending download.
115 base::WaitableEvent* file_download_event_;
116
117 // Resulting error code for pending download.
118 base::PlatformFileError file_download_error_;
119
120 // List of files received from the camera. 98 // List of files received from the camera.
121 std::vector<base::FilePath> file_paths_; 99 std::vector<base::FilePath> file_paths_;
122 100
123 // Set to true when all file metadata has been received from the camera. 101 // Set to true when all file metadata has been received from the camera.
124 bool received_all_files_; 102 bool received_all_files_;
125 103
104 ReadDirectorySuccessCallback read_directory_success_callback_;
105 ErrorCallback read_directory_error_callback_;
106
107 CreateSnapshotFileSuccessCallback read_file_success_callback_;
108 ErrorCallback read_file_error_callback_;
109
126 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplMac); 110 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplMac);
127 }; 111 };
128 112
129 } // namespace chrome 113 } // namespace chrome
130 114
131 #endif // CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_MAC_H_ 115 #endif // CHROME_BROWSER_MEDIA_GALLERY_MTP_DEVICE_DELEGATE_IMPL_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698