| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // MTPDeviceTaskHelper lives on the UI thread. MTPDeviceTaskHelperMapService | 25 // MTPDeviceTaskHelper lives on the UI thread. MTPDeviceTaskHelperMapService |
| 26 // owns the MTPDeviceTaskHelper objects. MTPDeviceTaskHelper is instantiated per | 26 // owns the MTPDeviceTaskHelper objects. MTPDeviceTaskHelper is instantiated per |
| 27 // MTP device storage. | 27 // MTP device storage. |
| 28 class MTPDeviceTaskHelper { | 28 class MTPDeviceTaskHelper { |
| 29 public: | 29 public: |
| 30 typedef base::Callback<void(bool succeeded)> OpenStorageCallback; | 30 typedef base::Callback<void(bool succeeded)> OpenStorageCallback; |
| 31 | 31 |
| 32 typedef MTPDeviceAsyncDelegate::GetFileInfoSuccessCallback | 32 typedef MTPDeviceAsyncDelegate::GetFileInfoSuccessCallback |
| 33 GetFileInfoSuccessCallback; | 33 GetFileInfoSuccessCallback; |
| 34 | 34 |
| 35 typedef base::Callback<void(int)> ReadBytesSuccessCallback; |
| 36 |
| 35 typedef base::Callback<void(const fileapi::AsyncFileUtil::EntryList&)> | 37 typedef base::Callback<void(const fileapi::AsyncFileUtil::EntryList&)> |
| 36 ReadDirectorySuccessCallback; | 38 ReadDirectorySuccessCallback; |
| 37 | 39 |
| 38 typedef MTPDeviceAsyncDelegate::ErrorCallback ErrorCallback; | 40 typedef MTPDeviceAsyncDelegate::ErrorCallback ErrorCallback; |
| 39 | 41 |
| 40 MTPDeviceTaskHelper(); | 42 MTPDeviceTaskHelper(); |
| 41 ~MTPDeviceTaskHelper(); | 43 ~MTPDeviceTaskHelper(); |
| 42 | 44 |
| 43 // Dispatches the request to the MediaTransferProtocolManager to open the MTP | 45 // Dispatches the request to the MediaTransferProtocolManager to open the MTP |
| 44 // storage for communication. | 46 // storage for communication. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // object. | 84 // object. |
| 83 // | 85 // |
| 84 // |request_info| specifies the snapshot file request params. | 86 // |request_info| specifies the snapshot file request params. |
| 85 // |snapshot_file_info| specifies the metadata of the snapshot file. | 87 // |snapshot_file_info| specifies the metadata of the snapshot file. |
| 86 void WriteDataIntoSnapshotFile( | 88 void WriteDataIntoSnapshotFile( |
| 87 const SnapshotRequestInfo& request_info, | 89 const SnapshotRequestInfo& request_info, |
| 88 const base::File::Info& snapshot_file_info); | 90 const base::File::Info& snapshot_file_info); |
| 89 | 91 |
| 90 // Dispatches the read bytes request to the MediaTransferProtocolManager. | 92 // Dispatches the read bytes request to the MediaTransferProtocolManager. |
| 91 // | 93 // |
| 92 // |request| contains details about the byte request including the file path, | 94 // |success_callback| is invoked on the IO thread to notify the caller about |
| 93 // byte range, and the callbacks. The callbacks specified within |request| are | 95 // the number of bytes read. |
| 94 // called on the IO thread to notify the caller about success or failure. | 96 // |
| 95 void ReadBytes(const MTPDeviceAsyncDelegate::ReadBytesRequest& request); | 97 // If there is an error, |error_callback| is invoked on the IO thread to |
| 98 // notify the caller about the file error. |
| 99 void ReadBytes(const std::string& device_file_relative_path, |
| 100 net::IOBuffer* buf, int64 offset, int buf_len, |
| 101 const ReadBytesSuccessCallback& success_callback, |
| 102 const ErrorCallback& error_callback); |
| 96 | 103 |
| 97 // Dispatches the CloseStorage request to the MediaTransferProtocolManager. | 104 // Dispatches the CloseStorage request to the MediaTransferProtocolManager. |
| 98 void CloseStorage() const; | 105 void CloseStorage() const; |
| 99 | 106 |
| 100 private: | 107 private: |
| 101 // Query callback for OpenStorage() to run |callback| on the IO thread. | 108 // Query callback for OpenStorage() to run |callback| on the IO thread. |
| 102 // | 109 // |
| 103 // If OpenStorage request succeeds, |error| is set to false and | 110 // If OpenStorage request succeeds, |error| is set to false and |
| 104 // |device_handle| contains the handle to communicate with the MTP device. | 111 // |device_handle| contains the handle to communicate with the MTP device. |
| 105 // | 112 // |
| (...skipping 26 matching lines...) Expand all Loading... |
| 132 // If there is an error, |error| is set to true, |file_entries| is empty | 139 // If there is an error, |error| is set to true, |file_entries| is empty |
| 133 // and |error_callback| is invoked on the IO thread to notify the caller. | 140 // and |error_callback| is invoked on the IO thread to notify the caller. |
| 134 void OnDidReadDirectoryByPath( | 141 void OnDidReadDirectoryByPath( |
| 135 const ReadDirectorySuccessCallback& success_callback, | 142 const ReadDirectorySuccessCallback& success_callback, |
| 136 const ErrorCallback& error_callback, | 143 const ErrorCallback& error_callback, |
| 137 const std::vector<MtpFileEntry>& file_entries, | 144 const std::vector<MtpFileEntry>& file_entries, |
| 138 bool error) const; | 145 bool error) const; |
| 139 | 146 |
| 140 // Query callback for ReadBytes(); | 147 // Query callback for ReadBytes(); |
| 141 // | 148 // |
| 142 // If there is no error, |error| is set to false, the buffer within |request| | 149 // If there is no error, |error| is set to false, the buffer |buf| is written |
| 143 // is written to, and the success callback within |request| is invoked on the | 150 // to, and |success_callback| is invoked on the IO thread to notify the |
| 144 // IO thread to notify the caller. | 151 // caller. |
| 145 // | 152 // |
| 146 // If there is an error, |error| is set to true, the buffer within |request| | 153 // If there is an error, |error| is set to true, |buf| is untouched, and |
| 147 // is untouched, and the error callback within |request| is invoked on the | 154 // |error_callback| is invoked on the IO thread to notify the caller. |
| 148 // IO thread to notify the caller. | |
| 149 void OnDidReadBytes( | 155 void OnDidReadBytes( |
| 150 const MTPDeviceAsyncDelegate::ReadBytesRequest& request, | 156 net::IOBuffer* buf, int buf_len, |
| 157 const ReadBytesSuccessCallback& success_callback, |
| 158 const ErrorCallback& error_callback, |
| 151 const std::string& data, | 159 const std::string& data, |
| 152 bool error) const; | 160 bool error) const; |
| 153 | 161 |
| 154 // Called when the device is uninitialized. | 162 // Called when the device is uninitialized. |
| 155 // | 163 // |
| 156 // Runs |error_callback| on the IO thread to notify the caller about the | 164 // Runs |error_callback| on the IO thread to notify the caller about the |
| 157 // device |error|. | 165 // device |error|. |
| 158 void HandleDeviceError(const ErrorCallback& error_callback, | 166 void HandleDeviceError(const ErrorCallback& error_callback, |
| 159 base::File::Error error) const; | 167 base::File::Error error) const; |
| 160 | 168 |
| 161 // Handle to communicate with the MTP device. | 169 // Handle to communicate with the MTP device. |
| 162 std::string device_handle_; | 170 std::string device_handle_; |
| 163 | 171 |
| 164 // Used to handle WriteDataInfoSnapshotFile request. | 172 // Used to handle WriteDataInfoSnapshotFile request. |
| 165 scoped_ptr<MTPReadFileWorker> read_file_worker_; | 173 scoped_ptr<MTPReadFileWorker> read_file_worker_; |
| 166 | 174 |
| 167 // For callbacks that may run after destruction. | 175 // For callbacks that may run after destruction. |
| 168 base::WeakPtrFactory<MTPDeviceTaskHelper> weak_ptr_factory_; | 176 base::WeakPtrFactory<MTPDeviceTaskHelper> weak_ptr_factory_; |
| 169 | 177 |
| 170 DISALLOW_COPY_AND_ASSIGN(MTPDeviceTaskHelper); | 178 DISALLOW_COPY_AND_ASSIGN(MTPDeviceTaskHelper); |
| 171 }; | 179 }; |
| 172 | 180 |
| 173 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_H_ | 181 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_H_ |
| OLD | NEW |