| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/media_galleries/linux/mtp_device_object_enumerator.h" | 8 #include "chrome/browser/media_galleries/linux/mtp_device_object_enumerator.h" |
| 9 #include "chrome/browser/media_galleries/linux/mtp_read_file_worker.h" | 9 #include "chrome/browser/media_galleries/linux/mtp_read_file_worker.h" |
| 10 #include "chrome/browser/media_galleries/linux/snapshot_file_details.h" | 10 #include "chrome/browser/media_galleries/linux/snapshot_file_details.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 weak_ptr_factory_.GetWeakPtr(), | 54 weak_ptr_factory_.GetWeakPtr(), |
| 55 callback)); | 55 callback)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void MTPDeviceTaskHelper::GetFileInfoByPath( | 58 void MTPDeviceTaskHelper::GetFileInfoByPath( |
| 59 const std::string& file_path, | 59 const std::string& file_path, |
| 60 const GetFileInfoSuccessCallback& success_callback, | 60 const GetFileInfoSuccessCallback& success_callback, |
| 61 const ErrorCallback& error_callback) { | 61 const ErrorCallback& error_callback) { |
| 62 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 62 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 63 if (device_handle_.empty()) | 63 if (device_handle_.empty()) |
| 64 return HandleDeviceError(error_callback, base::PLATFORM_FILE_ERROR_FAILED); | 64 return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED); |
| 65 | 65 |
| 66 GetMediaTransferProtocolManager()->GetFileInfoByPath( | 66 GetMediaTransferProtocolManager()->GetFileInfoByPath( |
| 67 device_handle_, file_path, | 67 device_handle_, file_path, |
| 68 base::Bind(&MTPDeviceTaskHelper::OnGetFileInfo, | 68 base::Bind(&MTPDeviceTaskHelper::OnGetFileInfo, |
| 69 weak_ptr_factory_.GetWeakPtr(), | 69 weak_ptr_factory_.GetWeakPtr(), |
| 70 success_callback, | 70 success_callback, |
| 71 error_callback)); | 71 error_callback)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void MTPDeviceTaskHelper::ReadDirectoryByPath( | 74 void MTPDeviceTaskHelper::ReadDirectoryByPath( |
| 75 const std::string& dir_path, | 75 const std::string& dir_path, |
| 76 const ReadDirectorySuccessCallback& success_callback, | 76 const ReadDirectorySuccessCallback& success_callback, |
| 77 const ErrorCallback& error_callback) { | 77 const ErrorCallback& error_callback) { |
| 78 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 78 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 79 if (device_handle_.empty()) | 79 if (device_handle_.empty()) |
| 80 return HandleDeviceError(error_callback, base::PLATFORM_FILE_ERROR_FAILED); | 80 return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED); |
| 81 | 81 |
| 82 GetMediaTransferProtocolManager()->ReadDirectoryByPath( | 82 GetMediaTransferProtocolManager()->ReadDirectoryByPath( |
| 83 device_handle_, dir_path, | 83 device_handle_, dir_path, |
| 84 base::Bind(&MTPDeviceTaskHelper::OnDidReadDirectoryByPath, | 84 base::Bind(&MTPDeviceTaskHelper::OnDidReadDirectoryByPath, |
| 85 weak_ptr_factory_.GetWeakPtr(), | 85 weak_ptr_factory_.GetWeakPtr(), |
| 86 success_callback, | 86 success_callback, |
| 87 error_callback)); | 87 error_callback)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void MTPDeviceTaskHelper::WriteDataIntoSnapshotFile( | 90 void MTPDeviceTaskHelper::WriteDataIntoSnapshotFile( |
| 91 const SnapshotRequestInfo& request_info, | 91 const SnapshotRequestInfo& request_info, |
| 92 const base::PlatformFileInfo& snapshot_file_info) { | 92 const base::File::Info& snapshot_file_info) { |
| 93 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 93 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 94 if (device_handle_.empty()) { | 94 if (device_handle_.empty()) { |
| 95 return HandleDeviceError(request_info.error_callback, | 95 return HandleDeviceError(request_info.error_callback, |
| 96 base::PLATFORM_FILE_ERROR_FAILED); | 96 base::File::FILE_ERROR_FAILED); |
| 97 } | 97 } |
| 98 | 98 |
| 99 if (!read_file_worker_) | 99 if (!read_file_worker_) |
| 100 read_file_worker_.reset(new MTPReadFileWorker(device_handle_)); | 100 read_file_worker_.reset(new MTPReadFileWorker(device_handle_)); |
| 101 read_file_worker_->WriteDataIntoSnapshotFile(request_info, | 101 read_file_worker_->WriteDataIntoSnapshotFile(request_info, |
| 102 snapshot_file_info); | 102 snapshot_file_info); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void MTPDeviceTaskHelper::CloseStorage() const { | 105 void MTPDeviceTaskHelper::CloseStorage() const { |
| 106 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 106 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 122 } | 122 } |
| 123 | 123 |
| 124 void MTPDeviceTaskHelper::OnGetFileInfo( | 124 void MTPDeviceTaskHelper::OnGetFileInfo( |
| 125 const GetFileInfoSuccessCallback& success_callback, | 125 const GetFileInfoSuccessCallback& success_callback, |
| 126 const ErrorCallback& error_callback, | 126 const ErrorCallback& error_callback, |
| 127 const MtpFileEntry& file_entry, | 127 const MtpFileEntry& file_entry, |
| 128 bool error) const { | 128 bool error) const { |
| 129 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 129 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 130 if (error) { | 130 if (error) { |
| 131 return HandleDeviceError(error_callback, | 131 return HandleDeviceError(error_callback, |
| 132 base::PLATFORM_FILE_ERROR_NOT_FOUND); | 132 base::File::FILE_ERROR_NOT_FOUND); |
| 133 } | 133 } |
| 134 | 134 |
| 135 base::PlatformFileInfo file_entry_info; | 135 base::File::Info file_entry_info; |
| 136 file_entry_info.size = file_entry.file_size(); | 136 file_entry_info.size = file_entry.file_size(); |
| 137 file_entry_info.is_directory = | 137 file_entry_info.is_directory = |
| 138 file_entry.file_type() == MtpFileEntry::FILE_TYPE_FOLDER; | 138 file_entry.file_type() == MtpFileEntry::FILE_TYPE_FOLDER; |
| 139 file_entry_info.is_symbolic_link = false; | 139 file_entry_info.is_symbolic_link = false; |
| 140 file_entry_info.last_modified = | 140 file_entry_info.last_modified = |
| 141 base::Time::FromTimeT(file_entry.modification_time()); | 141 base::Time::FromTimeT(file_entry.modification_time()); |
| 142 file_entry_info.last_accessed = file_entry_info.last_modified; | 142 file_entry_info.last_accessed = file_entry_info.last_modified; |
| 143 file_entry_info.creation_time = base::Time(); | 143 file_entry_info.creation_time = base::Time(); |
| 144 content::BrowserThread::PostTask(content::BrowserThread::IO, | 144 content::BrowserThread::PostTask(content::BrowserThread::IO, |
| 145 FROM_HERE, | 145 FROM_HERE, |
| 146 base::Bind(success_callback, | 146 base::Bind(success_callback, |
| 147 file_entry_info)); | 147 file_entry_info)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void MTPDeviceTaskHelper::OnDidReadDirectoryByPath( | 150 void MTPDeviceTaskHelper::OnDidReadDirectoryByPath( |
| 151 const ReadDirectorySuccessCallback& success_callback, | 151 const ReadDirectorySuccessCallback& success_callback, |
| 152 const ErrorCallback& error_callback, | 152 const ErrorCallback& error_callback, |
| 153 const std::vector<MtpFileEntry>& file_entries, | 153 const std::vector<MtpFileEntry>& file_entries, |
| 154 bool error) const { | 154 bool error) const { |
| 155 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 155 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 156 if (error) | 156 if (error) |
| 157 return HandleDeviceError(error_callback, base::PLATFORM_FILE_ERROR_FAILED); | 157 return HandleDeviceError(error_callback, base::File::FILE_ERROR_FAILED); |
| 158 | 158 |
| 159 fileapi::AsyncFileUtil::EntryList entries; | 159 fileapi::AsyncFileUtil::EntryList entries; |
| 160 base::FilePath current; | 160 base::FilePath current; |
| 161 MTPDeviceObjectEnumerator file_enum(file_entries); | 161 MTPDeviceObjectEnumerator file_enum(file_entries); |
| 162 while (!(current = file_enum.Next()).empty()) { | 162 while (!(current = file_enum.Next()).empty()) { |
| 163 fileapi::DirectoryEntry entry; | 163 fileapi::DirectoryEntry entry; |
| 164 entry.name = fileapi::VirtualPath::BaseName(current).value(); | 164 entry.name = fileapi::VirtualPath::BaseName(current).value(); |
| 165 entry.is_directory = file_enum.IsDirectory(); | 165 entry.is_directory = file_enum.IsDirectory(); |
| 166 entry.size = file_enum.Size(); | 166 entry.size = file_enum.Size(); |
| 167 entry.last_modified_time = file_enum.LastModifiedTime(); | 167 entry.last_modified_time = file_enum.LastModifiedTime(); |
| 168 entries.push_back(entry); | 168 entries.push_back(entry); |
| 169 } | 169 } |
| 170 content::BrowserThread::PostTask(content::BrowserThread::IO, | 170 content::BrowserThread::PostTask(content::BrowserThread::IO, |
| 171 FROM_HERE, | 171 FROM_HERE, |
| 172 base::Bind(success_callback, entries)); | 172 base::Bind(success_callback, entries)); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void MTPDeviceTaskHelper::HandleDeviceError( | 175 void MTPDeviceTaskHelper::HandleDeviceError( |
| 176 const ErrorCallback& error_callback, | 176 const ErrorCallback& error_callback, |
| 177 base::PlatformFileError error) const { | 177 base::File::Error error) const { |
| 178 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 178 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 179 content::BrowserThread::PostTask(content::BrowserThread::IO, | 179 content::BrowserThread::PostTask(content::BrowserThread::IO, |
| 180 FROM_HERE, | 180 FROM_HERE, |
| 181 base::Bind(error_callback, error)); | 181 base::Bind(error_callback, error)); |
| 182 } | 182 } |
| OLD | NEW |