| 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" | |
| 11 #include "base/strings/string_number_conversions.h" | |
| 12 #include "chrome/browser/media_galleries/linux/mtp_device_object_enumerator.h" | 10 #include "chrome/browser/media_galleries/linux/mtp_device_object_enumerator.h" |
| 13 #include "chrome/browser/media_galleries/linux/mtp_read_file_worker.h" | 11 #include "chrome/browser/media_galleries/linux/mtp_read_file_worker.h" |
| 14 #include "chrome/browser/media_galleries/linux/snapshot_file_details.h" | 12 #include "chrome/browser/media_galleries/linux/snapshot_file_details.h" |
| 15 #include "components/storage_monitor/storage_monitor.h" | 13 #include "components/storage_monitor/storage_monitor.h" |
| 16 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 17 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | 15 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
| 18 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| 19 #include "storage/browser/fileapi/async_file_util.h" | 17 #include "storage/browser/fileapi/async_file_util.h" |
| 20 #include "storage/common/fileapi/file_system_util.h" | 18 #include "storage/common/fileapi/file_system_util.h" |
| 21 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 const ErrorCallback& error_callback) { | 159 const ErrorCallback& error_callback) { |
| 162 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 160 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 163 | 161 |
| 164 GetMediaTransferProtocolManager()->RenameObject( | 162 GetMediaTransferProtocolManager()->RenameObject( |
| 165 device_handle_, object_id, new_name, | 163 device_handle_, object_id, new_name, |
| 166 base::Bind(&MTPDeviceTaskHelper::OnRenameObject, | 164 base::Bind(&MTPDeviceTaskHelper::OnRenameObject, |
| 167 weak_ptr_factory_.GetWeakPtr(), success_callback, | 165 weak_ptr_factory_.GetWeakPtr(), success_callback, |
| 168 error_callback)); | 166 error_callback)); |
| 169 } | 167 } |
| 170 | 168 |
| 169 MTPDeviceTaskHelper::MTPEntry::MTPEntry() : file_id(0) {} |
| 170 |
| 171 // TODO(yawano) storage_name is not used, delete it. | 171 // TODO(yawano) storage_name is not used, delete it. |
| 172 void MTPDeviceTaskHelper::CopyFileFromLocal( | 172 void MTPDeviceTaskHelper::CopyFileFromLocal( |
| 173 const std::string& storage_name, | 173 const std::string& storage_name, |
| 174 const int source_file_descriptor, | 174 const int source_file_descriptor, |
| 175 const uint32 parent_id, | 175 const uint32 parent_id, |
| 176 const std::string& file_name, | 176 const std::string& file_name, |
| 177 const CopyFileFromLocalSuccessCallback& success_callback, | 177 const CopyFileFromLocalSuccessCallback& success_callback, |
| 178 const ErrorCallback& error_callback) { | 178 const ErrorCallback& error_callback) { |
| 179 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 179 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 180 | 180 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 void MTPDeviceTaskHelper::OnDidReadDirectory( | 253 void MTPDeviceTaskHelper::OnDidReadDirectory( |
| 254 const ReadDirectorySuccessCallback& success_callback, | 254 const ReadDirectorySuccessCallback& success_callback, |
| 255 const ErrorCallback& error_callback, | 255 const ErrorCallback& error_callback, |
| 256 const std::vector<MtpFileEntry>& file_entries, | 256 const std::vector<MtpFileEntry>& file_entries, |
| 257 bool has_more, | 257 bool has_more, |
| 258 bool error) const { | 258 bool error) const { |
| 259 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 259 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 260 if (error) | 260 if (error) |
| 261 return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED); | 261 return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED); |
| 262 | 262 |
| 263 storage::AsyncFileUtil::EntryList entries; | 263 MTPEntries entries; |
| 264 base::FilePath current; | 264 base::FilePath current; |
| 265 MTPDeviceObjectEnumerator file_enum(file_entries); | 265 MTPDeviceObjectEnumerator file_enum(file_entries); |
| 266 while (!(current = file_enum.Next()).empty()) { | 266 while (!(current = file_enum.Next()).empty()) { |
| 267 storage::DirectoryEntry entry; | 267 MTPEntry entry; |
| 268 entry.name = storage::VirtualPath::BaseName(current).value(); | 268 entry.name = storage::VirtualPath::BaseName(current).value(); |
| 269 uint32 file_id = 0; | 269 bool ret = file_enum.GetEntryId(&entry.file_id); |
| 270 bool ret = file_enum.GetEntryId(&file_id); | |
| 271 DCHECK(ret); | 270 DCHECK(ret); |
| 272 entry.name.push_back(','); | 271 entry.file_info.is_directory = file_enum.IsDirectory(); |
| 273 entry.name += base::UintToString(file_id); | 272 entry.file_info.size = file_enum.Size(); |
| 274 entry.is_directory = file_enum.IsDirectory(); | 273 entry.file_info.last_modified = file_enum.LastModifiedTime(); |
| 275 entry.size = file_enum.Size(); | |
| 276 entry.last_modified_time = file_enum.LastModifiedTime(); | |
| 277 entries.push_back(entry); | 274 entries.push_back(entry); |
| 278 } | 275 } |
| 279 content::BrowserThread::PostTask( | 276 content::BrowserThread::PostTask( |
| 280 content::BrowserThread::IO, | 277 content::BrowserThread::IO, |
| 281 FROM_HERE, | 278 FROM_HERE, |
| 282 base::Bind(success_callback, entries, has_more)); | 279 base::Bind(success_callback, entries, has_more)); |
| 283 } | 280 } |
| 284 | 281 |
| 285 void MTPDeviceTaskHelper::OnGetFileInfoToReadBytes( | 282 void MTPDeviceTaskHelper::OnGetFileInfoToReadBytes( |
| 286 const MTPDeviceAsyncDelegate::ReadBytesRequest& request, | 283 const MTPDeviceAsyncDelegate::ReadBytesRequest& request, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 } | 390 } |
| 394 | 391 |
| 395 void MTPDeviceTaskHelper::HandleDeviceError( | 392 void MTPDeviceTaskHelper::HandleDeviceError( |
| 396 const ErrorCallback& error_callback, | 393 const ErrorCallback& error_callback, |
| 397 base::File::Error error) const { | 394 base::File::Error error) const { |
| 398 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 395 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 399 content::BrowserThread::PostTask(content::BrowserThread::IO, | 396 content::BrowserThread::PostTask(content::BrowserThread::IO, |
| 400 FROM_HERE, | 397 FROM_HERE, |
| 401 base::Bind(error_callback, error)); | 398 base::Bind(error_callback, error)); |
| 402 } | 399 } |
| OLD | NEW |