| 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 "components/sync/driver/glue/sync_backend_host_impl.h" | 5 #include "components/sync/driver/glue/sync_backend_host_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "components/sync/engine/events/protocol_event.h" | 31 #include "components/sync/engine/events/protocol_event.h" |
| 32 #include "components/sync/engine/sync_string_conversions.h" | 32 #include "components/sync/engine/sync_string_conversions.h" |
| 33 | 33 |
| 34 // Helper macros to log with the syncer thread name; useful when there | 34 // Helper macros to log with the syncer thread name; useful when there |
| 35 // are multiple syncers involved. | 35 // are multiple syncers involved. |
| 36 | 36 |
| 37 #define SLOG(severity) LOG(severity) << name_ << ": " | 37 #define SLOG(severity) LOG(severity) << name_ << ": " |
| 38 | 38 |
| 39 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " | 39 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " |
| 40 | 40 |
| 41 namespace syncer { | 41 using syncer::InternalComponentsFactory; |
| 42 |
| 43 namespace browser_sync { |
| 42 | 44 |
| 43 SyncBackendHostImpl::SyncBackendHostImpl( | 45 SyncBackendHostImpl::SyncBackendHostImpl( |
| 44 const std::string& name, | 46 const std::string& name, |
| 45 SyncClient* sync_client, | 47 sync_driver::SyncClient* sync_client, |
| 46 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, | 48 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, |
| 47 invalidation::InvalidationService* invalidator, | 49 invalidation::InvalidationService* invalidator, |
| 48 const base::WeakPtr<SyncPrefs>& sync_prefs, | 50 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, |
| 49 const base::FilePath& sync_folder) | 51 const base::FilePath& sync_folder) |
| 50 : frontend_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 52 : frontend_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 51 sync_client_(sync_client), | 53 sync_client_(sync_client), |
| 52 ui_thread_(ui_thread), | 54 ui_thread_(ui_thread), |
| 53 name_(name), | 55 name_(name), |
| 54 initialized_(false), | 56 initialized_(false), |
| 55 sync_prefs_(sync_prefs), | 57 sync_prefs_(sync_prefs), |
| 56 frontend_(NULL), | 58 frontend_(NULL), |
| 57 cached_passphrase_type_(PassphraseType::IMPLICIT_PASSPHRASE), | 59 cached_passphrase_type_(syncer::PassphraseType::IMPLICIT_PASSPHRASE), |
| 58 invalidator_(invalidator), | 60 invalidator_(invalidator), |
| 59 invalidation_handler_registered_(false), | 61 invalidation_handler_registered_(false), |
| 60 weak_ptr_factory_(this) { | 62 weak_ptr_factory_(this) { |
| 61 core_ = new SyncBackendHostCore(name_, sync_folder, | 63 core_ = new SyncBackendHostCore(name_, sync_folder, |
| 62 sync_prefs_->IsFirstSetupComplete(), | 64 sync_prefs_->IsFirstSetupComplete(), |
| 63 weak_ptr_factory_.GetWeakPtr()); | 65 weak_ptr_factory_.GetWeakPtr()); |
| 64 } | 66 } |
| 65 | 67 |
| 66 SyncBackendHostImpl::~SyncBackendHostImpl() { | 68 SyncBackendHostImpl::~SyncBackendHostImpl() { |
| 67 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; | 69 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; |
| 68 DCHECK(!registrar_.get()); | 70 DCHECK(!registrar_.get()); |
| 69 } | 71 } |
| 70 | 72 |
| 71 void SyncBackendHostImpl::Initialize( | 73 void SyncBackendHostImpl::Initialize( |
| 72 SyncFrontend* frontend, | 74 sync_driver::SyncFrontend* frontend, |
| 73 std::unique_ptr<base::Thread> sync_thread, | 75 std::unique_ptr<base::Thread> sync_thread, |
| 74 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, | 76 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, |
| 75 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, | 77 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, |
| 76 const WeakHandle<JsEventHandler>& event_handler, | 78 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
| 77 const GURL& sync_service_url, | 79 const GURL& sync_service_url, |
| 78 const std::string& sync_user_agent, | 80 const std::string& sync_user_agent, |
| 79 const SyncCredentials& credentials, | 81 const syncer::SyncCredentials& credentials, |
| 80 bool delete_sync_data_folder, | 82 bool delete_sync_data_folder, |
| 81 std::unique_ptr<SyncManagerFactory> sync_manager_factory, | 83 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory, |
| 82 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, | 84 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>& |
| 85 unrecoverable_error_handler, |
| 83 const base::Closure& report_unrecoverable_error_function, | 86 const base::Closure& report_unrecoverable_error_function, |
| 84 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, | 87 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, |
| 85 std::unique_ptr<SyncEncryptionHandler::NigoriState> saved_nigori_state) { | 88 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> |
| 86 registrar_.reset(new SyncBackendRegistrar(name_, sync_client_, | 89 saved_nigori_state) { |
| 87 std::move(sync_thread), ui_thread_, | 90 registrar_.reset(new browser_sync::SyncBackendRegistrar( |
| 88 db_thread, file_thread)); | 91 name_, sync_client_, std::move(sync_thread), ui_thread_, db_thread, |
| 92 file_thread)); |
| 89 CHECK(registrar_->sync_thread()); | 93 CHECK(registrar_->sync_thread()); |
| 90 | 94 |
| 91 frontend_ = frontend; | 95 frontend_ = frontend; |
| 92 DCHECK(frontend); | 96 DCHECK(frontend); |
| 93 | 97 |
| 94 std::vector<scoped_refptr<ModelSafeWorker>> workers; | 98 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers; |
| 95 registrar_->GetWorkers(&workers); | 99 registrar_->GetWorkers(&workers); |
| 96 | 100 |
| 97 InternalComponentsFactory::Switches factory_switches = { | 101 InternalComponentsFactory::Switches factory_switches = { |
| 98 InternalComponentsFactory::ENCRYPTION_KEYSTORE, | 102 InternalComponentsFactory::ENCRYPTION_KEYSTORE, |
| 99 InternalComponentsFactory::BACKOFF_NORMAL}; | 103 InternalComponentsFactory::BACKOFF_NORMAL}; |
| 100 | 104 |
| 101 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); | 105 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
| 102 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { | 106 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { |
| 103 factory_switches.backoff_override = | 107 factory_switches.backoff_override = |
| 104 InternalComponentsFactory::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; | 108 InternalComponentsFactory::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; |
| 105 } | 109 } |
| 106 if (cl->HasSwitch(switches::kSyncEnableGetUpdateAvoidance)) { | 110 if (cl->HasSwitch(switches::kSyncEnableGetUpdateAvoidance)) { |
| 107 factory_switches.pre_commit_updates_policy = | 111 factory_switches.pre_commit_updates_policy = |
| 108 InternalComponentsFactory::FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE; | 112 InternalComponentsFactory::FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE; |
| 109 } | 113 } |
| 110 | 114 |
| 111 std::map<ModelType, int64_t> invalidation_versions; | 115 std::map<syncer::ModelType, int64_t> invalidation_versions; |
| 112 sync_prefs_->GetInvalidationVersions(&invalidation_versions); | 116 sync_prefs_->GetInvalidationVersions(&invalidation_versions); |
| 113 | 117 |
| 114 std::unique_ptr<DoInitializeOptions> init_opts(new DoInitializeOptions( | 118 std::unique_ptr<DoInitializeOptions> init_opts(new DoInitializeOptions( |
| 115 registrar_->sync_thread()->message_loop(), registrar_.get(), workers, | 119 registrar_->sync_thread()->message_loop(), registrar_.get(), workers, |
| 116 sync_client_->GetExtensionsActivity(), event_handler, sync_service_url, | 120 sync_client_->GetExtensionsActivity(), event_handler, sync_service_url, |
| 117 sync_user_agent, http_post_provider_factory_getter.Run( | 121 sync_user_agent, http_post_provider_factory_getter.Run( |
| 118 core_->GetRequestContextCancelationSignal()), | 122 core_->GetRequestContextCancelationSignal()), |
| 119 credentials, invalidator_ ? invalidator_->GetInvalidatorClientId() : "", | 123 credentials, invalidator_ ? invalidator_->GetInvalidatorClientId() : "", |
| 120 std::move(sync_manager_factory), delete_sync_data_folder, | 124 std::move(sync_manager_factory), delete_sync_data_folder, |
| 121 sync_prefs_->GetEncryptionBootstrapToken(), | 125 sync_prefs_->GetEncryptionBootstrapToken(), |
| 122 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), | 126 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), |
| 123 std::unique_ptr<InternalComponentsFactory>( | 127 std::unique_ptr<InternalComponentsFactory>( |
| 124 new InternalComponentsFactoryImpl(factory_switches)), | 128 new syncer::InternalComponentsFactoryImpl(factory_switches)), |
| 125 unrecoverable_error_handler, report_unrecoverable_error_function, | 129 unrecoverable_error_handler, report_unrecoverable_error_function, |
| 126 std::move(saved_nigori_state), invalidation_versions)); | 130 std::move(saved_nigori_state), invalidation_versions)); |
| 127 InitCore(std::move(init_opts)); | 131 InitCore(std::move(init_opts)); |
| 128 } | 132 } |
| 129 | 133 |
| 130 void SyncBackendHostImpl::TriggerRefresh(const ModelTypeSet& types) { | 134 void SyncBackendHostImpl::TriggerRefresh(const syncer::ModelTypeSet& types) { |
| 131 DCHECK(ui_thread_->BelongsToCurrentThread()); | 135 DCHECK(ui_thread_->BelongsToCurrentThread()); |
| 132 registrar_->sync_thread()->task_runner()->PostTask( | 136 registrar_->sync_thread()->task_runner()->PostTask( |
| 133 FROM_HERE, | 137 FROM_HERE, |
| 134 base::Bind(&SyncBackendHostCore::DoRefreshTypes, core_, types)); | 138 base::Bind(&SyncBackendHostCore::DoRefreshTypes, core_, types)); |
| 135 } | 139 } |
| 136 | 140 |
| 137 void SyncBackendHostImpl::UpdateCredentials( | 141 void SyncBackendHostImpl::UpdateCredentials( |
| 138 const SyncCredentials& credentials) { | 142 const syncer::SyncCredentials& credentials) { |
| 139 DCHECK(registrar_->sync_thread()->IsRunning()); | 143 DCHECK(registrar_->sync_thread()->IsRunning()); |
| 140 registrar_->sync_thread()->task_runner()->PostTask( | 144 registrar_->sync_thread()->task_runner()->PostTask( |
| 141 FROM_HERE, base::Bind(&SyncBackendHostCore::DoUpdateCredentials, | 145 FROM_HERE, base::Bind(&SyncBackendHostCore::DoUpdateCredentials, |
| 142 core_, credentials)); | 146 core_, credentials)); |
| 143 } | 147 } |
| 144 | 148 |
| 145 void SyncBackendHostImpl::StartSyncingWithServer() { | 149 void SyncBackendHostImpl::StartSyncingWithServer() { |
| 146 SDVLOG(1) << "SyncBackendHostImpl::StartSyncingWithServer called."; | 150 SDVLOG(1) << "SyncBackendHostImpl::StartSyncingWithServer called."; |
| 147 | 151 |
| 148 ModelSafeRoutingInfo routing_info; | 152 syncer::ModelSafeRoutingInfo routing_info; |
| 149 registrar_->GetModelSafeRoutingInfo(&routing_info); | 153 registrar_->GetModelSafeRoutingInfo(&routing_info); |
| 150 | 154 |
| 151 registrar_->sync_thread()->task_runner()->PostTask( | 155 registrar_->sync_thread()->task_runner()->PostTask( |
| 152 FROM_HERE, base::Bind(&SyncBackendHostCore::DoStartSyncing, core_, | 156 FROM_HERE, base::Bind(&SyncBackendHostCore::DoStartSyncing, core_, |
| 153 routing_info, sync_prefs_->GetLastPollTime())); | 157 routing_info, sync_prefs_->GetLastPollTime())); |
| 154 } | 158 } |
| 155 | 159 |
| 156 void SyncBackendHostImpl::SetEncryptionPassphrase(const std::string& passphrase, | 160 void SyncBackendHostImpl::SetEncryptionPassphrase(const std::string& passphrase, |
| 157 bool is_explicit) { | 161 bool is_explicit) { |
| 158 DCHECK(registrar_->sync_thread()->IsRunning()); | 162 DCHECK(registrar_->sync_thread()->IsRunning()); |
| 159 if (!IsNigoriEnabled()) { | 163 if (!IsNigoriEnabled()) { |
| 160 NOTREACHED() << "SetEncryptionPassphrase must never be called when nigori" | 164 NOTREACHED() << "SetEncryptionPassphrase must never be called when nigori" |
| 161 " is disabled."; | 165 " is disabled."; |
| 162 return; | 166 return; |
| 163 } | 167 } |
| 164 | 168 |
| 165 // We should never be called with an empty passphrase. | 169 // We should never be called with an empty passphrase. |
| 166 DCHECK(!passphrase.empty()); | 170 DCHECK(!passphrase.empty()); |
| 167 | 171 |
| 168 // This should only be called by the frontend. | 172 // This should only be called by the frontend. |
| 169 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 173 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
| 170 | 174 |
| 171 // SetEncryptionPassphrase should never be called if we are currently | 175 // SetEncryptionPassphrase should never be called if we are currently |
| 172 // encrypted with an explicit passphrase. | 176 // encrypted with an explicit passphrase. |
| 173 DCHECK(cached_passphrase_type_ == PassphraseType::KEYSTORE_PASSPHRASE || | 177 DCHECK( |
| 174 cached_passphrase_type_ == PassphraseType::IMPLICIT_PASSPHRASE); | 178 cached_passphrase_type_ == syncer::PassphraseType::KEYSTORE_PASSPHRASE || |
| 179 cached_passphrase_type_ == syncer::PassphraseType::IMPLICIT_PASSPHRASE); |
| 175 | 180 |
| 176 // Post an encryption task on the syncer thread. | 181 // Post an encryption task on the syncer thread. |
| 177 registrar_->sync_thread()->task_runner()->PostTask( | 182 registrar_->sync_thread()->task_runner()->PostTask( |
| 178 FROM_HERE, base::Bind(&SyncBackendHostCore::DoSetEncryptionPassphrase, | 183 FROM_HERE, base::Bind(&SyncBackendHostCore::DoSetEncryptionPassphrase, |
| 179 core_, passphrase, is_explicit)); | 184 core_, passphrase, is_explicit)); |
| 180 } | 185 } |
| 181 | 186 |
| 182 bool SyncBackendHostImpl::SetDecryptionPassphrase( | 187 bool SyncBackendHostImpl::SetDecryptionPassphrase( |
| 183 const std::string& passphrase) { | 188 const std::string& passphrase) { |
| 184 if (!IsNigoriEnabled()) { | 189 if (!IsNigoriEnabled()) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 frontend_ = NULL; | 232 frontend_ = NULL; |
| 228 | 233 |
| 229 DCHECK(registrar_->sync_thread()->IsRunning()); | 234 DCHECK(registrar_->sync_thread()->IsRunning()); |
| 230 | 235 |
| 231 registrar_->RequestWorkerStopOnUIThread(); | 236 registrar_->RequestWorkerStopOnUIThread(); |
| 232 | 237 |
| 233 core_->ShutdownOnUIThread(); | 238 core_->ShutdownOnUIThread(); |
| 234 } | 239 } |
| 235 | 240 |
| 236 std::unique_ptr<base::Thread> SyncBackendHostImpl::Shutdown( | 241 std::unique_ptr<base::Thread> SyncBackendHostImpl::Shutdown( |
| 237 ShutdownReason reason) { | 242 syncer::ShutdownReason reason) { |
| 238 // StopSyncingForShutdown() (which nulls out |frontend_|) should be | 243 // StopSyncingForShutdown() (which nulls out |frontend_|) should be |
| 239 // called first. | 244 // called first. |
| 240 DCHECK(!frontend_); | 245 DCHECK(!frontend_); |
| 241 DCHECK(registrar_->sync_thread()->IsRunning()); | 246 DCHECK(registrar_->sync_thread()->IsRunning()); |
| 242 | 247 |
| 243 bool sync_thread_claimed = (reason != BROWSER_SHUTDOWN); | 248 bool sync_thread_claimed = (reason != syncer::BROWSER_SHUTDOWN); |
| 244 | 249 |
| 245 if (invalidation_handler_registered_) { | 250 if (invalidation_handler_registered_) { |
| 246 if (reason == DISABLE_SYNC) { | 251 if (reason == syncer::DISABLE_SYNC) { |
| 247 UnregisterInvalidationIds(); | 252 UnregisterInvalidationIds(); |
| 248 } | 253 } |
| 249 invalidator_->UnregisterInvalidationHandler(this); | 254 invalidator_->UnregisterInvalidationHandler(this); |
| 250 invalidator_ = NULL; | 255 invalidator_ = NULL; |
| 251 } | 256 } |
| 252 invalidation_handler_registered_ = false; | 257 invalidation_handler_registered_ = false; |
| 253 | 258 |
| 254 model_type_connector_.reset(); | 259 model_type_connector_.reset(); |
| 255 | 260 |
| 256 // Shut down and destroy sync manager. | 261 // Shut down and destroy sync manager. |
| 257 registrar_->sync_thread()->task_runner()->PostTask( | 262 registrar_->sync_thread()->task_runner()->PostTask( |
| 258 FROM_HERE, | 263 FROM_HERE, |
| 259 base::Bind(&SyncBackendHostCore::DoShutdown, core_, reason)); | 264 base::Bind(&SyncBackendHostCore::DoShutdown, core_, reason)); |
| 260 core_ = NULL; | 265 core_ = NULL; |
| 261 | 266 |
| 262 // Worker cleanup. | 267 // Worker cleanup. |
| 263 SyncBackendRegistrar* detached_registrar = registrar_.release(); | 268 SyncBackendRegistrar* detached_registrar = registrar_.release(); |
| 264 detached_registrar->sync_thread()->task_runner()->PostTask( | 269 detached_registrar->sync_thread()->task_runner()->PostTask( |
| 265 FROM_HERE, base::Bind(&SyncBackendRegistrar::Shutdown, | 270 FROM_HERE, base::Bind(&SyncBackendRegistrar::Shutdown, |
| 266 base::Unretained(detached_registrar))); | 271 base::Unretained(detached_registrar))); |
| 267 | 272 |
| 268 if (sync_thread_claimed) | 273 if (sync_thread_claimed) |
| 269 return detached_registrar->ReleaseSyncThread(); | 274 return detached_registrar->ReleaseSyncThread(); |
| 270 else | 275 else |
| 271 return std::unique_ptr<base::Thread>(); | 276 return std::unique_ptr<base::Thread>(); |
| 272 } | 277 } |
| 273 | 278 |
| 274 void SyncBackendHostImpl::UnregisterInvalidationIds() { | 279 void SyncBackendHostImpl::UnregisterInvalidationIds() { |
| 275 if (invalidation_handler_registered_) { | 280 if (invalidation_handler_registered_) { |
| 276 CHECK(invalidator_->UpdateRegisteredInvalidationIds(this, ObjectIdSet())); | 281 CHECK(invalidator_->UpdateRegisteredInvalidationIds(this, |
| 282 syncer::ObjectIdSet())); |
| 277 } | 283 } |
| 278 } | 284 } |
| 279 | 285 |
| 280 ModelTypeSet SyncBackendHostImpl::ConfigureDataTypes( | 286 syncer::ModelTypeSet SyncBackendHostImpl::ConfigureDataTypes( |
| 281 ConfigureReason reason, | 287 syncer::ConfigureReason reason, |
| 282 const DataTypeConfigStateMap& config_state_map, | 288 const DataTypeConfigStateMap& config_state_map, |
| 283 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task, | 289 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& |
| 290 ready_task, |
| 284 const base::Callback<void()>& retry_callback) { | 291 const base::Callback<void()>& retry_callback) { |
| 285 // Only one configure is allowed at a time. This is guaranteed by our | 292 // Only one configure is allowed at a time. This is guaranteed by our |
| 286 // callers. The SyncBackendHostImpl requests one configure as the backend is | 293 // callers. The SyncBackendHostImpl requests one configure as the backend is |
| 287 // initializing and waits for it to complete. After initialization, all | 294 // initializing and waits for it to complete. After initialization, all |
| 288 // configurations will pass through the DataTypeManager, which is careful to | 295 // configurations will pass through the DataTypeManager, which is careful to |
| 289 // never send a new configure request until the current request succeeds. | 296 // never send a new configure request until the current request succeeds. |
| 290 | 297 |
| 291 // The SyncBackendRegistrar's routing info will be updated by adding the | 298 // The SyncBackendRegistrar's routing info will be updated by adding the |
| 292 // types_to_add to the list then removing types_to_remove. Any types which | 299 // types_to_add to the list then removing types_to_remove. Any types which |
| 293 // are not in either of those sets will remain untouched. | 300 // are not in either of those sets will remain untouched. |
| 294 // | 301 // |
| 295 // Types which were not in the list previously are not fully downloaded, so we | 302 // Types which were not in the list previously are not fully downloaded, so we |
| 296 // must ask the syncer to download them. Any newly supported datatypes will | 303 // must ask the syncer to download them. Any newly supported datatypes will |
| 297 // not have been in that routing info list, so they will be among the types | 304 // not have been in that routing info list, so they will be among the types |
| 298 // downloaded if they are enabled. | 305 // downloaded if they are enabled. |
| 299 // | 306 // |
| 300 // The SyncBackendRegistrar's state was initially derived from the types | 307 // The SyncBackendRegistrar's state was initially derived from the types |
| 301 // detected to have been downloaded in the database. Afterwards it is | 308 // detected to have been downloaded in the database. Afterwards it is |
| 302 // modified only by this function. We expect it to remain in sync with the | 309 // modified only by this function. We expect it to remain in sync with the |
| 303 // backend because configuration requests are never aborted; they are retried | 310 // backend because configuration requests are never aborted; they are retried |
| 304 // until they succeed or the backend is shut down. | 311 // until they succeed or the backend is shut down. |
| 305 | 312 |
| 306 ModelTypeSet disabled_types = GetDataTypesInState(DISABLED, config_state_map); | 313 syncer::ModelTypeSet disabled_types = |
| 307 ModelTypeSet fatal_types = GetDataTypesInState(FATAL, config_state_map); | 314 GetDataTypesInState(DISABLED, config_state_map); |
| 308 ModelTypeSet crypto_types = GetDataTypesInState(CRYPTO, config_state_map); | 315 syncer::ModelTypeSet fatal_types = |
| 309 ModelTypeSet unready_types = GetDataTypesInState(UNREADY, config_state_map); | 316 GetDataTypesInState(FATAL, config_state_map); |
| 317 syncer::ModelTypeSet crypto_types = |
| 318 GetDataTypesInState(CRYPTO, config_state_map); |
| 319 syncer::ModelTypeSet unready_types = |
| 320 GetDataTypesInState(UNREADY, config_state_map); |
| 310 | 321 |
| 311 disabled_types.PutAll(fatal_types); | 322 disabled_types.PutAll(fatal_types); |
| 312 disabled_types.PutAll(crypto_types); | 323 disabled_types.PutAll(crypto_types); |
| 313 disabled_types.PutAll(unready_types); | 324 disabled_types.PutAll(unready_types); |
| 314 | 325 |
| 315 ModelTypeSet active_types = | 326 syncer::ModelTypeSet active_types = |
| 316 GetDataTypesInState(CONFIGURE_ACTIVE, config_state_map); | 327 GetDataTypesInState(CONFIGURE_ACTIVE, config_state_map); |
| 317 ModelTypeSet clean_first_types = | 328 syncer::ModelTypeSet clean_first_types = |
| 318 GetDataTypesInState(CONFIGURE_CLEAN, config_state_map); | 329 GetDataTypesInState(CONFIGURE_CLEAN, config_state_map); |
| 319 ModelTypeSet types_to_download = registrar_->ConfigureDataTypes( | 330 syncer::ModelTypeSet types_to_download = registrar_->ConfigureDataTypes( |
| 320 Union(active_types, clean_first_types), disabled_types); | 331 syncer::Union(active_types, clean_first_types), disabled_types); |
| 321 types_to_download.PutAll(clean_first_types); | 332 types_to_download.PutAll(clean_first_types); |
| 322 types_to_download.RemoveAll(ProxyTypes()); | 333 types_to_download.RemoveAll(syncer::ProxyTypes()); |
| 323 if (!types_to_download.Empty()) | 334 if (!types_to_download.Empty()) |
| 324 types_to_download.Put(NIGORI); | 335 types_to_download.Put(syncer::NIGORI); |
| 325 | 336 |
| 326 // TODO(sync): crbug.com/137550. | 337 // TODO(sync): crbug.com/137550. |
| 327 // It's dangerous to configure types that have progress markers. Types with | 338 // It's dangerous to configure types that have progress markers. Types with |
| 328 // progress markers can trigger a MIGRATION_DONE response. We are not | 339 // progress markers can trigger a MIGRATION_DONE response. We are not |
| 329 // prepared to handle a migration during a configure, so we must ensure that | 340 // prepared to handle a migration during a configure, so we must ensure that |
| 330 // all our types_to_download actually contain no data before we sync them. | 341 // all our types_to_download actually contain no data before we sync them. |
| 331 // | 342 // |
| 332 // One common way to end up in this situation used to be types which | 343 // One common way to end up in this situation used to be types which |
| 333 // downloaded some or all of their data but have not applied it yet. We avoid | 344 // downloaded some or all of their data but have not applied it yet. We avoid |
| 334 // problems with those types by purging the data of any such partially synced | 345 // problems with those types by purging the data of any such partially synced |
| 335 // types soon after we load the directory. | 346 // types soon after we load the directory. |
| 336 // | 347 // |
| 337 // Another possible scenario is that we have newly supported or newly enabled | 348 // Another possible scenario is that we have newly supported or newly enabled |
| 338 // data types being downloaded here but the nigori type, which is always | 349 // data types being downloaded here but the nigori type, which is always |
| 339 // included in any GetUpdates request, requires migration. The server has | 350 // included in any GetUpdates request, requires migration. The server has |
| 340 // code to detect this scenario based on the configure reason, the fact that | 351 // code to detect this scenario based on the configure reason, the fact that |
| 341 // the nigori type is the only requested type which requires migration, and | 352 // the nigori type is the only requested type which requires migration, and |
| 342 // that the requested types list includes at least one non-nigori type. It | 353 // that the requested types list includes at least one non-nigori type. It |
| 343 // will not send a MIGRATION_DONE response in that case. We still need to be | 354 // will not send a MIGRATION_DONE response in that case. We still need to be |
| 344 // careful to not send progress markers for non-nigori types, though. If a | 355 // careful to not send progress markers for non-nigori types, though. If a |
| 345 // non-nigori type in the request requires migration, a MIGRATION_DONE | 356 // non-nigori type in the request requires migration, a MIGRATION_DONE |
| 346 // response will be sent. | 357 // response will be sent. |
| 347 | 358 |
| 348 ModelSafeRoutingInfo routing_info; | 359 syncer::ModelSafeRoutingInfo routing_info; |
| 349 registrar_->GetModelSafeRoutingInfo(&routing_info); | 360 registrar_->GetModelSafeRoutingInfo(&routing_info); |
| 350 | 361 |
| 351 ModelTypeSet current_types = registrar_->GetLastConfiguredTypes(); | 362 syncer::ModelTypeSet current_types = registrar_->GetLastConfiguredTypes(); |
| 352 ModelTypeSet types_to_purge = Difference(ModelTypeSet::All(), current_types); | 363 syncer::ModelTypeSet types_to_purge = |
| 353 ModelTypeSet inactive_types = | 364 syncer::Difference(syncer::ModelTypeSet::All(), current_types); |
| 365 syncer::ModelTypeSet inactive_types = |
| 354 GetDataTypesInState(CONFIGURE_INACTIVE, config_state_map); | 366 GetDataTypesInState(CONFIGURE_INACTIVE, config_state_map); |
| 355 types_to_purge.RemoveAll(inactive_types); | 367 types_to_purge.RemoveAll(inactive_types); |
| 356 types_to_purge.RemoveAll(unready_types); | 368 types_to_purge.RemoveAll(unready_types); |
| 357 | 369 |
| 358 // If a type has already been disabled and unapplied or journaled, it will | 370 // If a type has already been disabled and unapplied or journaled, it will |
| 359 // not be part of the |types_to_purge| set, and therefore does not need | 371 // not be part of the |types_to_purge| set, and therefore does not need |
| 360 // to be acted on again. | 372 // to be acted on again. |
| 361 fatal_types.RetainAll(types_to_purge); | 373 fatal_types.RetainAll(types_to_purge); |
| 362 ModelTypeSet unapply_types = Union(crypto_types, clean_first_types); | 374 syncer::ModelTypeSet unapply_types = |
| 375 syncer::Union(crypto_types, clean_first_types); |
| 363 unapply_types.RetainAll(types_to_purge); | 376 unapply_types.RetainAll(types_to_purge); |
| 364 | 377 |
| 365 DCHECK(Intersection(current_types, fatal_types).Empty()); | 378 DCHECK(syncer::Intersection(current_types, fatal_types).Empty()); |
| 366 DCHECK(Intersection(current_types, crypto_types).Empty()); | 379 DCHECK(syncer::Intersection(current_types, crypto_types).Empty()); |
| 367 DCHECK(current_types.HasAll(types_to_download)); | 380 DCHECK(current_types.HasAll(types_to_download)); |
| 368 | 381 |
| 369 SDVLOG(1) << "Types " << ModelTypeSetToString(types_to_download) | 382 SDVLOG(1) << "Types " << syncer::ModelTypeSetToString(types_to_download) |
| 370 << " added; calling DoConfigureSyncer"; | 383 << " added; calling DoConfigureSyncer"; |
| 371 // Divide up the types into their corresponding actions (each is mutually | 384 // Divide up the types into their corresponding actions (each is mutually |
| 372 // exclusive): | 385 // exclusive): |
| 373 // - Types which have just been added to the routing info (types_to_download): | 386 // - Types which have just been added to the routing info (types_to_download): |
| 374 // are downloaded. | 387 // are downloaded. |
| 375 // - Types which have encountered a fatal error (fatal_types) are deleted | 388 // - Types which have encountered a fatal error (fatal_types) are deleted |
| 376 // from the directory and journaled in the delete journal. | 389 // from the directory and journaled in the delete journal. |
| 377 // - Types which have encountered a cryptographer error (crypto_types) are | 390 // - Types which have encountered a cryptographer error (crypto_types) are |
| 378 // unapplied (local state is purged but sync state is not). | 391 // unapplied (local state is purged but sync state is not). |
| 379 // - All other types not in the routing info (types just disabled) are deleted | 392 // - All other types not in the routing info (types just disabled) are deleted |
| 380 // from the directory. | 393 // from the directory. |
| 381 // - Everything else (enabled types and already disabled types) is not | 394 // - Everything else (enabled types and already disabled types) is not |
| 382 // touched. | 395 // touched. |
| 383 RequestConfigureSyncer(reason, types_to_download, types_to_purge, fatal_types, | 396 RequestConfigureSyncer(reason, types_to_download, types_to_purge, fatal_types, |
| 384 unapply_types, inactive_types, routing_info, | 397 unapply_types, inactive_types, routing_info, |
| 385 ready_task, retry_callback); | 398 ready_task, retry_callback); |
| 386 | 399 |
| 387 DCHECK(Intersection(active_types, types_to_purge).Empty()); | 400 DCHECK(syncer::Intersection(active_types, types_to_purge).Empty()); |
| 388 DCHECK(Intersection(active_types, fatal_types).Empty()); | 401 DCHECK(syncer::Intersection(active_types, fatal_types).Empty()); |
| 389 DCHECK(Intersection(active_types, unapply_types).Empty()); | 402 DCHECK(syncer::Intersection(active_types, unapply_types).Empty()); |
| 390 DCHECK(Intersection(active_types, inactive_types).Empty()); | 403 DCHECK(syncer::Intersection(active_types, inactive_types).Empty()); |
| 391 return Difference(active_types, types_to_download); | 404 return syncer::Difference(active_types, types_to_download); |
| 392 } | 405 } |
| 393 | 406 |
| 394 void SyncBackendHostImpl::EnableEncryptEverything() { | 407 void SyncBackendHostImpl::EnableEncryptEverything() { |
| 395 registrar_->sync_thread()->task_runner()->PostTask( | 408 registrar_->sync_thread()->task_runner()->PostTask( |
| 396 FROM_HERE, | 409 FROM_HERE, |
| 397 base::Bind(&SyncBackendHostCore::DoEnableEncryptEverything, core_)); | 410 base::Bind(&SyncBackendHostCore::DoEnableEncryptEverything, core_)); |
| 398 } | 411 } |
| 399 | 412 |
| 400 void SyncBackendHostImpl::ActivateDirectoryDataType( | 413 void SyncBackendHostImpl::ActivateDirectoryDataType( |
| 401 ModelType type, | 414 syncer::ModelType type, |
| 402 ModelSafeGroup group, | 415 syncer::ModelSafeGroup group, |
| 403 ChangeProcessor* change_processor) { | 416 sync_driver::ChangeProcessor* change_processor) { |
| 404 registrar_->ActivateDataType(type, group, change_processor, GetUserShare()); | 417 registrar_->ActivateDataType(type, group, change_processor, GetUserShare()); |
| 405 } | 418 } |
| 406 | 419 |
| 407 void SyncBackendHostImpl::DeactivateDirectoryDataType(ModelType type) { | 420 void SyncBackendHostImpl::DeactivateDirectoryDataType(syncer::ModelType type) { |
| 408 registrar_->DeactivateDataType(type); | 421 registrar_->DeactivateDataType(type); |
| 409 } | 422 } |
| 410 | 423 |
| 411 void SyncBackendHostImpl::ActivateNonBlockingDataType( | 424 void SyncBackendHostImpl::ActivateNonBlockingDataType( |
| 412 ModelType type, | 425 syncer::ModelType type, |
| 413 std::unique_ptr<ActivationContext> activation_context) { | 426 std::unique_ptr<syncer_v2::ActivationContext> activation_context) { |
| 414 registrar_->RegisterNonBlockingType(type); | 427 registrar_->RegisterNonBlockingType(type); |
| 415 if (activation_context->data_type_state.initial_sync_done()) | 428 if (activation_context->data_type_state.initial_sync_done()) |
| 416 registrar_->AddRestoredNonBlockingType(type); | 429 registrar_->AddRestoredNonBlockingType(type); |
| 417 model_type_connector_->ConnectType(type, std::move(activation_context)); | 430 model_type_connector_->ConnectType(type, std::move(activation_context)); |
| 418 } | 431 } |
| 419 | 432 |
| 420 void SyncBackendHostImpl::DeactivateNonBlockingDataType(ModelType type) { | 433 void SyncBackendHostImpl::DeactivateNonBlockingDataType( |
| 434 syncer::ModelType type) { |
| 421 model_type_connector_->DisconnectType(type); | 435 model_type_connector_->DisconnectType(type); |
| 422 } | 436 } |
| 423 | 437 |
| 424 UserShare* SyncBackendHostImpl::GetUserShare() const { | 438 syncer::UserShare* SyncBackendHostImpl::GetUserShare() const { |
| 425 return core_->sync_manager()->GetUserShare(); | 439 return core_->sync_manager()->GetUserShare(); |
| 426 } | 440 } |
| 427 | 441 |
| 428 SyncBackendHostImpl::Status SyncBackendHostImpl::GetDetailedStatus() { | 442 SyncBackendHostImpl::Status SyncBackendHostImpl::GetDetailedStatus() { |
| 429 DCHECK(initialized()); | 443 DCHECK(initialized()); |
| 430 return core_->sync_manager()->GetDetailedStatus(); | 444 return core_->sync_manager()->GetDetailedStatus(); |
| 431 } | 445 } |
| 432 | 446 |
| 433 SyncCycleSnapshot SyncBackendHostImpl::GetLastCycleSnapshot() const { | 447 syncer::SyncCycleSnapshot SyncBackendHostImpl::GetLastCycleSnapshot() const { |
| 434 return last_snapshot_; | 448 return last_snapshot_; |
| 435 } | 449 } |
| 436 | 450 |
| 437 bool SyncBackendHostImpl::HasUnsyncedItems() const { | 451 bool SyncBackendHostImpl::HasUnsyncedItems() const { |
| 438 DCHECK(initialized()); | 452 DCHECK(initialized()); |
| 439 return core_->sync_manager()->HasUnsyncedItems(); | 453 return core_->sync_manager()->HasUnsyncedItems(); |
| 440 } | 454 } |
| 441 | 455 |
| 442 bool SyncBackendHostImpl::IsNigoriEnabled() const { | 456 bool SyncBackendHostImpl::IsNigoriEnabled() const { |
| 443 return registrar_.get() && registrar_->IsNigoriEnabled(); | 457 return registrar_.get() && registrar_->IsNigoriEnabled(); |
| 444 } | 458 } |
| 445 | 459 |
| 446 PassphraseType SyncBackendHostImpl::GetPassphraseType() const { | 460 syncer::PassphraseType SyncBackendHostImpl::GetPassphraseType() const { |
| 447 return cached_passphrase_type_; | 461 return cached_passphrase_type_; |
| 448 } | 462 } |
| 449 | 463 |
| 450 base::Time SyncBackendHostImpl::GetExplicitPassphraseTime() const { | 464 base::Time SyncBackendHostImpl::GetExplicitPassphraseTime() const { |
| 451 return cached_explicit_passphrase_time_; | 465 return cached_explicit_passphrase_time_; |
| 452 } | 466 } |
| 453 | 467 |
| 454 bool SyncBackendHostImpl::IsCryptographerReady( | 468 bool SyncBackendHostImpl::IsCryptographerReady( |
| 455 const BaseTransaction* trans) const { | 469 const syncer::BaseTransaction* trans) const { |
| 456 return initialized() && trans->GetCryptographer() && | 470 return initialized() && trans->GetCryptographer() && |
| 457 trans->GetCryptographer()->is_ready(); | 471 trans->GetCryptographer()->is_ready(); |
| 458 } | 472 } |
| 459 | 473 |
| 460 void SyncBackendHostImpl::GetModelSafeRoutingInfo( | 474 void SyncBackendHostImpl::GetModelSafeRoutingInfo( |
| 461 ModelSafeRoutingInfo* out) const { | 475 syncer::ModelSafeRoutingInfo* out) const { |
| 462 if (initialized()) { | 476 if (initialized()) { |
| 463 CHECK(registrar_.get()); | 477 CHECK(registrar_.get()); |
| 464 registrar_->GetModelSafeRoutingInfo(out); | 478 registrar_->GetModelSafeRoutingInfo(out); |
| 465 } else { | 479 } else { |
| 466 NOTREACHED(); | 480 NOTREACHED(); |
| 467 } | 481 } |
| 468 } | 482 } |
| 469 | 483 |
| 470 void SyncBackendHostImpl::FlushDirectory() const { | 484 void SyncBackendHostImpl::FlushDirectory() const { |
| 471 DCHECK(initialized()); | 485 DCHECK(initialized()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 } | 518 } |
| 505 | 519 |
| 506 void SyncBackendHostImpl::InitCore( | 520 void SyncBackendHostImpl::InitCore( |
| 507 std::unique_ptr<DoInitializeOptions> options) { | 521 std::unique_ptr<DoInitializeOptions> options) { |
| 508 registrar_->sync_thread()->task_runner()->PostTask( | 522 registrar_->sync_thread()->task_runner()->PostTask( |
| 509 FROM_HERE, base::Bind(&SyncBackendHostCore::DoInitialize, core_, | 523 FROM_HERE, base::Bind(&SyncBackendHostCore::DoInitialize, core_, |
| 510 base::Passed(&options))); | 524 base::Passed(&options))); |
| 511 } | 525 } |
| 512 | 526 |
| 513 void SyncBackendHostImpl::RequestConfigureSyncer( | 527 void SyncBackendHostImpl::RequestConfigureSyncer( |
| 514 ConfigureReason reason, | 528 syncer::ConfigureReason reason, |
| 515 ModelTypeSet to_download, | 529 syncer::ModelTypeSet to_download, |
| 516 ModelTypeSet to_purge, | 530 syncer::ModelTypeSet to_purge, |
| 517 ModelTypeSet to_journal, | 531 syncer::ModelTypeSet to_journal, |
| 518 ModelTypeSet to_unapply, | 532 syncer::ModelTypeSet to_unapply, |
| 519 ModelTypeSet to_ignore, | 533 syncer::ModelTypeSet to_ignore, |
| 520 const ModelSafeRoutingInfo& routing_info, | 534 const syncer::ModelSafeRoutingInfo& routing_info, |
| 521 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task, | 535 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& |
| 536 ready_task, |
| 522 const base::Closure& retry_callback) { | 537 const base::Closure& retry_callback) { |
| 523 DoConfigureSyncerTypes config_types; | 538 DoConfigureSyncerTypes config_types; |
| 524 config_types.to_download = to_download; | 539 config_types.to_download = to_download; |
| 525 config_types.to_purge = to_purge; | 540 config_types.to_purge = to_purge; |
| 526 config_types.to_journal = to_journal; | 541 config_types.to_journal = to_journal; |
| 527 config_types.to_unapply = to_unapply; | 542 config_types.to_unapply = to_unapply; |
| 528 registrar_->sync_thread()->task_runner()->PostTask( | 543 registrar_->sync_thread()->task_runner()->PostTask( |
| 529 FROM_HERE, | 544 FROM_HERE, |
| 530 base::Bind(&SyncBackendHostCore::DoConfigureSyncer, core_, reason, | 545 base::Bind(&SyncBackendHostCore::DoConfigureSyncer, core_, reason, |
| 531 config_types, routing_info, ready_task, retry_callback)); | 546 config_types, routing_info, ready_task, retry_callback)); |
| 532 } | 547 } |
| 533 | 548 |
| 534 void SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop( | 549 void SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop( |
| 535 const ModelTypeSet enabled_types, | 550 const syncer::ModelTypeSet enabled_types, |
| 536 const ModelTypeSet succeeded_configuration_types, | 551 const syncer::ModelTypeSet succeeded_configuration_types, |
| 537 const ModelTypeSet failed_configuration_types, | 552 const syncer::ModelTypeSet failed_configuration_types, |
| 538 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task) { | 553 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& |
| 554 ready_task) { |
| 539 if (!frontend_) | 555 if (!frontend_) |
| 540 return; | 556 return; |
| 541 | 557 |
| 542 if (invalidator_) { | 558 if (invalidator_) { |
| 543 CHECK(invalidator_->UpdateRegisteredInvalidationIds( | 559 CHECK(invalidator_->UpdateRegisteredInvalidationIds( |
| 544 this, ModelTypeSetToObjectIdSet(enabled_types))); | 560 this, ModelTypeSetToObjectIdSet(enabled_types))); |
| 545 } | 561 } |
| 546 | 562 |
| 547 if (!ready_task.is_null()) | 563 if (!ready_task.is_null()) |
| 548 ready_task.Run(succeeded_configuration_types, failed_configuration_types); | 564 ready_task.Run(succeeded_configuration_types, failed_configuration_types); |
| 549 } | 565 } |
| 550 | 566 |
| 551 void SyncBackendHostImpl::AddExperimentalTypes() { | 567 void SyncBackendHostImpl::AddExperimentalTypes() { |
| 552 CHECK(initialized()); | 568 CHECK(initialized()); |
| 553 Experiments experiments; | 569 syncer::Experiments experiments; |
| 554 if (core_->sync_manager()->ReceivedExperiment(&experiments)) | 570 if (core_->sync_manager()->ReceivedExperiment(&experiments)) |
| 555 frontend_->OnExperimentsChanged(experiments); | 571 frontend_->OnExperimentsChanged(experiments); |
| 556 } | 572 } |
| 557 | 573 |
| 558 void SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop( | 574 void SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop( |
| 559 const WeakHandle<JsBackend> js_backend, | 575 const syncer::WeakHandle<syncer::JsBackend> js_backend, |
| 560 const WeakHandle<DataTypeDebugInfoListener> debug_info_listener, | 576 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener> |
| 561 std::unique_ptr<ModelTypeConnector> model_type_connector, | 577 debug_info_listener, |
| 578 std::unique_ptr<syncer_v2::ModelTypeConnector> model_type_connector, |
| 562 const std::string& cache_guid) { | 579 const std::string& cache_guid) { |
| 563 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 580 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
| 564 | 581 |
| 565 model_type_connector_ = std::move(model_type_connector); | 582 model_type_connector_ = std::move(model_type_connector); |
| 566 | 583 |
| 567 if (!frontend_) | 584 if (!frontend_) |
| 568 return; | 585 return; |
| 569 | 586 |
| 570 initialized_ = true; | 587 initialized_ = true; |
| 571 | 588 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 584 AddExperimentalTypes(); | 601 AddExperimentalTypes(); |
| 585 frontend_->OnBackendInitialized(js_backend, debug_info_listener, cache_guid, | 602 frontend_->OnBackendInitialized(js_backend, debug_info_listener, cache_guid, |
| 586 true); | 603 true); |
| 587 } | 604 } |
| 588 | 605 |
| 589 void SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop() { | 606 void SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop() { |
| 590 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 607 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
| 591 if (!frontend_) | 608 if (!frontend_) |
| 592 return; | 609 return; |
| 593 | 610 |
| 594 frontend_->OnBackendInitialized(WeakHandle<JsBackend>(), | 611 frontend_->OnBackendInitialized( |
| 595 WeakHandle<DataTypeDebugInfoListener>(), "", | 612 syncer::WeakHandle<syncer::JsBackend>(), |
| 596 false); | 613 syncer::WeakHandle<syncer::DataTypeDebugInfoListener>(), "", false); |
| 597 } | 614 } |
| 598 | 615 |
| 599 void SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop( | 616 void SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop( |
| 600 const SyncCycleSnapshot& snapshot) { | 617 const syncer::SyncCycleSnapshot& snapshot) { |
| 601 if (!frontend_) | 618 if (!frontend_) |
| 602 return; | 619 return; |
| 603 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 620 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
| 604 | 621 |
| 605 last_snapshot_ = snapshot; | 622 last_snapshot_ = snapshot; |
| 606 | 623 |
| 607 SDVLOG(1) << "Got snapshot " << snapshot.ToString(); | 624 SDVLOG(1) << "Got snapshot " << snapshot.ToString(); |
| 608 | 625 |
| 609 if (!snapshot.poll_finish_time().is_null()) | 626 if (!snapshot.poll_finish_time().is_null()) |
| 610 sync_prefs_->SetLastPollTime(snapshot.poll_finish_time()); | 627 sync_prefs_->SetLastPollTime(snapshot.poll_finish_time()); |
| 611 | 628 |
| 612 // Process any changes to the datatypes we're syncing. | 629 // Process any changes to the datatypes we're syncing. |
| 613 // TODO(sync): add support for removing types. | 630 // TODO(sync): add support for removing types. |
| 614 if (initialized()) | 631 if (initialized()) |
| 615 AddExperimentalTypes(); | 632 AddExperimentalTypes(); |
| 616 | 633 |
| 617 if (initialized()) | 634 if (initialized()) |
| 618 frontend_->OnSyncCycleCompleted(); | 635 frontend_->OnSyncCycleCompleted(); |
| 619 } | 636 } |
| 620 | 637 |
| 621 void SyncBackendHostImpl::RetryConfigurationOnFrontendLoop( | 638 void SyncBackendHostImpl::RetryConfigurationOnFrontendLoop( |
| 622 const base::Closure& retry_callback) { | 639 const base::Closure& retry_callback) { |
| 623 SDVLOG(1) << "Failed to complete configuration, informing of retry."; | 640 SDVLOG(1) << "Failed to complete configuration, informing of retry."; |
| 624 retry_callback.Run(); | 641 retry_callback.Run(); |
| 625 } | 642 } |
| 626 | 643 |
| 627 void SyncBackendHostImpl::PersistEncryptionBootstrapToken( | 644 void SyncBackendHostImpl::PersistEncryptionBootstrapToken( |
| 628 const std::string& token, | 645 const std::string& token, |
| 629 BootstrapTokenType token_type) { | 646 syncer::BootstrapTokenType token_type) { |
| 630 CHECK(sync_prefs_.get()); | 647 CHECK(sync_prefs_.get()); |
| 631 if (token_type == PASSPHRASE_BOOTSTRAP_TOKEN) | 648 if (token_type == syncer::PASSPHRASE_BOOTSTRAP_TOKEN) |
| 632 sync_prefs_->SetEncryptionBootstrapToken(token); | 649 sync_prefs_->SetEncryptionBootstrapToken(token); |
| 633 else | 650 else |
| 634 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token); | 651 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token); |
| 635 } | 652 } |
| 636 | 653 |
| 637 void SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop( | 654 void SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop( |
| 638 const SyncProtocolError& sync_error) { | 655 const syncer::SyncProtocolError& sync_error) { |
| 639 if (!frontend_) | 656 if (!frontend_) |
| 640 return; | 657 return; |
| 641 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 658 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
| 642 frontend_->OnActionableError(sync_error); | 659 frontend_->OnActionableError(sync_error); |
| 643 } | 660 } |
| 644 | 661 |
| 645 void SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop( | 662 void SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop( |
| 646 ModelTypeSet types) { | 663 syncer::ModelTypeSet types) { |
| 647 if (!frontend_) | 664 if (!frontend_) |
| 648 return; | 665 return; |
| 649 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 666 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
| 650 frontend_->OnMigrationNeededForTypes(types); | 667 frontend_->OnMigrationNeededForTypes(types); |
| 651 } | 668 } |
| 652 | 669 |
| 653 void SyncBackendHostImpl::OnInvalidatorStateChange(InvalidatorState state) { | 670 void SyncBackendHostImpl::OnInvalidatorStateChange( |
| 671 syncer::InvalidatorState state) { |
| 654 registrar_->sync_thread()->task_runner()->PostTask( | 672 registrar_->sync_thread()->task_runner()->PostTask( |
| 655 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnInvalidatorStateChange, | 673 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnInvalidatorStateChange, |
| 656 core_, state)); | 674 core_, state)); |
| 657 } | 675 } |
| 658 | 676 |
| 659 void SyncBackendHostImpl::OnIncomingInvalidation( | 677 void SyncBackendHostImpl::OnIncomingInvalidation( |
| 660 const ObjectIdInvalidationMap& invalidation_map) { | 678 const syncer::ObjectIdInvalidationMap& invalidation_map) { |
| 661 registrar_->sync_thread()->task_runner()->PostTask( | 679 registrar_->sync_thread()->task_runner()->PostTask( |
| 662 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnIncomingInvalidation, | 680 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnIncomingInvalidation, |
| 663 core_, invalidation_map)); | 681 core_, invalidation_map)); |
| 664 } | 682 } |
| 665 | 683 |
| 666 std::string SyncBackendHostImpl::GetOwnerName() const { | 684 std::string SyncBackendHostImpl::GetOwnerName() const { |
| 667 return "SyncBackendHostImpl"; | 685 return "SyncBackendHostImpl"; |
| 668 } | 686 } |
| 669 | 687 |
| 670 bool SyncBackendHostImpl::CheckPassphraseAgainstCachedPendingKeys( | 688 bool SyncBackendHostImpl::CheckPassphraseAgainstCachedPendingKeys( |
| 671 const std::string& passphrase) const { | 689 const std::string& passphrase) const { |
| 672 DCHECK(cached_pending_keys_.has_blob()); | 690 DCHECK(cached_pending_keys_.has_blob()); |
| 673 DCHECK(!passphrase.empty()); | 691 DCHECK(!passphrase.empty()); |
| 674 Nigori nigori; | 692 syncer::Nigori nigori; |
| 675 nigori.InitByDerivation("localhost", "dummy", passphrase); | 693 nigori.InitByDerivation("localhost", "dummy", passphrase); |
| 676 std::string plaintext; | 694 std::string plaintext; |
| 677 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); | 695 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); |
| 678 DVLOG_IF(1, result) << "Passphrase failed to decrypt pending keys."; | 696 DVLOG_IF(1, result) << "Passphrase failed to decrypt pending keys."; |
| 679 return result; | 697 return result; |
| 680 } | 698 } |
| 681 | 699 |
| 682 void SyncBackendHostImpl::NotifyPassphraseRequired( | 700 void SyncBackendHostImpl::NotifyPassphraseRequired( |
| 683 PassphraseRequiredReason reason, | 701 syncer::PassphraseRequiredReason reason, |
| 684 sync_pb::EncryptedData pending_keys) { | 702 sync_pb::EncryptedData pending_keys) { |
| 685 if (!frontend_) | 703 if (!frontend_) |
| 686 return; | 704 return; |
| 687 | 705 |
| 688 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 706 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
| 689 | 707 |
| 690 // Update our cache of the cryptographer's pending keys. | 708 // Update our cache of the cryptographer's pending keys. |
| 691 cached_pending_keys_ = pending_keys; | 709 cached_pending_keys_ = pending_keys; |
| 692 | 710 |
| 693 frontend_->OnPassphraseRequired(reason, pending_keys); | 711 frontend_->OnPassphraseRequired(reason, pending_keys); |
| 694 } | 712 } |
| 695 | 713 |
| 696 void SyncBackendHostImpl::NotifyPassphraseAccepted() { | 714 void SyncBackendHostImpl::NotifyPassphraseAccepted() { |
| 697 if (!frontend_) | 715 if (!frontend_) |
| 698 return; | 716 return; |
| 699 | 717 |
| 700 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 718 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
| 701 | 719 |
| 702 // Clear our cache of the cryptographer's pending keys. | 720 // Clear our cache of the cryptographer's pending keys. |
| 703 cached_pending_keys_.clear_blob(); | 721 cached_pending_keys_.clear_blob(); |
| 704 frontend_->OnPassphraseAccepted(); | 722 frontend_->OnPassphraseAccepted(); |
| 705 } | 723 } |
| 706 | 724 |
| 707 void SyncBackendHostImpl::NotifyEncryptedTypesChanged( | 725 void SyncBackendHostImpl::NotifyEncryptedTypesChanged( |
| 708 ModelTypeSet encrypted_types, | 726 syncer::ModelTypeSet encrypted_types, |
| 709 bool encrypt_everything) { | 727 bool encrypt_everything) { |
| 710 if (!frontend_) | 728 if (!frontend_) |
| 711 return; | 729 return; |
| 712 | 730 |
| 713 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 731 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
| 714 frontend_->OnEncryptedTypesChanged(encrypted_types, encrypt_everything); | 732 frontend_->OnEncryptedTypesChanged(encrypted_types, encrypt_everything); |
| 715 } | 733 } |
| 716 | 734 |
| 717 void SyncBackendHostImpl::NotifyEncryptionComplete() { | 735 void SyncBackendHostImpl::NotifyEncryptionComplete() { |
| 718 if (!frontend_) | 736 if (!frontend_) |
| 719 return; | 737 return; |
| 720 | 738 |
| 721 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 739 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
| 722 frontend_->OnEncryptionComplete(); | 740 frontend_->OnEncryptionComplete(); |
| 723 } | 741 } |
| 724 | 742 |
| 725 void SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop( | 743 void SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop( |
| 726 PassphraseType type, | 744 syncer::PassphraseType type, |
| 727 base::Time explicit_passphrase_time) { | 745 base::Time explicit_passphrase_time) { |
| 728 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 746 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
| 729 DVLOG(1) << "Passphrase type changed to " << PassphraseTypeToString(type); | 747 DVLOG(1) << "Passphrase type changed to " |
| 748 << syncer::PassphraseTypeToString(type); |
| 730 cached_passphrase_type_ = type; | 749 cached_passphrase_type_ = type; |
| 731 cached_explicit_passphrase_time_ = explicit_passphrase_time; | 750 cached_explicit_passphrase_time_ = explicit_passphrase_time; |
| 732 } | 751 } |
| 733 | 752 |
| 734 void SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop( | 753 void SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop( |
| 735 const SyncEncryptionHandler::NigoriState& nigori_state) { | 754 const syncer::SyncEncryptionHandler::NigoriState& nigori_state) { |
| 736 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 755 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
| 737 frontend_->OnLocalSetPassphraseEncryption(nigori_state); | 756 frontend_->OnLocalSetPassphraseEncryption(nigori_state); |
| 738 } | 757 } |
| 739 | 758 |
| 740 void SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop( | 759 void SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop( |
| 741 ConnectionStatus status) { | 760 syncer::ConnectionStatus status) { |
| 742 if (!frontend_) | 761 if (!frontend_) |
| 743 return; | 762 return; |
| 744 | 763 |
| 745 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 764 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
| 746 | 765 |
| 747 DVLOG(1) << "Connection status changed: " << ConnectionStatusToString(status); | 766 DVLOG(1) << "Connection status changed: " |
| 767 << syncer::ConnectionStatusToString(status); |
| 748 frontend_->OnConnectionStatusChange(status); | 768 frontend_->OnConnectionStatusChange(status); |
| 749 } | 769 } |
| 750 | 770 |
| 751 void SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop( | 771 void SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop( |
| 752 std::unique_ptr<ProtocolEvent> event) { | 772 std::unique_ptr<syncer::ProtocolEvent> event) { |
| 753 if (!frontend_) | 773 if (!frontend_) |
| 754 return; | 774 return; |
| 755 frontend_->OnProtocolEvent(*event); | 775 frontend_->OnProtocolEvent(*event); |
| 756 } | 776 } |
| 757 | 777 |
| 758 void SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop( | 778 void SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop( |
| 759 ModelType type, | 779 syncer::ModelType type, |
| 760 const CommitCounters& counters) { | 780 const syncer::CommitCounters& counters) { |
| 761 if (!frontend_) | 781 if (!frontend_) |
| 762 return; | 782 return; |
| 763 frontend_->OnDirectoryTypeCommitCounterUpdated(type, counters); | 783 frontend_->OnDirectoryTypeCommitCounterUpdated(type, counters); |
| 764 } | 784 } |
| 765 | 785 |
| 766 void SyncBackendHostImpl::HandleDirectoryUpdateCountersUpdatedOnFrontendLoop( | 786 void SyncBackendHostImpl::HandleDirectoryUpdateCountersUpdatedOnFrontendLoop( |
| 767 ModelType type, | 787 syncer::ModelType type, |
| 768 const UpdateCounters& counters) { | 788 const syncer::UpdateCounters& counters) { |
| 769 if (!frontend_) | 789 if (!frontend_) |
| 770 return; | 790 return; |
| 771 frontend_->OnDirectoryTypeUpdateCounterUpdated(type, counters); | 791 frontend_->OnDirectoryTypeUpdateCounterUpdated(type, counters); |
| 772 } | 792 } |
| 773 | 793 |
| 774 void SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop( | 794 void SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop( |
| 775 ModelType type, | 795 syncer::ModelType type, |
| 776 const StatusCounters& counters) { | 796 const syncer::StatusCounters& counters) { |
| 777 if (!frontend_) | 797 if (!frontend_) |
| 778 return; | 798 return; |
| 779 frontend_->OnDirectoryTypeStatusCounterUpdated(type, counters); | 799 frontend_->OnDirectoryTypeStatusCounterUpdated(type, counters); |
| 780 } | 800 } |
| 781 | 801 |
| 782 void SyncBackendHostImpl::UpdateInvalidationVersions( | 802 void SyncBackendHostImpl::UpdateInvalidationVersions( |
| 783 const std::map<ModelType, int64_t>& invalidation_versions) { | 803 const std::map<syncer::ModelType, int64_t>& invalidation_versions) { |
| 784 sync_prefs_->UpdateInvalidationVersions(invalidation_versions); | 804 sync_prefs_->UpdateInvalidationVersions(invalidation_versions); |
| 785 } | 805 } |
| 786 | 806 |
| 787 base::MessageLoop* SyncBackendHostImpl::GetSyncLoopForTesting() { | 807 base::MessageLoop* SyncBackendHostImpl::GetSyncLoopForTesting() { |
| 788 return registrar_->sync_thread()->message_loop(); | 808 return registrar_->sync_thread()->message_loop(); |
| 789 } | 809 } |
| 790 | 810 |
| 791 void SyncBackendHostImpl::RefreshTypesForTest(ModelTypeSet types) { | 811 void SyncBackendHostImpl::RefreshTypesForTest(syncer::ModelTypeSet types) { |
| 792 DCHECK(ui_thread_->BelongsToCurrentThread()); | 812 DCHECK(ui_thread_->BelongsToCurrentThread()); |
| 793 | 813 |
| 794 registrar_->sync_thread()->task_runner()->PostTask( | 814 registrar_->sync_thread()->task_runner()->PostTask( |
| 795 FROM_HERE, | 815 FROM_HERE, |
| 796 base::Bind(&SyncBackendHostCore::DoRefreshTypes, core_, types)); | 816 base::Bind(&SyncBackendHostCore::DoRefreshTypes, core_, types)); |
| 797 } | 817 } |
| 798 | 818 |
| 799 void SyncBackendHostImpl::ClearServerData( | 819 void SyncBackendHostImpl::ClearServerData( |
| 800 const SyncManager::ClearServerDataCallback& callback) { | 820 const syncer::SyncManager::ClearServerDataCallback& callback) { |
| 801 DCHECK(ui_thread_->BelongsToCurrentThread()); | 821 DCHECK(ui_thread_->BelongsToCurrentThread()); |
| 802 registrar_->sync_thread()->task_runner()->PostTask( | 822 registrar_->sync_thread()->task_runner()->PostTask( |
| 803 FROM_HERE, base::Bind(&SyncBackendHostCore::DoClearServerData, | 823 FROM_HERE, base::Bind(&SyncBackendHostCore::DoClearServerData, |
| 804 core_, callback)); | 824 core_, callback)); |
| 805 } | 825 } |
| 806 | 826 |
| 807 void SyncBackendHostImpl::OnCookieJarChanged(bool account_mismatch, | 827 void SyncBackendHostImpl::OnCookieJarChanged(bool account_mismatch, |
| 808 bool empty_jar) { | 828 bool empty_jar) { |
| 809 DCHECK(ui_thread_->BelongsToCurrentThread()); | 829 DCHECK(ui_thread_->BelongsToCurrentThread()); |
| 810 registrar_->sync_thread()->task_runner()->PostTask( | 830 registrar_->sync_thread()->task_runner()->PostTask( |
| 811 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnCookieJarChanged, | 831 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnCookieJarChanged, |
| 812 core_, account_mismatch, empty_jar)); | 832 core_, account_mismatch, empty_jar)); |
| 813 } | 833 } |
| 814 | 834 |
| 815 void SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop( | 835 void SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop( |
| 816 const SyncManager::ClearServerDataCallback& frontend_callback) { | 836 const syncer::SyncManager::ClearServerDataCallback& frontend_callback) { |
| 817 DCHECK(ui_thread_->BelongsToCurrentThread()); | 837 DCHECK(ui_thread_->BelongsToCurrentThread()); |
| 818 frontend_callback.Run(); | 838 frontend_callback.Run(); |
| 819 } | 839 } |
| 820 | 840 |
| 821 } // namespace syncer | 841 } // namespace browser_sync |
| 822 | 842 |
| 823 #undef SDVLOG | 843 #undef SDVLOG |
| 824 | 844 |
| 825 #undef SLOG | 845 #undef SLOG |
| OLD | NEW |