| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_H_ | 5 #ifndef COMPONENTS_SYNC_ENGINE_SYNC_ENGINE_H_ |
| 6 #define COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_H_ | 6 #define COMPONENTS_SYNC_ENGINE_SYNC_ENGINE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "components/sync/base/model_type.h" | 15 #include "components/sync/base/model_type.h" |
| 16 #include "components/sync/base/weak_handle.h" | 16 #include "components/sync/base/weak_handle.h" |
| 17 #include "components/sync/driver/backend_data_type_configurer.h" | |
| 18 #include "components/sync/engine/configure_reason.h" | 17 #include "components/sync/engine/configure_reason.h" |
| 19 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" | 18 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" |
| 19 #include "components/sync/engine/model_type_configurer.h" |
| 20 #include "components/sync/engine/shutdown_reason.h" | 20 #include "components/sync/engine/shutdown_reason.h" |
| 21 #include "components/sync/engine/sync_manager.h" | 21 #include "components/sync/engine/sync_manager.h" |
| 22 #include "components/sync/engine/sync_manager_factory.h" | 22 #include "components/sync/engine/sync_manager_factory.h" |
| 23 | 23 |
| 24 class GURL; | 24 class GURL; |
| 25 | 25 |
| 26 namespace syncer { | 26 namespace syncer { |
| 27 | 27 |
| 28 class CancelationSignal; | 28 class CancelationSignal; |
| 29 class HttpPostProviderFactory; | 29 class HttpPostProviderFactory; |
| 30 class SyncFrontend; | 30 class SyncEngineHost; |
| 31 class SyncManagerFactory; | 31 class SyncManagerFactory; |
| 32 class UnrecoverableErrorHandler; | 32 class UnrecoverableErrorHandler; |
| 33 | 33 |
| 34 // An API to "host" the top level SyncAPI element. | 34 // The interface into the sync engine, which is the part of sync that performs |
| 35 // | 35 // communication between model types and the sync server. In prod the engine |
| 36 // This class handles dispatch of potentially blocking calls to appropriate | 36 // will always live on the sync thread and the object implementing this |
| 37 // threads and ensures that the SyncFrontend is only accessed on the UI loop. | 37 // interface will handle crossing threads if necessary. |
| 38 class SyncBackendHost : public BackendDataTypeConfigurer { | 38 class SyncEngine : public ModelTypeConfigurer { |
| 39 public: | 39 public: |
| 40 typedef SyncStatus Status; | 40 typedef SyncStatus Status; |
| 41 typedef base::Callback<std::unique_ptr<HttpPostProviderFactory>( | 41 typedef base::Callback<std::unique_ptr<HttpPostProviderFactory>( |
| 42 CancelationSignal*)> | 42 CancelationSignal*)> |
| 43 HttpPostProviderFactoryGetter; | 43 HttpPostProviderFactoryGetter; |
| 44 | 44 |
| 45 // Stubs used by implementing classes. | 45 // Stubs used by implementing classes. |
| 46 SyncBackendHost(); | 46 SyncEngine(); |
| 47 ~SyncBackendHost() override; | 47 ~SyncEngine() override; |
| 48 | 48 |
| 49 // Called on the frontend's thread to kick off asynchronous initialization. | 49 // Kicks off asynchronous initialization. Optionally deletes sync data during |
| 50 // Optionally deletes the "Sync Data" folder during init in order to make | 50 // init in order to make sure we're starting fresh. |
| 51 // sure we're starting fresh. | |
| 52 // | 51 // |
| 53 // |saved_nigori_state| is optional nigori state to restore from a previous | 52 // |saved_nigori_state| is optional nigori state to restore from a previous |
| 54 // backend instance. May be null. | 53 // engine instance. May be null. |
| 55 virtual void Initialize( | 54 virtual void Initialize( |
| 56 SyncFrontend* frontend, | 55 SyncEngineHost* host, |
| 57 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner, | 56 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner, |
| 58 const WeakHandle<JsEventHandler>& event_handler, | 57 const WeakHandle<JsEventHandler>& event_handler, |
| 59 const GURL& service_url, | 58 const GURL& service_url, |
| 60 const std::string& sync_user_agent, | 59 const std::string& sync_user_agent, |
| 61 const SyncCredentials& credentials, | 60 const SyncCredentials& credentials, |
| 62 bool delete_sync_data_folder, | 61 bool delete_sync_data_folder, |
| 63 bool enable_local_sync_backend, | 62 bool enable_local_sync_backend, |
| 64 const base::FilePath& local_sync_backend_folder, | 63 const base::FilePath& local_sync_backend_folder, |
| 65 std::unique_ptr<SyncManagerFactory> sync_manager_factory, | 64 std::unique_ptr<SyncManagerFactory> sync_manager_factory, |
| 66 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, | 65 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, |
| 67 const base::Closure& report_unrecoverable_error_function, | 66 const base::Closure& report_unrecoverable_error_function, |
| 68 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, | 67 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, |
| 69 std::unique_ptr<SyncEncryptionHandler::NigoriState> | 68 std::unique_ptr<SyncEncryptionHandler::NigoriState> |
| 70 saved_nigori_state) = 0; | 69 saved_nigori_state) = 0; |
| 71 | 70 |
| 72 // Called on the frontend's thread to trigger a refresh. | 71 // Inform the engine to trigger a sync cycle for |types|. |
| 73 virtual void TriggerRefresh(const ModelTypeSet& types) = 0; | 72 virtual void TriggerRefresh(const ModelTypeSet& types) = 0; |
| 74 | 73 |
| 75 // Called on the frontend's thread to update SyncCredentials. | 74 // Updates the engine's SyncCredentials. |
| 76 virtual void UpdateCredentials(const SyncCredentials& credentials) = 0; | 75 virtual void UpdateCredentials(const SyncCredentials& credentials) = 0; |
| 77 | 76 |
| 78 // This starts the SyncerThread running a Syncer object to communicate with | 77 // This starts the sync engine running a Syncer object to communicate with |
| 79 // sync servers. Until this is called, no changes will leave or enter this | 78 // sync servers. Until this is called, no changes will leave or enter this |
| 80 // browser from the cloud / sync servers. | 79 // browser from the cloud / sync servers. |
| 81 // Called on |frontend_loop_|. | |
| 82 virtual void StartSyncingWithServer() = 0; | 80 virtual void StartSyncingWithServer() = 0; |
| 83 | 81 |
| 84 // Called on |frontend_loop_| to asynchronously set a new passphrase for | 82 // Asynchronously set a new passphrase for encryption. Note that it is an |
| 85 // encryption. Note that it is an error to call SetEncryptionPassphrase under | 83 // error to call SetEncryptionPassphrase under the following circumstances: |
| 86 // the following circumstances: | |
| 87 // - An explicit passphrase has already been set | 84 // - An explicit passphrase has already been set |
| 88 // - |is_explicit| is true and we have pending keys. | 85 // - |is_explicit| is true and we have pending keys. |
| 89 // When |is_explicit| is false, a couple of things could happen: | 86 // When |is_explicit| is false, a couple of things could happen: |
| 90 // - If there are pending keys, we try to decrypt them. If decryption works, | 87 // - If there are pending keys, we try to decrypt them. If decryption works, |
| 91 // this acts like a call to SetDecryptionPassphrase. If not, the GAIA | 88 // this acts like a call to SetDecryptionPassphrase. If not, the GAIA |
| 92 // passphrase passed in is cached so we can re-encrypt with it in future. | 89 // passphrase passed in is cached so we can re-encrypt with it in future. |
| 93 // - If there are no pending keys, data is encrypted with |passphrase| (this | 90 // - If there are no pending keys, data is encrypted with |passphrase| (this |
| 94 // is a no-op if data was already encrypted with |passphrase|.) | 91 // is a no-op if data was already encrypted with |passphrase|.) |
| 95 virtual void SetEncryptionPassphrase(const std::string& passphrase, | 92 virtual void SetEncryptionPassphrase(const std::string& passphrase, |
| 96 bool is_explicit) = 0; | 93 bool is_explicit) = 0; |
| 97 | 94 |
| 98 // Called on |frontend_loop_| to use the provided passphrase to asynchronously | 95 // Use the provided passphrase to asynchronously attempt decryption. Returns |
| 99 // attempt decryption. Returns false immediately if the passphrase could not | 96 // false immediately if the passphrase could not be used to decrypt a locally |
| 100 // be used to decrypt a locally cached copy of encrypted keys; returns true | 97 // cached copy of encrypted keys; returns true otherwise. If new encrypted |
| 101 // otherwise. If new encrypted keys arrive during the asynchronous call, | 98 // keys arrive during the asynchronous call, OnPassphraseRequired may be |
| 102 // OnPassphraseRequired may be triggered at a later time. It is an error to | 99 // triggered at a later time. It is an error to call this when there are no |
| 103 // call this when there are no pending keys. | 100 // pending keys. |
| 104 virtual bool SetDecryptionPassphrase(const std::string& passphrase) | 101 virtual bool SetDecryptionPassphrase(const std::string& passphrase) |
| 105 WARN_UNUSED_RESULT = 0; | 102 WARN_UNUSED_RESULT = 0; |
| 106 | 103 |
| 107 // Called on |frontend_loop_| to kick off shutdown procedure. Attempts to cut | 104 // Kick off shutdown procedure. Attempts to cut short any long-lived or |
| 108 // short any long-lived or blocking sync thread tasks so that the shutdown on | 105 // blocking sync thread tasks so that the shutdown on sync thread task that |
| 109 // sync thread task that we're about to post won't have to wait very long. | 106 // we're about to post won't have to wait very long. |
| 110 virtual void StopSyncingForShutdown() = 0; | 107 virtual void StopSyncingForShutdown() = 0; |
| 111 | 108 |
| 112 // Called on |frontend_loop_| to kick off shutdown. | |
| 113 // See the implementation and Core::DoShutdown for details. | 109 // See the implementation and Core::DoShutdown for details. |
| 114 // Must be called *after* StopSyncingForShutdown. | 110 // Must be called *after* StopSyncingForShutdown. |
| 115 virtual void Shutdown(ShutdownReason reason) = 0; | 111 virtual void Shutdown(ShutdownReason reason) = 0; |
| 116 | 112 |
| 117 // Removes all current registrations from the backend on the | 113 // Removes all current registrations from the backend on the |
| 118 // InvalidationService. | 114 // InvalidationService. |
| 119 virtual void UnregisterInvalidationIds() = 0; | 115 virtual void UnregisterInvalidationIds() = 0; |
| 120 | 116 |
| 121 // Changes the set of data types that are currently being synced. | 117 // Changes the set of data types that are currently being synced. |
| 122 // The ready_task will be run when configuration is done with the | 118 // The ready_task will be run when configuration is done with the |
| 123 // set of all types that failed configuration (i.e., if its argument | 119 // set of all types that failed configuration (i.e., if its argument |
| 124 // is non-empty, then an error was encountered). | 120 // is non-empty, then an error was encountered). |
| 125 // Returns the set of types that are ready to start without needing any | 121 // Returns the set of types that are ready to start without needing any |
| 126 // further sync activity. | 122 // further sync activity. |
| 127 // BackendDataTypeConfigurer implementation. | 123 // ModelTypeConfigurer implementation. |
| 128 ModelTypeSet ConfigureDataTypes( | 124 ModelTypeSet ConfigureDataTypes( |
| 129 ConfigureReason reason, | 125 ConfigureReason reason, |
| 130 const DataTypeConfigStateMap& config_state_map, | 126 const DataTypeConfigStateMap& config_state_map, |
| 131 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task, | 127 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task, |
| 132 const base::Callback<void()>& retry_callback) override = 0; | 128 const base::Callback<void()>& retry_callback) override = 0; |
| 133 | 129 |
| 134 // Turns on encryption of all present and future sync data. | 130 // Turns on encryption of all present and future sync data. |
| 135 virtual void EnableEncryptEverything() = 0; | 131 virtual void EnableEncryptEverything() = 0; |
| 136 | 132 |
| 137 // Called on |frontend_loop_| to obtain a handle to the UserShare needed for | 133 // Obtain a handle to the UserShare needed for creating transactions. Should |
| 138 // creating transactions. Should not be called before we signal | 134 // not be called before we signal initialization is complete with |
| 139 // initialization is complete with OnBackendInitialized(). | 135 // OnBackendInitialized(). |
| 140 virtual UserShare* GetUserShare() const = 0; | 136 virtual UserShare* GetUserShare() const = 0; |
| 141 | 137 |
| 142 // Called from any thread to obtain current status information in detailed or | 138 // Called from any thread to obtain current status information in detailed or |
| 143 // summarized form. | 139 // summarized form. |
| 144 virtual Status GetDetailedStatus() = 0; | 140 virtual Status GetDetailedStatus() = 0; |
| 145 virtual SyncCycleSnapshot GetLastCycleSnapshot() const = 0; | 141 virtual SyncCycleSnapshot GetLastCycleSnapshot() const = 0; |
| 146 | 142 |
| 147 // Determines if the underlying sync engine has made any local changes to | 143 // Determines if the underlying sync engine has made any local changes to |
| 148 // items that have not yet been synced with the server. | 144 // items that have not yet been synced with the server. |
| 149 // ONLY CALL THIS IF OnInitializationComplete was called! | 145 // ONLY CALL THIS IF OnInitializationComplete was called! |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 | 188 |
| 193 // See SyncManager::ClearServerData. | 189 // See SyncManager::ClearServerData. |
| 194 virtual void ClearServerData( | 190 virtual void ClearServerData( |
| 195 const SyncManager::ClearServerDataCallback& callback) = 0; | 191 const SyncManager::ClearServerDataCallback& callback) = 0; |
| 196 | 192 |
| 197 // Notify the syncer that the cookie jar has changed. | 193 // Notify the syncer that the cookie jar has changed. |
| 198 // See SyncManager::OnCookieJarChanged. | 194 // See SyncManager::OnCookieJarChanged. |
| 199 virtual void OnCookieJarChanged(bool account_mismatch, bool empty_jar) = 0; | 195 virtual void OnCookieJarChanged(bool account_mismatch, bool empty_jar) = 0; |
| 200 | 196 |
| 201 private: | 197 private: |
| 202 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 198 DISALLOW_COPY_AND_ASSIGN(SyncEngine); |
| 203 }; | 199 }; |
| 204 | 200 |
| 205 } // namespace syncer | 201 } // namespace syncer |
| 206 | 202 |
| 207 #endif // COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_H_ | 203 #endif // COMPONENTS_SYNC_ENGINE_SYNC_ENGINE_H_ |
| OLD | NEW |