| 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "components/invalidation/public/invalidation_service.h" | 16 #include "components/invalidation/public/invalidation_service.h" |
| 17 #include "components/invalidation/public/object_id_invalidation_map.h" | 17 #include "components/invalidation/public/object_id_invalidation_map.h" |
| 18 #include "components/signin/core/browser/signin_client.h" | 18 #include "components/signin/core/browser/signin_client.h" |
| 19 #include "components/sync/base/experiments.h" | 19 #include "components/sync/base/experiments.h" |
| 20 #include "components/sync/base/invalidation_helper.h" | 20 #include "components/sync/base/invalidation_helper.h" |
| 21 #include "components/sync/base/sync_prefs.h" | 21 #include "components/sync/base/sync_prefs.h" |
| 22 #include "components/sync/driver/glue/sync_backend_host_core.h" | 22 #include "components/sync/driver/glue/sync_backend_host_core.h" |
| 23 #include "components/sync/driver/glue/sync_backend_registrar.h" | 23 #include "components/sync/driver/glue/sync_backend_registrar.h" |
| 24 #include "components/sync/driver/sync_client.h" | 24 #include "components/sync/driver/sync_client.h" |
| 25 #include "components/sync/driver/sync_driver_switches.h" | 25 #include "components/sync/driver/sync_driver_switches.h" |
| 26 #include "components/sync/driver/sync_frontend.h" | |
| 27 #include "components/sync/engine/activation_context.h" | 26 #include "components/sync/engine/activation_context.h" |
| 28 #include "components/sync/engine/engine_components_factory.h" | 27 #include "components/sync/engine/engine_components_factory.h" |
| 29 #include "components/sync/engine/engine_components_factory_impl.h" | 28 #include "components/sync/engine/engine_components_factory_impl.h" |
| 30 #include "components/sync/engine/events/protocol_event.h" | 29 #include "components/sync/engine/events/protocol_event.h" |
| 31 #include "components/sync/engine/net/http_bridge.h" | 30 #include "components/sync/engine/net/http_bridge.h" |
| 31 #include "components/sync/engine/sync_engine_host.h" |
| 32 #include "components/sync/engine/sync_manager_factory.h" | 32 #include "components/sync/engine/sync_manager_factory.h" |
| 33 #include "components/sync/engine/sync_string_conversions.h" | 33 #include "components/sync/engine/sync_string_conversions.h" |
| 34 #include "components/sync/syncable/base_transaction.h" | 34 #include "components/sync/syncable/base_transaction.h" |
| 35 | 35 |
| 36 // Helper macros to log with the syncer thread name; useful when there | 36 // Helper macros to log with the syncer thread name; useful when there |
| 37 // are multiple syncers involved. | 37 // are multiple syncers involved. |
| 38 | 38 |
| 39 #define SLOG(severity) LOG(severity) << name_ << ": " | 39 #define SLOG(severity) LOG(severity) << name_ << ": " |
| 40 | 40 |
| 41 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " | 41 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " |
| 42 | 42 |
| 43 namespace syncer { | 43 namespace syncer { |
| 44 | 44 |
| 45 SyncBackendHostImpl::SyncBackendHostImpl( | 45 SyncBackendHostImpl::SyncBackendHostImpl( |
| 46 const std::string& name, | 46 const std::string& name, |
| 47 SyncClient* sync_client, | 47 SyncClient* sync_client, |
| 48 invalidation::InvalidationService* invalidator, | 48 invalidation::InvalidationService* invalidator, |
| 49 const base::WeakPtr<SyncPrefs>& sync_prefs, | 49 const base::WeakPtr<SyncPrefs>& sync_prefs, |
| 50 const base::FilePath& sync_folder) | 50 const base::FilePath& sync_folder) |
| 51 : sync_client_(sync_client), | 51 : sync_client_(sync_client), |
| 52 name_(name), | 52 name_(name), |
| 53 initialized_(false), | |
| 54 sync_prefs_(sync_prefs), | 53 sync_prefs_(sync_prefs), |
| 55 frontend_(nullptr), | |
| 56 cached_passphrase_type_(PassphraseType::IMPLICIT_PASSPHRASE), | |
| 57 invalidator_(invalidator), | 54 invalidator_(invalidator), |
| 58 invalidation_handler_registered_(false), | |
| 59 weak_ptr_factory_(this) { | 55 weak_ptr_factory_(this) { |
| 60 core_ = new SyncBackendHostCore(name_, sync_folder, | 56 core_ = new SyncBackendHostCore(name_, sync_folder, |
| 61 weak_ptr_factory_.GetWeakPtr()); | 57 weak_ptr_factory_.GetWeakPtr()); |
| 62 } | 58 } |
| 63 | 59 |
| 64 SyncBackendHostImpl::~SyncBackendHostImpl() { | 60 SyncBackendHostImpl::~SyncBackendHostImpl() { |
| 65 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; | 61 DCHECK(!core_.get() && !host_) << "Must call Shutdown before destructor."; |
| 66 DCHECK(!registrar_.get()); | 62 DCHECK(!registrar_.get()); |
| 67 } | 63 } |
| 68 | 64 |
| 69 void SyncBackendHostImpl::Initialize( | 65 void SyncBackendHostImpl::Initialize( |
| 70 SyncFrontend* frontend, | 66 SyncEngineHost* host, |
| 71 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner, | 67 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner, |
| 72 const WeakHandle<JsEventHandler>& event_handler, | 68 const WeakHandle<JsEventHandler>& event_handler, |
| 73 const GURL& sync_service_url, | 69 const GURL& sync_service_url, |
| 74 const std::string& sync_user_agent, | 70 const std::string& sync_user_agent, |
| 75 const SyncCredentials& credentials, | 71 const SyncCredentials& credentials, |
| 76 bool delete_sync_data_folder, | 72 bool delete_sync_data_folder, |
| 77 bool enable_local_sync_backend, | 73 bool enable_local_sync_backend, |
| 78 const base::FilePath& local_sync_backend_folder, | 74 const base::FilePath& local_sync_backend_folder, |
| 79 std::unique_ptr<SyncManagerFactory> sync_manager_factory, | 75 std::unique_ptr<SyncManagerFactory> sync_manager_factory, |
| 80 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, | 76 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, |
| 81 const base::Closure& report_unrecoverable_error_function, | 77 const base::Closure& report_unrecoverable_error_function, |
| 82 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, | 78 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, |
| 83 std::unique_ptr<SyncEncryptionHandler::NigoriState> saved_nigori_state) { | 79 std::unique_ptr<SyncEncryptionHandler::NigoriState> saved_nigori_state) { |
| 84 CHECK(sync_task_runner); | 80 CHECK(sync_task_runner); |
| 85 sync_task_runner_ = sync_task_runner; | 81 sync_task_runner_ = sync_task_runner; |
| 86 | 82 |
| 87 registrar_ = base::MakeUnique<SyncBackendRegistrar>( | 83 registrar_ = base::MakeUnique<SyncBackendRegistrar>( |
| 88 name_, base::Bind(&SyncClient::CreateModelWorkerForGroup, | 84 name_, base::Bind(&SyncClient::CreateModelWorkerForGroup, |
| 89 base::Unretained(sync_client_))); | 85 base::Unretained(sync_client_))); |
| 90 | 86 |
| 91 DCHECK(frontend); | 87 DCHECK(host); |
| 92 frontend_ = frontend; | 88 host_ = host; |
| 93 | 89 |
| 94 std::vector<scoped_refptr<ModelSafeWorker>> workers; | 90 std::vector<scoped_refptr<ModelSafeWorker>> workers; |
| 95 registrar_->GetWorkers(&workers); | 91 registrar_->GetWorkers(&workers); |
| 96 | 92 |
| 97 EngineComponentsFactory::Switches factory_switches = { | 93 EngineComponentsFactory::Switches factory_switches = { |
| 98 EngineComponentsFactory::ENCRYPTION_KEYSTORE, | 94 EngineComponentsFactory::ENCRYPTION_KEYSTORE, |
| 99 EngineComponentsFactory::BACKOFF_NORMAL}; | 95 EngineComponentsFactory::BACKOFF_NORMAL}; |
| 100 | 96 |
| 101 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); | 97 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
| 102 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { | 98 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 ModelSafeRoutingInfo routing_info; | 148 ModelSafeRoutingInfo routing_info; |
| 153 registrar_->GetModelSafeRoutingInfo(&routing_info); | 149 registrar_->GetModelSafeRoutingInfo(&routing_info); |
| 154 | 150 |
| 155 sync_task_runner_->PostTask( | 151 sync_task_runner_->PostTask( |
| 156 FROM_HERE, base::Bind(&SyncBackendHostCore::DoStartSyncing, core_, | 152 FROM_HERE, base::Bind(&SyncBackendHostCore::DoStartSyncing, core_, |
| 157 routing_info, sync_prefs_->GetLastPollTime())); | 153 routing_info, sync_prefs_->GetLastPollTime())); |
| 158 } | 154 } |
| 159 | 155 |
| 160 void SyncBackendHostImpl::SetEncryptionPassphrase(const std::string& passphrase, | 156 void SyncBackendHostImpl::SetEncryptionPassphrase(const std::string& passphrase, |
| 161 bool is_explicit) { | 157 bool is_explicit) { |
| 158 DCHECK(thread_checker_.CalledOnValidThread()); |
| 159 |
| 162 if (!IsNigoriEnabled()) { | 160 if (!IsNigoriEnabled()) { |
| 163 NOTREACHED() << "SetEncryptionPassphrase must never be called when nigori" | 161 NOTREACHED() << "SetEncryptionPassphrase must never be called when nigori" |
| 164 " is disabled."; | 162 " is disabled."; |
| 165 return; | 163 return; |
| 166 } | 164 } |
| 167 | 165 |
| 168 // We should never be called with an empty passphrase. | 166 // We should never be called with an empty passphrase. |
| 169 DCHECK(!passphrase.empty()); | 167 DCHECK(!passphrase.empty()); |
| 170 | 168 |
| 171 // This should only be called by the frontend. | |
| 172 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 173 | |
| 174 // SetEncryptionPassphrase should never be called if we are currently | 169 // SetEncryptionPassphrase should never be called if we are currently |
| 175 // encrypted with an explicit passphrase. | 170 // encrypted with an explicit passphrase. |
| 176 DCHECK(cached_passphrase_type_ == PassphraseType::KEYSTORE_PASSPHRASE || | 171 DCHECK(cached_passphrase_type_ == PassphraseType::KEYSTORE_PASSPHRASE || |
| 177 cached_passphrase_type_ == PassphraseType::IMPLICIT_PASSPHRASE); | 172 cached_passphrase_type_ == PassphraseType::IMPLICIT_PASSPHRASE); |
| 178 | 173 |
| 179 // Post an encryption task on the syncer thread. | 174 // Post an encryption task on the syncer thread. |
| 180 sync_task_runner_->PostTask( | 175 sync_task_runner_->PostTask( |
| 181 FROM_HERE, base::Bind(&SyncBackendHostCore::DoSetEncryptionPassphrase, | 176 FROM_HERE, base::Bind(&SyncBackendHostCore::DoSetEncryptionPassphrase, |
| 182 core_, passphrase, is_explicit)); | 177 core_, passphrase, is_explicit)); |
| 183 } | 178 } |
| 184 | 179 |
| 185 bool SyncBackendHostImpl::SetDecryptionPassphrase( | 180 bool SyncBackendHostImpl::SetDecryptionPassphrase( |
| 186 const std::string& passphrase) { | 181 const std::string& passphrase) { |
| 182 DCHECK(thread_checker_.CalledOnValidThread()); |
| 183 |
| 187 if (!IsNigoriEnabled()) { | 184 if (!IsNigoriEnabled()) { |
| 188 NOTREACHED() << "SetDecryptionPassphrase must never be called when nigori" | 185 NOTREACHED() << "SetDecryptionPassphrase must never be called when nigori" |
| 189 " is disabled."; | 186 " is disabled."; |
| 190 return false; | 187 return false; |
| 191 } | 188 } |
| 192 | 189 |
| 193 // We should never be called with an empty passphrase. | 190 // We should never be called with an empty passphrase. |
| 194 DCHECK(!passphrase.empty()); | 191 DCHECK(!passphrase.empty()); |
| 195 | 192 |
| 196 // This should only be called by the frontend. | |
| 197 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 198 | |
| 199 // This should only be called when we have cached pending keys. | 193 // This should only be called when we have cached pending keys. |
| 200 DCHECK(cached_pending_keys_.has_blob()); | 194 DCHECK(cached_pending_keys_.has_blob()); |
| 201 | 195 |
| 202 // Check the passphrase that was provided against our local cache of the | 196 // Check the passphrase that was provided against our local cache of the |
| 203 // cryptographer's pending keys. If this was unsuccessful, the UI layer can | 197 // cryptographer's pending keys. If this was unsuccessful, the UI layer can |
| 204 // immediately call OnPassphraseRequired without showing the user a spinner. | 198 // immediately call OnPassphraseRequired without showing the user a spinner. |
| 205 if (!CheckPassphraseAgainstCachedPendingKeys(passphrase)) | 199 if (!CheckPassphraseAgainstCachedPendingKeys(passphrase)) |
| 206 return false; | 200 return false; |
| 207 | 201 |
| 208 // Post a decryption task on the syncer thread. | 202 // Post a decryption task on the syncer thread. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 221 // trigger a new OnPassphraseRequired if it needs to. | 215 // trigger a new OnPassphraseRequired if it needs to. |
| 222 NotifyPassphraseAccepted(); | 216 NotifyPassphraseAccepted(); |
| 223 return true; | 217 return true; |
| 224 } | 218 } |
| 225 | 219 |
| 226 void SyncBackendHostImpl::StopSyncingForShutdown() { | 220 void SyncBackendHostImpl::StopSyncingForShutdown() { |
| 227 DCHECK(thread_checker_.CalledOnValidThread()); | 221 DCHECK(thread_checker_.CalledOnValidThread()); |
| 228 | 222 |
| 229 // Stop getting messages from the sync thread. | 223 // Stop getting messages from the sync thread. |
| 230 weak_ptr_factory_.InvalidateWeakPtrs(); | 224 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 231 // Immediately stop sending messages to the frontend. | 225 // Immediately stop sending messages to the host. |
| 232 frontend_ = nullptr; | 226 host_ = nullptr; |
| 233 | 227 |
| 234 registrar_->RequestWorkerStopOnUIThread(); | 228 registrar_->RequestWorkerStopOnUIThread(); |
| 235 | 229 |
| 236 core_->ShutdownOnUIThread(); | 230 core_->ShutdownOnUIThread(); |
| 237 } | 231 } |
| 238 | 232 |
| 239 void SyncBackendHostImpl::Shutdown(ShutdownReason reason) { | 233 void SyncBackendHostImpl::Shutdown(ShutdownReason reason) { |
| 240 // StopSyncingForShutdown() (which nulls out |frontend_|) should be | 234 // StopSyncingForShutdown() (which nulls out |host_|) should be |
| 241 // called first. | 235 // called first. |
| 242 DCHECK(!frontend_); | 236 DCHECK(!host_); |
| 243 | 237 |
| 244 if (invalidation_handler_registered_) { | 238 if (invalidation_handler_registered_) { |
| 245 if (reason == DISABLE_SYNC) { | 239 if (reason == DISABLE_SYNC) { |
| 246 UnregisterInvalidationIds(); | 240 UnregisterInvalidationIds(); |
| 247 } | 241 } |
| 248 invalidator_->UnregisterInvalidationHandler(this); | 242 invalidator_->UnregisterInvalidationHandler(this); |
| 249 invalidator_ = nullptr; | 243 invalidator_ = nullptr; |
| 250 } | 244 } |
| 251 invalidation_handler_registered_ = false; | 245 invalidation_handler_registered_ = false; |
| 252 | 246 |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 } | 528 } |
| 535 | 529 |
| 536 if (!ready_task.is_null()) | 530 if (!ready_task.is_null()) |
| 537 ready_task.Run(succeeded_configuration_types, failed_configuration_types); | 531 ready_task.Run(succeeded_configuration_types, failed_configuration_types); |
| 538 } | 532 } |
| 539 | 533 |
| 540 void SyncBackendHostImpl::AddExperimentalTypes() { | 534 void SyncBackendHostImpl::AddExperimentalTypes() { |
| 541 CHECK(initialized()); | 535 CHECK(initialized()); |
| 542 Experiments experiments; | 536 Experiments experiments; |
| 543 if (core_->sync_manager()->ReceivedExperiment(&experiments)) | 537 if (core_->sync_manager()->ReceivedExperiment(&experiments)) |
| 544 frontend_->OnExperimentsChanged(experiments); | 538 host_->OnExperimentsChanged(experiments); |
| 545 } | 539 } |
| 546 | 540 |
| 547 void SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop( | 541 void SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop( |
| 548 const WeakHandle<JsBackend> js_backend, | 542 const WeakHandle<JsBackend> js_backend, |
| 549 const WeakHandle<DataTypeDebugInfoListener> debug_info_listener, | 543 const WeakHandle<DataTypeDebugInfoListener> debug_info_listener, |
| 550 std::unique_ptr<ModelTypeConnector> model_type_connector, | 544 std::unique_ptr<ModelTypeConnector> model_type_connector, |
| 551 const std::string& cache_guid) { | 545 const std::string& cache_guid) { |
| 552 DCHECK(thread_checker_.CalledOnValidThread()); | 546 DCHECK(thread_checker_.CalledOnValidThread()); |
| 553 | 547 |
| 554 model_type_connector_ = std::move(model_type_connector); | 548 model_type_connector_ = std::move(model_type_connector); |
| 555 | 549 |
| 556 initialized_ = true; | 550 initialized_ = true; |
| 557 | 551 |
| 558 if (invalidator_) { | 552 if (invalidator_) { |
| 559 invalidator_->RegisterInvalidationHandler(this); | 553 invalidator_->RegisterInvalidationHandler(this); |
| 560 invalidation_handler_registered_ = true; | 554 invalidation_handler_registered_ = true; |
| 561 | 555 |
| 562 // Fake a state change to initialize the SyncManager's cached invalidator | 556 // Fake a state change to initialize the SyncManager's cached invalidator |
| 563 // state. | 557 // state. |
| 564 OnInvalidatorStateChange(invalidator_->GetInvalidatorState()); | 558 OnInvalidatorStateChange(invalidator_->GetInvalidatorState()); |
| 565 } | 559 } |
| 566 | 560 |
| 567 // Now that we've downloaded the control types, we can see if there are any | 561 // Now that we've downloaded the control types, we can see if there are any |
| 568 // experimental types to enable. This should be done before we inform | 562 // experimental types to enable. This should be done before we inform |
| 569 // the frontend to ensure they're visible in the customize screen. | 563 // the host to ensure they're visible in the customize screen. |
| 570 AddExperimentalTypes(); | 564 AddExperimentalTypes(); |
| 571 frontend_->OnBackendInitialized(js_backend, debug_info_listener, cache_guid, | 565 host_->OnBackendInitialized(js_backend, debug_info_listener, cache_guid, |
| 572 true); | 566 true); |
| 573 } | 567 } |
| 574 | 568 |
| 575 void SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop() { | 569 void SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop() { |
| 576 DCHECK(thread_checker_.CalledOnValidThread()); | 570 DCHECK(thread_checker_.CalledOnValidThread()); |
| 577 frontend_->OnBackendInitialized(WeakHandle<JsBackend>(), | 571 host_->OnBackendInitialized(WeakHandle<JsBackend>(), |
| 578 WeakHandle<DataTypeDebugInfoListener>(), "", | 572 WeakHandle<DataTypeDebugInfoListener>(), "", |
| 579 false); | 573 false); |
| 580 } | 574 } |
| 581 | 575 |
| 582 void SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop( | 576 void SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop( |
| 583 const SyncCycleSnapshot& snapshot) { | 577 const SyncCycleSnapshot& snapshot) { |
| 584 DCHECK(thread_checker_.CalledOnValidThread()); | 578 DCHECK(thread_checker_.CalledOnValidThread()); |
| 585 | 579 |
| 586 last_snapshot_ = snapshot; | 580 last_snapshot_ = snapshot; |
| 587 | 581 |
| 588 SDVLOG(1) << "Got snapshot " << snapshot.ToString(); | 582 SDVLOG(1) << "Got snapshot " << snapshot.ToString(); |
| 589 | 583 |
| 590 if (!snapshot.poll_finish_time().is_null()) | 584 if (!snapshot.poll_finish_time().is_null()) |
| 591 sync_prefs_->SetLastPollTime(snapshot.poll_finish_time()); | 585 sync_prefs_->SetLastPollTime(snapshot.poll_finish_time()); |
| 592 | 586 |
| 593 // Process any changes to the datatypes we're syncing. | 587 // Process any changes to the datatypes we're syncing. |
| 594 // TODO(sync): add support for removing types. | 588 // TODO(sync): add support for removing types. |
| 595 if (initialized()) | 589 if (initialized()) |
| 596 AddExperimentalTypes(); | 590 AddExperimentalTypes(); |
| 597 | 591 |
| 598 if (initialized()) | 592 if (initialized()) |
| 599 frontend_->OnSyncCycleCompleted(); | 593 host_->OnSyncCycleCompleted(); |
| 600 } | 594 } |
| 601 | 595 |
| 602 void SyncBackendHostImpl::RetryConfigurationOnFrontendLoop( | 596 void SyncBackendHostImpl::RetryConfigurationOnFrontendLoop( |
| 603 const base::Closure& retry_callback) { | 597 const base::Closure& retry_callback) { |
| 604 SDVLOG(1) << "Failed to complete configuration, informing of retry."; | 598 SDVLOG(1) << "Failed to complete configuration, informing of retry."; |
| 605 retry_callback.Run(); | 599 retry_callback.Run(); |
| 606 } | 600 } |
| 607 | 601 |
| 608 void SyncBackendHostImpl::PersistEncryptionBootstrapToken( | 602 void SyncBackendHostImpl::PersistEncryptionBootstrapToken( |
| 609 const std::string& token, | 603 const std::string& token, |
| 610 BootstrapTokenType token_type) { | 604 BootstrapTokenType token_type) { |
| 611 CHECK(sync_prefs_.get()); | 605 CHECK(sync_prefs_.get()); |
| 612 if (token_type == PASSPHRASE_BOOTSTRAP_TOKEN) | 606 if (token_type == PASSPHRASE_BOOTSTRAP_TOKEN) |
| 613 sync_prefs_->SetEncryptionBootstrapToken(token); | 607 sync_prefs_->SetEncryptionBootstrapToken(token); |
| 614 else | 608 else |
| 615 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token); | 609 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token); |
| 616 } | 610 } |
| 617 | 611 |
| 618 void SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop( | 612 void SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop( |
| 619 const SyncProtocolError& sync_error) { | 613 const SyncProtocolError& sync_error) { |
| 620 DCHECK(thread_checker_.CalledOnValidThread()); | 614 DCHECK(thread_checker_.CalledOnValidThread()); |
| 621 frontend_->OnActionableError(sync_error); | 615 host_->OnActionableError(sync_error); |
| 622 } | 616 } |
| 623 | 617 |
| 624 void SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop( | 618 void SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop( |
| 625 ModelTypeSet types) { | 619 ModelTypeSet types) { |
| 626 DCHECK(thread_checker_.CalledOnValidThread()); | 620 DCHECK(thread_checker_.CalledOnValidThread()); |
| 627 frontend_->OnMigrationNeededForTypes(types); | 621 host_->OnMigrationNeededForTypes(types); |
| 628 } | 622 } |
| 629 | 623 |
| 630 void SyncBackendHostImpl::OnInvalidatorStateChange(InvalidatorState state) { | 624 void SyncBackendHostImpl::OnInvalidatorStateChange(InvalidatorState state) { |
| 631 sync_task_runner_->PostTask( | 625 sync_task_runner_->PostTask( |
| 632 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnInvalidatorStateChange, | 626 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnInvalidatorStateChange, |
| 633 core_, state)); | 627 core_, state)); |
| 634 } | 628 } |
| 635 | 629 |
| 636 void SyncBackendHostImpl::OnIncomingInvalidation( | 630 void SyncBackendHostImpl::OnIncomingInvalidation( |
| 637 const ObjectIdInvalidationMap& invalidation_map) { | 631 const ObjectIdInvalidationMap& invalidation_map) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 657 } | 651 } |
| 658 | 652 |
| 659 void SyncBackendHostImpl::NotifyPassphraseRequired( | 653 void SyncBackendHostImpl::NotifyPassphraseRequired( |
| 660 PassphraseRequiredReason reason, | 654 PassphraseRequiredReason reason, |
| 661 sync_pb::EncryptedData pending_keys) { | 655 sync_pb::EncryptedData pending_keys) { |
| 662 DCHECK(thread_checker_.CalledOnValidThread()); | 656 DCHECK(thread_checker_.CalledOnValidThread()); |
| 663 | 657 |
| 664 // Update our cache of the cryptographer's pending keys. | 658 // Update our cache of the cryptographer's pending keys. |
| 665 cached_pending_keys_ = pending_keys; | 659 cached_pending_keys_ = pending_keys; |
| 666 | 660 |
| 667 frontend_->OnPassphraseRequired(reason, pending_keys); | 661 host_->OnPassphraseRequired(reason, pending_keys); |
| 668 } | 662 } |
| 669 | 663 |
| 670 void SyncBackendHostImpl::NotifyPassphraseAccepted() { | 664 void SyncBackendHostImpl::NotifyPassphraseAccepted() { |
| 671 DCHECK(thread_checker_.CalledOnValidThread()); | 665 DCHECK(thread_checker_.CalledOnValidThread()); |
| 672 // Clear our cache of the cryptographer's pending keys. | 666 // Clear our cache of the cryptographer's pending keys. |
| 673 cached_pending_keys_.clear_blob(); | 667 cached_pending_keys_.clear_blob(); |
| 674 frontend_->OnPassphraseAccepted(); | 668 host_->OnPassphraseAccepted(); |
| 675 } | 669 } |
| 676 | 670 |
| 677 void SyncBackendHostImpl::NotifyEncryptedTypesChanged( | 671 void SyncBackendHostImpl::NotifyEncryptedTypesChanged( |
| 678 ModelTypeSet encrypted_types, | 672 ModelTypeSet encrypted_types, |
| 679 bool encrypt_everything) { | 673 bool encrypt_everything) { |
| 680 DCHECK(thread_checker_.CalledOnValidThread()); | 674 DCHECK(thread_checker_.CalledOnValidThread()); |
| 681 frontend_->OnEncryptedTypesChanged(encrypted_types, encrypt_everything); | 675 host_->OnEncryptedTypesChanged(encrypted_types, encrypt_everything); |
| 682 } | 676 } |
| 683 | 677 |
| 684 void SyncBackendHostImpl::NotifyEncryptionComplete() { | 678 void SyncBackendHostImpl::NotifyEncryptionComplete() { |
| 685 DCHECK(thread_checker_.CalledOnValidThread()); | 679 DCHECK(thread_checker_.CalledOnValidThread()); |
| 686 frontend_->OnEncryptionComplete(); | 680 host_->OnEncryptionComplete(); |
| 687 } | 681 } |
| 688 | 682 |
| 689 void SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop( | 683 void SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop( |
| 690 PassphraseType type, | 684 PassphraseType type, |
| 691 base::Time explicit_passphrase_time) { | 685 base::Time explicit_passphrase_time) { |
| 692 DCHECK(thread_checker_.CalledOnValidThread()); | 686 DCHECK(thread_checker_.CalledOnValidThread()); |
| 693 DVLOG(1) << "Passphrase type changed to " << PassphraseTypeToString(type); | 687 DVLOG(1) << "Passphrase type changed to " << PassphraseTypeToString(type); |
| 694 cached_passphrase_type_ = type; | 688 cached_passphrase_type_ = type; |
| 695 cached_explicit_passphrase_time_ = explicit_passphrase_time; | 689 cached_explicit_passphrase_time_ = explicit_passphrase_time; |
| 696 } | 690 } |
| 697 | 691 |
| 698 void SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop( | 692 void SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop( |
| 699 const SyncEncryptionHandler::NigoriState& nigori_state) { | 693 const SyncEncryptionHandler::NigoriState& nigori_state) { |
| 700 DCHECK(thread_checker_.CalledOnValidThread()); | 694 DCHECK(thread_checker_.CalledOnValidThread()); |
| 701 frontend_->OnLocalSetPassphraseEncryption(nigori_state); | 695 host_->OnLocalSetPassphraseEncryption(nigori_state); |
| 702 } | 696 } |
| 703 | 697 |
| 704 void SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop( | 698 void SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop( |
| 705 ConnectionStatus status) { | 699 ConnectionStatus status) { |
| 706 DCHECK(thread_checker_.CalledOnValidThread()); | 700 DCHECK(thread_checker_.CalledOnValidThread()); |
| 707 | |
| 708 DVLOG(1) << "Connection status changed: " << ConnectionStatusToString(status); | 701 DVLOG(1) << "Connection status changed: " << ConnectionStatusToString(status); |
| 709 frontend_->OnConnectionStatusChange(status); | 702 host_->OnConnectionStatusChange(status); |
| 710 } | 703 } |
| 711 | 704 |
| 712 void SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop( | 705 void SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop( |
| 713 std::unique_ptr<ProtocolEvent> event) { | 706 std::unique_ptr<ProtocolEvent> event) { |
| 714 frontend_->OnProtocolEvent(*event); | 707 DCHECK(thread_checker_.CalledOnValidThread()); |
| 708 host_->OnProtocolEvent(*event); |
| 715 } | 709 } |
| 716 | 710 |
| 717 void SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop( | 711 void SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop( |
| 718 ModelType type, | 712 ModelType type, |
| 719 const CommitCounters& counters) { | 713 const CommitCounters& counters) { |
| 720 frontend_->OnDirectoryTypeCommitCounterUpdated(type, counters); | 714 DCHECK(thread_checker_.CalledOnValidThread()); |
| 715 host_->OnDirectoryTypeCommitCounterUpdated(type, counters); |
| 721 } | 716 } |
| 722 | 717 |
| 723 void SyncBackendHostImpl::HandleDirectoryUpdateCountersUpdatedOnFrontendLoop( | 718 void SyncBackendHostImpl::HandleDirectoryUpdateCountersUpdatedOnFrontendLoop( |
| 724 ModelType type, | 719 ModelType type, |
| 725 const UpdateCounters& counters) { | 720 const UpdateCounters& counters) { |
| 726 frontend_->OnDirectoryTypeUpdateCounterUpdated(type, counters); | 721 DCHECK(thread_checker_.CalledOnValidThread()); |
| 722 host_->OnDirectoryTypeUpdateCounterUpdated(type, counters); |
| 727 } | 723 } |
| 728 | 724 |
| 729 void SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop( | 725 void SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop( |
| 730 ModelType type, | 726 ModelType type, |
| 731 const StatusCounters& counters) { | 727 const StatusCounters& counters) { |
| 732 frontend_->OnDatatypeStatusCounterUpdated(type, counters); | 728 DCHECK(thread_checker_.CalledOnValidThread()); |
| 729 host_->OnDatatypeStatusCounterUpdated(type, counters); |
| 733 } | 730 } |
| 734 | 731 |
| 735 void SyncBackendHostImpl::UpdateInvalidationVersions( | 732 void SyncBackendHostImpl::UpdateInvalidationVersions( |
| 736 const std::map<ModelType, int64_t>& invalidation_versions) { | 733 const std::map<ModelType, int64_t>& invalidation_versions) { |
| 734 DCHECK(thread_checker_.CalledOnValidThread()); |
| 737 sync_prefs_->UpdateInvalidationVersions(invalidation_versions); | 735 sync_prefs_->UpdateInvalidationVersions(invalidation_versions); |
| 738 } | 736 } |
| 739 | 737 |
| 740 void SyncBackendHostImpl::RefreshTypesForTest(ModelTypeSet types) { | 738 void SyncBackendHostImpl::RefreshTypesForTest(ModelTypeSet types) { |
| 741 DCHECK(thread_checker_.CalledOnValidThread()); | 739 DCHECK(thread_checker_.CalledOnValidThread()); |
| 742 sync_task_runner_->PostTask( | 740 sync_task_runner_->PostTask( |
| 743 FROM_HERE, | 741 FROM_HERE, |
| 744 base::Bind(&SyncBackendHostCore::DoRefreshTypes, core_, types)); | 742 base::Bind(&SyncBackendHostCore::DoRefreshTypes, core_, types)); |
| 745 } | 743 } |
| 746 | 744 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 764 const SyncManager::ClearServerDataCallback& frontend_callback) { | 762 const SyncManager::ClearServerDataCallback& frontend_callback) { |
| 765 DCHECK(thread_checker_.CalledOnValidThread()); | 763 DCHECK(thread_checker_.CalledOnValidThread()); |
| 766 frontend_callback.Run(); | 764 frontend_callback.Run(); |
| 767 } | 765 } |
| 768 | 766 |
| 769 } // namespace syncer | 767 } // namespace syncer |
| 770 | 768 |
| 771 #undef SDVLOG | 769 #undef SDVLOG |
| 772 | 770 |
| 773 #undef SLOG | 771 #undef SLOG |
| OLD | NEW |