| 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 if (error) { | 207 if (error) { |
| 208 return HandleDeviceError(request.error_callback, | 208 return HandleDeviceError(request.error_callback, |
| 209 base::File::FILE_ERROR_FAILED); | 209 base::File::FILE_ERROR_FAILED); |
| 210 } | 210 } |
| 211 | 211 |
| 212 base::File::Info file_info = FileInfoFromMTPFileEntry(file_entry); | 212 base::File::Info file_info = FileInfoFromMTPFileEntry(file_entry); |
| 213 if (file_info.is_directory) { | 213 if (file_info.is_directory) { |
| 214 return HandleDeviceError(request.error_callback, | 214 return HandleDeviceError(request.error_callback, |
| 215 base::File::FILE_ERROR_NOT_A_FILE); | 215 base::File::FILE_ERROR_NOT_A_FILE); |
| 216 } else if (file_info.size < 0 || file_info.size > kuint32max || | 216 } else if (file_info.size < 0 || file_info.size > kuint32max || |
| 217 request.offset >= file_info.size) { | 217 request.offset > file_info.size) { |
| 218 return HandleDeviceError(request.error_callback, | 218 return HandleDeviceError(request.error_callback, |
| 219 base::File::FILE_ERROR_FAILED); | 219 base::File::FILE_ERROR_FAILED); |
| 220 } else if (request.offset == file_info.size) { |
| 221 content::BrowserThread::PostTask(content::BrowserThread::IO, |
| 222 FROM_HERE, |
| 223 base::Bind(request.success_callback, |
| 224 file_info, 0u)); |
| 225 return; |
| 220 } | 226 } |
| 221 | 227 |
| 222 uint32 bytes_to_read = std::min( | 228 uint32 bytes_to_read = std::min( |
| 223 base::checked_cast<uint32>(request.buf_len), | 229 base::checked_cast<uint32>(request.buf_len), |
| 224 base::saturated_cast<uint32>(file_info.size - request.offset)); | 230 base::saturated_cast<uint32>(file_info.size - request.offset)); |
| 225 | 231 |
| 226 GetMediaTransferProtocolManager()->ReadFileChunkByPath( | 232 GetMediaTransferProtocolManager()->ReadFileChunkByPath( |
| 227 device_handle_, | 233 device_handle_, |
| 228 request.device_file_relative_path, | 234 request.device_file_relative_path, |
| 229 base::checked_cast<uint32>(request.offset), | 235 base::checked_cast<uint32>(request.offset), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 253 } | 259 } |
| 254 | 260 |
| 255 void MTPDeviceTaskHelper::HandleDeviceError( | 261 void MTPDeviceTaskHelper::HandleDeviceError( |
| 256 const ErrorCallback& error_callback, | 262 const ErrorCallback& error_callback, |
| 257 base::File::Error error) const { | 263 base::File::Error error) const { |
| 258 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 264 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 259 content::BrowserThread::PostTask(content::BrowserThread::IO, | 265 content::BrowserThread::PostTask(content::BrowserThread::IO, |
| 260 FROM_HERE, | 266 FROM_HERE, |
| 261 base::Bind(error_callback, error)); | 267 base::Bind(error_callback, error)); |
| 262 } | 268 } |
| OLD | NEW |