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/sync_file_system/drive_file_sync_service.h" | 5 #include "chrome/browser/sync_file_system/drive_file_sync_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 case SYNC_OPERATION_IGNORE: { | 345 case SYNC_OPERATION_IGNORE: { |
346 // We cannot call DidApplyLocalChange here since we should not cancel | 346 // We cannot call DidApplyLocalChange here since we should not cancel |
347 // the remote pending change. | 347 // the remote pending change. |
348 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); | 348 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); |
349 callback.Run(fileapi::SYNC_STATUS_OK); | 349 callback.Run(fileapi::SYNC_STATUS_OK); |
350 return; | 350 return; |
351 } | 351 } |
352 case SYNC_OPERATION_CONFLICT: { | 352 case SYNC_OPERATION_CONFLICT: { |
353 // Mark the file as conflicted. | 353 // Mark the file as conflicted. |
354 DriveMetadata metadata; | 354 DriveMetadata metadata; |
355 metadata_store_->ReadEntry(url, &metadata); | 355 const fileapi::SyncStatusCode status = |
| 356 metadata_store_->ReadEntry(url, &metadata); |
| 357 if (status == fileapi::SYNC_DATABASE_ERROR_NOT_FOUND) { |
| 358 // The file is not yet in the metadata store. |
| 359 RemoteChange remote_change; |
| 360 const bool has_remote_change = GetPendingChangeForFileSystemURL( |
| 361 url, &remote_change); |
| 362 DCHECK(has_remote_change); |
| 363 metadata.set_resource_id(remote_change.resource_id); |
| 364 metadata.set_md5_checksum(std::string()); |
| 365 } |
356 metadata.set_conflicted(true); | 366 metadata.set_conflicted(true); |
357 metadata_store_->UpdateEntry( | 367 metadata_store_->UpdateEntry( |
358 url, metadata, | 368 url, metadata, |
359 base::Bind(&DriveFileSyncService::DidApplyLocalChange, | 369 base::Bind(&DriveFileSyncService::DidApplyLocalChange, |
360 AsWeakPtr(), base::Passed(&token), url, | 370 AsWeakPtr(), base::Passed(&token), url, |
361 google_apis::HTTP_CONFLICT, callback)); | 371 google_apis::HTTP_CONFLICT, callback)); |
362 return; | 372 return; |
363 } | 373 } |
364 case SYNC_OPERATION_FAILED: { | 374 case SYNC_OPERATION_FAILED: { |
365 DidApplyLocalChange(token.Pass(), url, google_apis::GDATA_OTHER_ERROR, | 375 DidApplyLocalChange(token.Pass(), url, google_apis::GDATA_OTHER_ERROR, |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 entry->updated_time())); | 645 entry->updated_time())); |
636 } | 646 } |
637 | 647 |
638 DriveFileSyncService::SyncOperationType | 648 DriveFileSyncService::SyncOperationType |
639 DriveFileSyncService::ResolveSyncOperationType( | 649 DriveFileSyncService::ResolveSyncOperationType( |
640 const fileapi::FileChange& local_file_change, | 650 const fileapi::FileChange& local_file_change, |
641 const fileapi::FileSystemURL& url) { | 651 const fileapi::FileSystemURL& url) { |
642 // TODO(nhiroki): check metadata.conflicted() flag before checking the pending | 652 // TODO(nhiroki): check metadata.conflicted() flag before checking the pending |
643 // change queue (http://crbug.com/162798). | 653 // change queue (http://crbug.com/162798). |
644 | 654 |
645 URLToChange::const_iterator found_url = url_to_change_.find(url.origin()); | 655 RemoteChange remote_change; |
646 if (found_url != url_to_change_.end()) { | 656 const bool has_remote_change = GetPendingChangeForFileSystemURL( |
647 const PathToChange& path_to_change = found_url->second; | 657 url, &remote_change); |
648 PathToChange::const_iterator found_path = path_to_change.find(url.path()); | |
649 if (found_path != path_to_change.end()) { | |
650 // Remote change for the file identified by |url| exists in the pending | |
651 // change queue. | |
652 const fileapi::FileChange& remote_file_change = found_path->second.change; | |
653 | 658 |
654 // (RemoteChange) + (LocalChange) -> (Operation Type) | 659 if (has_remote_change) { |
655 // AddOrUpdate + AddOrUpdate -> CONFLICT | 660 // Remote change for the file identified by |url| exists in the pending |
656 // AddOrUpdate + Delete -> IGNORE | 661 // change queue. |
657 // Delete + AddOrUpdate -> UPLOAD_NEW_FILE | 662 const fileapi::FileChange& remote_file_change = remote_change.change; |
658 // Delete + Delete -> IGNORE | |
659 | 663 |
660 if (remote_file_change.IsAddOrUpdate() && | 664 // (RemoteChange) + (LocalChange) -> (Operation Type) |
661 local_file_change.IsAddOrUpdate()) | 665 // AddOrUpdate + AddOrUpdate -> CONFLICT |
662 return SYNC_OPERATION_CONFLICT; | 666 // AddOrUpdate + Delete -> IGNORE |
663 else if (remote_file_change.IsDelete() && | 667 // Delete + AddOrUpdate -> UPLOAD_NEW_FILE |
664 local_file_change.IsAddOrUpdate()) | 668 // Delete + Delete -> IGNORE |
665 return SYNC_OPERATION_UPLOAD_NEW_FILE; | 669 |
666 else if (local_file_change.IsDelete()) | 670 if (remote_file_change.IsAddOrUpdate() && |
667 return SYNC_OPERATION_IGNORE; | 671 local_file_change.IsAddOrUpdate()) |
668 NOTREACHED(); | 672 return SYNC_OPERATION_CONFLICT; |
669 return SYNC_OPERATION_FAILED; | 673 else if (remote_file_change.IsDelete() && |
670 } | 674 local_file_change.IsAddOrUpdate()) |
| 675 return SYNC_OPERATION_UPLOAD_NEW_FILE; |
| 676 else if (local_file_change.IsDelete()) |
| 677 return SYNC_OPERATION_IGNORE; |
| 678 NOTREACHED(); |
| 679 return SYNC_OPERATION_FAILED; |
671 } | 680 } |
672 | 681 |
673 DriveMetadata metadata; | 682 DriveMetadata metadata; |
674 if (metadata_store_->ReadEntry(url, &metadata) == fileapi::SYNC_STATUS_OK) { | 683 if (metadata_store_->ReadEntry(url, &metadata) == fileapi::SYNC_STATUS_OK) { |
675 // The remote file identified by |url| exists on Drive. | 684 // The remote file identified by |url| exists on Drive. |
676 switch (local_file_change.change()) { | 685 switch (local_file_change.change()) { |
677 case fileapi::FileChange::FILE_CHANGE_ADD_OR_UPDATE: | 686 case fileapi::FileChange::FILE_CHANGE_ADD_OR_UPDATE: |
678 return SYNC_OPERATION_UPLOAD_EXISTING_FILE; | 687 return SYNC_OPERATION_UPLOAD_EXISTING_FILE; |
679 case fileapi::FileChange::FILE_CHANGE_DELETE: | 688 case fileapi::FileChange::FILE_CHANGE_DELETE: |
680 return SYNC_OPERATION_DELETE_FILE; | 689 return SYNC_OPERATION_DELETE_FILE; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 PathToChange::iterator found_change = path_to_change->find(url.path()); | 875 PathToChange::iterator found_change = path_to_change->find(url.path()); |
867 if (found_change == path_to_change->end()) | 876 if (found_change == path_to_change->end()) |
868 return; | 877 return; |
869 | 878 |
870 pending_changes_.erase(found_change->second.position_in_queue); | 879 pending_changes_.erase(found_change->second.position_in_queue); |
871 path_to_change->erase(found_change); | 880 path_to_change->erase(found_change); |
872 if (path_to_change->empty()) | 881 if (path_to_change->empty()) |
873 url_to_change_.erase(found_origin); | 882 url_to_change_.erase(found_origin); |
874 } | 883 } |
875 | 884 |
| 885 bool DriveFileSyncService::GetPendingChangeForFileSystemURL( |
| 886 const fileapi::FileSystemURL& url, |
| 887 RemoteChange* change) const { |
| 888 DCHECK(change); |
| 889 URLToChange::const_iterator found_url = url_to_change_.find(url.origin()); |
| 890 if (found_url == url_to_change_.end()) |
| 891 return false; |
| 892 const PathToChange& path_to_change = found_url->second; |
| 893 PathToChange::const_iterator found_path = path_to_change.find(url.path()); |
| 894 if (found_path == path_to_change.end()) |
| 895 return false; |
| 896 *change = found_path->second; |
| 897 return true; |
| 898 } |
| 899 |
876 } // namespace sync_file_system | 900 } // namespace sync_file_system |
OLD | NEW |