Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/sync/glue/sync_backend_host.h" | 5 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 // This includes refreshing encryption, setting up the device info change | 191 // This includes refreshing encryption, setting up the device info change |
| 192 // processor, etc. | 192 // processor, etc. |
| 193 void DoInitialProcessControlTypes(); | 193 void DoInitialProcessControlTypes(); |
| 194 | 194 |
| 195 // Some parts of DoInitialProcessControlTypes() may be executed on a different | 195 // Some parts of DoInitialProcessControlTypes() may be executed on a different |
| 196 // thread. This function asynchronously continues the work started in | 196 // thread. This function asynchronously continues the work started in |
| 197 // DoInitialProcessControlTypes() once that other thread gets back to us. | 197 // DoInitialProcessControlTypes() once that other thread gets back to us. |
| 198 void DoFinishInitialProcessControlTypes(); | 198 void DoFinishInitialProcessControlTypes(); |
| 199 | 199 |
| 200 // The shutdown order is a bit complicated: | 200 // The shutdown order is a bit complicated: |
| 201 // 1) Call DoStopSyncManagerForShutdown() from |frontend_loop_| to request | 201 // 1) Call the SyncManagerStopHandle's RequestStop() from |frontend_loop_| to |
| 202 // sync manager to stop as soon as possible. | 202 // request sync manager to stop as soon as possible. |
| 203 // 2) Post DoShutdown() to sync loop to clean up backend state, save | 203 // 2) Post DoShutdown() to sync loop to clean up backend state, save |
| 204 // directory and destroy sync manager. | 204 // directory and destroy sync manager. |
| 205 void DoStopSyncManagerForShutdown(); | 205 void DoShutdown(bool sync_disabled, |
| 206 void DoShutdown(bool sync_disabled); | 206 scoped_ptr<syncer::CancelationSignal> signal1, |
|
tim (not reviewing)
2013/09/16 18:30:11
Explain here why we pass ownership of these signal
rlarocque
2013/09/16 18:39:09
It's explained in a comment near where this functi
| |
| 207 scoped_ptr<syncer::CancelationSignal> signal2); | |
| 207 void DoDestroySyncManager(); | 208 void DoDestroySyncManager(); |
| 208 | 209 |
| 209 // Configuration methods that must execute on sync loop. | 210 // Configuration methods that must execute on sync loop. |
| 210 void DoConfigureSyncer( | 211 void DoConfigureSyncer( |
| 211 syncer::ConfigureReason reason, | 212 syncer::ConfigureReason reason, |
| 212 const DoConfigureSyncerTypes& config_types, | 213 const DoConfigureSyncerTypes& config_types, |
| 213 const syncer::ModelSafeRoutingInfo routing_info, | 214 const syncer::ModelSafeRoutingInfo routing_info, |
| 214 const base::Callback<void(syncer::ModelTypeSet, | 215 const base::Callback<void(syncer::ModelTypeSet, |
| 215 syncer::ModelTypeSet)>& ready_task, | 216 syncer::ModelTypeSet)>& ready_task, |
| 216 const base::Closure& retry_callback); | 217 const base::Closure& retry_callback); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 profile_(profile), | 299 profile_(profile), |
| 299 name_(name), | 300 name_(name), |
| 300 core_(new Core(name_, profile_->GetPath().Append(kSyncDataFolderName), | 301 core_(new Core(name_, profile_->GetPath().Append(kSyncDataFolderName), |
| 301 weak_ptr_factory_.GetWeakPtr())), | 302 weak_ptr_factory_.GetWeakPtr())), |
| 302 initialization_state_(NOT_ATTEMPTED), | 303 initialization_state_(NOT_ATTEMPTED), |
| 303 sync_prefs_(sync_prefs), | 304 sync_prefs_(sync_prefs), |
| 304 frontend_(NULL), | 305 frontend_(NULL), |
| 305 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE), | 306 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE), |
| 306 invalidator_( | 307 invalidator_( |
| 307 invalidation::InvalidationServiceFactory::GetForProfile(profile)), | 308 invalidation::InvalidationServiceFactory::GetForProfile(profile)), |
| 308 invalidation_handler_registered_(false) { | 309 invalidation_handler_registered_(false), |
| 310 factory_cancelation_signal_(new syncer::CancelationSignal()), | |
| 311 scm_cancelation_signal_(new syncer::CancelationSignal()) { | |
| 309 } | 312 } |
| 310 | 313 |
| 311 SyncBackendHost::SyncBackendHost(Profile* profile) | 314 SyncBackendHost::SyncBackendHost(Profile* profile) |
| 312 : weak_ptr_factory_(this), | 315 : weak_ptr_factory_(this), |
| 313 frontend_loop_(base::MessageLoop::current()), | 316 frontend_loop_(base::MessageLoop::current()), |
| 314 profile_(profile), | 317 profile_(profile), |
| 315 name_("Unknown"), | 318 name_("Unknown"), |
| 316 initialization_state_(NOT_ATTEMPTED), | 319 initialization_state_(NOT_ATTEMPTED), |
| 317 frontend_(NULL), | 320 frontend_(NULL), |
| 318 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE), | 321 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE), |
| 319 invalidation_handler_registered_(false) { | 322 invalidation_handler_registered_(false) { |
| 320 } | 323 } |
| 321 | 324 |
| 322 SyncBackendHost::~SyncBackendHost() { | 325 SyncBackendHost::~SyncBackendHost() { |
| 323 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; | 326 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; |
| 324 DCHECK(!registrar_.get()); | 327 DCHECK(!registrar_.get()); |
| 325 } | 328 } |
| 326 | 329 |
| 327 namespace { | |
| 328 | |
| 329 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( | |
| 330 const scoped_refptr<net::URLRequestContextGetter>& getter, | |
| 331 const NetworkTimeTracker::UpdateCallback& update_callback) { | |
| 332 chrome::VersionInfo version_info; | |
| 333 return scoped_ptr<syncer::HttpPostProviderFactory>( | |
| 334 new syncer::HttpBridgeFactory( | |
| 335 getter.get(), | |
| 336 DeviceInfo::MakeUserAgentForSyncApi(version_info), | |
| 337 update_callback)); | |
| 338 } | |
| 339 | |
| 340 } // namespace | |
| 341 | |
| 342 void SyncBackendHost::Initialize( | 330 void SyncBackendHost::Initialize( |
| 343 SyncFrontend* frontend, | 331 SyncFrontend* frontend, |
| 344 scoped_ptr<base::Thread> sync_thread, | 332 scoped_ptr<base::Thread> sync_thread, |
| 345 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 333 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
| 346 const GURL& sync_service_url, | 334 const GURL& sync_service_url, |
| 347 const SyncCredentials& credentials, | 335 const SyncCredentials& credentials, |
| 348 bool delete_sync_data_folder, | 336 bool delete_sync_data_folder, |
| 349 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, | 337 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, |
| 350 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, | 338 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, |
| 351 syncer::ReportUnrecoverableErrorFunction | 339 syncer::ReportUnrecoverableErrorFunction |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 381 initialization_state_ = CREATING_SYNC_MANAGER; | 369 initialization_state_ = CREATING_SYNC_MANAGER; |
| 382 | 370 |
| 383 scoped_ptr<DoInitializeOptions> init_opts(new DoInitializeOptions( | 371 scoped_ptr<DoInitializeOptions> init_opts(new DoInitializeOptions( |
| 384 registrar_->sync_thread()->message_loop(), | 372 registrar_->sync_thread()->message_loop(), |
| 385 registrar_.get(), | 373 registrar_.get(), |
| 386 routing_info, | 374 routing_info, |
| 387 workers, | 375 workers, |
| 388 extensions_activity_monitor_.GetExtensionsActivity(), | 376 extensions_activity_monitor_.GetExtensionsActivity(), |
| 389 event_handler, | 377 event_handler, |
| 390 sync_service_url, | 378 sync_service_url, |
| 391 base::Bind(&MakeHttpBridgeFactory, | 379 scoped_ptr<syncer::HttpPostProviderFactory>( |
| 392 make_scoped_refptr(profile_->GetRequestContext()), | 380 new syncer::HttpBridgeFactory( |
| 393 NetworkTimeTracker::BuildNotifierUpdateCallback()), | 381 make_scoped_refptr(profile_->GetRequestContext()), |
| 382 NetworkTimeTracker::BuildNotifierUpdateCallback(), | |
| 383 factory_cancelation_signal_.get())), | |
| 394 credentials, | 384 credentials, |
| 395 invalidator_->GetInvalidatorClientId(), | 385 invalidator_->GetInvalidatorClientId(), |
| 396 sync_manager_factory.Pass(), | 386 sync_manager_factory.Pass(), |
| 397 delete_sync_data_folder, | 387 delete_sync_data_folder, |
| 398 sync_prefs_->GetEncryptionBootstrapToken(), | 388 sync_prefs_->GetEncryptionBootstrapToken(), |
| 399 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), | 389 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), |
| 400 scoped_ptr<InternalComponentsFactory>( | 390 scoped_ptr<InternalComponentsFactory>( |
| 401 new InternalComponentsFactoryImpl(factory_switches)).Pass(), | 391 new InternalComponentsFactoryImpl(factory_switches)).Pass(), |
| 402 unrecoverable_error_handler.Pass(), | 392 unrecoverable_error_handler.Pass(), |
| 403 report_unrecoverable_error_function, | 393 report_unrecoverable_error_function, |
| 404 !cl->HasSwitch(switches::kSyncDisableOAuth2Token))); | 394 !cl->HasSwitch(switches::kSyncDisableOAuth2Token), |
| 395 scm_cancelation_signal_.get())); | |
| 405 InitCore(init_opts.Pass()); | 396 InitCore(init_opts.Pass()); |
| 406 } | 397 } |
| 407 | 398 |
| 408 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { | 399 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { |
| 409 DCHECK(registrar_->sync_thread()->IsRunning()); | 400 DCHECK(registrar_->sync_thread()->IsRunning()); |
| 410 registrar_->sync_thread()->message_loop()->PostTask(FROM_HERE, | 401 registrar_->sync_thread()->message_loop()->PostTask(FROM_HERE, |
| 411 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, | 402 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, |
| 412 core_.get(), | 403 core_.get(), |
| 413 credentials)); | 404 credentials)); |
| 414 } | 405 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 // clicks OK, immediately reopens the advanced settings dialog, and gets an | 476 // clicks OK, immediately reopens the advanced settings dialog, and gets an |
| 486 // unnecessary prompt for a passphrase. | 477 // unnecessary prompt for a passphrase. |
| 487 // Note: It is not guaranteed that the passphrase will be accepted by the | 478 // Note: It is not guaranteed that the passphrase will be accepted by the |
| 488 // syncer thread, since we could receive a new nigori node while the task is | 479 // syncer thread, since we could receive a new nigori node while the task is |
| 489 // pending. This scenario is a valid race, and SetDecryptionPassphrase can | 480 // pending. This scenario is a valid race, and SetDecryptionPassphrase can |
| 490 // trigger a new OnPassphraseRequired if it needs to. | 481 // trigger a new OnPassphraseRequired if it needs to. |
| 491 NotifyPassphraseAccepted(); | 482 NotifyPassphraseAccepted(); |
| 492 return true; | 483 return true; |
| 493 } | 484 } |
| 494 | 485 |
| 495 void SyncBackendHost::StopSyncManagerForShutdown() { | |
| 496 DCHECK_GT(initialization_state_, NOT_ATTEMPTED); | |
| 497 if (initialization_state_ == CREATING_SYNC_MANAGER) { | |
| 498 // We post here to implicitly wait for the SyncManager to be created, | |
| 499 // if needed. We have to wait, since we need to shutdown immediately, | |
| 500 // and we need to tell the SyncManager so it can abort any activity | |
| 501 // (net I/O, data application). | |
| 502 DCHECK(registrar_->sync_thread()->IsRunning()); | |
| 503 registrar_->sync_thread()->message_loop()->PostTask(FROM_HERE, | |
| 504 base::Bind(&SyncBackendHost::Core::DoStopSyncManagerForShutdown, | |
| 505 core_.get())); | |
| 506 } else { | |
| 507 core_->DoStopSyncManagerForShutdown(); | |
| 508 } | |
| 509 } | |
| 510 | |
| 511 void SyncBackendHost::StopSyncingForShutdown() { | 486 void SyncBackendHost::StopSyncingForShutdown() { |
| 512 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 487 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); |
| 488 DCHECK_GT(initialization_state_, NOT_ATTEMPTED); | |
| 513 | 489 |
| 514 // Immediately stop sending messages to the frontend. | 490 // Immediately stop sending messages to the frontend. |
| 515 frontend_ = NULL; | 491 frontend_ = NULL; |
| 516 | 492 |
| 517 // Stop listening for and forwarding locally-triggered sync refresh requests. | 493 // Stop listening for and forwarding locally-triggered sync refresh requests. |
| 518 notification_registrar_.RemoveAll(); | 494 notification_registrar_.RemoveAll(); |
| 519 | 495 |
| 520 DCHECK(registrar_->sync_thread()->IsRunning()); | 496 DCHECK(registrar_->sync_thread()->IsRunning()); |
| 521 | 497 |
| 522 registrar_->RequestWorkerStopOnUIThread(); | 498 registrar_->RequestWorkerStopOnUIThread(); |
| 523 | 499 |
| 524 StopSyncManagerForShutdown(); | 500 // This will cut short any blocking network tasks, cut short any in-progress |
| 501 // sync cycles, and prevent the creation of new blocking network tasks and new | |
| 502 // sync cycles. If there was an in-progress network request, it would have | |
| 503 // had a reference to the RequestContextGetter. This reference will be | |
| 504 // dropped by the time this function returns. | |
| 505 // | |
| 506 // It is safe to call this even if Sync's backend classes have not been | |
| 507 // initialized yet. Those classes will receive the message when the sync | |
| 508 // thread finally getes around to constructing them. | |
| 509 scm_cancelation_signal_->RequestStop(); | |
| 510 | |
| 511 // This will drop the HttpBridgeFactory's reference to the | |
| 512 // RequestContextGetter. Once this has been called, the HttpBridgeFactory can | |
| 513 // no longer be used to create new HttpBridge instances. We can get away with | |
| 514 // this because the scm_cancelation_signal_ has already been signalled, which | |
| 515 // guarantees that the ServerConnectionManager will no longer attempt to | |
| 516 // create new connections. | |
| 517 factory_cancelation_signal_->RequestStop(); | |
| 525 } | 518 } |
| 526 | 519 |
| 527 scoped_ptr<base::Thread> SyncBackendHost::Shutdown(ShutdownOption option) { | 520 scoped_ptr<base::Thread> SyncBackendHost::Shutdown(ShutdownOption option) { |
| 528 // StopSyncingForShutdown() (which nulls out |frontend_|) should be | 521 // StopSyncingForShutdown() (which nulls out |frontend_|) should be |
| 529 // called first. | 522 // called first. |
| 530 DCHECK(!frontend_); | 523 DCHECK(!frontend_); |
| 531 DCHECK(registrar_->sync_thread()->IsRunning()); | 524 DCHECK(registrar_->sync_thread()->IsRunning()); |
| 532 | 525 |
| 533 bool sync_disabled = (option == DISABLE_AND_CLAIM_THREAD); | 526 bool sync_disabled = (option == DISABLE_AND_CLAIM_THREAD); |
| 534 bool sync_thread_claimed = | 527 bool sync_thread_claimed = |
| 535 (option == DISABLE_AND_CLAIM_THREAD || option == STOP_AND_CLAIM_THREAD); | 528 (option == DISABLE_AND_CLAIM_THREAD || option == STOP_AND_CLAIM_THREAD); |
| 536 | 529 |
| 537 if (invalidation_handler_registered_) { | 530 if (invalidation_handler_registered_) { |
| 538 if (sync_disabled) { | 531 if (sync_disabled) { |
| 539 UnregisterInvalidationIds(); | 532 UnregisterInvalidationIds(); |
| 540 } | 533 } |
| 541 invalidator_->UnregisterInvalidationHandler(this); | 534 invalidator_->UnregisterInvalidationHandler(this); |
| 542 invalidator_ = NULL; | 535 invalidator_ = NULL; |
| 543 } | 536 } |
| 544 invalidation_handler_registered_ = false; | 537 invalidation_handler_registered_ = false; |
| 545 | 538 |
| 546 // Shut down and destroy sync manager. | 539 // Shut down and destroy sync manager. |
| 540 // | |
| 541 // We're about to drop our reference to the |core_|. The only thing keeping | |
| 542 // it alive will be the reference that lives inside this closure we're about | |
| 543 // to post to the sync thread. If this closure doesn't run right away, it's | |
| 544 // possible that our Core will outlive us. | |
| 545 // | |
| 546 // This is a problem for the CancelationSignals, which must outlive the | |
| 547 // classes that reference them. In this case, it is safe to destroy them only | |
| 548 // after the call to DoDestroySyncManager completes. The SyncBackendHost | |
| 549 // might not live that long, but this closure will. We pass ownership of the | |
| 550 // CancelationSignals to this closure to keep them alive. | |
| 547 registrar_->sync_thread()->message_loop()->PostTask( | 551 registrar_->sync_thread()->message_loop()->PostTask( |
| 548 FROM_HERE, | 552 FROM_HERE, |
| 549 base::Bind(&SyncBackendHost::Core::DoShutdown, | 553 base::Bind(&SyncBackendHost::Core::DoShutdown, |
| 550 core_.get(), sync_disabled)); | 554 core_.get(), sync_disabled, |
| 555 base::Passed(&factory_cancelation_signal_), | |
| 556 base::Passed(&scm_cancelation_signal_))); | |
| 551 core_ = NULL; | 557 core_ = NULL; |
| 552 | 558 |
| 553 // Worker cleanup. | 559 // Worker cleanup. |
| 554 SyncBackendRegistrar* detached_registrar = registrar_.release(); | 560 SyncBackendRegistrar* detached_registrar = registrar_.release(); |
| 555 detached_registrar->sync_thread()->message_loop()->PostTask( | 561 detached_registrar->sync_thread()->message_loop()->PostTask( |
| 556 FROM_HERE, | 562 FROM_HERE, |
| 557 base::Bind(&SyncBackendRegistrar::Shutdown, | 563 base::Bind(&SyncBackendRegistrar::Shutdown, |
| 558 base::Unretained(detached_registrar))); | 564 base::Unretained(detached_registrar))); |
| 559 | 565 |
| 560 js_backend_.Reset(); | 566 js_backend_.Reset(); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 865 } | 871 } |
| 866 | 872 |
| 867 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( | 873 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( |
| 868 base::MessageLoop* sync_loop, | 874 base::MessageLoop* sync_loop, |
| 869 SyncBackendRegistrar* registrar, | 875 SyncBackendRegistrar* registrar, |
| 870 const syncer::ModelSafeRoutingInfo& routing_info, | 876 const syncer::ModelSafeRoutingInfo& routing_info, |
| 871 const std::vector<syncer::ModelSafeWorker*>& workers, | 877 const std::vector<syncer::ModelSafeWorker*>& workers, |
| 872 const scoped_refptr<syncer::ExtensionsActivity>& extensions_activity, | 878 const scoped_refptr<syncer::ExtensionsActivity>& extensions_activity, |
| 873 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 879 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
| 874 const GURL& service_url, | 880 const GURL& service_url, |
| 875 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, | 881 scoped_ptr<syncer::HttpPostProviderFactory> http_bridge_factory, |
| 876 const syncer::SyncCredentials& credentials, | 882 const syncer::SyncCredentials& credentials, |
| 877 const std::string& invalidator_client_id, | 883 const std::string& invalidator_client_id, |
| 878 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, | 884 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, |
| 879 bool delete_sync_data_folder, | 885 bool delete_sync_data_folder, |
| 880 const std::string& restored_key_for_bootstrapping, | 886 const std::string& restored_key_for_bootstrapping, |
| 881 const std::string& restored_keystore_key_for_bootstrapping, | 887 const std::string& restored_keystore_key_for_bootstrapping, |
| 882 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 888 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
| 883 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, | 889 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, |
| 884 syncer::ReportUnrecoverableErrorFunction | 890 syncer::ReportUnrecoverableErrorFunction |
| 885 report_unrecoverable_error_function, | 891 report_unrecoverable_error_function, |
| 886 bool use_oauth2_token) | 892 bool use_oauth2_token, |
| 893 syncer::CancelationSignal* const scm_cancelation_signal) | |
| 887 : sync_loop(sync_loop), | 894 : sync_loop(sync_loop), |
| 888 registrar(registrar), | 895 registrar(registrar), |
| 889 routing_info(routing_info), | 896 routing_info(routing_info), |
| 890 workers(workers), | 897 workers(workers), |
| 891 extensions_activity(extensions_activity), | 898 extensions_activity(extensions_activity), |
| 892 event_handler(event_handler), | 899 event_handler(event_handler), |
| 893 service_url(service_url), | 900 service_url(service_url), |
| 894 make_http_bridge_factory_fn(make_http_bridge_factory_fn), | 901 http_bridge_factory(http_bridge_factory.Pass()), |
| 895 credentials(credentials), | 902 credentials(credentials), |
| 896 invalidator_client_id(invalidator_client_id), | 903 invalidator_client_id(invalidator_client_id), |
| 897 sync_manager_factory(sync_manager_factory.Pass()), | 904 sync_manager_factory(sync_manager_factory.Pass()), |
| 898 delete_sync_data_folder(delete_sync_data_folder), | 905 delete_sync_data_folder(delete_sync_data_folder), |
| 899 restored_key_for_bootstrapping(restored_key_for_bootstrapping), | 906 restored_key_for_bootstrapping(restored_key_for_bootstrapping), |
| 900 restored_keystore_key_for_bootstrapping( | 907 restored_keystore_key_for_bootstrapping( |
| 901 restored_keystore_key_for_bootstrapping), | 908 restored_keystore_key_for_bootstrapping), |
| 902 internal_components_factory(internal_components_factory.Pass()), | 909 internal_components_factory(internal_components_factory.Pass()), |
| 903 unrecoverable_error_handler(unrecoverable_error_handler.Pass()), | 910 unrecoverable_error_handler(unrecoverable_error_handler.Pass()), |
| 904 report_unrecoverable_error_function( | 911 report_unrecoverable_error_function( |
| 905 report_unrecoverable_error_function), | 912 report_unrecoverable_error_function), |
| 906 use_oauth2_token(use_oauth2_token) { | 913 use_oauth2_token(use_oauth2_token), |
| 914 scm_cancelation_signal(scm_cancelation_signal) { | |
| 907 } | 915 } |
| 908 | 916 |
| 909 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} | 917 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} |
| 910 | 918 |
| 911 SyncBackendHost::Core::Core(const std::string& name, | 919 SyncBackendHost::Core::Core(const std::string& name, |
| 912 const base::FilePath& sync_data_folder_path, | 920 const base::FilePath& sync_data_folder_path, |
| 913 const base::WeakPtr<SyncBackendHost>& backend) | 921 const base::WeakPtr<SyncBackendHost>& backend) |
| 914 : name_(name), | 922 : name_(name), |
| 915 sync_data_folder_path_(sync_data_folder_path), | 923 sync_data_folder_path_(sync_data_folder_path), |
| 916 host_(backend), | 924 host_(backend), |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1126 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1134 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| 1127 sync_manager_->OnIncomingInvalidation(invalidation_map); | 1135 sync_manager_->OnIncomingInvalidation(invalidation_map); |
| 1128 } | 1136 } |
| 1129 | 1137 |
| 1130 void SyncBackendHost::Core::DoInitialize( | 1138 void SyncBackendHost::Core::DoInitialize( |
| 1131 scoped_ptr<DoInitializeOptions> options) { | 1139 scoped_ptr<DoInitializeOptions> options) { |
| 1132 DCHECK(!sync_loop_); | 1140 DCHECK(!sync_loop_); |
| 1133 sync_loop_ = options->sync_loop; | 1141 sync_loop_ = options->sync_loop; |
| 1134 DCHECK(sync_loop_); | 1142 DCHECK(sync_loop_); |
| 1135 | 1143 |
| 1144 // Finish initializing the HttpBridgeFactory. We do this here because | |
| 1145 // building the user agent may block on some platforms. | |
| 1146 chrome::VersionInfo version_info; | |
| 1147 options->http_bridge_factory->Init( | |
| 1148 DeviceInfo::MakeUserAgentForSyncApi(version_info)); | |
| 1149 | |
| 1136 // Blow away the partial or corrupt sync data folder before doing any more | 1150 // Blow away the partial or corrupt sync data folder before doing any more |
| 1137 // initialization, if necessary. | 1151 // initialization, if necessary. |
| 1138 if (options->delete_sync_data_folder) { | 1152 if (options->delete_sync_data_folder) { |
| 1139 DeleteSyncDataFolder(); | 1153 DeleteSyncDataFolder(); |
| 1140 } | 1154 } |
| 1141 | 1155 |
| 1142 // Make sure that the directory exists before initializing the backend. | 1156 // Make sure that the directory exists before initializing the backend. |
| 1143 // If it already exists, this will do no harm. | 1157 // If it already exists, this will do no harm. |
| 1144 if (!file_util::CreateDirectory(sync_data_folder_path_)) { | 1158 if (!file_util::CreateDirectory(sync_data_folder_path_)) { |
| 1145 DLOG(FATAL) << "Sync Data directory creation failed."; | 1159 DLOG(FATAL) << "Sync Data directory creation failed."; |
| 1146 } | 1160 } |
| 1147 | 1161 |
| 1148 DCHECK(!registrar_); | 1162 DCHECK(!registrar_); |
| 1149 registrar_ = options->registrar; | 1163 registrar_ = options->registrar; |
| 1150 DCHECK(registrar_); | 1164 DCHECK(registrar_); |
| 1151 | 1165 |
| 1152 sync_manager_ = options->sync_manager_factory->CreateSyncManager(name_); | 1166 sync_manager_ = options->sync_manager_factory->CreateSyncManager(name_); |
| 1153 sync_manager_->AddObserver(this); | 1167 sync_manager_->AddObserver(this); |
| 1154 sync_manager_->Init(sync_data_folder_path_, | 1168 sync_manager_->Init(sync_data_folder_path_, |
| 1155 options->event_handler, | 1169 options->event_handler, |
| 1156 options->service_url.host() + options->service_url.path(), | 1170 options->service_url.host() + options->service_url.path(), |
| 1157 options->service_url.EffectiveIntPort(), | 1171 options->service_url.EffectiveIntPort(), |
| 1158 options->service_url.SchemeIsSecure(), | 1172 options->service_url.SchemeIsSecure(), |
| 1159 options->make_http_bridge_factory_fn.Run().Pass(), | 1173 options->http_bridge_factory.Pass(), |
| 1160 options->workers, | 1174 options->workers, |
| 1161 options->extensions_activity, | 1175 options->extensions_activity, |
| 1162 options->registrar /* as SyncManager::ChangeDelegate */, | 1176 options->registrar /* as SyncManager::ChangeDelegate */, |
| 1163 options->credentials, | 1177 options->credentials, |
| 1164 options->invalidator_client_id, | 1178 options->invalidator_client_id, |
| 1165 options->restored_key_for_bootstrapping, | 1179 options->restored_key_for_bootstrapping, |
| 1166 options->restored_keystore_key_for_bootstrapping, | 1180 options->restored_keystore_key_for_bootstrapping, |
| 1167 options->internal_components_factory.get(), | 1181 options->internal_components_factory.get(), |
| 1168 &encryptor_, | 1182 &encryptor_, |
| 1169 options->unrecoverable_error_handler.Pass(), | 1183 options->unrecoverable_error_handler.Pass(), |
| 1170 options->report_unrecoverable_error_function, | 1184 options->report_unrecoverable_error_function, |
| 1171 options->use_oauth2_token); | 1185 options->use_oauth2_token, |
| 1186 options->scm_cancelation_signal); | |
| 1172 | 1187 |
| 1173 // |sync_manager_| may end up being NULL here in tests (in | 1188 // |sync_manager_| may end up being NULL here in tests (in |
| 1174 // synchronous initialization mode). | 1189 // synchronous initialization mode). |
| 1175 // | 1190 // |
| 1176 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | 1191 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). |
| 1177 if (sync_manager_) { | 1192 if (sync_manager_) { |
| 1178 // Now check the command line to see if we need to simulate an | 1193 // Now check the command line to see if we need to simulate an |
| 1179 // unrecoverable error for testing purpose. Note the error is thrown | 1194 // unrecoverable error for testing purpose. Note the error is thrown |
| 1180 // only if the initialization succeeded. Also it makes sense to use this | 1195 // only if the initialization succeeded. Also it makes sense to use this |
| 1181 // flag only when restarting the browser with an account already setup. If | 1196 // flag only when restarting the browser with an account already setup. If |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1271 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1286 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| 1272 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( | 1287 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( |
| 1273 passphrase); | 1288 passphrase); |
| 1274 } | 1289 } |
| 1275 | 1290 |
| 1276 void SyncBackendHost::Core::DoEnableEncryptEverything() { | 1291 void SyncBackendHost::Core::DoEnableEncryptEverything() { |
| 1277 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1292 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
| 1278 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); | 1293 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); |
| 1279 } | 1294 } |
| 1280 | 1295 |
| 1281 void SyncBackendHost::Core::DoStopSyncManagerForShutdown() { | 1296 void SyncBackendHost::Core::DoShutdown( |
| 1282 if (sync_manager_) | 1297 bool sync_disabled, |
| 1283 sync_manager_->StopSyncingForShutdown(); | 1298 scoped_ptr<syncer::CancelationSignal> signal1, |
| 1284 } | 1299 scoped_ptr<syncer::CancelationSignal> signal2) { |
| 1300 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | |
| 1285 | 1301 |
| 1286 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { | |
| 1287 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | |
| 1288 // It's safe to do this even if the type was never activated. | 1302 // It's safe to do this even if the type was never activated. |
| 1289 registrar_->DeactivateDataType(syncer::DEVICE_INFO); | 1303 registrar_->DeactivateDataType(syncer::DEVICE_INFO); |
| 1290 synced_device_tracker_.reset(); | 1304 synced_device_tracker_.reset(); |
| 1291 | 1305 |
| 1292 DoDestroySyncManager(); | 1306 DoDestroySyncManager(); |
| 1293 | 1307 |
| 1294 registrar_ = NULL; | 1308 registrar_ = NULL; |
| 1295 | 1309 |
| 1296 if (sync_disabled) | 1310 if (sync_disabled) |
| 1297 DeleteSyncDataFolder(); | 1311 DeleteSyncDataFolder(); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1605 | 1619 |
| 1606 base::MessageLoop* SyncBackendHost::GetSyncLoopForTesting() { | 1620 base::MessageLoop* SyncBackendHost::GetSyncLoopForTesting() { |
| 1607 return registrar_->sync_thread()->message_loop(); | 1621 return registrar_->sync_thread()->message_loop(); |
| 1608 } | 1622 } |
| 1609 | 1623 |
| 1610 #undef SDVLOG | 1624 #undef SDVLOG |
| 1611 | 1625 |
| 1612 #undef SLOG | 1626 #undef SLOG |
| 1613 | 1627 |
| 1614 } // namespace browser_sync | 1628 } // namespace browser_sync |
| OLD | NEW |