| 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/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 NOTREACHED(); | 122 NOTREACHED(); |
| 123 SyncTaskManager::NotifyTaskDone(token.Pass(), SYNC_STATUS_FAILED); | 123 SyncTaskManager::NotifyTaskDone(token.Pass(), SYNC_STATUS_FAILED); |
| 124 return; | 124 return; |
| 125 } | 125 } |
| 126 | 126 |
| 127 dirty_tracker_ = make_scoped_ptr(new FileTracker); | 127 dirty_tracker_ = make_scoped_ptr(new FileTracker); |
| 128 if (metadata_database()->GetNormalPriorityDirtyTracker( | 128 if (metadata_database()->GetNormalPriorityDirtyTracker( |
| 129 dirty_tracker_.get())) { | 129 dirty_tracker_.get())) { |
| 130 token->RecordLog(base::StringPrintf( | 130 token->RecordLog(base::StringPrintf( |
| 131 "Start: tracker_id=%" PRId64, dirty_tracker_->tracker_id())); | 131 "Start: tracker_id=%" PRId64, dirty_tracker_->tracker_id())); |
| 132 metadata_database()->LowerTrackerPriority(dirty_tracker_->tracker_id()); |
| 132 ResolveRemoteChange(token.Pass()); | 133 ResolveRemoteChange(token.Pass()); |
| 133 return; | 134 return; |
| 134 } | 135 } |
| 135 | 136 |
| 136 token->RecordLog("Nothing to do."); | 137 token->RecordLog("Nothing to do."); |
| 137 SyncTaskManager::NotifyTaskDone(token.Pass(), SYNC_STATUS_NO_CHANGE_TO_SYNC); | 138 SyncTaskManager::NotifyTaskDone(token.Pass(), SYNC_STATUS_NO_CHANGE_TO_SYNC); |
| 138 } | 139 } |
| 139 | 140 |
| 140 void RemoteToLocalSyncer::ResolveRemoteChange(scoped_ptr<SyncTaskToken> token) { | 141 void RemoteToLocalSyncer::ResolveRemoteChange(scoped_ptr<SyncTaskToken> token) { |
| 141 DCHECK(dirty_tracker_); | 142 DCHECK(dirty_tracker_); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 338 } |
| 338 | 339 |
| 339 void RemoteToLocalSyncer::DidUpdateDatabaseForRemoteMetadata( | 340 void RemoteToLocalSyncer::DidUpdateDatabaseForRemoteMetadata( |
| 340 scoped_ptr<SyncTaskToken> token, | 341 scoped_ptr<SyncTaskToken> token, |
| 341 SyncStatusCode status) { | 342 SyncStatusCode status) { |
| 342 if (status != SYNC_STATUS_OK) { | 343 if (status != SYNC_STATUS_OK) { |
| 343 SyncCompleted(token.Pass(), status); | 344 SyncCompleted(token.Pass(), status); |
| 344 return; | 345 return; |
| 345 } | 346 } |
| 346 | 347 |
| 348 metadata_database()->PromoteDemotedTracker(dirty_tracker_->tracker_id()); |
| 349 |
| 347 // Do not update |dirty_tracker_|. | 350 // Do not update |dirty_tracker_|. |
| 348 SyncCompleted(token.Pass(), SYNC_STATUS_RETRY); | 351 SyncCompleted(token.Pass(), SYNC_STATUS_RETRY); |
| 349 } | 352 } |
| 350 | 353 |
| 351 void RemoteToLocalSyncer::DidPrepareForAddOrUpdateFile( | 354 void RemoteToLocalSyncer::DidPrepareForAddOrUpdateFile( |
| 352 scoped_ptr<SyncTaskToken> token, | 355 scoped_ptr<SyncTaskToken> token, |
| 353 SyncStatusCode status) { | 356 SyncStatusCode status) { |
| 354 if (status != SYNC_STATUS_OK) { | 357 if (status != SYNC_STATUS_OK) { |
| 355 SyncCompleted(token.Pass(), status); | 358 SyncCompleted(token.Pass(), status); |
| 356 return; | 359 return; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 376 sync_action_ = SYNC_ACTION_UPDATED; | 379 sync_action_ = SYNC_ACTION_UPDATED; |
| 377 // Download the file and overwrite the existing local file. | 380 // Download the file and overwrite the existing local file. |
| 378 DownloadFile(token.Pass()); | 381 DownloadFile(token.Pass()); |
| 379 return; | 382 return; |
| 380 } | 383 } |
| 381 | 384 |
| 382 DCHECK_EQ(SYNC_FILE_TYPE_DIRECTORY, local_metadata_->file_type); | 385 DCHECK_EQ(SYNC_FILE_TYPE_DIRECTORY, local_metadata_->file_type); |
| 383 | 386 |
| 384 // Got a remote regular file modification for existing local folder. | 387 // Got a remote regular file modification for existing local folder. |
| 385 // Our policy prioritize folders in this case. | 388 // Our policy prioritize folders in this case. |
| 386 // Lower the priority of the tracker to prevent repeated remote sync to the | 389 // Let local-to-remote sync phase process this change. |
| 387 // same tracker, and let local-to-remote sync phase process this change. | |
| 388 metadata_database()->LowerTrackerPriority(dirty_tracker_->tracker_id()); | |
| 389 remote_change_processor()->RecordFakeLocalChange( | 390 remote_change_processor()->RecordFakeLocalChange( |
| 390 url_, | 391 url_, |
| 391 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 392 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
| 392 local_metadata_->file_type), | 393 local_metadata_->file_type), |
| 393 SyncCompletedCallback(token.Pass())); | 394 SyncCompletedCallback(token.Pass())); |
| 394 return; | 395 return; |
| 395 } | 396 } |
| 396 | 397 |
| 397 DCHECK(local_changes_->back().IsAddOrUpdate()); | 398 DCHECK(local_changes_->back().IsAddOrUpdate()); |
| 398 // Conflict case. | 399 // Conflict case. |
| 399 // Do nothing for the change now, and handle this in LocalToRemoteSync phase. | 400 // Do nothing for the change now, and handle this in LocalToRemoteSync phase. |
| 400 | |
| 401 // Lower the priority of the tracker to prevent repeated remote sync to the | |
| 402 // same tracker. | |
| 403 metadata_database()->LowerTrackerPriority(dirty_tracker_->tracker_id()); | |
| 404 SyncCompleted(token.Pass(), SYNC_STATUS_RETRY); | 401 SyncCompleted(token.Pass(), SYNC_STATUS_RETRY); |
| 405 } | 402 } |
| 406 | 403 |
| 407 void RemoteToLocalSyncer::HandleFolderUpdate( | 404 void RemoteToLocalSyncer::HandleFolderUpdate( |
| 408 scoped_ptr<SyncTaskToken> token) { | 405 scoped_ptr<SyncTaskToken> token) { |
| 409 DCHECK(dirty_tracker_); | 406 DCHECK(dirty_tracker_); |
| 410 DCHECK(dirty_tracker_->active()); | 407 DCHECK(dirty_tracker_->active()); |
| 411 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | 408 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); |
| 412 | 409 |
| 413 DCHECK(remote_metadata_); | 410 DCHECK(remote_metadata_); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 | 718 |
| 722 base::FilePath path = file.path(); | 719 base::FilePath path = file.path(); |
| 723 const std::string md5 = drive::util::GetMd5Digest(path); | 720 const std::string md5 = drive::util::GetMd5Digest(path); |
| 724 if (md5.empty()) { | 721 if (md5.empty()) { |
| 725 SyncCompleted(token.Pass(), SYNC_FILE_ERROR_NOT_FOUND); | 722 SyncCompleted(token.Pass(), SYNC_FILE_ERROR_NOT_FOUND); |
| 726 return; | 723 return; |
| 727 } | 724 } |
| 728 | 725 |
| 729 if (md5 != remote_metadata_->details().md5()) { | 726 if (md5 != remote_metadata_->details().md5()) { |
| 730 // File has been modified since last metadata retrieval. | 727 // File has been modified since last metadata retrieval. |
| 731 | |
| 732 // Lower the priority of the tracker to prevent repeated remote sync to the | |
| 733 // same tracker. | |
| 734 metadata_database()->LowerTrackerPriority(dirty_tracker_->tracker_id()); | |
| 735 SyncCompleted(token.Pass(), SYNC_STATUS_RETRY); | 728 SyncCompleted(token.Pass(), SYNC_STATUS_RETRY); |
| 736 return; | 729 return; |
| 737 } | 730 } |
| 738 | 731 |
| 739 remote_change_processor()->ApplyRemoteChange( | 732 remote_change_processor()->ApplyRemoteChange( |
| 740 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE), | 733 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE), |
| 741 path, url_, | 734 path, url_, |
| 742 base::Bind(&RemoteToLocalSyncer::DidApplyDownload, | 735 base::Bind(&RemoteToLocalSyncer::DidApplyDownload, |
| 743 weak_ptr_factory_.GetWeakPtr(), | 736 weak_ptr_factory_.GetWeakPtr(), |
| 744 base::Passed(&token), base::Passed(&file))); | 737 base::Passed(&token), base::Passed(&file))); |
| 745 } | 738 } |
| 746 | 739 |
| 747 void RemoteToLocalSyncer::DidApplyDownload(scoped_ptr<SyncTaskToken> token, | 740 void RemoteToLocalSyncer::DidApplyDownload(scoped_ptr<SyncTaskToken> token, |
| 748 webkit_blob::ScopedFile, | 741 webkit_blob::ScopedFile, |
| 749 SyncStatusCode status) { | 742 SyncStatusCode status) { |
| 750 if (status != SYNC_STATUS_OK) | |
| 751 metadata_database()->LowerTrackerPriority(dirty_tracker_->tracker_id()); | |
| 752 SyncCompleted(token.Pass(), status); | 743 SyncCompleted(token.Pass(), status); |
| 753 } | 744 } |
| 754 | 745 |
| 755 void RemoteToLocalSyncer::CreateFolder(scoped_ptr<SyncTaskToken> token) { | 746 void RemoteToLocalSyncer::CreateFolder(scoped_ptr<SyncTaskToken> token) { |
| 756 remote_change_processor()->ApplyRemoteChange( | 747 remote_change_processor()->ApplyRemoteChange( |
| 757 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 748 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
| 758 SYNC_FILE_TYPE_DIRECTORY), | 749 SYNC_FILE_TYPE_DIRECTORY), |
| 759 base::FilePath(), url_, | 750 base::FilePath(), url_, |
| 760 SyncCompletedCallback(token.Pass())); | 751 SyncCompletedCallback(token.Pass())); |
| 761 } | 752 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 775 | 766 |
| 776 SyncStatusCallback RemoteToLocalSyncer::SyncCompletedCallback( | 767 SyncStatusCallback RemoteToLocalSyncer::SyncCompletedCallback( |
| 777 scoped_ptr<SyncTaskToken> token) { | 768 scoped_ptr<SyncTaskToken> token) { |
| 778 return base::Bind(&RemoteToLocalSyncer::SyncCompleted, | 769 return base::Bind(&RemoteToLocalSyncer::SyncCompleted, |
| 779 weak_ptr_factory_.GetWeakPtr(), | 770 weak_ptr_factory_.GetWeakPtr(), |
| 780 base::Passed(&token)); | 771 base::Passed(&token)); |
| 781 } | 772 } |
| 782 | 773 |
| 783 } // namespace drive_backend | 774 } // namespace drive_backend |
| 784 } // namespace sync_file_system | 775 } // namespace sync_file_system |
| OLD | NEW |