| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/drive/file_system/copy_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // Copies a file from |src_file_path| to |dest_file_path| on the local | 30 // Copies a file from |src_file_path| to |dest_file_path| on the local |
| 31 // file system using file_util::CopyFile. | 31 // file system using file_util::CopyFile. |
| 32 // Returns FILE_ERROR_OK on success or FILE_ERROR_FAILED otherwise. | 32 // Returns FILE_ERROR_OK on success or FILE_ERROR_FAILED otherwise. |
| 33 FileError CopyLocalFileOnBlockingPool( | 33 FileError CopyLocalFileOnBlockingPool( |
| 34 const base::FilePath& src_file_path, | 34 const base::FilePath& src_file_path, |
| 35 const base::FilePath& dest_file_path) { | 35 const base::FilePath& dest_file_path) { |
| 36 return file_util::CopyFile(src_file_path, dest_file_path) ? | 36 return file_util::CopyFile(src_file_path, dest_file_path) ? |
| 37 FILE_ERROR_OK : FILE_ERROR_FAILED; | 37 FILE_ERROR_OK : FILE_ERROR_FAILED; |
| 38 } | 38 } |
| 39 | 39 |
| 40 // Stores a file to the cache and mark it dirty. |
| 41 FileError StoreAndMarkDirty(internal::FileCache* cache, |
| 42 const std::string& resource_id, |
| 43 const std::string& md5, |
| 44 const base::FilePath& local_file_path) { |
| 45 FileError error = cache->Store(resource_id, md5, local_file_path, |
| 46 internal::FileCache::FILE_OPERATION_COPY); |
| 47 if (error != FILE_ERROR_OK) |
| 48 return error; |
| 49 return cache->MarkDirty(resource_id, md5); |
| 50 } |
| 51 |
| 40 } // namespace | 52 } // namespace |
| 41 | 53 |
| 42 CopyOperation::CopyOperation(base::SequencedTaskRunner* blocking_task_runner, | 54 CopyOperation::CopyOperation(base::SequencedTaskRunner* blocking_task_runner, |
| 43 OperationObserver* observer, | 55 OperationObserver* observer, |
| 44 JobScheduler* scheduler, | 56 JobScheduler* scheduler, |
| 45 internal::ResourceMetadata* metadata, | 57 internal::ResourceMetadata* metadata, |
| 46 internal::FileCache* cache, | 58 internal::FileCache* cache, |
| 47 google_apis::DriveServiceInterface* drive_service) | 59 google_apis::DriveServiceInterface* drive_service) |
| 48 : blocking_task_runner_(blocking_task_runner), | 60 : blocking_task_runner_(blocking_task_runner), |
| 49 observer_(observer), | 61 observer_(observer), |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 void CopyOperation::ScheduleTransferRegularFileAfterGetResourceEntry( | 199 void CopyOperation::ScheduleTransferRegularFileAfterGetResourceEntry( |
| 188 const base::FilePath& local_file_path, | 200 const base::FilePath& local_file_path, |
| 189 const FileOperationCallback& callback, | 201 const FileOperationCallback& callback, |
| 190 FileError error, | 202 FileError error, |
| 191 scoped_ptr<ResourceEntry> entry) { | 203 scoped_ptr<ResourceEntry> entry) { |
| 192 if (error != FILE_ERROR_OK) { | 204 if (error != FILE_ERROR_OK) { |
| 193 callback.Run(error); | 205 callback.Run(error); |
| 194 return; | 206 return; |
| 195 } | 207 } |
| 196 | 208 |
| 197 cache_->StoreLocallyModifiedOnUIThread( | 209 ResourceEntry* entry_ptr = entry.get(); |
| 198 entry->resource_id(), | 210 base::PostTaskAndReplyWithResult( |
| 199 entry->file_specific_info().md5(), | 211 blocking_task_runner_, |
| 200 local_file_path, | 212 FROM_HERE, |
| 201 internal::FileCache::FILE_OPERATION_COPY, | 213 base::Bind(&StoreAndMarkDirty, |
| 202 callback); | 214 cache_, |
| 215 entry_ptr->resource_id(), |
| 216 entry_ptr->file_specific_info().md5(), |
| 217 local_file_path), |
| 218 base::Bind(&CopyOperation::ScheduleTransferRegularFileAfterStore, |
| 219 weak_ptr_factory_.GetWeakPtr(), |
| 220 base::Passed(&entry), |
| 221 callback)); |
| 222 } |
| 223 |
| 224 void CopyOperation::ScheduleTransferRegularFileAfterStore( |
| 225 scoped_ptr<ResourceEntry> entry, |
| 226 const FileOperationCallback& callback, |
| 227 FileError error) { |
| 228 if (error == FILE_ERROR_OK) |
| 229 observer_->OnCacheFileUploadNeededByOperation(entry->resource_id()); |
| 230 callback.Run(error); |
| 203 } | 231 } |
| 204 | 232 |
| 205 void CopyOperation::CopyHostedDocumentToDirectory( | 233 void CopyOperation::CopyHostedDocumentToDirectory( |
| 206 const base::FilePath& dir_path, | 234 const base::FilePath& dir_path, |
| 207 const std::string& resource_id, | 235 const std::string& resource_id, |
| 208 const base::FilePath::StringType& new_name, | 236 const base::FilePath::StringType& new_name, |
| 209 const FileOperationCallback& callback) { | 237 const FileOperationCallback& callback) { |
| 210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 211 DCHECK(!callback.is_null()); | 239 DCHECK(!callback.is_null()); |
| 212 | 240 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 canonicalized_resource_id, | 474 canonicalized_resource_id, |
| 447 // Drop the document extension, which should not be | 475 // Drop the document extension, which should not be |
| 448 // in the document title. | 476 // in the document title. |
| 449 // TODO(yoshiki): Remove this code with crbug.com/223304. | 477 // TODO(yoshiki): Remove this code with crbug.com/223304. |
| 450 remote_dest_file_path.BaseName().RemoveExtension().value(), | 478 remote_dest_file_path.BaseName().RemoveExtension().value(), |
| 451 callback); | 479 callback); |
| 452 } | 480 } |
| 453 | 481 |
| 454 } // namespace file_system | 482 } // namespace file_system |
| 455 } // namespace drive | 483 } // namespace drive |
| OLD | NEW |