| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 return HandleDeviceError(request.error_callback, | 129 return HandleDeviceError(request.error_callback, |
| 130 base::File::FILE_ERROR_FAILED); | 130 base::File::FILE_ERROR_FAILED); |
| 131 } | 131 } |
| 132 | 132 |
| 133 GetMediaTransferProtocolManager()->GetFileInfo( | 133 GetMediaTransferProtocolManager()->GetFileInfo( |
| 134 device_handle_, request.file_id, | 134 device_handle_, request.file_id, |
| 135 base::Bind(&MTPDeviceTaskHelper::OnGetFileInfoToReadBytes, | 135 base::Bind(&MTPDeviceTaskHelper::OnGetFileInfoToReadBytes, |
| 136 weak_ptr_factory_.GetWeakPtr(), request)); | 136 weak_ptr_factory_.GetWeakPtr(), request)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void MTPDeviceTaskHelper::CopyFileFromLocal( |
| 140 const std::string& storage_name, |
| 141 const uint32 source_file_descriptor, |
| 142 const uint32 parent_id, |
| 143 const std::string& file_name, |
| 144 const CopyFileFromLocalSuccessCallback& success_callback, |
| 145 const ErrorCallback& error_callback) { |
| 146 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 147 |
| 148 GetMediaTransferProtocolManager()->CopyFileFromLocal( |
| 149 device_handle_, source_file_descriptor, parent_id, file_name, |
| 150 base::Bind(&MTPDeviceTaskHelper::OnCopyFileFromLocal, |
| 151 weak_ptr_factory_.GetWeakPtr(), success_callback, |
| 152 error_callback)); |
| 153 } |
| 154 |
| 139 void MTPDeviceTaskHelper::CloseStorage() const { | 155 void MTPDeviceTaskHelper::CloseStorage() const { |
| 140 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 156 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 141 if (device_handle_.empty()) | 157 if (device_handle_.empty()) |
| 142 return; | 158 return; |
| 143 GetMediaTransferProtocolManager()->CloseStorage(device_handle_, | 159 GetMediaTransferProtocolManager()->CloseStorage(device_handle_, |
| 144 base::Bind(&DoNothing)); | 160 base::Bind(&DoNothing)); |
| 145 } | 161 } |
| 146 | 162 |
| 147 void MTPDeviceTaskHelper::OnDidOpenStorage( | 163 void MTPDeviceTaskHelper::OnDidOpenStorage( |
| 148 const OpenStorageCallback& completion_callback, | 164 const OpenStorageCallback& completion_callback, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 275 |
| 260 CHECK_LE(base::checked_cast<int>(data.length()), request.buf_len); | 276 CHECK_LE(base::checked_cast<int>(data.length()), request.buf_len); |
| 261 std::copy(data.begin(), data.end(), request.buf->data()); | 277 std::copy(data.begin(), data.end(), request.buf->data()); |
| 262 | 278 |
| 263 content::BrowserThread::PostTask(content::BrowserThread::IO, | 279 content::BrowserThread::PostTask(content::BrowserThread::IO, |
| 264 FROM_HERE, | 280 FROM_HERE, |
| 265 base::Bind(request.success_callback, | 281 base::Bind(request.success_callback, |
| 266 file_info, data.length())); | 282 file_info, data.length())); |
| 267 } | 283 } |
| 268 | 284 |
| 285 void MTPDeviceTaskHelper::OnCopyFileFromLocal( |
| 286 const CopyFileFromLocalSuccessCallback& success_callback, |
| 287 const ErrorCallback& error_callback, |
| 288 const bool error) const { |
| 289 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 290 if (error) { |
| 291 content::BrowserThread::PostTask( |
| 292 content::BrowserThread::IO, FROM_HERE, |
| 293 base::Bind(error_callback, base::File::FILE_ERROR_FAILED)); |
| 294 return; |
| 295 } |
| 296 |
| 297 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
| 298 base::Bind(success_callback)); |
| 299 } |
| 300 |
| 269 void MTPDeviceTaskHelper::HandleDeviceError( | 301 void MTPDeviceTaskHelper::HandleDeviceError( |
| 270 const ErrorCallback& error_callback, | 302 const ErrorCallback& error_callback, |
| 271 base::File::Error error) const { | 303 base::File::Error error) const { |
| 272 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 304 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 273 content::BrowserThread::PostTask(content::BrowserThread::IO, | 305 content::BrowserThread::PostTask(content::BrowserThread::IO, |
| 274 FROM_HERE, | 306 FROM_HERE, |
| 275 base::Bind(error_callback, error)); | 307 base::Bind(error_callback, error)); |
| 276 } | 308 } |
| OLD | NEW |