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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/sync/glue/sync_backend_host.h" | 7 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
| 20 #include "base/timer.h" | 20 #include "base/timer.h" |
| 21 #include "base/tracked_objects.h" | 21 #include "base/tracked_objects.h" |
| 22 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| 23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/signin/token_service.h" | 25 #include "chrome/browser/signin/token_service.h" |
| 26 #include "chrome/browser/signin/token_service_factory.h" | 26 #include "chrome/browser/signin/token_service_factory.h" |
| 27 #include "chrome/browser/sync/glue/bridged_invalidator.h" | 27 #include "chrome/browser/sync/glue/android_invalidator_bridge.h" |
| 28 #include "chrome/browser/sync/glue/android_invalidator_bridge_proxy.h" | |
| 28 #include "chrome/browser/sync/glue/change_processor.h" | 29 #include "chrome/browser/sync/glue/change_processor.h" |
| 29 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 30 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
| 30 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" | |
| 31 #include "chrome/browser/sync/glue/device_info.h" | 31 #include "chrome/browser/sync/glue/device_info.h" |
| 32 #include "chrome/browser/sync/glue/sync_backend_registrar.h" | 32 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
| 33 #include "chrome/browser/sync/glue/synced_device_tracker.h" | 33 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
| 34 #include "chrome/browser/sync/invalidations/invalidator_storage.h" | 34 #include "chrome/browser/sync/invalidations/invalidator_storage.h" |
| 35 #include "chrome/browser/sync/sync_prefs.h" | 35 #include "chrome/browser/sync/sync_prefs.h" |
| 36 #include "chrome/common/chrome_notification_types.h" | 36 #include "chrome/common/chrome_notification_types.h" |
| 37 #include "chrome/common/chrome_notification_types.h" | |
| 37 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/chrome_version_info.h" | 39 #include "chrome/common/chrome_version_info.h" |
| 39 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| 41 #include "content/public/browser/notification_details.h" | |
| 40 #include "content/public/browser/notification_service.h" | 42 #include "content/public/browser/notification_service.h" |
| 43 #include "content/public/browser/notification_source.h" | |
| 41 #include "content/public/common/content_client.h" | 44 #include "content/public/common/content_client.h" |
| 42 #include "google_apis/gaia/gaia_constants.h" | 45 #include "google_apis/gaia/gaia_constants.h" |
| 43 #include "jingle/notifier/base/notification_method.h" | 46 #include "jingle/notifier/base/notification_method.h" |
| 44 #include "jingle/notifier/base/notifier_options.h" | 47 #include "jingle/notifier/base/notifier_options.h" |
| 45 #include "net/base/host_port_pair.h" | 48 #include "net/base/host_port_pair.h" |
| 46 #include "net/url_request/url_request_context_getter.h" | 49 #include "net/url_request/url_request_context_getter.h" |
| 47 #include "sync/internal_api/public/base_transaction.h" | 50 #include "sync/internal_api/public/base_transaction.h" |
| 48 #include "sync/internal_api/public/engine/model_safe_worker.h" | 51 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 49 #include "sync/internal_api/public/http_bridge.h" | 52 #include "sync/internal_api/public/http_bridge.h" |
| 50 #include "sync/internal_api/public/internal_components_factory_impl.h" | 53 #include "sync/internal_api/public/internal_components_factory_impl.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 | 167 |
| 165 // Called to turn on encryption of all sync data as well as | 168 // Called to turn on encryption of all sync data as well as |
| 166 // reencrypt everything. | 169 // reencrypt everything. |
| 167 void DoEnableEncryptEverything(); | 170 void DoEnableEncryptEverything(); |
| 168 | 171 |
| 169 // Called at startup to download the control types. Will invoke | 172 // Called at startup to download the control types. Will invoke |
| 170 // DoInitialProcessControlTypes on success, and OnControlTypesDownloadRetry | 173 // DoInitialProcessControlTypes on success, and OnControlTypesDownloadRetry |
| 171 // if an error occurred. | 174 // if an error occurred. |
| 172 void DoDownloadControlTypes(); | 175 void DoDownloadControlTypes(); |
| 173 | 176 |
| 177 // Ask the syncer check for updates for the specified types. | |
|
Nicolas Zea
2013/01/28 23:48:43
"syncer to check for server updates"
rlarocque
2013/01/29 18:48:58
Done.
| |
| 178 void DoRefreshTypes(syncer::ModelTypeSet types); | |
| 179 | |
| 174 // Invoked if we failed to download the necessary control types at startup. | 180 // Invoked if we failed to download the necessary control types at startup. |
| 175 // Invokes SyncBackendHost::HandleControlTypesDownloadRetry. | 181 // Invokes SyncBackendHost::HandleControlTypesDownloadRetry. |
| 176 void OnControlTypesDownloadRetry(); | 182 void OnControlTypesDownloadRetry(); |
| 177 | 183 |
| 178 // Called to perform tasks which require the control data to be downloaded. | 184 // Called to perform tasks which require the control data to be downloaded. |
| 179 // This includes refreshing encryption, setting up the device info change | 185 // This includes refreshing encryption, setting up the device info change |
| 180 // processor, etc. | 186 // processor, etc. |
| 181 void DoInitialProcessControlTypes(); | 187 void DoInitialProcessControlTypes(); |
| 182 | 188 |
| 183 // Some parts of DoInitialProcessControlTypes() may be executed on a different | 189 // Some parts of DoInitialProcessControlTypes() may be executed on a different |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 syncer::WeakHandle<SyncBackendHost> host_; | 263 syncer::WeakHandle<SyncBackendHost> host_; |
| 258 | 264 |
| 259 // The loop where all the sync backend operations happen. | 265 // The loop where all the sync backend operations happen. |
| 260 // Non-NULL only between calls to DoInitialize() and DoShutdown(). | 266 // Non-NULL only between calls to DoInitialize() and DoShutdown(). |
| 261 MessageLoop* sync_loop_; | 267 MessageLoop* sync_loop_; |
| 262 | 268 |
| 263 // Our parent's registrar (not owned). Non-NULL only between | 269 // Our parent's registrar (not owned). Non-NULL only between |
| 264 // calls to DoInitialize() and DoShutdown(). | 270 // calls to DoInitialize() and DoShutdown(). |
| 265 SyncBackendRegistrar* registrar_; | 271 SyncBackendRegistrar* registrar_; |
| 266 | 272 |
| 267 // Our parent's notification bridge (not owned). Non-NULL only | |
| 268 // between calls to DoInitialize() and DoShutdown(). | |
| 269 ChromeSyncNotificationBridge* chrome_sync_notification_bridge_; | |
| 270 | |
| 271 // The timer used to periodically call SaveChanges. | 273 // The timer used to periodically call SaveChanges. |
| 272 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_; | 274 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_; |
| 273 | 275 |
| 274 // Our encryptor, which uses Chrome's encryption functions. | 276 // Our encryptor, which uses Chrome's encryption functions. |
| 275 ChromeEncryptor encryptor_; | 277 ChromeEncryptor encryptor_; |
| 276 | 278 |
| 277 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. | 279 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. |
| 278 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; | 280 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; |
| 279 | 281 |
| 280 // The top-level syncapi entry point. Lives on the sync thread. | 282 // The top-level syncapi entry point. Lives on the sync thread. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | 372 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), |
| 371 profile_->GetRequestContext()), | 373 profile_->GetRequestContext()), |
| 372 content::GetUserAgent(GURL()), | 374 content::GetUserAgent(GURL()), |
| 373 base::WeakPtr<syncer::InvalidationStateTracker>()), | 375 base::WeakPtr<syncer::InvalidationStateTracker>()), |
| 374 frontend_(NULL), | 376 frontend_(NULL), |
| 375 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { | 377 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { |
| 376 } | 378 } |
| 377 | 379 |
| 378 SyncBackendHost::~SyncBackendHost() { | 380 SyncBackendHost::~SyncBackendHost() { |
| 379 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; | 381 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; |
| 380 DCHECK(!chrome_sync_notification_bridge_.get()); | 382 DCHECK(!android_invalidator_bridge_.get()); |
| 381 DCHECK(!registrar_.get()); | 383 DCHECK(!registrar_.get()); |
| 382 } | 384 } |
| 383 | 385 |
| 384 namespace { | 386 namespace { |
| 385 | 387 |
| 386 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( | 388 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( |
| 387 const scoped_refptr<net::URLRequestContextGetter>& getter) { | 389 const scoped_refptr<net::URLRequestContextGetter>& getter) { |
| 388 chrome::VersionInfo version_info; | 390 chrome::VersionInfo version_info; |
| 389 return scoped_ptr<syncer::HttpPostProviderFactory>( | 391 return scoped_ptr<syncer::HttpPostProviderFactory>( |
| 390 new syncer::HttpBridgeFactory( | 392 new syncer::HttpBridgeFactory( |
| 391 getter, DeviceInfo::MakeUserAgentForSyncApi(version_info))); | 393 getter, DeviceInfo::MakeUserAgentForSyncApi(version_info))); |
| 392 } | 394 } |
| 393 | 395 |
| 394 } // namespace | 396 } // namespace |
| 395 | 397 |
| 396 void SyncBackendHost::Initialize( | 398 void SyncBackendHost::Initialize( |
| 397 SyncFrontend* frontend, | 399 SyncFrontend* frontend, |
| 398 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 400 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
| 399 const GURL& sync_service_url, | 401 const GURL& sync_service_url, |
| 400 const SyncCredentials& credentials, | 402 const SyncCredentials& credentials, |
| 401 bool delete_sync_data_folder, | 403 bool delete_sync_data_folder, |
| 402 syncer::SyncManagerFactory* sync_manager_factory, | 404 syncer::SyncManagerFactory* sync_manager_factory, |
| 403 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, | 405 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 404 syncer::ReportUnrecoverableErrorFunction | 406 syncer::ReportUnrecoverableErrorFunction |
| 405 report_unrecoverable_error_function) { | 407 report_unrecoverable_error_function) { |
| 406 if (!sync_thread_.Start()) | 408 if (!sync_thread_.Start()) |
| 407 return; | 409 return; |
| 408 | 410 |
| 409 chrome_sync_notification_bridge_.reset( | 411 android_invalidator_bridge_.reset( |
| 410 new ChromeSyncNotificationBridge( | 412 new AndroidInvalidatorBridge( |
| 411 profile_, sync_thread_.message_loop_proxy())); | 413 profile_, sync_thread_.message_loop_proxy())); |
| 412 | 414 |
| 413 frontend_ = frontend; | 415 frontend_ = frontend; |
| 414 DCHECK(frontend); | 416 DCHECK(frontend); |
| 415 | 417 |
| 416 registrar_.reset(new SyncBackendRegistrar(name_, | 418 registrar_.reset(new SyncBackendRegistrar(name_, |
| 417 profile_, | 419 profile_, |
| 418 sync_thread_.message_loop())); | 420 sync_thread_.message_loop())); |
| 419 syncer::ModelSafeRoutingInfo routing_info; | 421 syncer::ModelSafeRoutingInfo routing_info; |
| 420 std::vector<syncer::ModelSafeWorker*> workers; | 422 std::vector<syncer::ModelSafeWorker*> workers; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 441 sync_thread_.message_loop(), | 443 sync_thread_.message_loop(), |
| 442 registrar_.get(), | 444 registrar_.get(), |
| 443 routing_info, | 445 routing_info, |
| 444 workers, | 446 workers, |
| 445 &extensions_activity_monitor_, | 447 &extensions_activity_monitor_, |
| 446 event_handler, | 448 event_handler, |
| 447 sync_service_url, | 449 sync_service_url, |
| 448 base::Bind(&MakeHttpBridgeFactory, | 450 base::Bind(&MakeHttpBridgeFactory, |
| 449 make_scoped_refptr(profile_->GetRequestContext())), | 451 make_scoped_refptr(profile_->GetRequestContext())), |
| 450 credentials, | 452 credentials, |
| 451 chrome_sync_notification_bridge_.get(), | 453 android_invalidator_bridge_.get(), |
| 452 &invalidator_factory_, | 454 &invalidator_factory_, |
| 453 sync_manager_factory, | 455 sync_manager_factory, |
| 454 delete_sync_data_folder, | 456 delete_sync_data_folder, |
| 455 sync_prefs_->GetEncryptionBootstrapToken(), | 457 sync_prefs_->GetEncryptionBootstrapToken(), |
| 456 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), | 458 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), |
| 457 new InternalComponentsFactoryImpl(factory_switches), | 459 new InternalComponentsFactoryImpl(factory_switches), |
| 458 unrecoverable_error_handler, | 460 unrecoverable_error_handler, |
| 459 report_unrecoverable_error_function)); | 461 report_unrecoverable_error_function)); |
| 460 } | 462 } |
| 461 | 463 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 core_->DoStopSyncManagerForShutdown(closure); | 572 core_->DoStopSyncManagerForShutdown(closure); |
| 571 } | 573 } |
| 572 } | 574 } |
| 573 | 575 |
| 574 void SyncBackendHost::StopSyncingForShutdown() { | 576 void SyncBackendHost::StopSyncingForShutdown() { |
| 575 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 577 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 576 | 578 |
| 577 // Immediately stop sending messages to the frontend. | 579 // Immediately stop sending messages to the frontend. |
| 578 frontend_ = NULL; | 580 frontend_ = NULL; |
| 579 | 581 |
| 582 // Stop listening for and forwarding locally-triggered sync refresh requests. | |
| 583 notification_registrar_.RemoveAll(); | |
| 584 | |
| 580 // Thread shutdown should occur in the following order: | 585 // Thread shutdown should occur in the following order: |
| 581 // - Sync Thread | 586 // - Sync Thread |
| 582 // - UI Thread (stops some time after we return from this call). | 587 // - UI Thread (stops some time after we return from this call). |
| 583 // | 588 // |
| 584 // In order to achieve this, we first shutdown components from the UI thread | 589 // In order to achieve this, we first shutdown components from the UI thread |
| 585 // and send signals to abort components that may be busy on the sync thread. | 590 // and send signals to abort components that may be busy on the sync thread. |
| 586 // The callback (OnSyncerShutdownComplete) will happen on the sync thread, | 591 // The callback (OnSyncerShutdownComplete) will happen on the sync thread, |
| 587 // after which we'll shutdown components on the sync thread, and then be | 592 // after which we'll shutdown components on the sync thread, and then be |
| 588 // able to stop the sync loop. | 593 // able to stop the sync loop. |
| 589 if (sync_thread_.IsRunning()) { | 594 if (sync_thread_.IsRunning()) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 614 void SyncBackendHost::Shutdown(bool sync_disabled) { | 619 void SyncBackendHost::Shutdown(bool sync_disabled) { |
| 615 // StopSyncingForShutdown() (which nulls out |frontend_|) should be | 620 // StopSyncingForShutdown() (which nulls out |frontend_|) should be |
| 616 // called first. | 621 // called first. |
| 617 DCHECK(!frontend_); | 622 DCHECK(!frontend_); |
| 618 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. | 623 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. |
| 619 if (sync_thread_.IsRunning()) { | 624 if (sync_thread_.IsRunning()) { |
| 620 sync_thread_.message_loop()->PostTask(FROM_HERE, | 625 sync_thread_.message_loop()->PostTask(FROM_HERE, |
| 621 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), | 626 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), |
| 622 sync_disabled)); | 627 sync_disabled)); |
| 623 | 628 |
| 624 if (chrome_sync_notification_bridge_.get()) | 629 if (android_invalidator_bridge_.get()) |
| 625 chrome_sync_notification_bridge_->StopForShutdown(); | 630 android_invalidator_bridge_->StopForShutdown(); |
| 626 } | 631 } |
| 627 | 632 |
| 628 // Stop will return once the thread exits, which will be after DoShutdown | 633 // Stop will return once the thread exits, which will be after DoShutdown |
| 629 // runs. DoShutdown needs to run from sync_thread_ because the sync backend | 634 // runs. DoShutdown needs to run from sync_thread_ because the sync backend |
| 630 // requires any thread that opened sqlite handles to relinquish them | 635 // requires any thread that opened sqlite handles to relinquish them |
| 631 // personally. We need to join threads, because otherwise the main Chrome | 636 // personally. We need to join threads, because otherwise the main Chrome |
| 632 // thread (ui loop) can exit before DoShutdown finishes, at which point | 637 // thread (ui loop) can exit before DoShutdown finishes, at which point |
| 633 // virtually anything the sync backend does (or the post-back to | 638 // virtually anything the sync backend does (or the post-back to |
| 634 // frontend_loop_ by our Core) will epically fail because the CRT won't be | 639 // frontend_loop_ by our Core) will epically fail because the CRT won't be |
| 635 // initialized. | 640 // initialized. |
| 636 // Since we are blocking the UI thread here, we need to turn ourselves in | 641 // Since we are blocking the UI thread here, we need to turn ourselves in |
| 637 // with the ThreadRestriction police. For sentencing and how we plan to fix | 642 // with the ThreadRestriction police. For sentencing and how we plan to fix |
| 638 // this, see bug 19757. | 643 // this, see bug 19757. |
| 639 base::Time stop_thread_start_time = base::Time::Now(); | 644 base::Time stop_thread_start_time = base::Time::Now(); |
| 640 { | 645 { |
| 641 base::ThreadRestrictions::ScopedAllowIO allow_io; | 646 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 642 sync_thread_.Stop(); | 647 sync_thread_.Stop(); |
| 643 } | 648 } |
| 644 base::TimeDelta stop_sync_thread_time = base::Time::Now() - | 649 base::TimeDelta stop_sync_thread_time = base::Time::Now() - |
| 645 stop_thread_start_time; | 650 stop_thread_start_time; |
| 646 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", | 651 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", |
| 647 stop_sync_thread_time); | 652 stop_sync_thread_time); |
| 648 | 653 |
| 649 registrar_.reset(); | 654 registrar_.reset(); |
| 650 js_backend_.Reset(); | 655 js_backend_.Reset(); |
| 651 chrome_sync_notification_bridge_.reset(); | 656 android_invalidator_bridge_.reset(); |
| 652 core_ = NULL; // Releases reference to core_. | 657 core_ = NULL; // Releases reference to core_. |
| 653 } | 658 } |
| 654 | 659 |
| 655 void SyncBackendHost::ConfigureDataTypes( | 660 void SyncBackendHost::ConfigureDataTypes( |
| 656 syncer::ConfigureReason reason, | 661 syncer::ConfigureReason reason, |
| 657 syncer::ModelTypeSet types_to_add, | 662 syncer::ModelTypeSet types_to_add, |
| 658 syncer::ModelTypeSet types_to_remove, | 663 syncer::ModelTypeSet types_to_remove, |
| 659 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, | 664 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, |
| 660 const base::Callback<void()>& retry_callback) { | 665 const base::Callback<void()>& retry_callback) { |
| 661 // Only one configure is allowed at a time. This is guaranteed by our | 666 // Only one configure is allowed at a time. This is guaranteed by our |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 832 | 837 |
| 833 initialization_state_ = INITIALIZATING_CONTROL_TYPES; | 838 initialization_state_ = INITIALIZATING_CONTROL_TYPES; |
| 834 | 839 |
| 835 js_backend_ = js_backend; | 840 js_backend_ = js_backend; |
| 836 debug_info_listener_ = debug_info_listener; | 841 debug_info_listener_ = debug_info_listener; |
| 837 | 842 |
| 838 // Inform the registrar of those types that have been fully downloaded and | 843 // Inform the registrar of those types that have been fully downloaded and |
| 839 // applied. | 844 // applied. |
| 840 registrar_->SetInitialTypes(restored_types); | 845 registrar_->SetInitialTypes(restored_types); |
| 841 | 846 |
| 847 // Start forwarding refresh requests to the SyncManager | |
| 848 notification_registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | |
| 849 content::Source<Profile>(profile_)); | |
| 850 | |
| 842 // Kick off the next step in SyncBackendHost initialization by downloading | 851 // Kick off the next step in SyncBackendHost initialization by downloading |
| 843 // any necessary control types. | 852 // any necessary control types. |
| 844 sync_thread_.message_loop()->PostTask( | 853 sync_thread_.message_loop()->PostTask( |
| 845 FROM_HERE, | 854 FROM_HERE, |
| 846 base::Bind(&SyncBackendHost::Core::DoDownloadControlTypes, | 855 base::Bind(&SyncBackendHost::Core::DoDownloadControlTypes, |
| 847 core_.get())); | 856 core_.get())); |
| 848 } | 857 } |
| 849 | 858 |
| 859 void SyncBackendHost::Observe( | |
| 860 int type, | |
| 861 const content::NotificationSource& source, | |
| 862 const content::NotificationDetails& details) { | |
| 863 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 864 DCHECK_EQ(type, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL); | |
| 865 | |
| 866 content::Details<const syncer::ModelTypeInvalidationMap> | |
| 867 state_details(details); | |
| 868 const syncer::ModelTypeInvalidationMap& invalidation_map = | |
| 869 *(state_details.ptr()); | |
| 870 const syncer::ModelTypeSet types = | |
| 871 ModelTypeInvalidationMapToSet(invalidation_map); | |
| 872 sync_thread_.message_loop()->PostTask(FROM_HERE, | |
| 873 base::Bind(&SyncBackendHost::Core::DoRefreshTypes, core_.get(), types)); | |
| 874 } | |
| 875 | |
| 850 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( | 876 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( |
| 851 MessageLoop* sync_loop, | 877 MessageLoop* sync_loop, |
| 852 SyncBackendRegistrar* registrar, | 878 SyncBackendRegistrar* registrar, |
| 853 const syncer::ModelSafeRoutingInfo& routing_info, | 879 const syncer::ModelSafeRoutingInfo& routing_info, |
| 854 const std::vector<syncer::ModelSafeWorker*>& workers, | 880 const std::vector<syncer::ModelSafeWorker*>& workers, |
| 855 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, | 881 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, |
| 856 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 882 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
| 857 const GURL& service_url, | 883 const GURL& service_url, |
| 858 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, | 884 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, |
| 859 const syncer::SyncCredentials& credentials, | 885 const syncer::SyncCredentials& credentials, |
| 860 ChromeSyncNotificationBridge* chrome_sync_notification_bridge, | 886 AndroidInvalidatorBridge* android_invalidator_bridge, |
| 861 syncer::InvalidatorFactory* invalidator_factory, | 887 syncer::InvalidatorFactory* invalidator_factory, |
| 862 syncer::SyncManagerFactory* sync_manager_factory, | 888 syncer::SyncManagerFactory* sync_manager_factory, |
| 863 bool delete_sync_data_folder, | 889 bool delete_sync_data_folder, |
| 864 const std::string& restored_key_for_bootstrapping, | 890 const std::string& restored_key_for_bootstrapping, |
| 865 const std::string& restored_keystore_key_for_bootstrapping, | 891 const std::string& restored_keystore_key_for_bootstrapping, |
| 866 InternalComponentsFactory* internal_components_factory, | 892 InternalComponentsFactory* internal_components_factory, |
| 867 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, | 893 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 868 syncer::ReportUnrecoverableErrorFunction | 894 syncer::ReportUnrecoverableErrorFunction |
| 869 report_unrecoverable_error_function) | 895 report_unrecoverable_error_function) |
| 870 : sync_loop(sync_loop), | 896 : sync_loop(sync_loop), |
| 871 registrar(registrar), | 897 registrar(registrar), |
| 872 routing_info(routing_info), | 898 routing_info(routing_info), |
| 873 workers(workers), | 899 workers(workers), |
| 874 extensions_activity_monitor(extensions_activity_monitor), | 900 extensions_activity_monitor(extensions_activity_monitor), |
| 875 event_handler(event_handler), | 901 event_handler(event_handler), |
| 876 service_url(service_url), | 902 service_url(service_url), |
| 877 make_http_bridge_factory_fn(make_http_bridge_factory_fn), | 903 make_http_bridge_factory_fn(make_http_bridge_factory_fn), |
| 878 credentials(credentials), | 904 credentials(credentials), |
| 879 chrome_sync_notification_bridge(chrome_sync_notification_bridge), | 905 android_invalidator_bridge(android_invalidator_bridge), |
| 880 invalidator_factory(invalidator_factory), | 906 invalidator_factory(invalidator_factory), |
| 881 sync_manager_factory(sync_manager_factory), | 907 sync_manager_factory(sync_manager_factory), |
| 882 delete_sync_data_folder(delete_sync_data_folder), | 908 delete_sync_data_folder(delete_sync_data_folder), |
| 883 restored_key_for_bootstrapping(restored_key_for_bootstrapping), | 909 restored_key_for_bootstrapping(restored_key_for_bootstrapping), |
| 884 restored_keystore_key_for_bootstrapping( | 910 restored_keystore_key_for_bootstrapping( |
| 885 restored_keystore_key_for_bootstrapping), | 911 restored_keystore_key_for_bootstrapping), |
| 886 internal_components_factory(internal_components_factory), | 912 internal_components_factory(internal_components_factory), |
| 887 unrecoverable_error_handler(unrecoverable_error_handler), | 913 unrecoverable_error_handler(unrecoverable_error_handler), |
| 888 report_unrecoverable_error_function( | 914 report_unrecoverable_error_function( |
| 889 report_unrecoverable_error_function) { | 915 report_unrecoverable_error_function) { |
| 890 } | 916 } |
| 891 | 917 |
| 892 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} | 918 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} |
| 893 | 919 |
| 894 SyncBackendHost::Core::Core(const std::string& name, | 920 SyncBackendHost::Core::Core(const std::string& name, |
| 895 const FilePath& sync_data_folder_path, | 921 const FilePath& sync_data_folder_path, |
| 896 const base::WeakPtr<SyncBackendHost>& backend) | 922 const base::WeakPtr<SyncBackendHost>& backend) |
| 897 : name_(name), | 923 : name_(name), |
| 898 sync_data_folder_path_(sync_data_folder_path), | 924 sync_data_folder_path_(sync_data_folder_path), |
| 899 host_(backend), | 925 host_(backend), |
| 900 sync_loop_(NULL), | 926 sync_loop_(NULL), |
| 901 registrar_(NULL), | 927 registrar_(NULL), |
| 902 chrome_sync_notification_bridge_(NULL), | |
| 903 registered_as_invalidation_handler_(false) { | 928 registered_as_invalidation_handler_(false) { |
| 904 DCHECK(backend.get()); | 929 DCHECK(backend.get()); |
| 905 } | 930 } |
| 906 | 931 |
| 907 SyncBackendHost::Core::~Core() { | 932 SyncBackendHost::Core::~Core() { |
| 908 DCHECK(!sync_manager_.get()); | 933 DCHECK(!sync_manager_.get()); |
| 909 DCHECK(!sync_loop_); | 934 DCHECK(!sync_loop_); |
| 910 } | 935 } |
| 911 | 936 |
| 912 void SyncBackendHost::Core::OnSyncCycleCompleted( | 937 void SyncBackendHost::Core::OnSyncCycleCompleted( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 933 sync_manager_->ConfigureSyncer( | 958 sync_manager_->ConfigureSyncer( |
| 934 syncer::CONFIGURE_REASON_NEW_CLIENT, | 959 syncer::CONFIGURE_REASON_NEW_CLIENT, |
| 935 new_control_types, | 960 new_control_types, |
| 936 routing_info, | 961 routing_info, |
| 937 base::Bind(&SyncBackendHost::Core::DoInitialProcessControlTypes, | 962 base::Bind(&SyncBackendHost::Core::DoInitialProcessControlTypes, |
| 938 this), | 963 this), |
| 939 base::Bind(&SyncBackendHost::Core::OnControlTypesDownloadRetry, | 964 base::Bind(&SyncBackendHost::Core::OnControlTypesDownloadRetry, |
| 940 this)); | 965 this)); |
| 941 } | 966 } |
| 942 | 967 |
| 968 void SyncBackendHost::Core::DoRefreshTypes(syncer::ModelTypeSet types) { | |
| 969 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
| 970 sync_manager_->RefreshTypes(types); | |
| 971 } | |
| 972 | |
| 943 void SyncBackendHost::Core::OnControlTypesDownloadRetry() { | 973 void SyncBackendHost::Core::OnControlTypesDownloadRetry() { |
| 944 host_.Call(FROM_HERE, | 974 host_.Call(FROM_HERE, |
| 945 &SyncBackendHost::HandleControlTypesDownloadRetry); | 975 &SyncBackendHost::HandleControlTypesDownloadRetry); |
| 946 } | 976 } |
| 947 | 977 |
| 948 void SyncBackendHost::Core::OnInitializationComplete( | 978 void SyncBackendHost::Core::OnInitializationComplete( |
| 949 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 979 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 950 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 980 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 951 debug_info_listener, | 981 debug_info_listener, |
| 952 bool success, | 982 bool success, |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1121 // Make sure that the directory exists before initializing the backend. | 1151 // Make sure that the directory exists before initializing the backend. |
| 1122 // If it already exists, this will do no harm. | 1152 // If it already exists, this will do no harm. |
| 1123 if (!file_util::CreateDirectory(sync_data_folder_path_)) { | 1153 if (!file_util::CreateDirectory(sync_data_folder_path_)) { |
| 1124 DLOG(FATAL) << "Sync Data directory creation failed."; | 1154 DLOG(FATAL) << "Sync Data directory creation failed."; |
| 1125 } | 1155 } |
| 1126 | 1156 |
| 1127 DCHECK(!registrar_); | 1157 DCHECK(!registrar_); |
| 1128 registrar_ = options.registrar; | 1158 registrar_ = options.registrar; |
| 1129 DCHECK(registrar_); | 1159 DCHECK(registrar_); |
| 1130 | 1160 |
| 1131 DCHECK(!chrome_sync_notification_bridge_); | |
| 1132 chrome_sync_notification_bridge_ = options.chrome_sync_notification_bridge; | |
| 1133 DCHECK(chrome_sync_notification_bridge_); | |
| 1134 | |
| 1135 #if defined(OS_ANDROID) | |
| 1136 // Android uses ChromeSyncNotificationBridge exclusively. | |
| 1137 const syncer::InvalidatorState kDefaultInvalidatorState = | |
| 1138 syncer::INVALIDATIONS_ENABLED; | |
| 1139 #else | |
| 1140 const syncer::InvalidatorState kDefaultInvalidatorState = | |
| 1141 syncer::DEFAULT_INVALIDATION_ERROR; | |
| 1142 #endif | |
| 1143 | |
| 1144 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_); | 1161 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_); |
| 1145 sync_manager_->AddObserver(this); | 1162 sync_manager_->AddObserver(this); |
| 1146 sync_manager_->Init( | 1163 sync_manager_->Init( |
| 1147 sync_data_folder_path_, | 1164 sync_data_folder_path_, |
| 1148 options.event_handler, | 1165 options.event_handler, |
| 1149 options.service_url.host() + options.service_url.path(), | 1166 options.service_url.host() + options.service_url.path(), |
| 1150 options.service_url.EffectiveIntPort(), | 1167 options.service_url.EffectiveIntPort(), |
| 1151 options.service_url.SchemeIsSecure(), | 1168 options.service_url.SchemeIsSecure(), |
| 1152 options.make_http_bridge_factory_fn.Run().Pass(), | 1169 options.make_http_bridge_factory_fn.Run().Pass(), |
| 1153 options.workers, | 1170 options.workers, |
| 1154 options.extensions_activity_monitor, | 1171 options.extensions_activity_monitor, |
| 1155 options.registrar /* as SyncManager::ChangeDelegate */, | 1172 options.registrar /* as SyncManager::ChangeDelegate */, |
| 1156 options.credentials, | 1173 options.credentials, |
| 1157 scoped_ptr<syncer::Invalidator>(new BridgedInvalidator( | 1174 #if defined(OS_ANDROID) |
| 1158 options.chrome_sync_notification_bridge, | 1175 scoped_ptr<syncer::Invalidator>( |
| 1159 options.invalidator_factory->CreateInvalidator(), | 1176 new AndroidInvalidatorBridgeProxy( |
| 1160 kDefaultInvalidatorState)), | 1177 options.android_invalidator_bridge)), |
| 1178 #else | |
| 1179 scoped_ptr<syncer::Invalidator>( | |
| 1180 options.invalidator_factory->CreateInvalidator()), | |
| 1181 #endif | |
| 1161 options.restored_key_for_bootstrapping, | 1182 options.restored_key_for_bootstrapping, |
| 1162 options.restored_keystore_key_for_bootstrapping, | 1183 options.restored_keystore_key_for_bootstrapping, |
| 1163 scoped_ptr<InternalComponentsFactory>( | 1184 scoped_ptr<InternalComponentsFactory>( |
| 1164 options.internal_components_factory), | 1185 options.internal_components_factory), |
| 1165 &encryptor_, | 1186 &encryptor_, |
| 1166 options.unrecoverable_error_handler, | 1187 options.unrecoverable_error_handler, |
| 1167 options.report_unrecoverable_error_function); | 1188 options.report_unrecoverable_error_function); |
| 1168 | 1189 |
| 1169 // |sync_manager_| may end up being NULL here in tests (in | 1190 // |sync_manager_| may end up being NULL here in tests (in |
| 1170 // synchronous initialization mode). | 1191 // synchronous initialization mode). |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1300 } | 1321 } |
| 1301 | 1322 |
| 1302 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { | 1323 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { |
| 1303 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1324 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1304 // It's safe to do this even if the type was never activated. | 1325 // It's safe to do this even if the type was never activated. |
| 1305 registrar_->DeactivateDataType(syncer::DEVICE_INFO); | 1326 registrar_->DeactivateDataType(syncer::DEVICE_INFO); |
| 1306 synced_device_tracker_.reset(); | 1327 synced_device_tracker_.reset(); |
| 1307 | 1328 |
| 1308 DoDestroySyncManager(); | 1329 DoDestroySyncManager(); |
| 1309 | 1330 |
| 1310 chrome_sync_notification_bridge_ = NULL; | |
| 1311 registrar_ = NULL; | 1331 registrar_ = NULL; |
| 1312 | 1332 |
| 1313 if (sync_disabled) | 1333 if (sync_disabled) |
| 1314 DeleteSyncDataFolder(); | 1334 DeleteSyncDataFolder(); |
| 1315 | 1335 |
| 1316 sync_loop_ = NULL; | 1336 sync_loop_ = NULL; |
| 1317 | 1337 |
| 1318 host_.Reset(); | 1338 host_.Reset(); |
| 1319 } | 1339 } |
| 1320 | 1340 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1605 DVLOG(1) << "Connection status changed: " | 1625 DVLOG(1) << "Connection status changed: " |
| 1606 << syncer::ConnectionStatusToString(status); | 1626 << syncer::ConnectionStatusToString(status); |
| 1607 frontend_->OnConnectionStatusChange(status); | 1627 frontend_->OnConnectionStatusChange(status); |
| 1608 } | 1628 } |
| 1609 | 1629 |
| 1610 #undef SDVLOG | 1630 #undef SDVLOG |
| 1611 | 1631 |
| 1612 #undef SLOG | 1632 #undef SLOG |
| 1613 | 1633 |
| 1614 } // namespace browser_sync | 1634 } // namespace browser_sync |
| OLD | NEW |