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" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
15 #include "chrome/browser/drive/drive_api_util.h" | 15 #include "chrome/browser/drive/drive_api_util.h" |
16 #include "chrome/browser/drive/drive_service_interface.h" | 16 #include "chrome/browser/drive/drive_service_interface.h" |
17 #include "chrome/browser/sync_file_system/drive_backend/callback_helper.h" | 17 #include "chrome/browser/sync_file_system/drive_backend/callback_helper.h" |
18 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_util.h" | 18 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_util.h" |
19 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" | 19 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" |
20 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h" | 20 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h" |
21 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" | 21 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" |
22 #include "chrome/browser/sync_file_system/drive_backend/sync_task_token.h" | 22 #include "chrome/browser/sync_file_system/drive_backend/sync_task_token.h" |
23 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" | 23 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" |
24 #include "chrome/browser/sync_file_system/logger.h" | 24 #include "chrome/browser/sync_file_system/logger.h" |
25 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 25 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
26 #include "extensions/common/extension.h" | 26 #include "extensions/common/extension.h" |
27 #include "google_apis/drive/drive_api_parser.h" | 27 #include "google_apis/drive/drive_api_parser.h" |
28 #include "google_apis/drive/gdata_wapi_parser.h" | 28 #include "google_apis/drive/gdata_wapi_parser.h" |
29 #include "webkit/common/fileapi/file_system_util.h" | 29 #include "storage/common/fileapi/file_system_util.h" |
30 | 30 |
31 namespace sync_file_system { | 31 namespace sync_file_system { |
32 namespace drive_backend { | 32 namespace drive_backend { |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 bool BuildFileSystemURL( | 36 bool BuildFileSystemURL(MetadataDatabase* metadata_database, |
37 MetadataDatabase* metadata_database, | 37 const FileTracker& tracker, |
38 const FileTracker& tracker, | 38 storage::FileSystemURL* url) { |
39 fileapi::FileSystemURL* url) { | |
40 base::FilePath path; | 39 base::FilePath path; |
41 if (!metadata_database->BuildPathForTracker( | 40 if (!metadata_database->BuildPathForTracker( |
42 tracker.tracker_id(), &path)) | 41 tracker.tracker_id(), &path)) |
43 return false; | 42 return false; |
44 | 43 |
45 GURL origin = | 44 GURL origin = |
46 extensions::Extension::GetBaseURLFromExtensionId(tracker.app_id()); | 45 extensions::Extension::GetBaseURLFromExtensionId(tracker.app_id()); |
47 *url = sync_file_system::CreateSyncableFileSystemURL(origin, path); | 46 *url = sync_file_system::CreateSyncableFileSystemURL(origin, path); |
48 | 47 |
49 return true; | 48 return true; |
(...skipping 23 matching lines...) Expand all Loading... |
73 scoped_ptr<FileMetadata> GetFileMetadata(MetadataDatabase* database, | 72 scoped_ptr<FileMetadata> GetFileMetadata(MetadataDatabase* database, |
74 const std::string& file_id) { | 73 const std::string& file_id) { |
75 scoped_ptr<FileMetadata> metadata(new FileMetadata); | 74 scoped_ptr<FileMetadata> metadata(new FileMetadata); |
76 if (!database->FindFileByFileID(file_id, metadata.get())) | 75 if (!database->FindFileByFileID(file_id, metadata.get())) |
77 metadata.reset(); | 76 metadata.reset(); |
78 return metadata.Pass(); | 77 return metadata.Pass(); |
79 } | 78 } |
80 | 79 |
81 // Creates a temporary file in |dir_path|. This must be called on an | 80 // Creates a temporary file in |dir_path|. This must be called on an |
82 // IO-allowed task runner, and the runner must be given as |file_task_runner|. | 81 // IO-allowed task runner, and the runner must be given as |file_task_runner|. |
83 webkit_blob::ScopedFile CreateTemporaryFile( | 82 storage::ScopedFile CreateTemporaryFile(base::TaskRunner* file_task_runner) { |
84 base::TaskRunner* file_task_runner) { | |
85 base::FilePath temp_file_path; | 83 base::FilePath temp_file_path; |
86 if (!base::CreateTemporaryFile(&temp_file_path)) | 84 if (!base::CreateTemporaryFile(&temp_file_path)) |
87 return webkit_blob::ScopedFile(); | 85 return storage::ScopedFile(); |
88 | 86 |
89 return webkit_blob::ScopedFile( | 87 return storage::ScopedFile(temp_file_path, |
90 temp_file_path, | 88 storage::ScopedFile::DELETE_ON_SCOPE_OUT, |
91 webkit_blob::ScopedFile::DELETE_ON_SCOPE_OUT, | 89 file_task_runner); |
92 file_task_runner); | |
93 } | 90 } |
94 | 91 |
95 } // namespace | 92 } // namespace |
96 | 93 |
97 RemoteToLocalSyncer::RemoteToLocalSyncer(SyncEngineContext* sync_context) | 94 RemoteToLocalSyncer::RemoteToLocalSyncer(SyncEngineContext* sync_context) |
98 : sync_context_(sync_context), | 95 : sync_context_(sync_context), |
99 sync_action_(SYNC_ACTION_NONE), | 96 sync_action_(SYNC_ACTION_NONE), |
100 prepared_(false), | 97 prepared_(false), |
101 sync_root_deletion_(false), | 98 sync_root_deletion_(false), |
102 weak_ptr_factory_(this) { | 99 weak_ptr_factory_(this) { |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 remote_change_processor()->ApplyRemoteChange( | 680 remote_change_processor()->ApplyRemoteChange( |
684 FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_UNKNOWN), | 681 FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_UNKNOWN), |
685 base::FilePath(), | 682 base::FilePath(), |
686 url_, | 683 url_, |
687 SyncCompletedCallback(token.Pass())); | 684 SyncCompletedCallback(token.Pass())); |
688 } | 685 } |
689 | 686 |
690 void RemoteToLocalSyncer::DownloadFile(scoped_ptr<SyncTaskToken> token) { | 687 void RemoteToLocalSyncer::DownloadFile(scoped_ptr<SyncTaskToken> token) { |
691 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); | 688 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); |
692 | 689 |
693 webkit_blob::ScopedFile file = CreateTemporaryFile( | 690 storage::ScopedFile file = CreateTemporaryFile( |
694 make_scoped_refptr(sync_context_->GetWorkerTaskRunner())); | 691 make_scoped_refptr(sync_context_->GetWorkerTaskRunner())); |
695 | 692 |
696 base::FilePath path = file.path(); | 693 base::FilePath path = file.path(); |
697 drive_service()->DownloadFile( | 694 drive_service()->DownloadFile( |
698 path, remote_metadata_->file_id(), | 695 path, remote_metadata_->file_id(), |
699 base::Bind(&RemoteToLocalSyncer::DidDownloadFile, | 696 base::Bind(&RemoteToLocalSyncer::DidDownloadFile, |
700 weak_ptr_factory_.GetWeakPtr(), | 697 weak_ptr_factory_.GetWeakPtr(), |
701 base::Passed(&token), base::Passed(&file)), | 698 base::Passed(&token), base::Passed(&file)), |
702 google_apis::GetContentCallback(), | 699 google_apis::GetContentCallback(), |
703 google_apis::ProgressCallback()); | 700 google_apis::ProgressCallback()); |
704 } | 701 } |
705 | 702 |
706 void RemoteToLocalSyncer::DidDownloadFile(scoped_ptr<SyncTaskToken> token, | 703 void RemoteToLocalSyncer::DidDownloadFile(scoped_ptr<SyncTaskToken> token, |
707 webkit_blob::ScopedFile file, | 704 storage::ScopedFile file, |
708 google_apis::GDataErrorCode error, | 705 google_apis::GDataErrorCode error, |
709 const base::FilePath&) { | 706 const base::FilePath&) { |
710 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); | 707 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); |
711 | 708 |
712 SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error); | 709 SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error); |
713 if (status != SYNC_STATUS_OK) { | 710 if (status != SYNC_STATUS_OK) { |
714 SyncCompleted(token.Pass(), status); | 711 SyncCompleted(token.Pass(), status); |
715 return; | 712 return; |
716 } | 713 } |
717 | 714 |
(...skipping 12 matching lines...) Expand all Loading... |
730 | 727 |
731 remote_change_processor()->ApplyRemoteChange( | 728 remote_change_processor()->ApplyRemoteChange( |
732 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE), | 729 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE), |
733 path, url_, | 730 path, url_, |
734 base::Bind(&RemoteToLocalSyncer::DidApplyDownload, | 731 base::Bind(&RemoteToLocalSyncer::DidApplyDownload, |
735 weak_ptr_factory_.GetWeakPtr(), | 732 weak_ptr_factory_.GetWeakPtr(), |
736 base::Passed(&token), base::Passed(&file))); | 733 base::Passed(&token), base::Passed(&file))); |
737 } | 734 } |
738 | 735 |
739 void RemoteToLocalSyncer::DidApplyDownload(scoped_ptr<SyncTaskToken> token, | 736 void RemoteToLocalSyncer::DidApplyDownload(scoped_ptr<SyncTaskToken> token, |
740 webkit_blob::ScopedFile, | 737 storage::ScopedFile, |
741 SyncStatusCode status) { | 738 SyncStatusCode status) { |
742 SyncCompleted(token.Pass(), status); | 739 SyncCompleted(token.Pass(), status); |
743 } | 740 } |
744 | 741 |
745 void RemoteToLocalSyncer::CreateFolder(scoped_ptr<SyncTaskToken> token) { | 742 void RemoteToLocalSyncer::CreateFolder(scoped_ptr<SyncTaskToken> token) { |
746 remote_change_processor()->ApplyRemoteChange( | 743 remote_change_processor()->ApplyRemoteChange( |
747 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 744 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
748 SYNC_FILE_TYPE_DIRECTORY), | 745 SYNC_FILE_TYPE_DIRECTORY), |
749 base::FilePath(), url_, | 746 base::FilePath(), url_, |
750 SyncCompletedCallback(token.Pass())); | 747 SyncCompletedCallback(token.Pass())); |
(...skipping 14 matching lines...) Expand all Loading... |
765 | 762 |
766 SyncStatusCallback RemoteToLocalSyncer::SyncCompletedCallback( | 763 SyncStatusCallback RemoteToLocalSyncer::SyncCompletedCallback( |
767 scoped_ptr<SyncTaskToken> token) { | 764 scoped_ptr<SyncTaskToken> token) { |
768 return base::Bind(&RemoteToLocalSyncer::SyncCompleted, | 765 return base::Bind(&RemoteToLocalSyncer::SyncCompleted, |
769 weak_ptr_factory_.GetWeakPtr(), | 766 weak_ptr_factory_.GetWeakPtr(), |
770 base::Passed(&token)); | 767 base::Passed(&token)); |
771 } | 768 } |
772 | 769 |
773 } // namespace drive_backend | 770 } // namespace drive_backend |
774 } // namespace sync_file_system | 771 } // namespace sync_file_system |
OLD | NEW |