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 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper.h" | 5 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 base::File::FILE_ERROR_FAILED); | 102 base::File::FILE_ERROR_FAILED); |
103 } | 103 } |
104 | 104 |
105 if (!read_file_worker_) | 105 if (!read_file_worker_) |
106 read_file_worker_.reset(new MTPReadFileWorker(device_handle_)); | 106 read_file_worker_.reset(new MTPReadFileWorker(device_handle_)); |
107 read_file_worker_->WriteDataIntoSnapshotFile(request_info, | 107 read_file_worker_->WriteDataIntoSnapshotFile(request_info, |
108 snapshot_file_info); | 108 snapshot_file_info); |
109 } | 109 } |
110 | 110 |
111 void MTPDeviceTaskHelper::ReadBytes( | 111 void MTPDeviceTaskHelper::ReadBytes( |
112 const MTPDeviceAsyncDelegate::ReadBytesRequest& request) { | 112 const std::string& device_file_relative_path, |
| 113 net::IOBuffer* buf, int64 offset, int buf_len, |
| 114 const ReadBytesSuccessCallback& success_callback, |
| 115 const ErrorCallback& error_callback) { |
113 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 116 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
114 if (device_handle_.empty()) { | 117 if (device_handle_.empty()) { |
115 return HandleDeviceError(request.error_callback, | 118 return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED); |
116 base::File::FILE_ERROR_FAILED); | |
117 } | 119 } |
118 | 120 |
119 GetMediaTransferProtocolManager()->ReadFileChunkByPath( | 121 GetMediaTransferProtocolManager()->ReadFileChunkByPath( |
120 device_handle_, | 122 device_handle_, |
121 request.device_file_relative_path, | 123 device_file_relative_path, |
122 base::checked_cast<uint32>(request.offset), | 124 base::checked_cast<uint32>(offset), |
123 base::checked_cast<uint32>(request.buf_len), | 125 base::checked_cast<uint32>(buf_len), |
124 base::Bind(&MTPDeviceTaskHelper::OnDidReadBytes, | 126 base::Bind(&MTPDeviceTaskHelper::OnDidReadBytes, |
125 weak_ptr_factory_.GetWeakPtr(), request)); | 127 weak_ptr_factory_.GetWeakPtr(), make_scoped_refptr(buf), |
| 128 buf_len, success_callback, error_callback)); |
126 } | 129 } |
127 | 130 |
128 void MTPDeviceTaskHelper::CloseStorage() const { | 131 void MTPDeviceTaskHelper::CloseStorage() const { |
129 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 132 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
130 if (device_handle_.empty()) | 133 if (device_handle_.empty()) |
131 return; | 134 return; |
132 GetMediaTransferProtocolManager()->CloseStorage(device_handle_, | 135 GetMediaTransferProtocolManager()->CloseStorage(device_handle_, |
133 base::Bind(&DoNothing)); | 136 base::Bind(&DoNothing)); |
134 } | 137 } |
135 | 138 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 entry.size = file_enum.Size(); | 192 entry.size = file_enum.Size(); |
190 entry.last_modified_time = file_enum.LastModifiedTime(); | 193 entry.last_modified_time = file_enum.LastModifiedTime(); |
191 entries.push_back(entry); | 194 entries.push_back(entry); |
192 } | 195 } |
193 content::BrowserThread::PostTask(content::BrowserThread::IO, | 196 content::BrowserThread::PostTask(content::BrowserThread::IO, |
194 FROM_HERE, | 197 FROM_HERE, |
195 base::Bind(success_callback, entries)); | 198 base::Bind(success_callback, entries)); |
196 } | 199 } |
197 | 200 |
198 void MTPDeviceTaskHelper::OnDidReadBytes( | 201 void MTPDeviceTaskHelper::OnDidReadBytes( |
199 const MTPDeviceAsyncDelegate::ReadBytesRequest& request, | 202 net::IOBuffer* buf, int buf_len, |
| 203 const ReadBytesSuccessCallback& success_callback, |
| 204 const ErrorCallback& error_callback, |
200 const std::string& data, | 205 const std::string& data, |
201 bool error) const { | 206 bool error) const { |
202 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 207 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
203 if (error) { | 208 if (error) { |
204 return HandleDeviceError(request.error_callback, | 209 return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED); |
205 base::File::FILE_ERROR_FAILED); | |
206 } | 210 } |
207 | 211 |
208 CHECK_LE(base::checked_cast<int>(data.length()), request.buf_len); | 212 CHECK_LE(base::checked_cast<int>(data.length()), buf_len); |
209 std::copy(data.begin(), data.end(), request.buf->data()); | 213 std::copy(data.begin(), data.end(), buf->data()); |
210 | 214 |
211 content::BrowserThread::PostTask(content::BrowserThread::IO, | 215 content::BrowserThread::PostTask(content::BrowserThread::IO, |
212 FROM_HERE, | 216 FROM_HERE, |
213 base::Bind(request.success_callback, | 217 base::Bind(success_callback, data.length())); |
214 data.length())); | |
215 } | 218 } |
216 | 219 |
217 void MTPDeviceTaskHelper::HandleDeviceError( | 220 void MTPDeviceTaskHelper::HandleDeviceError( |
218 const ErrorCallback& error_callback, | 221 const ErrorCallback& error_callback, |
219 base::File::Error error) const { | 222 base::File::Error error) const { |
220 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 223 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
221 content::BrowserThread::PostTask(content::BrowserThread::IO, | 224 content::BrowserThread::PostTask(content::BrowserThread::IO, |
222 FROM_HERE, | 225 FROM_HERE, |
223 base::Bind(error_callback, error)); | 226 base::Bind(error_callback, error)); |
224 } | 227 } |
OLD | NEW |