Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.cc

Issue 558603002: [SyncFS] Make MetadataDatabase operations synchronous (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@01_create
Patch Set: +TODO Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); 308 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread());
309 309
310 SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error); 310 SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error);
311 if (status != SYNC_STATUS_OK && 311 if (status != SYNC_STATUS_OK &&
312 error != google_apis::HTTP_NOT_FOUND) { 312 error != google_apis::HTTP_NOT_FOUND) {
313 SyncCompleted(token.Pass(), status); 313 SyncCompleted(token.Pass(), status);
314 return; 314 return;
315 } 315 }
316 316
317 if (error == google_apis::HTTP_NOT_FOUND) { 317 if (error == google_apis::HTTP_NOT_FOUND) {
318 metadata_database()->UpdateByDeletedRemoteFile( 318 status = metadata_database()->UpdateByDeletedRemoteFile(
319 dirty_tracker_->file_id(), SyncCompletedCallback(token.Pass())); 319 dirty_tracker_->file_id());
320 SyncCompleted(token.Pass(), status);
320 return; 321 return;
321 } 322 }
322 323
323 if (!entry) { 324 if (!entry) {
324 NOTREACHED(); 325 NOTREACHED();
325 SyncCompleted(token.Pass(), SYNC_STATUS_FAILED); 326 SyncCompleted(token.Pass(), SYNC_STATUS_FAILED);
326 return; 327 return;
327 } 328 }
328 329
329 metadata_database()->UpdateByFileResource( 330 status = metadata_database()->UpdateByFileResource(*entry);
330 *entry, 331 // TODO(tzik): Expand this function.
331 base::Bind(&RemoteToLocalSyncer::DidUpdateDatabaseForRemoteMetadata, 332 DidUpdateDatabaseForRemoteMetadata(token.Pass(), status);
332 weak_ptr_factory_.GetWeakPtr(),
333 base::Passed(&token)));
334 } 333 }
335 334
336 void RemoteToLocalSyncer::DidUpdateDatabaseForRemoteMetadata( 335 void RemoteToLocalSyncer::DidUpdateDatabaseForRemoteMetadata(
337 scoped_ptr<SyncTaskToken> token, 336 scoped_ptr<SyncTaskToken> token,
338 SyncStatusCode status) { 337 SyncStatusCode status) {
339 if (status != SYNC_STATUS_OK) { 338 if (status != SYNC_STATUS_OK) {
340 SyncCompleted(token.Pass(), status); 339 SyncCompleted(token.Pass(), status);
341 return; 340 return;
342 } 341 }
343 342
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 576
578 if (!file_list->next_link().is_empty()) { 577 if (!file_list->next_link().is_empty()) {
579 drive_service()->GetRemainingFileList( 578 drive_service()->GetRemainingFileList(
580 file_list->next_link(), 579 file_list->next_link(),
581 base::Bind(&RemoteToLocalSyncer::DidListFolderContent, 580 base::Bind(&RemoteToLocalSyncer::DidListFolderContent,
582 weak_ptr_factory_.GetWeakPtr(), 581 weak_ptr_factory_.GetWeakPtr(),
583 base::Passed(&token), base::Passed(&children))); 582 base::Passed(&token), base::Passed(&children)));
584 return; 583 return;
585 } 584 }
586 585
587 metadata_database()->PopulateFolderByChildList( 586 status = metadata_database()->PopulateFolderByChildList(
588 dirty_tracker_->file_id(), *children, 587 dirty_tracker_->file_id(), *children);
589 SyncCompletedCallback(token.Pass())); 588 SyncCompleted(token.Pass(), status);
590 } 589 }
591 590
592 void RemoteToLocalSyncer::SyncCompleted(scoped_ptr<SyncTaskToken> token, 591 void RemoteToLocalSyncer::SyncCompleted(scoped_ptr<SyncTaskToken> token,
593 SyncStatusCode status) { 592 SyncStatusCode status) {
594 token->RecordLog(base::StringPrintf( 593 token->RecordLog(base::StringPrintf(
595 "[Remote -> Local]: Finished: action=%s, tracker=%" PRId64 " status=%s", 594 "[Remote -> Local]: Finished: action=%s, tracker=%" PRId64 " status=%s",
596 SyncActionToString(sync_action_), dirty_tracker_->tracker_id(), 595 SyncActionToString(sync_action_), dirty_tracker_->tracker_id(),
597 SyncStatusCodeToString(status))); 596 SyncStatusCodeToString(status)));
598 597
599 if (sync_root_deletion_) { 598 if (sync_root_deletion_) {
(...skipping 20 matching lines...) Expand all
620 HasDisabledAppRoot(metadata_database(), *dirty_tracker_)) { 619 HasDisabledAppRoot(metadata_database(), *dirty_tracker_)) {
621 // Operations for an inactive tracker don't update file content. 620 // Operations for an inactive tracker don't update file content.
622 if (dirty_tracker_->has_synced_details()) 621 if (dirty_tracker_->has_synced_details())
623 updated_details.set_md5(dirty_tracker_->synced_details().md5()); 622 updated_details.set_md5(dirty_tracker_->synced_details().md5());
624 if (!dirty_tracker_->active()) { 623 if (!dirty_tracker_->active()) {
625 // Keep missing true, as the change hasn't been synced to local. 624 // Keep missing true, as the change hasn't been synced to local.
626 updated_details.clear_md5(); 625 updated_details.clear_md5();
627 updated_details.set_missing(true); 626 updated_details.set_missing(true);
628 } 627 }
629 } 628 }
630 metadata_database()->UpdateTracker( 629
631 dirty_tracker_->tracker_id(), 630 status = metadata_database()->UpdateTracker(
632 updated_details, 631 dirty_tracker_->tracker_id(), updated_details);
633 base::Bind(&RemoteToLocalSyncer::FinalizeSync, 632 // TODO(tzik): Expand this function.
634 weak_ptr_factory_.GetWeakPtr(), 633 FinalizeSync(token.Pass(), status);
635 base::Passed(&token)));
636 } 634 }
637 635
638 void RemoteToLocalSyncer::FinalizeSync(scoped_ptr<SyncTaskToken> token, 636 void RemoteToLocalSyncer::FinalizeSync(scoped_ptr<SyncTaskToken> token,
639 SyncStatusCode status) { 637 SyncStatusCode status) {
640 if (prepared_) { 638 if (prepared_) {
641 remote_change_processor()->FinalizeRemoteSync( 639 remote_change_processor()->FinalizeRemoteSync(
642 url_, false /* clear_local_change */, 640 url_, false /* clear_local_change */,
643 base::Bind(SyncTaskManager::NotifyTaskDone, 641 base::Bind(SyncTaskManager::NotifyTaskDone,
644 base::Passed(&token), status)); 642 base::Passed(&token), status));
645 return; 643 return;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 760
763 SyncStatusCallback RemoteToLocalSyncer::SyncCompletedCallback( 761 SyncStatusCallback RemoteToLocalSyncer::SyncCompletedCallback(
764 scoped_ptr<SyncTaskToken> token) { 762 scoped_ptr<SyncTaskToken> token) {
765 return base::Bind(&RemoteToLocalSyncer::SyncCompleted, 763 return base::Bind(&RemoteToLocalSyncer::SyncCompleted,
766 weak_ptr_factory_.GetWeakPtr(), 764 weak_ptr_factory_.GetWeakPtr(),
767 base::Passed(&token)); 765 base::Passed(&token));
768 } 766 }
769 767
770 } // namespace drive_backend 768 } // namespace drive_backend
771 } // namespace sync_file_system 769 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698