| 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" |
| 11 #include "chrome/browser/chromeos/drive/drive.pb.h" | 11 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 12 #include "chrome/browser/chromeos/drive/file_cache.h" | 12 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 13 #include "chrome/browser/chromeos/drive/file_system/create_file_operation.h" | 13 #include "chrome/browser/chromeos/drive/file_system/create_file_operation.h" |
| 14 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" | 14 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" |
| 15 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" | 15 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" |
| 16 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" | 16 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" |
| 17 #include "chrome/browser/chromeos/drive/file_system_util.h" | 17 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 18 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 18 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| 19 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" | 19 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" |
| 20 #include "chrome/browser/drive/drive_api_util.h" | 20 #include "chrome/browser/drive/drive_api_util.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 | 22 |
| 23 using content::BrowserThread; | 23 using content::BrowserThread; |
| 24 | 24 |
| 25 namespace drive { | 25 namespace drive { |
| 26 namespace file_system { | 26 namespace file_system { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Copies a file from |src_file_path| to |dest_file_path| on the local | |
| 31 // file system using base::CopyFile. | |
| 32 // Returns FILE_ERROR_OK on success or FILE_ERROR_FAILED otherwise. | |
| 33 FileError CopyLocalFileOnBlockingPool( | |
| 34 const base::FilePath& src_file_path, | |
| 35 const base::FilePath& dest_file_path) { | |
| 36 return base::CopyFile(src_file_path, dest_file_path) ? | |
| 37 FILE_ERROR_OK : FILE_ERROR_FAILED; | |
| 38 } | |
| 39 | |
| 40 // Stores a file to the cache and mark it dirty. | 30 // Stores a file to the cache and mark it dirty. |
| 41 FileError StoreAndMarkDirty(internal::FileCache* cache, | 31 FileError StoreAndMarkDirty(internal::FileCache* cache, |
| 42 const std::string& resource_id, | 32 const std::string& resource_id, |
| 43 const std::string& md5, | 33 const std::string& md5, |
| 44 const base::FilePath& local_file_path) { | 34 const base::FilePath& local_file_path) { |
| 45 FileError error = cache->Store(resource_id, md5, local_file_path, | 35 FileError error = cache->Store(resource_id, md5, local_file_path, |
| 46 internal::FileCache::FILE_OPERATION_COPY); | 36 internal::FileCache::FILE_OPERATION_COPY); |
| 47 if (error != FILE_ERROR_OK) | 37 if (error != FILE_ERROR_OK) |
| 48 return error; | 38 return error; |
| 49 return cache->MarkDirty(resource_id); | 39 return cache->MarkDirty(resource_id); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 109 |
| 120 metadata_->GetResourceEntryPairByPathsOnUIThread( | 110 metadata_->GetResourceEntryPairByPathsOnUIThread( |
| 121 src_file_path, | 111 src_file_path, |
| 122 dest_file_path.DirName(), | 112 dest_file_path.DirName(), |
| 123 base::Bind(&CopyOperation::CopyAfterGetResourceEntryPair, | 113 base::Bind(&CopyOperation::CopyAfterGetResourceEntryPair, |
| 124 weak_ptr_factory_.GetWeakPtr(), | 114 weak_ptr_factory_.GetWeakPtr(), |
| 125 dest_file_path, | 115 dest_file_path, |
| 126 callback)); | 116 callback)); |
| 127 } | 117 } |
| 128 | 118 |
| 129 void CopyOperation::TransferFileFromRemoteToLocal( | |
| 130 const base::FilePath& remote_src_file_path, | |
| 131 const base::FilePath& local_dest_file_path, | |
| 132 const FileOperationCallback& callback) { | |
| 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 134 DCHECK(!callback.is_null()); | |
| 135 | |
| 136 download_operation_->EnsureFileDownloadedByPath( | |
| 137 remote_src_file_path, | |
| 138 ClientContext(USER_INITIATED), | |
| 139 GetFileContentInitializedCallback(), | |
| 140 google_apis::GetContentCallback(), | |
| 141 base::Bind(&CopyOperation::OnGetFileCompleteForTransferFile, | |
| 142 weak_ptr_factory_.GetWeakPtr(), | |
| 143 local_dest_file_path, | |
| 144 callback)); | |
| 145 } | |
| 146 | |
| 147 void CopyOperation::OnGetFileCompleteForTransferFile( | |
| 148 const base::FilePath& local_dest_file_path, | |
| 149 const FileOperationCallback& callback, | |
| 150 FileError error, | |
| 151 const base::FilePath& local_file_path, | |
| 152 scoped_ptr<ResourceEntry> entry) { | |
| 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 154 DCHECK(!callback.is_null()); | |
| 155 | |
| 156 if (error != FILE_ERROR_OK) { | |
| 157 callback.Run(error); | |
| 158 return; | |
| 159 } | |
| 160 | |
| 161 // GetFileByPath downloads the file from Drive to a local cache, which is then | |
| 162 // copied to the actual destination path on the local file system using | |
| 163 // CopyLocalFileOnBlockingPool. | |
| 164 base::PostTaskAndReplyWithResult( | |
| 165 blocking_task_runner_.get(), | |
| 166 FROM_HERE, | |
| 167 base::Bind( | |
| 168 &CopyLocalFileOnBlockingPool, local_file_path, local_dest_file_path), | |
| 169 callback); | |
| 170 } | |
| 171 | |
| 172 void CopyOperation::TransferFileFromLocalToRemote( | 119 void CopyOperation::TransferFileFromLocalToRemote( |
| 173 const base::FilePath& local_src_file_path, | 120 const base::FilePath& local_src_file_path, |
| 174 const base::FilePath& remote_dest_file_path, | 121 const base::FilePath& remote_dest_file_path, |
| 175 const FileOperationCallback& callback) { | 122 const FileOperationCallback& callback) { |
| 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 177 DCHECK(!callback.is_null()); | 124 DCHECK(!callback.is_null()); |
| 178 | 125 |
| 179 int64* local_file_size = new int64(-1); | 126 int64* local_file_size = new int64(-1); |
| 180 ResourceEntry* parent_entry = new ResourceEntry; | 127 ResourceEntry* parent_entry = new ResourceEntry; |
| 181 base::PostTaskAndReplyWithResult( | 128 base::PostTaskAndReplyWithResult( |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 canonicalized_resource_id, | 512 canonicalized_resource_id, |
| 566 // Drop the document extension, which should not be | 513 // Drop the document extension, which should not be |
| 567 // in the document title. | 514 // in the document title. |
| 568 // TODO(yoshiki): Remove this code with crbug.com/223304. | 515 // TODO(yoshiki): Remove this code with crbug.com/223304. |
| 569 remote_dest_file_path.BaseName().RemoveExtension().value(), | 516 remote_dest_file_path.BaseName().RemoveExtension().value(), |
| 570 callback); | 517 callback); |
| 571 } | 518 } |
| 572 | 519 |
| 573 } // namespace file_system | 520 } // namespace file_system |
| 574 } // namespace drive | 521 } // namespace drive |
| OLD | NEW |