Chromium Code Reviews| 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 // An API to "host" the top level SyncAPI element. |
|
skym
2016/12/02 20:54:55
Still using the word host. Can you rewrite all of
maxbogue
2016/12/02 23:59:28
Done, PTAL.
| |
| 35 // | 35 // |
| 36 // This class handles dispatch of potentially blocking calls to appropriate | 36 // This class handles dispatch of potentially blocking calls to appropriate |
| 37 // threads and ensures that the SyncFrontend is only accessed on the UI loop. | 37 // threads and ensures that the SyncEngineHost is only accessed on the UI loop. |
| 38 class SyncBackendHost : public BackendDataTypeConfigurer { | 38 class SyncEngine : public ModelTypeConfigurer { |
| 39 public: | 39 public: |
| 40 typedef SyncStatus Status; | 40 typedef SyncStatus Status; |
|
skym
2016/12/02 20:54:55
This typedef is weird.
maxbogue
2016/12/02 23:59:28
Super weird but I ain't touching it in this CL.
| |
| 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 // Called on the host's thread to kick off asynchronous initialization. |
|
skym
2016/12/02 20:54:55
All methods on this class should now be on the hos
maxbogue
2016/12/02 23:59:28
I don't know why before; going forward it's how th
| |
| 50 // Optionally deletes the "Sync Data" folder during init in order to make | 50 // Optionally deletes the "Sync Data" folder during init in order to make |
| 51 // sure we're starting fresh. | 51 // sure we're starting fresh. |
| 52 // | 52 // |
| 53 // |saved_nigori_state| is optional nigori state to restore from a previous | 53 // |saved_nigori_state| is optional nigori state to restore from a previous |
| 54 // backend instance. May be null. | 54 // backend instance. May be null. |
| 55 virtual void Initialize( | 55 virtual void Initialize( |
| 56 SyncFrontend* frontend, | 56 SyncEngineHost* host, |
| 57 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner, | 57 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner, |
| 58 const WeakHandle<JsEventHandler>& event_handler, | 58 const WeakHandle<JsEventHandler>& event_handler, |
| 59 const GURL& service_url, | 59 const GURL& service_url, |
| 60 const std::string& sync_user_agent, | 60 const std::string& sync_user_agent, |
| 61 const SyncCredentials& credentials, | 61 const SyncCredentials& credentials, |
| 62 bool delete_sync_data_folder, | 62 bool delete_sync_data_folder, |
| 63 bool enable_local_sync_backend, | 63 bool enable_local_sync_backend, |
| 64 const base::FilePath& local_sync_backend_folder, | 64 const base::FilePath& local_sync_backend_folder, |
| 65 std::unique_ptr<SyncManagerFactory> sync_manager_factory, | 65 std::unique_ptr<SyncManagerFactory> sync_manager_factory, |
| 66 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, | 66 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, |
| 67 const base::Closure& report_unrecoverable_error_function, | 67 const base::Closure& report_unrecoverable_error_function, |
| 68 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, | 68 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, |
| 69 std::unique_ptr<SyncEncryptionHandler::NigoriState> | 69 std::unique_ptr<SyncEncryptionHandler::NigoriState> |
| 70 saved_nigori_state) = 0; | 70 saved_nigori_state) = 0; |
| 71 | 71 |
| 72 // Called on the frontend's thread to trigger a refresh. | 72 // Called on the host's thread to trigger a refresh. |
|
skym
2016/12/02 20:54:55
I'd just remove all of these comments. They no lon
maxbogue
2016/12/02 23:59:28
I re-wrote them to be more descriptive instead of
| |
| 73 virtual void TriggerRefresh(const ModelTypeSet& types) = 0; | 73 virtual void TriggerRefresh(const ModelTypeSet& types) = 0; |
| 74 | 74 |
| 75 // Called on the frontend's thread to update SyncCredentials. | 75 // Called on the host's thread to update SyncCredentials. |
|
skym
2016/12/02 20:54:55
Same.
maxbogue
2016/12/02 23:59:28
Done.
| |
| 76 virtual void UpdateCredentials(const SyncCredentials& credentials) = 0; | 76 virtual void UpdateCredentials(const SyncCredentials& credentials) = 0; |
| 77 | 77 |
| 78 // This starts the SyncerThread running a Syncer object to communicate with | 78 // This starts the SyncerThread running a Syncer object to communicate with |
| 79 // sync servers. Until this is called, no changes will leave or enter this | 79 // sync servers. Until this is called, no changes will leave or enter this |
| 80 // browser from the cloud / sync servers. | 80 // browser from the cloud / sync servers. |
| 81 // Called on |frontend_loop_|. | |
|
skym
2016/12/02 20:54:55
Yeah! Like this!
maxbogue
2016/12/02 23:59:28
Acknowledged.
| |
| 82 virtual void StartSyncingWithServer() = 0; | 81 virtual void StartSyncingWithServer() = 0; |
| 83 | 82 |
| 84 // Called on |frontend_loop_| to asynchronously set a new passphrase for | 83 // Asynchronously set a new passphrase for encryption. Note that it is an |
| 85 // encryption. Note that it is an error to call SetEncryptionPassphrase under | 84 // error to call SetEncryptionPassphrase under the following circumstances: |
| 86 // the following circumstances: | |
| 87 // - An explicit passphrase has already been set | 85 // - An explicit passphrase has already been set |
| 88 // - |is_explicit| is true and we have pending keys. | 86 // - |is_explicit| is true and we have pending keys. |
| 89 // When |is_explicit| is false, a couple of things could happen: | 87 // 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, | 88 // - 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 | 89 // 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. | 90 // 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 | 91 // - If there are no pending keys, data is encrypted with |passphrase| (this |
| 94 // is a no-op if data was already encrypted with |passphrase|.) | 92 // is a no-op if data was already encrypted with |passphrase|.) |
| 95 virtual void SetEncryptionPassphrase(const std::string& passphrase, | 93 virtual void SetEncryptionPassphrase(const std::string& passphrase, |
| 96 bool is_explicit) = 0; | 94 bool is_explicit) = 0; |
| 97 | 95 |
| 98 // Called on |frontend_loop_| to use the provided passphrase to asynchronously | 96 // Use the provided passphrase to asynchronously attempt decryption. Returns |
| 99 // attempt decryption. Returns false immediately if the passphrase could not | 97 // 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 | 98 // cached copy of encrypted keys; returns true otherwise. If new encrypted |
| 101 // otherwise. If new encrypted keys arrive during the asynchronous call, | 99 // keys arrive during the asynchronous call, OnPassphraseRequired may be |
| 102 // OnPassphraseRequired may be triggered at a later time. It is an error to | 100 // 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. | 101 // pending keys. |
| 104 virtual bool SetDecryptionPassphrase(const std::string& passphrase) | 102 virtual bool SetDecryptionPassphrase(const std::string& passphrase) |
| 105 WARN_UNUSED_RESULT = 0; | 103 WARN_UNUSED_RESULT = 0; |
| 106 | 104 |
| 107 // Called on |frontend_loop_| to kick off shutdown procedure. Attempts to cut | 105 // 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 | 106 // 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. | 107 // we're about to post won't have to wait very long. |
| 110 virtual void StopSyncingForShutdown() = 0; | 108 virtual void StopSyncingForShutdown() = 0; |
| 111 | 109 |
| 112 // Called on |frontend_loop_| to kick off shutdown. | |
| 113 // See the implementation and Core::DoShutdown for details. | 110 // See the implementation and Core::DoShutdown for details. |
| 114 // Must be called *after* StopSyncingForShutdown. | 111 // Must be called *after* StopSyncingForShutdown. |
| 115 virtual void Shutdown(ShutdownReason reason) = 0; | 112 virtual void Shutdown(ShutdownReason reason) = 0; |
| 116 | 113 |
| 117 // Removes all current registrations from the backend on the | 114 // Removes all current registrations from the backend on the |
| 118 // InvalidationService. | 115 // InvalidationService. |
| 119 virtual void UnregisterInvalidationIds() = 0; | 116 virtual void UnregisterInvalidationIds() = 0; |
| 120 | 117 |
| 121 // Changes the set of data types that are currently being synced. | 118 // Changes the set of data types that are currently being synced. |
| 122 // The ready_task will be run when configuration is done with the | 119 // 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 | 120 // set of all types that failed configuration (i.e., if its argument |
| 124 // is non-empty, then an error was encountered). | 121 // is non-empty, then an error was encountered). |
| 125 // Returns the set of types that are ready to start without needing any | 122 // Returns the set of types that are ready to start without needing any |
| 126 // further sync activity. | 123 // further sync activity. |
| 127 // BackendDataTypeConfigurer implementation. | 124 // ModelTypeConfigurer implementation. |
| 128 ModelTypeSet ConfigureDataTypes( | 125 ModelTypeSet ConfigureDataTypes( |
| 129 ConfigureReason reason, | 126 ConfigureReason reason, |
| 130 const DataTypeConfigStateMap& config_state_map, | 127 const DataTypeConfigStateMap& config_state_map, |
| 131 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task, | 128 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task, |
| 132 const base::Callback<void()>& retry_callback) override = 0; | 129 const base::Callback<void()>& retry_callback) override = 0; |
| 133 | 130 |
| 134 // Turns on encryption of all present and future sync data. | 131 // Turns on encryption of all present and future sync data. |
| 135 virtual void EnableEncryptEverything() = 0; | 132 virtual void EnableEncryptEverything() = 0; |
| 136 | 133 |
| 137 // Called on |frontend_loop_| to obtain a handle to the UserShare needed for | 134 // Obtain a handle to the UserShare needed for creating transactions. Should |
| 138 // creating transactions. Should not be called before we signal | 135 // not be called before we signal initialization is complete with |
| 139 // initialization is complete with OnBackendInitialized(). | 136 // OnBackendInitialized(). |
| 140 virtual UserShare* GetUserShare() const = 0; | 137 virtual UserShare* GetUserShare() const = 0; |
| 141 | 138 |
| 142 // Called from any thread to obtain current status information in detailed or | 139 // Called from any thread to obtain current status information in detailed or |
| 143 // summarized form. | 140 // summarized form. |
| 144 virtual Status GetDetailedStatus() = 0; | 141 virtual Status GetDetailedStatus() = 0; |
| 145 virtual SyncCycleSnapshot GetLastCycleSnapshot() const = 0; | 142 virtual SyncCycleSnapshot GetLastCycleSnapshot() const = 0; |
| 146 | 143 |
| 147 // Determines if the underlying sync engine has made any local changes to | 144 // Determines if the underlying sync engine has made any local changes to |
| 148 // items that have not yet been synced with the server. | 145 // items that have not yet been synced with the server. |
| 149 // ONLY CALL THIS IF OnInitializationComplete was called! | 146 // ONLY CALL THIS IF OnInitializationComplete was called! |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 | 189 |
| 193 // See SyncManager::ClearServerData. | 190 // See SyncManager::ClearServerData. |
| 194 virtual void ClearServerData( | 191 virtual void ClearServerData( |
| 195 const SyncManager::ClearServerDataCallback& callback) = 0; | 192 const SyncManager::ClearServerDataCallback& callback) = 0; |
| 196 | 193 |
| 197 // Notify the syncer that the cookie jar has changed. | 194 // Notify the syncer that the cookie jar has changed. |
| 198 // See SyncManager::OnCookieJarChanged. | 195 // See SyncManager::OnCookieJarChanged. |
| 199 virtual void OnCookieJarChanged(bool account_mismatch, bool empty_jar) = 0; | 196 virtual void OnCookieJarChanged(bool account_mismatch, bool empty_jar) = 0; |
| 200 | 197 |
| 201 private: | 198 private: |
| 202 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 199 DISALLOW_COPY_AND_ASSIGN(SyncEngine); |
| 203 }; | 200 }; |
| 204 | 201 |
| 205 } // namespace syncer | 202 } // namespace syncer |
| 206 | 203 |
| 207 #endif // COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_H_ | 204 #endif // COMPONENTS_SYNC_ENGINE_SYNC_ENGINE_H_ |
| OLD | NEW |