| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (error != FILE_ERROR_OK) | 156 if (error != FILE_ERROR_OK) |
| 157 return error; | 157 return error; |
| 158 | 158 |
| 159 return cache->Store(local_id, std::string(), cache_file_path, | 159 return cache->Store(local_id, std::string(), cache_file_path, |
| 160 internal::FileCache::FILE_OPERATION_COPY); | 160 internal::FileCache::FILE_OPERATION_COPY); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Stores the entry returned from the server and returns its path. | 163 // Stores the entry returned from the server and returns its path. |
| 164 FileError UpdateLocalStateForServerSideOperation( | 164 FileError UpdateLocalStateForServerSideOperation( |
| 165 internal::ResourceMetadata* metadata, | 165 internal::ResourceMetadata* metadata, |
| 166 scoped_ptr<google_apis::ResourceEntry> resource_entry, | 166 scoped_ptr<google_apis::FileResource> file_resource, |
| 167 base::FilePath* file_path) { | 167 base::FilePath* file_path) { |
| 168 DCHECK(resource_entry); | 168 DCHECK(file_resource); |
| 169 | 169 |
| 170 ResourceEntry entry; | 170 ResourceEntry entry; |
| 171 std::string parent_resource_id; | 171 std::string parent_resource_id; |
| 172 if (!ConvertToResourceEntry(*resource_entry, &entry, &parent_resource_id) || | 172 if (!ConvertToResourceEntry( |
| 173 *util::ConvertFileResourceToResourceEntry(*file_resource), |
| 174 &entry, &parent_resource_id) || |
| 173 parent_resource_id.empty()) | 175 parent_resource_id.empty()) |
| 174 return FILE_ERROR_NOT_A_FILE; | 176 return FILE_ERROR_NOT_A_FILE; |
| 175 | 177 |
| 176 std::string parent_local_id; | 178 std::string parent_local_id; |
| 177 FileError error = metadata->GetIdByResourceId(parent_resource_id, | 179 FileError error = metadata->GetIdByResourceId(parent_resource_id, |
| 178 &parent_local_id); | 180 &parent_local_id); |
| 179 if (error != FILE_ERROR_OK) | 181 if (error != FILE_ERROR_OK) |
| 180 return error; | 182 return error; |
| 181 entry.set_parent_local_id(parent_local_id); | 183 entry.set_parent_local_id(parent_local_id); |
| 182 | 184 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 scheduler_->CopyResource( | 488 scheduler_->CopyResource( |
| 487 resource_id, parent_resource_id, new_title, last_modified, | 489 resource_id, parent_resource_id, new_title, last_modified, |
| 488 base::Bind(&CopyOperation::UpdateAfterServerSideOperation, | 490 base::Bind(&CopyOperation::UpdateAfterServerSideOperation, |
| 489 weak_ptr_factory_.GetWeakPtr(), | 491 weak_ptr_factory_.GetWeakPtr(), |
| 490 callback)); | 492 callback)); |
| 491 } | 493 } |
| 492 | 494 |
| 493 void CopyOperation::UpdateAfterServerSideOperation( | 495 void CopyOperation::UpdateAfterServerSideOperation( |
| 494 const FileOperationCallback& callback, | 496 const FileOperationCallback& callback, |
| 495 google_apis::GDataErrorCode status, | 497 google_apis::GDataErrorCode status, |
| 496 scoped_ptr<google_apis::ResourceEntry> resource_entry) { | 498 scoped_ptr<google_apis::FileResource> entry) { |
| 497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 498 DCHECK(!callback.is_null()); | 500 DCHECK(!callback.is_null()); |
| 499 | 501 |
| 500 FileError error = GDataToFileError(status); | 502 FileError error = GDataToFileError(status); |
| 501 if (error != FILE_ERROR_OK) { | 503 if (error != FILE_ERROR_OK) { |
| 502 callback.Run(error); | 504 callback.Run(error); |
| 503 return; | 505 return; |
| 504 } | 506 } |
| 505 | 507 |
| 506 // The copy on the server side is completed successfully. Update the local | 508 // The copy on the server side is completed successfully. Update the local |
| 507 // metadata. | 509 // metadata. |
| 508 base::FilePath* file_path = new base::FilePath; | 510 base::FilePath* file_path = new base::FilePath; |
| 509 base::PostTaskAndReplyWithResult( | 511 base::PostTaskAndReplyWithResult( |
| 510 blocking_task_runner_.get(), | 512 blocking_task_runner_.get(), |
| 511 FROM_HERE, | 513 FROM_HERE, |
| 512 base::Bind(&UpdateLocalStateForServerSideOperation, | 514 base::Bind(&UpdateLocalStateForServerSideOperation, |
| 513 metadata_, base::Passed(&resource_entry), file_path), | 515 metadata_, base::Passed(&entry), file_path), |
| 514 base::Bind(&CopyOperation::UpdateAfterLocalStateUpdate, | 516 base::Bind(&CopyOperation::UpdateAfterLocalStateUpdate, |
| 515 weak_ptr_factory_.GetWeakPtr(), | 517 weak_ptr_factory_.GetWeakPtr(), |
| 516 callback, base::Owned(file_path))); | 518 callback, base::Owned(file_path))); |
| 517 } | 519 } |
| 518 | 520 |
| 519 void CopyOperation::UpdateAfterLocalStateUpdate( | 521 void CopyOperation::UpdateAfterLocalStateUpdate( |
| 520 const FileOperationCallback& callback, | 522 const FileOperationCallback& callback, |
| 521 base::FilePath* file_path, | 523 base::FilePath* file_path, |
| 522 FileError error) { | 524 FileError error) { |
| 523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 | 582 |
| 581 if (error == FILE_ERROR_OK) { | 583 if (error == FILE_ERROR_OK) { |
| 582 observer_->OnDirectoryChangedByOperation(remote_dest_path.DirName()); | 584 observer_->OnDirectoryChangedByOperation(remote_dest_path.DirName()); |
| 583 observer_->OnEntryUpdatedByOperation(*local_id); | 585 observer_->OnEntryUpdatedByOperation(*local_id); |
| 584 } | 586 } |
| 585 callback.Run(error); | 587 callback.Run(error); |
| 586 } | 588 } |
| 587 | 589 |
| 588 } // namespace file_system | 590 } // namespace file_system |
| 589 } // namespace drive | 591 } // namespace drive |
| OLD | NEW |