| 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/sync_file_system/drive_backend/remote_to_local_syncer.h
" | 5 #include "chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.h
" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 } | 273 } |
| 274 | 274 |
| 275 void RemoteToLocalSyncer::HandleMissingRemoteMetadata( | 275 void RemoteToLocalSyncer::HandleMissingRemoteMetadata( |
| 276 const SyncStatusCallback& callback) { | 276 const SyncStatusCallback& callback) { |
| 277 DCHECK(dirty_tracker_); | 277 DCHECK(dirty_tracker_); |
| 278 | 278 |
| 279 drive_service()->GetResourceEntry( | 279 drive_service()->GetResourceEntry( |
| 280 dirty_tracker_->file_id(), | 280 dirty_tracker_->file_id(), |
| 281 base::Bind(&RemoteToLocalSyncer::DidGetRemoteMetadata, | 281 base::Bind(&RemoteToLocalSyncer::DidGetRemoteMetadata, |
| 282 weak_ptr_factory_.GetWeakPtr(), | 282 weak_ptr_factory_.GetWeakPtr(), |
| 283 callback, | 283 callback)); |
| 284 metadata_database()->GetLargestKnownChangeID())); | |
| 285 } | 284 } |
| 286 | 285 |
| 287 void RemoteToLocalSyncer::DidGetRemoteMetadata( | 286 void RemoteToLocalSyncer::DidGetRemoteMetadata( |
| 288 const SyncStatusCallback& callback, | 287 const SyncStatusCallback& callback, |
| 289 int64 change_id, | |
| 290 google_apis::GDataErrorCode error, | 288 google_apis::GDataErrorCode error, |
| 291 scoped_ptr<google_apis::ResourceEntry> entry) { | 289 scoped_ptr<google_apis::ResourceEntry> entry) { |
| 290 SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error); |
| 291 if (status != SYNC_STATUS_OK && |
| 292 error != google_apis::HTTP_NOT_FOUND) { |
| 293 callback.Run(status); |
| 294 return; |
| 295 } |
| 296 |
| 297 if (error == google_apis::HTTP_NOT_FOUND) { |
| 298 metadata_database()->UpdateByDeletedRemoteFile( |
| 299 dirty_tracker_->file_id(), callback); |
| 300 return; |
| 301 } |
| 302 |
| 303 if (!entry) { |
| 304 NOTREACHED(); |
| 305 callback.Run(SYNC_STATUS_FAILED); |
| 306 return; |
| 307 } |
| 308 |
| 292 metadata_database()->UpdateByFileResource( | 309 metadata_database()->UpdateByFileResource( |
| 293 *drive::util::ConvertResourceEntryToFileResource(*entry), | 310 *drive::util::ConvertResourceEntryToFileResource(*entry), |
| 294 base::Bind(&RemoteToLocalSyncer::DidUpdateDatabaseForRemoteMetadata, | 311 base::Bind(&RemoteToLocalSyncer::DidUpdateDatabaseForRemoteMetadata, |
| 295 weak_ptr_factory_.GetWeakPtr(), callback)); | 312 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 296 } | 313 } |
| 297 | 314 |
| 298 void RemoteToLocalSyncer::DidUpdateDatabaseForRemoteMetadata( | 315 void RemoteToLocalSyncer::DidUpdateDatabaseForRemoteMetadata( |
| 299 const SyncStatusCallback& callback, | 316 const SyncStatusCallback& callback, |
| 300 SyncStatusCode status) { | 317 SyncStatusCode status) { |
| 301 if (status != SYNC_STATUS_OK) { | 318 if (status != SYNC_STATUS_OK) { |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 weak_ptr_factory_.GetWeakPtr(), | 528 weak_ptr_factory_.GetWeakPtr(), |
| 512 callback, | 529 callback, |
| 513 base::Passed(make_scoped_ptr(new FileIDList)))); | 530 base::Passed(make_scoped_ptr(new FileIDList)))); |
| 514 } | 531 } |
| 515 | 532 |
| 516 void RemoteToLocalSyncer::DidListFolderContent( | 533 void RemoteToLocalSyncer::DidListFolderContent( |
| 517 const SyncStatusCallback& callback, | 534 const SyncStatusCallback& callback, |
| 518 scoped_ptr<FileIDList> children, | 535 scoped_ptr<FileIDList> children, |
| 519 google_apis::GDataErrorCode error, | 536 google_apis::GDataErrorCode error, |
| 520 scoped_ptr<google_apis::ResourceList> resource_list) { | 537 scoped_ptr<google_apis::ResourceList> resource_list) { |
| 521 if (error != google_apis::HTTP_SUCCESS) { | 538 SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error); |
| 522 callback.Run(GDataErrorCodeToSyncStatusCode(error)); | 539 if (status != SYNC_STATUS_OK) { |
| 540 callback.Run(status); |
| 523 return; | 541 return; |
| 524 } | 542 } |
| 525 | 543 |
| 544 if (!resource_list) { |
| 545 NOTREACHED(); |
| 546 callback.Run(SYNC_STATUS_FAILED); |
| 547 return; |
| 548 } |
| 549 |
| 526 children->reserve(children->size() + resource_list->entries().size()); | 550 children->reserve(children->size() + resource_list->entries().size()); |
| 527 for (ScopedVector<google_apis::ResourceEntry>::const_iterator itr = | 551 for (ScopedVector<google_apis::ResourceEntry>::const_iterator itr = |
| 528 resource_list->entries().begin(); | 552 resource_list->entries().begin(); |
| 529 itr != resource_list->entries().end(); | 553 itr != resource_list->entries().end(); |
| 530 ++itr) { | 554 ++itr) { |
| 531 children->push_back((*itr)->resource_id()); | 555 children->push_back((*itr)->resource_id()); |
| 532 } | 556 } |
| 533 | 557 |
| 534 GURL next_feed; | 558 GURL next_feed; |
| 535 if (resource_list->GetNextFeedURL(&next_feed)) { | 559 if (resource_list->GetNextFeedURL(&next_feed)) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 weak_ptr_factory_.GetWeakPtr(), | 676 weak_ptr_factory_.GetWeakPtr(), |
| 653 callback, base::Passed(&file)), | 677 callback, base::Passed(&file)), |
| 654 google_apis::GetContentCallback(), | 678 google_apis::GetContentCallback(), |
| 655 google_apis::ProgressCallback()); | 679 google_apis::ProgressCallback()); |
| 656 } | 680 } |
| 657 | 681 |
| 658 void RemoteToLocalSyncer::DidDownloadFile(const SyncStatusCallback& callback, | 682 void RemoteToLocalSyncer::DidDownloadFile(const SyncStatusCallback& callback, |
| 659 webkit_blob::ScopedFile file, | 683 webkit_blob::ScopedFile file, |
| 660 google_apis::GDataErrorCode error, | 684 google_apis::GDataErrorCode error, |
| 661 const base::FilePath&) { | 685 const base::FilePath&) { |
| 662 if (error != google_apis::HTTP_SUCCESS) { | 686 SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error); |
| 663 callback.Run(GDataErrorCodeToSyncStatusCode(error)); | 687 if (status != SYNC_STATUS_OK) { |
| 688 callback.Run(status); |
| 664 return; | 689 return; |
| 665 } | 690 } |
| 666 | 691 |
| 667 base::FilePath path = file.path(); | 692 base::FilePath path = file.path(); |
| 668 base::PostTaskAndReplyWithResult( | 693 base::PostTaskAndReplyWithResult( |
| 669 sync_context_->GetBlockingTaskRunner(), FROM_HERE, | 694 sync_context_->GetBlockingTaskRunner(), FROM_HERE, |
| 670 base::Bind(&drive::util::GetMd5Digest, path), | 695 base::Bind(&drive::util::GetMd5Digest, path), |
| 671 base::Bind(&RemoteToLocalSyncer::DidCalculateMD5ForDownload, | 696 base::Bind(&RemoteToLocalSyncer::DidCalculateMD5ForDownload, |
| 672 weak_ptr_factory_.GetWeakPtr(), | 697 weak_ptr_factory_.GetWeakPtr(), |
| 673 callback, base::Passed(&file))); | 698 callback, base::Passed(&file))); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 return sync_context_->GetMetadataDatabase(); | 750 return sync_context_->GetMetadataDatabase(); |
| 726 } | 751 } |
| 727 | 752 |
| 728 RemoteChangeProcessor* RemoteToLocalSyncer::remote_change_processor() { | 753 RemoteChangeProcessor* RemoteToLocalSyncer::remote_change_processor() { |
| 729 DCHECK(sync_context_->GetRemoteChangeProcessor()); | 754 DCHECK(sync_context_->GetRemoteChangeProcessor()); |
| 730 return sync_context_->GetRemoteChangeProcessor(); | 755 return sync_context_->GetRemoteChangeProcessor(); |
| 731 } | 756 } |
| 732 | 757 |
| 733 } // namespace drive_backend | 758 } // namespace drive_backend |
| 734 } // namespace sync_file_system | 759 } // namespace sync_file_system |
| OLD | NEW |