| 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 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_ENGINE_INITIALIZER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_ENGINE_INITIALIZER_H_ |
| 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_ENGINE_INITIALIZER_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_ENGINE_INITIALIZER_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/scoped_vector.h" |
| 10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 11 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 13 #include "chrome/browser/google_apis/drive_common_callbacks.h" |
| 14 #include "chrome/browser/google_apis/gdata_errorcode.h" |
| 12 #include "chrome/browser/sync_file_system/sync_callbacks.h" | 15 #include "chrome/browser/sync_file_system/sync_callbacks.h" |
| 13 #include "chrome/browser/sync_file_system/sync_task.h" | 16 #include "chrome/browser/sync_file_system/sync_task.h" |
| 14 | 17 |
| 15 namespace drive { | 18 namespace drive { |
| 16 class DriveAPIService; | 19 class DriveServiceInterface; |
| 20 } |
| 21 |
| 22 namespace google_apis { |
| 23 class AboutResource; |
| 24 class ResourceEntry; |
| 25 class ResourceList; |
| 17 } | 26 } |
| 18 | 27 |
| 19 namespace sync_file_system { | 28 namespace sync_file_system { |
| 20 namespace drive_backend { | 29 namespace drive_backend { |
| 21 | 30 |
| 22 class MetadataDatabase; | 31 class MetadataDatabase; |
| 23 | 32 |
| 33 // This class performs initializion sequence of SyncEngine. |
| 34 // |
| 35 // After initialize sequence completed, the Database must have |
| 36 // - Largest change ID, |
| 37 // - Sync-root folder and its tracker, |
| 38 // - All children of sync-root folder that have inactive and non-dirty |
| 39 // trackers. |
| 40 // |
| 41 // The initialization sequence is: |
| 42 // - Open database and load its contents, |
| 43 // - If the database is already populated, complete the sequence. |
| 44 // - Get AboutResource to get the largest change ID and the Drive root folder |
| 45 // ID. |
| 46 // - Find the remote sync-root folder, whose title is |
| 47 // "Chrome Syncable FileSystem" and has no parent. |
| 48 // Note that if the initialization is interrupted by the browser restart or |
| 49 // an error, the sequence leaves the folder in the Drive root folder. So, if |
| 50 // we find the folder in the Drive root folder, handle it as the sync-root |
| 51 // folder. |
| 52 // - Create the remote sync-root folder if we don't have. |
| 53 // - Detach the remote sync-root folder from its parent if it has. |
| 54 // - Fetch the folder contents of the remote sync-root folder. |
| 55 // The contents are likely registered as app-root folders, but handle them |
| 56 // as regular inactive folders until they are registered explicitly. |
| 57 // - Populate database with the largest change ID, the sync-root folder and |
| 58 // its contents. |
| 59 // |
| 24 class SyncEngineInitializer : public SyncTask { | 60 class SyncEngineInitializer : public SyncTask { |
| 25 public: | 61 public: |
| 26 SyncEngineInitializer(base::SequencedTaskRunner* task_runner, | 62 SyncEngineInitializer(base::SequencedTaskRunner* task_runner, |
| 27 drive::DriveAPIService* drive_api, | 63 drive::DriveServiceInterface* drive_service, |
| 28 const base::FilePath& database_path); | 64 const base::FilePath& database_path); |
| 29 virtual ~SyncEngineInitializer(); | 65 virtual ~SyncEngineInitializer(); |
| 30 virtual void Run(const SyncStatusCallback& callback) OVERRIDE; | 66 virtual void Run(const SyncStatusCallback& callback) OVERRIDE; |
| 31 | 67 |
| 68 scoped_ptr<MetadataDatabase> PassMetadataDatabase(); |
| 69 |
| 32 private: | 70 private: |
| 71 typedef base::Callback<void(const SyncStatusCallback& callback)> Task; |
| 72 |
| 33 void DidCreateMetadataDatabase(const SyncStatusCallback& callback, | 73 void DidCreateMetadataDatabase(const SyncStatusCallback& callback, |
| 34 SyncStatusCode status, | 74 SyncStatusCode status, |
| 35 scoped_ptr<MetadataDatabase> instance); | 75 scoped_ptr<MetadataDatabase> instance); |
| 36 | 76 |
| 77 void GetAboutResource(const SyncStatusCallback& callback); |
| 78 void DidGetAboutResource( |
| 79 const SyncStatusCallback& callback, |
| 80 google_apis::GDataErrorCode error, |
| 81 scoped_ptr<google_apis::AboutResource> about_resource); |
| 82 void FindSyncRoot(const SyncStatusCallback& callback); |
| 83 void DidFindSyncRoot(const SyncStatusCallback& callback, |
| 84 google_apis::GDataErrorCode error, |
| 85 scoped_ptr<google_apis::ResourceList> resource_list); |
| 86 void CreateSyncRoot(const SyncStatusCallback& callback); |
| 87 void DidCreateSyncRoot(const SyncStatusCallback& callback, |
| 88 google_apis::GDataErrorCode error, |
| 89 scoped_ptr<google_apis::ResourceEntry> entry); |
| 90 void DetachSyncRoot(const SyncStatusCallback& callback); |
| 91 void DidDetachSyncRoot(const SyncStatusCallback& callback, |
| 92 google_apis::GDataErrorCode error); |
| 93 void ListAppRootFolders(const SyncStatusCallback& callback); |
| 94 void DidListAppRootFolders( |
| 95 const SyncStatusCallback& callback, |
| 96 google_apis::GDataErrorCode error, |
| 97 scoped_ptr<google_apis::ResourceList> resource_list); |
| 98 void PopulateDatabase(const SyncStatusCallback& callback); |
| 99 void DidPopulateDatabase(const SyncStatusCallback& callback, |
| 100 SyncStatusCode status); |
| 101 |
| 37 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 102 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 38 drive::DriveAPIService* drive_api_; | 103 drive::DriveServiceInterface* drive_service_; |
| 104 google_apis::CancelCallback cancel_callback_; |
| 39 base::FilePath database_path_; | 105 base::FilePath database_path_; |
| 40 | 106 |
| 41 scoped_ptr<MetadataDatabase> metadata_database_; | 107 scoped_ptr<MetadataDatabase> metadata_database_; |
| 108 ScopedVector<google_apis::ResourceEntry> app_root_folders_; |
| 109 |
| 110 int64 largest_change_id_; |
| 111 std::string root_folder_id_; |
| 112 |
| 113 scoped_ptr<google_apis::ResourceEntry> sync_root_folder_; |
| 42 | 114 |
| 43 base::WeakPtrFactory<SyncEngineInitializer> weak_ptr_factory_; | 115 base::WeakPtrFactory<SyncEngineInitializer> weak_ptr_factory_; |
| 44 | 116 |
| 45 DISALLOW_COPY_AND_ASSIGN(SyncEngineInitializer); | 117 DISALLOW_COPY_AND_ASSIGN(SyncEngineInitializer); |
| 46 }; | 118 }; |
| 47 | 119 |
| 48 } // namespace drive_backend | 120 } // namespace drive_backend |
| 49 } // namespace sync_file_system | 121 } // namespace sync_file_system |
| 50 | 122 |
| 51 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_ENGINE_INITIALIZER
_H_ | 123 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_ENGINE_INITIALIZER
_H_ |
| OLD | NEW |