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

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

Issue 437943002: [SyncFS] Remove usage of file task runner under drive_backend/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Work for nits Created 6 years, 4 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 | Annotate | Revision Log
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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 remote_change_processor()->ApplyRemoteChange( 682 remote_change_processor()->ApplyRemoteChange(
683 FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_UNKNOWN), 683 FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_UNKNOWN),
684 base::FilePath(), 684 base::FilePath(),
685 url_, 685 url_,
686 callback); 686 callback);
687 } 687 }
688 688
689 void RemoteToLocalSyncer::DownloadFile(const SyncStatusCallback& callback) { 689 void RemoteToLocalSyncer::DownloadFile(const SyncStatusCallback& callback) {
690 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); 690 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread());
691 691
692 base::Callback<void(webkit_blob::ScopedFile)> did_create_callback = 692 webkit_blob::ScopedFile file = CreateTemporaryFile(
693 base::Bind(&RemoteToLocalSyncer::DidCreateTemporaryFileForDownload, 693 make_scoped_refptr(sync_context_->GetWorkerTaskRunner()));
694 weak_ptr_factory_.GetWeakPtr(), callback);
695 694
696 sync_context_->GetFileTaskRunner()->PostTask(
697 FROM_HERE,
698 CreateComposedFunction(
699 base::Bind(&CreateTemporaryFile,
700 make_scoped_refptr(sync_context_->GetFileTaskRunner())),
701 RelayCallbackToTaskRunner(
702 sync_context_->GetWorkerTaskRunner(), FROM_HERE,
703 did_create_callback)));
704 }
705
706 void RemoteToLocalSyncer::DidCreateTemporaryFileForDownload(
707 const SyncStatusCallback& callback,
708 webkit_blob::ScopedFile file) {
709 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread());
710 base::FilePath path = file.path(); 695 base::FilePath path = file.path();
711 drive_service()->DownloadFile( 696 drive_service()->DownloadFile(
712 path, remote_metadata_->file_id(), 697 path, remote_metadata_->file_id(),
713 base::Bind(&RemoteToLocalSyncer::DidDownloadFile, 698 base::Bind(&RemoteToLocalSyncer::DidDownloadFile,
714 weak_ptr_factory_.GetWeakPtr(), 699 weak_ptr_factory_.GetWeakPtr(),
715 callback, base::Passed(&file)), 700 callback, base::Passed(&file)),
716 google_apis::GetContentCallback(), 701 google_apis::GetContentCallback(),
717 google_apis::ProgressCallback()); 702 google_apis::ProgressCallback());
718 } 703 }
719 704
720 void RemoteToLocalSyncer::DidDownloadFile(const SyncStatusCallback& callback, 705 void RemoteToLocalSyncer::DidDownloadFile(const SyncStatusCallback& callback,
721 webkit_blob::ScopedFile file, 706 webkit_blob::ScopedFile file,
722 google_apis::GDataErrorCode error, 707 google_apis::GDataErrorCode error,
723 const base::FilePath&) { 708 const base::FilePath&) {
724 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); 709 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread());
725 710
726 SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error); 711 SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error);
727 if (status != SYNC_STATUS_OK) { 712 if (status != SYNC_STATUS_OK) {
728 callback.Run(status); 713 callback.Run(status);
729 return; 714 return;
730 } 715 }
731 716
732 base::FilePath path = file.path(); 717 base::FilePath path = file.path();
733 base::Callback<void(const std::string&)> did_calculate_callback = 718 const std::string md5 = drive::util::GetMd5Digest(path);
734 base::Bind(&RemoteToLocalSyncer::DidCalculateMD5ForDownload,
735 weak_ptr_factory_.GetWeakPtr(),
736 callback, base::Passed(&file));
737
738 sync_context_->GetFileTaskRunner()->PostTask(
739 FROM_HERE,
740 CreateComposedFunction(
741 base::Bind(&drive::util::GetMd5Digest, path),
742 RelayCallbackToTaskRunner(
743 sync_context_->GetWorkerTaskRunner(), FROM_HERE,
744 did_calculate_callback)));
745 }
746
747 void RemoteToLocalSyncer::DidCalculateMD5ForDownload(
748 const SyncStatusCallback& callback,
749 webkit_blob::ScopedFile file,
750 const std::string& md5) {
751 if (md5.empty()) { 719 if (md5.empty()) {
752 callback.Run(SYNC_FILE_ERROR_NOT_FOUND); 720 callback.Run(SYNC_FILE_ERROR_NOT_FOUND);
753 return; 721 return;
754 } 722 }
755 723
756 if (md5 != remote_metadata_->details().md5()) { 724 if (md5 != remote_metadata_->details().md5()) {
757 // File has been modified since last metadata retrieval. 725 // File has been modified since last metadata retrieval.
758 726
759 // Lower the priority of the tracker to prevent repeated remote sync to the 727 // Lower the priority of the tracker to prevent repeated remote sync to the
760 // same tracker. 728 // same tracker.
761 metadata_database()->LowerTrackerPriority(dirty_tracker_->tracker_id()); 729 metadata_database()->LowerTrackerPriority(dirty_tracker_->tracker_id());
762 callback.Run(SYNC_STATUS_RETRY); 730 callback.Run(SYNC_STATUS_RETRY);
763 return; 731 return;
764 } 732 }
765 733
766 base::FilePath path = file.path();
767 remote_change_processor()->ApplyRemoteChange( 734 remote_change_processor()->ApplyRemoteChange(
768 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE), 735 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE),
769 path, url_, 736 path, url_,
770 base::Bind(&RemoteToLocalSyncer::DidApplyDownload, 737 base::Bind(&RemoteToLocalSyncer::DidApplyDownload,
771 weak_ptr_factory_.GetWeakPtr(), 738 weak_ptr_factory_.GetWeakPtr(),
772 callback, base::Passed(&file))); 739 callback, base::Passed(&file)));
773 } 740 }
774 741
775 void RemoteToLocalSyncer::DidApplyDownload(const SyncStatusCallback& callback, 742 void RemoteToLocalSyncer::DidApplyDownload(const SyncStatusCallback& callback,
776 webkit_blob::ScopedFile, 743 webkit_blob::ScopedFile,
(...skipping 26 matching lines...) Expand all
803 770
804 SyncStatusCallback RemoteToLocalSyncer::SyncCompletedCallback( 771 SyncStatusCallback RemoteToLocalSyncer::SyncCompletedCallback(
805 scoped_ptr<SyncTaskToken> token) { 772 scoped_ptr<SyncTaskToken> token) {
806 return base::Bind(&RemoteToLocalSyncer::SyncCompleted, 773 return base::Bind(&RemoteToLocalSyncer::SyncCompleted,
807 weak_ptr_factory_.GetWeakPtr(), 774 weak_ptr_factory_.GetWeakPtr(),
808 base::Passed(&token)); 775 base::Passed(&token));
809 } 776 }
810 777
811 } // namespace drive_backend 778 } // namespace drive_backend
812 } // namespace sync_file_system 779 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698