| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 weak_ptr_factory_.GetWeakPtr(), | 58 weak_ptr_factory_.GetWeakPtr(), |
| 59 callback)); | 59 callback)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void MTPDeviceTaskHelper::GetFileInfoByPath( | 62 void MTPDeviceTaskHelper::GetFileInfoByPath( |
| 63 const std::string& file_path, | 63 const std::string& file_path, |
| 64 const GetFileInfoSuccessCallback& success_callback, | 64 const GetFileInfoSuccessCallback& success_callback, |
| 65 const ErrorCallback& error_callback) { | 65 const ErrorCallback& error_callback) { |
| 66 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 66 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 67 if (device_handle_.empty()) | 67 if (device_handle_.empty()) |
| 68 return HandleDeviceError(error_callback, base::PLATFORM_FILE_ERROR_FAILED); | 68 return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED); |
| 69 | 69 |
| 70 GetMediaTransferProtocolManager()->GetFileInfoByPath( | 70 GetMediaTransferProtocolManager()->GetFileInfoByPath( |
| 71 device_handle_, file_path, | 71 device_handle_, file_path, |
| 72 base::Bind(&MTPDeviceTaskHelper::OnGetFileInfo, | 72 base::Bind(&MTPDeviceTaskHelper::OnGetFileInfo, |
| 73 weak_ptr_factory_.GetWeakPtr(), | 73 weak_ptr_factory_.GetWeakPtr(), |
| 74 success_callback, | 74 success_callback, |
| 75 error_callback)); | 75 error_callback)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void MTPDeviceTaskHelper::ReadDirectoryByPath( | 78 void MTPDeviceTaskHelper::ReadDirectoryByPath( |
| 79 const std::string& dir_path, | 79 const std::string& dir_path, |
| 80 const ReadDirectorySuccessCallback& success_callback, | 80 const ReadDirectorySuccessCallback& success_callback, |
| 81 const ErrorCallback& error_callback) { | 81 const ErrorCallback& error_callback) { |
| 82 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 82 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 83 if (device_handle_.empty()) | 83 if (device_handle_.empty()) |
| 84 return HandleDeviceError(error_callback, base::PLATFORM_FILE_ERROR_FAILED); | 84 return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED); |
| 85 | 85 |
| 86 GetMediaTransferProtocolManager()->ReadDirectoryByPath( | 86 GetMediaTransferProtocolManager()->ReadDirectoryByPath( |
| 87 device_handle_, dir_path, | 87 device_handle_, dir_path, |
| 88 base::Bind(&MTPDeviceTaskHelper::OnDidReadDirectoryByPath, | 88 base::Bind(&MTPDeviceTaskHelper::OnDidReadDirectoryByPath, |
| 89 weak_ptr_factory_.GetWeakPtr(), | 89 weak_ptr_factory_.GetWeakPtr(), |
| 90 success_callback, | 90 success_callback, |
| 91 error_callback)); | 91 error_callback)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void MTPDeviceTaskHelper::WriteDataIntoSnapshotFile( | 94 void MTPDeviceTaskHelper::WriteDataIntoSnapshotFile( |
| 95 const SnapshotRequestInfo& request_info, | 95 const SnapshotRequestInfo& request_info, |
| 96 const base::PlatformFileInfo& snapshot_file_info) { | 96 const base::File::Info& snapshot_file_info) { |
| 97 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 97 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 98 if (device_handle_.empty()) { | 98 if (device_handle_.empty()) { |
| 99 return HandleDeviceError(request_info.error_callback, | 99 return HandleDeviceError(request_info.error_callback, |
| 100 base::PLATFORM_FILE_ERROR_FAILED); | 100 base::File::FILE_ERROR_FAILED); |
| 101 } | 101 } |
| 102 | 102 |
| 103 if (!read_file_worker_) | 103 if (!read_file_worker_) |
| 104 read_file_worker_.reset(new MTPReadFileWorker(device_handle_)); | 104 read_file_worker_.reset(new MTPReadFileWorker(device_handle_)); |
| 105 read_file_worker_->WriteDataIntoSnapshotFile(request_info, | 105 read_file_worker_->WriteDataIntoSnapshotFile(request_info, |
| 106 snapshot_file_info); | 106 snapshot_file_info); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void MTPDeviceTaskHelper::ReadBytes( | 109 void MTPDeviceTaskHelper::ReadBytes( |
| 110 const MTPDeviceAsyncDelegate::ReadBytesRequest& request) { | 110 const MTPDeviceAsyncDelegate::ReadBytesRequest& request) { |
| 111 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 111 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 112 if (device_handle_.empty()) { | 112 if (device_handle_.empty()) { |
| 113 return HandleDeviceError(request.error_callback, | 113 return HandleDeviceError(request.error_callback, |
| 114 base::PLATFORM_FILE_ERROR_FAILED); | 114 base::File::FILE_ERROR_FAILED); |
| 115 } | 115 } |
| 116 | 116 |
| 117 GetMediaTransferProtocolManager()->ReadFileChunkByPath( | 117 GetMediaTransferProtocolManager()->ReadFileChunkByPath( |
| 118 device_handle_, | 118 device_handle_, |
| 119 request.device_file_relative_path, | 119 request.device_file_relative_path, |
| 120 base::checked_cast<uint32>(request.offset), | 120 base::checked_cast<uint32>(request.offset), |
| 121 base::checked_cast<uint32>(request.buf_len), | 121 base::checked_cast<uint32>(request.buf_len), |
| 122 base::Bind(&MTPDeviceTaskHelper::OnDidReadBytes, | 122 base::Bind(&MTPDeviceTaskHelper::OnDidReadBytes, |
| 123 weak_ptr_factory_.GetWeakPtr(), request)); | 123 weak_ptr_factory_.GetWeakPtr(), request)); |
| 124 } | 124 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 143 } | 143 } |
| 144 | 144 |
| 145 void MTPDeviceTaskHelper::OnGetFileInfo( | 145 void MTPDeviceTaskHelper::OnGetFileInfo( |
| 146 const GetFileInfoSuccessCallback& success_callback, | 146 const GetFileInfoSuccessCallback& success_callback, |
| 147 const ErrorCallback& error_callback, | 147 const ErrorCallback& error_callback, |
| 148 const MtpFileEntry& file_entry, | 148 const MtpFileEntry& file_entry, |
| 149 bool error) const { | 149 bool error) const { |
| 150 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 150 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 151 if (error) { | 151 if (error) { |
| 152 return HandleDeviceError(error_callback, | 152 return HandleDeviceError(error_callback, |
| 153 base::PLATFORM_FILE_ERROR_NOT_FOUND); | 153 base::File::FILE_ERROR_NOT_FOUND); |
| 154 } | 154 } |
| 155 | 155 |
| 156 base::PlatformFileInfo file_entry_info; | 156 base::File::Info file_entry_info; |
| 157 file_entry_info.size = file_entry.file_size(); | 157 file_entry_info.size = file_entry.file_size(); |
| 158 file_entry_info.is_directory = | 158 file_entry_info.is_directory = |
| 159 file_entry.file_type() == MtpFileEntry::FILE_TYPE_FOLDER; | 159 file_entry.file_type() == MtpFileEntry::FILE_TYPE_FOLDER; |
| 160 file_entry_info.is_symbolic_link = false; | 160 file_entry_info.is_symbolic_link = false; |
| 161 file_entry_info.last_modified = | 161 file_entry_info.last_modified = |
| 162 base::Time::FromTimeT(file_entry.modification_time()); | 162 base::Time::FromTimeT(file_entry.modification_time()); |
| 163 file_entry_info.last_accessed = file_entry_info.last_modified; | 163 file_entry_info.last_accessed = file_entry_info.last_modified; |
| 164 file_entry_info.creation_time = base::Time(); | 164 file_entry_info.creation_time = base::Time(); |
| 165 content::BrowserThread::PostTask(content::BrowserThread::IO, | 165 content::BrowserThread::PostTask(content::BrowserThread::IO, |
| 166 FROM_HERE, | 166 FROM_HERE, |
| 167 base::Bind(success_callback, | 167 base::Bind(success_callback, |
| 168 file_entry_info)); | 168 file_entry_info)); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void MTPDeviceTaskHelper::OnDidReadDirectoryByPath( | 171 void MTPDeviceTaskHelper::OnDidReadDirectoryByPath( |
| 172 const ReadDirectorySuccessCallback& success_callback, | 172 const ReadDirectorySuccessCallback& success_callback, |
| 173 const ErrorCallback& error_callback, | 173 const ErrorCallback& error_callback, |
| 174 const std::vector<MtpFileEntry>& file_entries, | 174 const std::vector<MtpFileEntry>& file_entries, |
| 175 bool error) const { | 175 bool error) const { |
| 176 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 176 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 177 if (error) | 177 if (error) |
| 178 return HandleDeviceError(error_callback, base::PLATFORM_FILE_ERROR_FAILED); | 178 return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED); |
| 179 | 179 |
| 180 fileapi::AsyncFileUtil::EntryList entries; | 180 fileapi::AsyncFileUtil::EntryList entries; |
| 181 base::FilePath current; | 181 base::FilePath current; |
| 182 MTPDeviceObjectEnumerator file_enum(file_entries); | 182 MTPDeviceObjectEnumerator file_enum(file_entries); |
| 183 while (!(current = file_enum.Next()).empty()) { | 183 while (!(current = file_enum.Next()).empty()) { |
| 184 fileapi::DirectoryEntry entry; | 184 fileapi::DirectoryEntry entry; |
| 185 entry.name = fileapi::VirtualPath::BaseName(current).value(); | 185 entry.name = fileapi::VirtualPath::BaseName(current).value(); |
| 186 entry.is_directory = file_enum.IsDirectory(); | 186 entry.is_directory = file_enum.IsDirectory(); |
| 187 entry.size = file_enum.Size(); | 187 entry.size = file_enum.Size(); |
| 188 entry.last_modified_time = file_enum.LastModifiedTime(); | 188 entry.last_modified_time = file_enum.LastModifiedTime(); |
| 189 entries.push_back(entry); | 189 entries.push_back(entry); |
| 190 } | 190 } |
| 191 content::BrowserThread::PostTask(content::BrowserThread::IO, | 191 content::BrowserThread::PostTask(content::BrowserThread::IO, |
| 192 FROM_HERE, | 192 FROM_HERE, |
| 193 base::Bind(success_callback, entries)); | 193 base::Bind(success_callback, entries)); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void MTPDeviceTaskHelper::OnDidReadBytes( | 196 void MTPDeviceTaskHelper::OnDidReadBytes( |
| 197 const MTPDeviceAsyncDelegate::ReadBytesRequest& request, | 197 const MTPDeviceAsyncDelegate::ReadBytesRequest& request, |
| 198 const std::string& data, | 198 const std::string& data, |
| 199 bool error) const { | 199 bool error) const { |
| 200 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 200 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 201 if (error) { | 201 if (error) { |
| 202 return HandleDeviceError(request.error_callback, | 202 return HandleDeviceError(request.error_callback, |
| 203 base::PLATFORM_FILE_ERROR_FAILED); | 203 base::File::FILE_ERROR_FAILED); |
| 204 } | 204 } |
| 205 | 205 |
| 206 CHECK_LE(base::checked_cast<int>(data.length()), request.buf_len); | 206 CHECK_LE(base::checked_cast<int>(data.length()), request.buf_len); |
| 207 std::copy(data.begin(), data.end(), request.buf->data()); | 207 std::copy(data.begin(), data.end(), request.buf->data()); |
| 208 | 208 |
| 209 content::BrowserThread::PostTask(content::BrowserThread::IO, | 209 content::BrowserThread::PostTask(content::BrowserThread::IO, |
| 210 FROM_HERE, | 210 FROM_HERE, |
| 211 base::Bind(request.success_callback, | 211 base::Bind(request.success_callback, |
| 212 data.length())); | 212 data.length())); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void MTPDeviceTaskHelper::HandleDeviceError( | 215 void MTPDeviceTaskHelper::HandleDeviceError( |
| 216 const ErrorCallback& error_callback, | 216 const ErrorCallback& error_callback, |
| 217 base::PlatformFileError error) const { | 217 base::File::Error error) const { |
| 218 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 218 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 219 content::BrowserThread::PostTask(content::BrowserThread::IO, | 219 content::BrowserThread::PostTask(content::BrowserThread::IO, |
| 220 FROM_HERE, | 220 FROM_HERE, |
| 221 base::Bind(error_callback, error)); | 221 base::Bind(error_callback, error)); |
| 222 } | 222 } |
| OLD | NEW |