| 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_DRIVER_GLUE_SYNC_BACKEND_HOST_H_ |
| 6 #define COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_H_ | 6 #define COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_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/threading/thread.h" | 14 #include "base/threading/thread.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/core/configure_reason.h" | 17 #include "components/sync/core/configure_reason.h" |
| 18 #include "components/sync/core/shutdown_reason.h" | 18 #include "components/sync/core/shutdown_reason.h" |
| 19 #include "components/sync/core/sync_manager.h" | 19 #include "components/sync/core/sync_manager.h" |
| 20 #include "components/sync/core/sync_manager_factory.h" | 20 #include "components/sync/core/sync_manager_factory.h" |
| 21 #include "components/sync/driver/backend_data_type_configurer.h" | 21 #include "components/sync/driver/backend_data_type_configurer.h" |
| 22 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" | 22 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" |
| 23 | 23 |
| 24 class GURL; | 24 class GURL; |
| 25 | 25 |
| 26 namespace base { | 26 namespace base { |
| 27 class MessageLoop; | 27 class MessageLoop; |
| 28 } | 28 } // namespace base |
| 29 | 29 |
| 30 namespace syncer { | 30 namespace syncer { |
| 31 |
| 31 class CancelationSignal; | 32 class CancelationSignal; |
| 33 class ChangeProcessor; |
| 32 class HttpPostProviderFactory; | 34 class HttpPostProviderFactory; |
| 35 class SyncFrontend; |
| 33 class SyncManagerFactory; | 36 class SyncManagerFactory; |
| 34 class UnrecoverableErrorHandler; | 37 class UnrecoverableErrorHandler; |
| 35 } | |
| 36 | |
| 37 namespace sync_driver { | |
| 38 class ChangeProcessor; | |
| 39 class SyncFrontend; | |
| 40 } | |
| 41 | |
| 42 namespace browser_sync { | |
| 43 | 38 |
| 44 // An API to "host" the top level SyncAPI element. | 39 // An API to "host" the top level SyncAPI element. |
| 45 // | 40 // |
| 46 // This class handles dispatch of potentially blocking calls to appropriate | 41 // This class handles dispatch of potentially blocking calls to appropriate |
| 47 // threads and ensures that the SyncFrontend is only accessed on the UI loop. | 42 // threads and ensures that the SyncFrontend is only accessed on the UI loop. |
| 48 class SyncBackendHost : public sync_driver::BackendDataTypeConfigurer { | 43 class SyncBackendHost : public BackendDataTypeConfigurer { |
| 49 public: | 44 public: |
| 50 typedef syncer::SyncStatus Status; | 45 typedef SyncStatus Status; |
| 51 typedef base::Callback<std::unique_ptr<syncer::HttpPostProviderFactory>( | 46 typedef base::Callback<std::unique_ptr<HttpPostProviderFactory>( |
| 52 syncer::CancelationSignal*)> | 47 CancelationSignal*)> |
| 53 HttpPostProviderFactoryGetter; | 48 HttpPostProviderFactoryGetter; |
| 54 | 49 |
| 55 // Stubs used by implementing classes. | 50 // Stubs used by implementing classes. |
| 56 SyncBackendHost(); | 51 SyncBackendHost(); |
| 57 ~SyncBackendHost() override; | 52 ~SyncBackendHost() override; |
| 58 | 53 |
| 59 // Called on the frontend's thread to kick off asynchronous initialization. | 54 // Called on the frontend's thread to kick off asynchronous initialization. |
| 60 // Optionally deletes the "Sync Data" folder during init in order to make | 55 // Optionally deletes the "Sync Data" folder during init in order to make |
| 61 // sure we're starting fresh. | 56 // sure we're starting fresh. |
| 62 // | 57 // |
| 63 // |saved_nigori_state| is optional nigori state to restore from a previous | 58 // |saved_nigori_state| is optional nigori state to restore from a previous |
| 64 // backend instance. May be null. | 59 // backend instance. May be null. |
| 65 virtual void Initialize( | 60 virtual void Initialize( |
| 66 sync_driver::SyncFrontend* frontend, | 61 SyncFrontend* frontend, |
| 67 std::unique_ptr<base::Thread> sync_thread, | 62 std::unique_ptr<base::Thread> sync_thread, |
| 68 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, | 63 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, |
| 69 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, | 64 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, |
| 70 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 65 const WeakHandle<JsEventHandler>& event_handler, |
| 71 const GURL& service_url, | 66 const GURL& service_url, |
| 72 const std::string& sync_user_agent, | 67 const std::string& sync_user_agent, |
| 73 const syncer::SyncCredentials& credentials, | 68 const SyncCredentials& credentials, |
| 74 bool delete_sync_data_folder, | 69 bool delete_sync_data_folder, |
| 75 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory, | 70 std::unique_ptr<SyncManagerFactory> sync_manager_factory, |
| 76 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>& | 71 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, |
| 77 unrecoverable_error_handler, | |
| 78 const base::Closure& report_unrecoverable_error_function, | 72 const base::Closure& report_unrecoverable_error_function, |
| 79 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, | 73 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, |
| 80 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> | 74 std::unique_ptr<SyncEncryptionHandler::NigoriState> |
| 81 saved_nigori_state) = 0; | 75 saved_nigori_state) = 0; |
| 82 | 76 |
| 83 // Called on the frontend's thread to trigger a refresh. | 77 // Called on the frontend's thread to trigger a refresh. |
| 84 virtual void TriggerRefresh(const syncer::ModelTypeSet& types) = 0; | 78 virtual void TriggerRefresh(const ModelTypeSet& types) = 0; |
| 85 | 79 |
| 86 // Called on the frontend's thread to update SyncCredentials. | 80 // Called on the frontend's thread to update SyncCredentials. |
| 87 virtual void UpdateCredentials( | 81 virtual void UpdateCredentials(const SyncCredentials& credentials) = 0; |
| 88 const syncer::SyncCredentials& credentials) = 0; | |
| 89 | 82 |
| 90 // This starts the SyncerThread running a Syncer object to communicate with | 83 // This starts the SyncerThread running a Syncer object to communicate with |
| 91 // sync servers. Until this is called, no changes will leave or enter this | 84 // sync servers. Until this is called, no changes will leave or enter this |
| 92 // browser from the cloud / sync servers. | 85 // browser from the cloud / sync servers. |
| 93 // Called on |frontend_loop_|. | 86 // Called on |frontend_loop_|. |
| 94 virtual void StartSyncingWithServer() = 0; | 87 virtual void StartSyncingWithServer() = 0; |
| 95 | 88 |
| 96 // Called on |frontend_loop_| to asynchronously set a new passphrase for | 89 // Called on |frontend_loop_| to asynchronously set a new passphrase for |
| 97 // encryption. Note that it is an error to call SetEncryptionPassphrase under | 90 // encryption. Note that it is an error to call SetEncryptionPassphrase under |
| 98 // the following circumstances: | 91 // the following circumstances: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 125 // See the implementation and Core::DoShutdown for details. | 118 // See the implementation and Core::DoShutdown for details. |
| 126 // Must be called *after* StopSyncingForShutdown. | 119 // Must be called *after* StopSyncingForShutdown. |
| 127 // For any reason other than BROWSER_SHUTDOWN, caller should claim sync | 120 // For any reason other than BROWSER_SHUTDOWN, caller should claim sync |
| 128 // thread because: | 121 // thread because: |
| 129 // * during browser shutdown sync thread is not claimed to avoid blocking | 122 // * during browser shutdown sync thread is not claimed to avoid blocking |
| 130 // browser shutdown on sync shutdown. | 123 // browser shutdown on sync shutdown. |
| 131 // * otherwise sync thread is claimed so that if sync backend is recreated | 124 // * otherwise sync thread is claimed so that if sync backend is recreated |
| 132 // later, initialization of new backend is serialized on previous sync | 125 // later, initialization of new backend is serialized on previous sync |
| 133 // thread after cleanup of previous backend to avoid old/new backends | 126 // thread after cleanup of previous backend to avoid old/new backends |
| 134 // interfere with each other. | 127 // interfere with each other. |
| 135 virtual std::unique_ptr<base::Thread> Shutdown( | 128 virtual std::unique_ptr<base::Thread> Shutdown(ShutdownReason reason) = 0; |
| 136 syncer::ShutdownReason reason) = 0; | |
| 137 | 129 |
| 138 // Removes all current registrations from the backend on the | 130 // Removes all current registrations from the backend on the |
| 139 // InvalidationService. | 131 // InvalidationService. |
| 140 virtual void UnregisterInvalidationIds() = 0; | 132 virtual void UnregisterInvalidationIds() = 0; |
| 141 | 133 |
| 142 // Changes the set of data types that are currently being synced. | 134 // Changes the set of data types that are currently being synced. |
| 143 // The ready_task will be run when configuration is done with the | 135 // The ready_task will be run when configuration is done with the |
| 144 // set of all types that failed configuration (i.e., if its argument | 136 // set of all types that failed configuration (i.e., if its argument |
| 145 // is non-empty, then an error was encountered). | 137 // is non-empty, then an error was encountered). |
| 146 // Returns the set of types that are ready to start without needing any | 138 // Returns the set of types that are ready to start without needing any |
| 147 // further sync activity. | 139 // further sync activity. |
| 148 // BackendDataTypeConfigurer implementation. | 140 // BackendDataTypeConfigurer implementation. |
| 149 syncer::ModelTypeSet ConfigureDataTypes( | 141 ModelTypeSet ConfigureDataTypes( |
| 150 syncer::ConfigureReason reason, | 142 ConfigureReason reason, |
| 151 const DataTypeConfigStateMap& config_state_map, | 143 const DataTypeConfigStateMap& config_state_map, |
| 152 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& | 144 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task, |
| 153 ready_task, | |
| 154 const base::Callback<void()>& retry_callback) override = 0; | 145 const base::Callback<void()>& retry_callback) override = 0; |
| 155 | 146 |
| 156 // Turns on encryption of all present and future sync data. | 147 // Turns on encryption of all present and future sync data. |
| 157 virtual void EnableEncryptEverything() = 0; | 148 virtual void EnableEncryptEverything() = 0; |
| 158 | 149 |
| 159 // Called on |frontend_loop_| to obtain a handle to the UserShare needed for | 150 // Called on |frontend_loop_| to obtain a handle to the UserShare needed for |
| 160 // creating transactions. Should not be called before we signal | 151 // creating transactions. Should not be called before we signal |
| 161 // initialization is complete with OnBackendInitialized(). | 152 // initialization is complete with OnBackendInitialized(). |
| 162 virtual syncer::UserShare* GetUserShare() const = 0; | 153 virtual UserShare* GetUserShare() const = 0; |
| 163 | 154 |
| 164 // Called from any thread to obtain current status information in detailed or | 155 // Called from any thread to obtain current status information in detailed or |
| 165 // summarized form. | 156 // summarized form. |
| 166 virtual Status GetDetailedStatus() = 0; | 157 virtual Status GetDetailedStatus() = 0; |
| 167 virtual syncer::SyncCycleSnapshot GetLastCycleSnapshot() const = 0; | 158 virtual SyncCycleSnapshot GetLastCycleSnapshot() const = 0; |
| 168 | 159 |
| 169 // Determines if the underlying sync engine has made any local changes to | 160 // Determines if the underlying sync engine has made any local changes to |
| 170 // items that have not yet been synced with the server. | 161 // items that have not yet been synced with the server. |
| 171 // ONLY CALL THIS IF OnInitializationComplete was called! | 162 // ONLY CALL THIS IF OnInitializationComplete was called! |
| 172 virtual bool HasUnsyncedItems() const = 0; | 163 virtual bool HasUnsyncedItems() const = 0; |
| 173 | 164 |
| 174 // Whether or not we are syncing encryption keys. | 165 // Whether or not we are syncing encryption keys. |
| 175 virtual bool IsNigoriEnabled() const = 0; | 166 virtual bool IsNigoriEnabled() const = 0; |
| 176 | 167 |
| 177 // Returns the type of passphrase being used to encrypt data. See | 168 // Returns the type of passphrase being used to encrypt data. See |
| 178 // sync_encryption_handler.h. | 169 // sync_encryption_handler.h. |
| 179 virtual syncer::PassphraseType GetPassphraseType() const = 0; | 170 virtual PassphraseType GetPassphraseType() const = 0; |
| 180 | 171 |
| 181 // If an explicit passphrase is in use, returns the time at which that | 172 // If an explicit passphrase is in use, returns the time at which that |
| 182 // passphrase was set (if available). | 173 // passphrase was set (if available). |
| 183 virtual base::Time GetExplicitPassphraseTime() const = 0; | 174 virtual base::Time GetExplicitPassphraseTime() const = 0; |
| 184 | 175 |
| 185 // True if the cryptographer has any keys available to attempt decryption. | 176 // True if the cryptographer has any keys available to attempt decryption. |
| 186 // Could mean we've downloaded and loaded Nigori objects, or we bootstrapped | 177 // Could mean we've downloaded and loaded Nigori objects, or we bootstrapped |
| 187 // using a token previously received. | 178 // using a token previously received. |
| 188 virtual bool IsCryptographerReady( | 179 virtual bool IsCryptographerReady(const BaseTransaction* trans) const = 0; |
| 189 const syncer::BaseTransaction* trans) const = 0; | |
| 190 | 180 |
| 191 virtual void GetModelSafeRoutingInfo( | 181 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) const = 0; |
| 192 syncer::ModelSafeRoutingInfo* out) const = 0; | |
| 193 | 182 |
| 194 // Send a message to the sync thread to persist the Directory to disk. | 183 // Send a message to the sync thread to persist the Directory to disk. |
| 195 virtual void FlushDirectory() const = 0; | 184 virtual void FlushDirectory() const = 0; |
| 196 | 185 |
| 197 // Requests that the backend forward to the fronent any protocol events in | 186 // Requests that the backend forward to the fronent any protocol events in |
| 198 // its buffer and begin forwarding automatically from now on. Repeated calls | 187 // its buffer and begin forwarding automatically from now on. Repeated calls |
| 199 // to this function may result in the same events being emitted several | 188 // to this function may result in the same events being emitted several |
| 200 // times. | 189 // times. |
| 201 virtual void RequestBufferedProtocolEventsAndEnableForwarding() = 0; | 190 virtual void RequestBufferedProtocolEventsAndEnableForwarding() = 0; |
| 202 | 191 |
| 203 // Disables protocol event forwarding. | 192 // Disables protocol event forwarding. |
| 204 virtual void DisableProtocolEventForwarding() = 0; | 193 virtual void DisableProtocolEventForwarding() = 0; |
| 205 | 194 |
| 206 // Enables the sending of directory type debug counters. Also, for every | 195 // Enables the sending of directory type debug counters. Also, for every |
| 207 // time it is called, it makes an explicit request that updates to an update | 196 // time it is called, it makes an explicit request that updates to an update |
| 208 // for all counters be emitted. | 197 // for all counters be emitted. |
| 209 virtual void EnableDirectoryTypeDebugInfoForwarding() = 0; | 198 virtual void EnableDirectoryTypeDebugInfoForwarding() = 0; |
| 210 | 199 |
| 211 // Disables the sending of directory type debug counters. | 200 // Disables the sending of directory type debug counters. |
| 212 virtual void DisableDirectoryTypeDebugInfoForwarding() = 0; | 201 virtual void DisableDirectoryTypeDebugInfoForwarding() = 0; |
| 213 | 202 |
| 214 virtual base::MessageLoop* GetSyncLoopForTesting() = 0; | 203 virtual base::MessageLoop* GetSyncLoopForTesting() = 0; |
| 215 | 204 |
| 216 // Triggers sync cycle to update |types|. | 205 // Triggers sync cycle to update |types|. |
| 217 virtual void RefreshTypesForTest(syncer::ModelTypeSet types) = 0; | 206 virtual void RefreshTypesForTest(ModelTypeSet types) = 0; |
| 218 | 207 |
| 219 // See SyncManager::ClearServerData. | 208 // See SyncManager::ClearServerData. |
| 220 virtual void ClearServerData( | 209 virtual void ClearServerData( |
| 221 const syncer::SyncManager::ClearServerDataCallback& callback) = 0; | 210 const SyncManager::ClearServerDataCallback& callback) = 0; |
| 222 | 211 |
| 223 // Notify the syncer that the cookie jar has changed. | 212 // Notify the syncer that the cookie jar has changed. |
| 224 // See SyncManager::OnCookieJarChanged. | 213 // See SyncManager::OnCookieJarChanged. |
| 225 virtual void OnCookieJarChanged(bool account_mismatch, bool empty_jar) = 0; | 214 virtual void OnCookieJarChanged(bool account_mismatch, bool empty_jar) = 0; |
| 226 | 215 |
| 227 private: | 216 private: |
| 228 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 217 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
| 229 }; | 218 }; |
| 230 | 219 |
| 231 } // namespace browser_sync | 220 } // namespace syncer |
| 232 | 221 |
| 233 #endif // COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_H_ | 222 #endif // COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_H_ |
| OLD | NEW |