| 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 <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 weak_ptr_factory_.GetWeakPtr()); | 67 weak_ptr_factory_.GetWeakPtr()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 SyncBackendHostImpl::~SyncBackendHostImpl() { | 70 SyncBackendHostImpl::~SyncBackendHostImpl() { |
| 71 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; | 71 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; |
| 72 DCHECK(!registrar_.get()); | 72 DCHECK(!registrar_.get()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void SyncBackendHostImpl::Initialize( | 75 void SyncBackendHostImpl::Initialize( |
| 76 sync_driver::SyncFrontend* frontend, | 76 sync_driver::SyncFrontend* frontend, |
| 77 scoped_ptr<base::Thread> sync_thread, | 77 std::unique_ptr<base::Thread> sync_thread, |
| 78 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, | 78 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, |
| 79 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, | 79 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, |
| 80 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 80 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
| 81 const GURL& sync_service_url, | 81 const GURL& sync_service_url, |
| 82 const std::string& sync_user_agent, | 82 const std::string& sync_user_agent, |
| 83 const syncer::SyncCredentials& credentials, | 83 const syncer::SyncCredentials& credentials, |
| 84 bool delete_sync_data_folder, | 84 bool delete_sync_data_folder, |
| 85 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, | 85 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory, |
| 86 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>& | 86 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>& |
| 87 unrecoverable_error_handler, | 87 unrecoverable_error_handler, |
| 88 const base::Closure& report_unrecoverable_error_function, | 88 const base::Closure& report_unrecoverable_error_function, |
| 89 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, | 89 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, |
| 90 scoped_ptr<syncer::SyncEncryptionHandler::NigoriState> saved_nigori_state) { | 90 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> |
| 91 saved_nigori_state) { |
| 91 registrar_.reset(new browser_sync::SyncBackendRegistrar( | 92 registrar_.reset(new browser_sync::SyncBackendRegistrar( |
| 92 name_, sync_client_, std::move(sync_thread), ui_thread_, db_thread, | 93 name_, sync_client_, std::move(sync_thread), ui_thread_, db_thread, |
| 93 file_thread)); | 94 file_thread)); |
| 94 CHECK(registrar_->sync_thread()); | 95 CHECK(registrar_->sync_thread()); |
| 95 | 96 |
| 96 frontend_ = frontend; | 97 frontend_ = frontend; |
| 97 DCHECK(frontend); | 98 DCHECK(frontend); |
| 98 | 99 |
| 99 syncer::ModelSafeRoutingInfo routing_info; | 100 syncer::ModelSafeRoutingInfo routing_info; |
| 100 std::vector<scoped_refptr<syncer::ModelSafeWorker> > workers; | 101 std::vector<scoped_refptr<syncer::ModelSafeWorker> > workers; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 116 InternalComponentsFactory::FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE; | 117 InternalComponentsFactory::FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE; |
| 117 } | 118 } |
| 118 syncer::PassphraseTransitionClearDataOption clear_data_option = | 119 syncer::PassphraseTransitionClearDataOption clear_data_option = |
| 119 syncer::PASSPHRASE_TRANSITION_DO_NOT_CLEAR_DATA; | 120 syncer::PASSPHRASE_TRANSITION_DO_NOT_CLEAR_DATA; |
| 120 if (cl->HasSwitch(switches::kSyncEnableClearDataOnPassphraseEncryption)) | 121 if (cl->HasSwitch(switches::kSyncEnableClearDataOnPassphraseEncryption)) |
| 121 clear_data_option = syncer::PASSPHRASE_TRANSITION_CLEAR_DATA; | 122 clear_data_option = syncer::PASSPHRASE_TRANSITION_CLEAR_DATA; |
| 122 | 123 |
| 123 std::map<syncer::ModelType, int64_t> invalidation_versions; | 124 std::map<syncer::ModelType, int64_t> invalidation_versions; |
| 124 sync_prefs_->GetInvalidationVersions(&invalidation_versions); | 125 sync_prefs_->GetInvalidationVersions(&invalidation_versions); |
| 125 | 126 |
| 126 scoped_ptr<DoInitializeOptions> init_opts(new DoInitializeOptions( | 127 std::unique_ptr<DoInitializeOptions> init_opts(new DoInitializeOptions( |
| 127 registrar_->sync_thread()->message_loop(), registrar_.get(), routing_info, | 128 registrar_->sync_thread()->message_loop(), registrar_.get(), routing_info, |
| 128 workers, sync_client_->GetExtensionsActivity(), event_handler, | 129 workers, sync_client_->GetExtensionsActivity(), event_handler, |
| 129 sync_service_url, sync_user_agent, | 130 sync_service_url, sync_user_agent, |
| 130 http_post_provider_factory_getter.Run( | 131 http_post_provider_factory_getter.Run( |
| 131 core_->GetRequestContextCancelationSignal()), | 132 core_->GetRequestContextCancelationSignal()), |
| 132 credentials, invalidator_ ? invalidator_->GetInvalidatorClientId() : "", | 133 credentials, invalidator_ ? invalidator_->GetInvalidatorClientId() : "", |
| 133 std::move(sync_manager_factory), delete_sync_data_folder, | 134 std::move(sync_manager_factory), delete_sync_data_folder, |
| 134 sync_prefs_->GetEncryptionBootstrapToken(), | 135 sync_prefs_->GetEncryptionBootstrapToken(), |
| 135 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), | 136 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), |
| 136 scoped_ptr<InternalComponentsFactory>( | 137 std::unique_ptr<InternalComponentsFactory>( |
| 137 new syncer::InternalComponentsFactoryImpl(factory_switches)), | 138 new syncer::InternalComponentsFactoryImpl(factory_switches)), |
| 138 unrecoverable_error_handler, report_unrecoverable_error_function, | 139 unrecoverable_error_handler, report_unrecoverable_error_function, |
| 139 std::move(saved_nigori_state), clear_data_option, invalidation_versions)); | 140 std::move(saved_nigori_state), clear_data_option, invalidation_versions)); |
| 140 InitCore(std::move(init_opts)); | 141 InitCore(std::move(init_opts)); |
| 141 } | 142 } |
| 142 | 143 |
| 143 void SyncBackendHostImpl::TriggerRefresh(const syncer::ModelTypeSet& types) { | 144 void SyncBackendHostImpl::TriggerRefresh(const syncer::ModelTypeSet& types) { |
| 144 DCHECK(ui_thread_->BelongsToCurrentThread()); | 145 DCHECK(ui_thread_->BelongsToCurrentThread()); |
| 145 registrar_->sync_thread()->task_runner()->PostTask( | 146 registrar_->sync_thread()->task_runner()->PostTask( |
| 146 FROM_HERE, | 147 FROM_HERE, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // Stop non-blocking sync types from sending any more requests to the syncer. | 243 // Stop non-blocking sync types from sending any more requests to the syncer. |
| 243 model_type_connector_.reset(); | 244 model_type_connector_.reset(); |
| 244 | 245 |
| 245 DCHECK(registrar_->sync_thread()->IsRunning()); | 246 DCHECK(registrar_->sync_thread()->IsRunning()); |
| 246 | 247 |
| 247 registrar_->RequestWorkerStopOnUIThread(); | 248 registrar_->RequestWorkerStopOnUIThread(); |
| 248 | 249 |
| 249 core_->ShutdownOnUIThread(); | 250 core_->ShutdownOnUIThread(); |
| 250 } | 251 } |
| 251 | 252 |
| 252 scoped_ptr<base::Thread> SyncBackendHostImpl::Shutdown( | 253 std::unique_ptr<base::Thread> SyncBackendHostImpl::Shutdown( |
| 253 syncer::ShutdownReason reason) { | 254 syncer::ShutdownReason reason) { |
| 254 // StopSyncingForShutdown() (which nulls out |frontend_|) should be | 255 // StopSyncingForShutdown() (which nulls out |frontend_|) should be |
| 255 // called first. | 256 // called first. |
| 256 DCHECK(!frontend_); | 257 DCHECK(!frontend_); |
| 257 DCHECK(registrar_->sync_thread()->IsRunning()); | 258 DCHECK(registrar_->sync_thread()->IsRunning()); |
| 258 | 259 |
| 259 bool sync_thread_claimed = (reason != syncer::BROWSER_SHUTDOWN); | 260 bool sync_thread_claimed = (reason != syncer::BROWSER_SHUTDOWN); |
| 260 | 261 |
| 261 if (invalidation_handler_registered_) { | 262 if (invalidation_handler_registered_) { |
| 262 if (reason == syncer::DISABLE_SYNC) { | 263 if (reason == syncer::DISABLE_SYNC) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 275 | 276 |
| 276 // Worker cleanup. | 277 // Worker cleanup. |
| 277 SyncBackendRegistrar* detached_registrar = registrar_.release(); | 278 SyncBackendRegistrar* detached_registrar = registrar_.release(); |
| 278 detached_registrar->sync_thread()->task_runner()->PostTask( | 279 detached_registrar->sync_thread()->task_runner()->PostTask( |
| 279 FROM_HERE, base::Bind(&SyncBackendRegistrar::Shutdown, | 280 FROM_HERE, base::Bind(&SyncBackendRegistrar::Shutdown, |
| 280 base::Unretained(detached_registrar))); | 281 base::Unretained(detached_registrar))); |
| 281 | 282 |
| 282 if (sync_thread_claimed) | 283 if (sync_thread_claimed) |
| 283 return detached_registrar->ReleaseSyncThread(); | 284 return detached_registrar->ReleaseSyncThread(); |
| 284 else | 285 else |
| 285 return scoped_ptr<base::Thread>(); | 286 return std::unique_ptr<base::Thread>(); |
| 286 } | 287 } |
| 287 | 288 |
| 288 void SyncBackendHostImpl::UnregisterInvalidationIds() { | 289 void SyncBackendHostImpl::UnregisterInvalidationIds() { |
| 289 if (invalidation_handler_registered_) { | 290 if (invalidation_handler_registered_) { |
| 290 CHECK(invalidator_->UpdateRegisteredInvalidationIds(this, | 291 CHECK(invalidator_->UpdateRegisteredInvalidationIds(this, |
| 291 syncer::ObjectIdSet())); | 292 syncer::ObjectIdSet())); |
| 292 } | 293 } |
| 293 } | 294 } |
| 294 | 295 |
| 295 syncer::ModelTypeSet SyncBackendHostImpl::ConfigureDataTypes( | 296 syncer::ModelTypeSet SyncBackendHostImpl::ConfigureDataTypes( |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 sync_driver::ChangeProcessor* change_processor) { | 434 sync_driver::ChangeProcessor* change_processor) { |
| 434 registrar_->ActivateDataType(type, group, change_processor, GetUserShare()); | 435 registrar_->ActivateDataType(type, group, change_processor, GetUserShare()); |
| 435 } | 436 } |
| 436 | 437 |
| 437 void SyncBackendHostImpl::DeactivateDirectoryDataType(syncer::ModelType type) { | 438 void SyncBackendHostImpl::DeactivateDirectoryDataType(syncer::ModelType type) { |
| 438 registrar_->DeactivateDataType(type); | 439 registrar_->DeactivateDataType(type); |
| 439 } | 440 } |
| 440 | 441 |
| 441 void SyncBackendHostImpl::ActivateNonBlockingDataType( | 442 void SyncBackendHostImpl::ActivateNonBlockingDataType( |
| 442 syncer::ModelType type, | 443 syncer::ModelType type, |
| 443 scoped_ptr<syncer_v2::ActivationContext> activation_context) { | 444 std::unique_ptr<syncer_v2::ActivationContext> activation_context) { |
| 444 registrar_->RegisterNonBlockingType(type); | 445 registrar_->RegisterNonBlockingType(type); |
| 445 model_type_connector_->ConnectType(type, std::move(activation_context)); | 446 model_type_connector_->ConnectType(type, std::move(activation_context)); |
| 446 } | 447 } |
| 447 | 448 |
| 448 void SyncBackendHostImpl::DeactivateNonBlockingDataType( | 449 void SyncBackendHostImpl::DeactivateNonBlockingDataType( |
| 449 syncer::ModelType type) { | 450 syncer::ModelType type) { |
| 450 model_type_connector_->DisconnectType(type); | 451 model_type_connector_->DisconnectType(type); |
| 451 } | 452 } |
| 452 | 453 |
| 453 syncer::UserShare* SyncBackendHostImpl::GetUserShare() const { | 454 syncer::UserShare* SyncBackendHostImpl::GetUserShare() const { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 void SyncBackendHostImpl::GetAllNodesForTypes( | 537 void SyncBackendHostImpl::GetAllNodesForTypes( |
| 537 syncer::ModelTypeSet types, | 538 syncer::ModelTypeSet types, |
| 538 base::Callback<void(const std::vector<syncer::ModelType>&, | 539 base::Callback<void(const std::vector<syncer::ModelType>&, |
| 539 ScopedVector<base::ListValue>)> callback) { | 540 ScopedVector<base::ListValue>)> callback) { |
| 540 DCHECK(initialized()); | 541 DCHECK(initialized()); |
| 541 registrar_->sync_thread()->task_runner()->PostTask( | 542 registrar_->sync_thread()->task_runner()->PostTask( |
| 542 FROM_HERE, base::Bind(&SyncBackendHostCore::GetAllNodesForTypes, core_, | 543 FROM_HERE, base::Bind(&SyncBackendHostCore::GetAllNodesForTypes, core_, |
| 543 types, frontend_loop_->task_runner(), callback)); | 544 types, frontend_loop_->task_runner(), callback)); |
| 544 } | 545 } |
| 545 | 546 |
| 546 void SyncBackendHostImpl::InitCore(scoped_ptr<DoInitializeOptions> options) { | 547 void SyncBackendHostImpl::InitCore( |
| 548 std::unique_ptr<DoInitializeOptions> options) { |
| 547 registrar_->sync_thread()->task_runner()->PostTask( | 549 registrar_->sync_thread()->task_runner()->PostTask( |
| 548 FROM_HERE, base::Bind(&SyncBackendHostCore::DoInitialize, core_.get(), | 550 FROM_HERE, base::Bind(&SyncBackendHostCore::DoInitialize, core_.get(), |
| 549 base::Passed(&options))); | 551 base::Passed(&options))); |
| 550 } | 552 } |
| 551 | 553 |
| 552 void SyncBackendHostImpl::RequestConfigureSyncer( | 554 void SyncBackendHostImpl::RequestConfigureSyncer( |
| 553 syncer::ConfigureReason reason, | 555 syncer::ConfigureReason reason, |
| 554 syncer::ModelTypeSet to_download, | 556 syncer::ModelTypeSet to_download, |
| 555 syncer::ModelTypeSet to_purge, | 557 syncer::ModelTypeSet to_purge, |
| 556 syncer::ModelTypeSet to_journal, | 558 syncer::ModelTypeSet to_journal, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 CHECK(initialized()); | 595 CHECK(initialized()); |
| 594 syncer::Experiments experiments; | 596 syncer::Experiments experiments; |
| 595 if (core_->sync_manager()->ReceivedExperiment(&experiments)) | 597 if (core_->sync_manager()->ReceivedExperiment(&experiments)) |
| 596 frontend_->OnExperimentsChanged(experiments); | 598 frontend_->OnExperimentsChanged(experiments); |
| 597 } | 599 } |
| 598 | 600 |
| 599 void SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop( | 601 void SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop( |
| 600 const syncer::WeakHandle<syncer::JsBackend> js_backend, | 602 const syncer::WeakHandle<syncer::JsBackend> js_backend, |
| 601 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener> | 603 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener> |
| 602 debug_info_listener, | 604 debug_info_listener, |
| 603 scoped_ptr<syncer_v2::ModelTypeConnector> model_type_connector, | 605 std::unique_ptr<syncer_v2::ModelTypeConnector> model_type_connector, |
| 604 const std::string& cache_guid) { | 606 const std::string& cache_guid) { |
| 605 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 607 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); |
| 606 | 608 |
| 607 model_type_connector_ = std::move(model_type_connector); | 609 model_type_connector_ = std::move(model_type_connector); |
| 608 | 610 |
| 609 if (!frontend_) | 611 if (!frontend_) |
| 610 return; | 612 return; |
| 611 | 613 |
| 612 initialized_ = true; | 614 initialized_ = true; |
| 613 | 615 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 | 795 |
| 794 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 796 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); |
| 795 | 797 |
| 796 DVLOG(1) << "Connection status changed: " | 798 DVLOG(1) << "Connection status changed: " |
| 797 << syncer::ConnectionStatusToString(status); | 799 << syncer::ConnectionStatusToString(status); |
| 798 frontend_->OnConnectionStatusChange(status); | 800 frontend_->OnConnectionStatusChange(status); |
| 799 } | 801 } |
| 800 | 802 |
| 801 void SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop( | 803 void SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop( |
| 802 syncer::ProtocolEvent* event) { | 804 syncer::ProtocolEvent* event) { |
| 803 scoped_ptr<syncer::ProtocolEvent> scoped_event(event); | 805 std::unique_ptr<syncer::ProtocolEvent> scoped_event(event); |
| 804 if (!frontend_) | 806 if (!frontend_) |
| 805 return; | 807 return; |
| 806 frontend_->OnProtocolEvent(*scoped_event); | 808 frontend_->OnProtocolEvent(*scoped_event); |
| 807 } | 809 } |
| 808 | 810 |
| 809 void SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop( | 811 void SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop( |
| 810 syncer::ModelType type, | 812 syncer::ModelType type, |
| 811 const syncer::CommitCounters& counters) { | 813 const syncer::CommitCounters& counters) { |
| 812 if (!frontend_) | 814 if (!frontend_) |
| 813 return; | 815 return; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 const syncer::SyncManager::ClearServerDataCallback& frontend_callback) { | 868 const syncer::SyncManager::ClearServerDataCallback& frontend_callback) { |
| 867 DCHECK(ui_thread_->BelongsToCurrentThread()); | 869 DCHECK(ui_thread_->BelongsToCurrentThread()); |
| 868 frontend_callback.Run(); | 870 frontend_callback.Run(); |
| 869 } | 871 } |
| 870 | 872 |
| 871 } // namespace browser_sync | 873 } // namespace browser_sync |
| 872 | 874 |
| 873 #undef SDVLOG | 875 #undef SDVLOG |
| 874 | 876 |
| 875 #undef SLOG | 877 #undef SLOG |
| OLD | NEW |