| 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 to check for updates for the specified types. |
| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 syncer::WeakHandle<SyncBackendHost> host_; | 264 syncer::WeakHandle<SyncBackendHost> host_; |
| 259 | 265 |
| 260 // The loop where all the sync backend operations happen. | 266 // The loop where all the sync backend operations happen. |
| 261 // Non-NULL only between calls to DoInitialize() and DoShutdown(). | 267 // Non-NULL only between calls to DoInitialize() and DoShutdown(). |
| 262 MessageLoop* sync_loop_; | 268 MessageLoop* sync_loop_; |
| 263 | 269 |
| 264 // Our parent's registrar (not owned). Non-NULL only between | 270 // Our parent's registrar (not owned). Non-NULL only between |
| 265 // calls to DoInitialize() and DoShutdown(). | 271 // calls to DoInitialize() and DoShutdown(). |
| 266 SyncBackendRegistrar* registrar_; | 272 SyncBackendRegistrar* registrar_; |
| 267 | 273 |
| 268 // Our parent's notification bridge (not owned). Non-NULL only | |
| 269 // between calls to DoInitialize() and DoShutdown(). | |
| 270 ChromeSyncNotificationBridge* chrome_sync_notification_bridge_; | |
| 271 | |
| 272 // The timer used to periodically call SaveChanges. | 274 // The timer used to periodically call SaveChanges. |
| 273 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_; | 275 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_; |
| 274 | 276 |
| 275 // Our encryptor, which uses Chrome's encryption functions. | 277 // Our encryptor, which uses Chrome's encryption functions. |
| 276 ChromeEncryptor encryptor_; | 278 ChromeEncryptor encryptor_; |
| 277 | 279 |
| 278 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. | 280 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. |
| 279 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; | 281 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; |
| 280 | 282 |
| 281 // The top-level syncapi entry point. Lives on the sync thread. | 283 // The top-level syncapi entry point. Lives on the sync thread. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), | 373 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), |
| 372 profile_->GetRequestContext()), | 374 profile_->GetRequestContext()), |
| 373 content::GetUserAgent(GURL()), | 375 content::GetUserAgent(GURL()), |
| 374 base::WeakPtr<syncer::InvalidationStateTracker>()), | 376 base::WeakPtr<syncer::InvalidationStateTracker>()), |
| 375 frontend_(NULL), | 377 frontend_(NULL), |
| 376 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { | 378 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { |
| 377 } | 379 } |
| 378 | 380 |
| 379 SyncBackendHost::~SyncBackendHost() { | 381 SyncBackendHost::~SyncBackendHost() { |
| 380 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; | 382 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; |
| 381 DCHECK(!chrome_sync_notification_bridge_.get()); | 383 DCHECK(!android_invalidator_bridge_.get()); |
| 382 DCHECK(!registrar_.get()); | 384 DCHECK(!registrar_.get()); |
| 383 } | 385 } |
| 384 | 386 |
| 385 namespace { | 387 namespace { |
| 386 | 388 |
| 387 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( | 389 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( |
| 388 const scoped_refptr<net::URLRequestContextGetter>& getter) { | 390 const scoped_refptr<net::URLRequestContextGetter>& getter) { |
| 389 chrome::VersionInfo version_info; | 391 chrome::VersionInfo version_info; |
| 390 return scoped_ptr<syncer::HttpPostProviderFactory>( | 392 return scoped_ptr<syncer::HttpPostProviderFactory>( |
| 391 new syncer::HttpBridgeFactory( | 393 new syncer::HttpBridgeFactory( |
| 392 getter, DeviceInfo::MakeUserAgentForSyncApi(version_info))); | 394 getter, DeviceInfo::MakeUserAgentForSyncApi(version_info))); |
| 393 } | 395 } |
| 394 | 396 |
| 395 } // namespace | 397 } // namespace |
| 396 | 398 |
| 397 void SyncBackendHost::Initialize( | 399 void SyncBackendHost::Initialize( |
| 398 SyncFrontend* frontend, | 400 SyncFrontend* frontend, |
| 399 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 401 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
| 400 const GURL& sync_service_url, | 402 const GURL& sync_service_url, |
| 401 const SyncCredentials& credentials, | 403 const SyncCredentials& credentials, |
| 402 bool delete_sync_data_folder, | 404 bool delete_sync_data_folder, |
| 403 syncer::SyncManagerFactory* sync_manager_factory, | 405 syncer::SyncManagerFactory* sync_manager_factory, |
| 404 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, | 406 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 405 syncer::ReportUnrecoverableErrorFunction | 407 syncer::ReportUnrecoverableErrorFunction |
| 406 report_unrecoverable_error_function) { | 408 report_unrecoverable_error_function) { |
| 407 if (!sync_thread_.Start()) | 409 if (!sync_thread_.Start()) |
| 408 return; | 410 return; |
| 409 | 411 |
| 410 chrome_sync_notification_bridge_.reset( | 412 android_invalidator_bridge_.reset( |
| 411 new ChromeSyncNotificationBridge( | 413 new AndroidInvalidatorBridge( |
| 412 profile_, sync_thread_.message_loop_proxy())); | 414 profile_, sync_thread_.message_loop_proxy())); |
| 413 | 415 |
| 414 frontend_ = frontend; | 416 frontend_ = frontend; |
| 415 DCHECK(frontend); | 417 DCHECK(frontend); |
| 416 | 418 |
| 417 registrar_.reset(new SyncBackendRegistrar(name_, | 419 registrar_.reset(new SyncBackendRegistrar(name_, |
| 418 profile_, | 420 profile_, |
| 419 sync_thread_.message_loop())); | 421 sync_thread_.message_loop())); |
| 420 syncer::ModelSafeRoutingInfo routing_info; | 422 syncer::ModelSafeRoutingInfo routing_info; |
| 421 std::vector<syncer::ModelSafeWorker*> workers; | 423 std::vector<syncer::ModelSafeWorker*> workers; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 442 sync_thread_.message_loop(), | 444 sync_thread_.message_loop(), |
| 443 registrar_.get(), | 445 registrar_.get(), |
| 444 routing_info, | 446 routing_info, |
| 445 workers, | 447 workers, |
| 446 &extensions_activity_monitor_, | 448 &extensions_activity_monitor_, |
| 447 event_handler, | 449 event_handler, |
| 448 sync_service_url, | 450 sync_service_url, |
| 449 base::Bind(&MakeHttpBridgeFactory, | 451 base::Bind(&MakeHttpBridgeFactory, |
| 450 make_scoped_refptr(profile_->GetRequestContext())), | 452 make_scoped_refptr(profile_->GetRequestContext())), |
| 451 credentials, | 453 credentials, |
| 452 chrome_sync_notification_bridge_.get(), | 454 android_invalidator_bridge_.get(), |
| 453 &invalidator_factory_, | 455 &invalidator_factory_, |
| 454 sync_manager_factory, | 456 sync_manager_factory, |
| 455 delete_sync_data_folder, | 457 delete_sync_data_folder, |
| 456 sync_prefs_->GetEncryptionBootstrapToken(), | 458 sync_prefs_->GetEncryptionBootstrapToken(), |
| 457 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), | 459 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), |
| 458 new InternalComponentsFactoryImpl(factory_switches), | 460 new InternalComponentsFactoryImpl(factory_switches), |
| 459 unrecoverable_error_handler, | 461 unrecoverable_error_handler, |
| 460 report_unrecoverable_error_function)); | 462 report_unrecoverable_error_function)); |
| 461 } | 463 } |
| 462 | 464 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 core_->DoStopSyncManagerForShutdown(closure); | 573 core_->DoStopSyncManagerForShutdown(closure); |
| 572 } | 574 } |
| 573 } | 575 } |
| 574 | 576 |
| 575 void SyncBackendHost::StopSyncingForShutdown() { | 577 void SyncBackendHost::StopSyncingForShutdown() { |
| 576 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 578 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 577 | 579 |
| 578 // Immediately stop sending messages to the frontend. | 580 // Immediately stop sending messages to the frontend. |
| 579 frontend_ = NULL; | 581 frontend_ = NULL; |
| 580 | 582 |
| 583 // Stop listening for and forwarding locally-triggered sync refresh requests. |
| 584 notification_registrar_.RemoveAll(); |
| 585 |
| 581 // Thread shutdown should occur in the following order: | 586 // Thread shutdown should occur in the following order: |
| 582 // - Sync Thread | 587 // - Sync Thread |
| 583 // - UI Thread (stops some time after we return from this call). | 588 // - UI Thread (stops some time after we return from this call). |
| 584 // | 589 // |
| 585 // In order to achieve this, we first shutdown components from the UI thread | 590 // In order to achieve this, we first shutdown components from the UI thread |
| 586 // and send signals to abort components that may be busy on the sync thread. | 591 // and send signals to abort components that may be busy on the sync thread. |
| 587 // The callback (OnSyncerShutdownComplete) will happen on the sync thread, | 592 // The callback (OnSyncerShutdownComplete) will happen on the sync thread, |
| 588 // after which we'll shutdown components on the sync thread, and then be | 593 // after which we'll shutdown components on the sync thread, and then be |
| 589 // able to stop the sync loop. | 594 // able to stop the sync loop. |
| 590 if (sync_thread_.IsRunning()) { | 595 if (sync_thread_.IsRunning()) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 615 void SyncBackendHost::Shutdown(bool sync_disabled) { | 620 void SyncBackendHost::Shutdown(bool sync_disabled) { |
| 616 // StopSyncingForShutdown() (which nulls out |frontend_|) should be | 621 // StopSyncingForShutdown() (which nulls out |frontend_|) should be |
| 617 // called first. | 622 // called first. |
| 618 DCHECK(!frontend_); | 623 DCHECK(!frontend_); |
| 619 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. | 624 // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. |
| 620 if (sync_thread_.IsRunning()) { | 625 if (sync_thread_.IsRunning()) { |
| 621 sync_thread_.message_loop()->PostTask(FROM_HERE, | 626 sync_thread_.message_loop()->PostTask(FROM_HERE, |
| 622 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), | 627 base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), |
| 623 sync_disabled)); | 628 sync_disabled)); |
| 624 | 629 |
| 625 if (chrome_sync_notification_bridge_.get()) | 630 if (android_invalidator_bridge_.get()) |
| 626 chrome_sync_notification_bridge_->StopForShutdown(); | 631 android_invalidator_bridge_->StopForShutdown(); |
| 627 } | 632 } |
| 628 | 633 |
| 629 // Stop will return once the thread exits, which will be after DoShutdown | 634 // Stop will return once the thread exits, which will be after DoShutdown |
| 630 // runs. DoShutdown needs to run from sync_thread_ because the sync backend | 635 // runs. DoShutdown needs to run from sync_thread_ because the sync backend |
| 631 // requires any thread that opened sqlite handles to relinquish them | 636 // requires any thread that opened sqlite handles to relinquish them |
| 632 // personally. We need to join threads, because otherwise the main Chrome | 637 // personally. We need to join threads, because otherwise the main Chrome |
| 633 // thread (ui loop) can exit before DoShutdown finishes, at which point | 638 // thread (ui loop) can exit before DoShutdown finishes, at which point |
| 634 // virtually anything the sync backend does (or the post-back to | 639 // virtually anything the sync backend does (or the post-back to |
| 635 // frontend_loop_ by our Core) will epically fail because the CRT won't be | 640 // frontend_loop_ by our Core) will epically fail because the CRT won't be |
| 636 // initialized. | 641 // initialized. |
| 637 // Since we are blocking the UI thread here, we need to turn ourselves in | 642 // Since we are blocking the UI thread here, we need to turn ourselves in |
| 638 // with the ThreadRestriction police. For sentencing and how we plan to fix | 643 // with the ThreadRestriction police. For sentencing and how we plan to fix |
| 639 // this, see bug 19757. | 644 // this, see bug 19757. |
| 640 base::Time stop_thread_start_time = base::Time::Now(); | 645 base::Time stop_thread_start_time = base::Time::Now(); |
| 641 { | 646 { |
| 642 base::ThreadRestrictions::ScopedAllowIO allow_io; | 647 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 643 sync_thread_.Stop(); | 648 sync_thread_.Stop(); |
| 644 } | 649 } |
| 645 base::TimeDelta stop_sync_thread_time = base::Time::Now() - | 650 base::TimeDelta stop_sync_thread_time = base::Time::Now() - |
| 646 stop_thread_start_time; | 651 stop_thread_start_time; |
| 647 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", | 652 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", |
| 648 stop_sync_thread_time); | 653 stop_sync_thread_time); |
| 649 | 654 |
| 650 registrar_.reset(); | 655 registrar_.reset(); |
| 651 js_backend_.Reset(); | 656 js_backend_.Reset(); |
| 652 chrome_sync_notification_bridge_.reset(); | 657 android_invalidator_bridge_.reset(); |
| 653 core_ = NULL; // Releases reference to core_. | 658 core_ = NULL; // Releases reference to core_. |
| 654 } | 659 } |
| 655 | 660 |
| 656 void SyncBackendHost::ConfigureDataTypes( | 661 void SyncBackendHost::ConfigureDataTypes( |
| 657 syncer::ConfigureReason reason, | 662 syncer::ConfigureReason reason, |
| 658 const DataTypeConfigStateMap& config_state_map, | 663 const DataTypeConfigStateMap& config_state_map, |
| 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 |
| 662 // callers. The SyncBackendHost requests one configure as the backend is | 667 // callers. The SyncBackendHost requests one configure as the backend is |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 | 842 |
| 838 initialization_state_ = INITIALIZATING_CONTROL_TYPES; | 843 initialization_state_ = INITIALIZATING_CONTROL_TYPES; |
| 839 | 844 |
| 840 js_backend_ = js_backend; | 845 js_backend_ = js_backend; |
| 841 debug_info_listener_ = debug_info_listener; | 846 debug_info_listener_ = debug_info_listener; |
| 842 | 847 |
| 843 // Inform the registrar of those types that have been fully downloaded and | 848 // Inform the registrar of those types that have been fully downloaded and |
| 844 // applied. | 849 // applied. |
| 845 registrar_->SetInitialTypes(restored_types); | 850 registrar_->SetInitialTypes(restored_types); |
| 846 | 851 |
| 852 // Start forwarding refresh requests to the SyncManager |
| 853 notification_registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
| 854 content::Source<Profile>(profile_)); |
| 855 |
| 847 // Kick off the next step in SyncBackendHost initialization by downloading | 856 // Kick off the next step in SyncBackendHost initialization by downloading |
| 848 // any necessary control types. | 857 // any necessary control types. |
| 849 sync_thread_.message_loop()->PostTask( | 858 sync_thread_.message_loop()->PostTask( |
| 850 FROM_HERE, | 859 FROM_HERE, |
| 851 base::Bind(&SyncBackendHost::Core::DoDownloadControlTypes, | 860 base::Bind(&SyncBackendHost::Core::DoDownloadControlTypes, |
| 852 core_.get())); | 861 core_.get())); |
| 853 } | 862 } |
| 854 | 863 |
| 864 void SyncBackendHost::Observe( |
| 865 int type, |
| 866 const content::NotificationSource& source, |
| 867 const content::NotificationDetails& details) { |
| 868 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 869 DCHECK_EQ(type, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL); |
| 870 |
| 871 content::Details<const syncer::ModelTypeInvalidationMap> |
| 872 state_details(details); |
| 873 const syncer::ModelTypeInvalidationMap& invalidation_map = |
| 874 *(state_details.ptr()); |
| 875 const syncer::ModelTypeSet types = |
| 876 ModelTypeInvalidationMapToSet(invalidation_map); |
| 877 sync_thread_.message_loop()->PostTask(FROM_HERE, |
| 878 base::Bind(&SyncBackendHost::Core::DoRefreshTypes, core_.get(), types)); |
| 879 } |
| 880 |
| 855 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( | 881 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( |
| 856 MessageLoop* sync_loop, | 882 MessageLoop* sync_loop, |
| 857 SyncBackendRegistrar* registrar, | 883 SyncBackendRegistrar* registrar, |
| 858 const syncer::ModelSafeRoutingInfo& routing_info, | 884 const syncer::ModelSafeRoutingInfo& routing_info, |
| 859 const std::vector<syncer::ModelSafeWorker*>& workers, | 885 const std::vector<syncer::ModelSafeWorker*>& workers, |
| 860 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, | 886 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, |
| 861 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 887 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
| 862 const GURL& service_url, | 888 const GURL& service_url, |
| 863 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, | 889 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, |
| 864 const syncer::SyncCredentials& credentials, | 890 const syncer::SyncCredentials& credentials, |
| 865 ChromeSyncNotificationBridge* chrome_sync_notification_bridge, | 891 AndroidInvalidatorBridge* android_invalidator_bridge, |
| 866 syncer::InvalidatorFactory* invalidator_factory, | 892 syncer::InvalidatorFactory* invalidator_factory, |
| 867 syncer::SyncManagerFactory* sync_manager_factory, | 893 syncer::SyncManagerFactory* sync_manager_factory, |
| 868 bool delete_sync_data_folder, | 894 bool delete_sync_data_folder, |
| 869 const std::string& restored_key_for_bootstrapping, | 895 const std::string& restored_key_for_bootstrapping, |
| 870 const std::string& restored_keystore_key_for_bootstrapping, | 896 const std::string& restored_keystore_key_for_bootstrapping, |
| 871 InternalComponentsFactory* internal_components_factory, | 897 InternalComponentsFactory* internal_components_factory, |
| 872 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, | 898 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 873 syncer::ReportUnrecoverableErrorFunction | 899 syncer::ReportUnrecoverableErrorFunction |
| 874 report_unrecoverable_error_function) | 900 report_unrecoverable_error_function) |
| 875 : sync_loop(sync_loop), | 901 : sync_loop(sync_loop), |
| 876 registrar(registrar), | 902 registrar(registrar), |
| 877 routing_info(routing_info), | 903 routing_info(routing_info), |
| 878 workers(workers), | 904 workers(workers), |
| 879 extensions_activity_monitor(extensions_activity_monitor), | 905 extensions_activity_monitor(extensions_activity_monitor), |
| 880 event_handler(event_handler), | 906 event_handler(event_handler), |
| 881 service_url(service_url), | 907 service_url(service_url), |
| 882 make_http_bridge_factory_fn(make_http_bridge_factory_fn), | 908 make_http_bridge_factory_fn(make_http_bridge_factory_fn), |
| 883 credentials(credentials), | 909 credentials(credentials), |
| 884 chrome_sync_notification_bridge(chrome_sync_notification_bridge), | 910 android_invalidator_bridge(android_invalidator_bridge), |
| 885 invalidator_factory(invalidator_factory), | 911 invalidator_factory(invalidator_factory), |
| 886 sync_manager_factory(sync_manager_factory), | 912 sync_manager_factory(sync_manager_factory), |
| 887 delete_sync_data_folder(delete_sync_data_folder), | 913 delete_sync_data_folder(delete_sync_data_folder), |
| 888 restored_key_for_bootstrapping(restored_key_for_bootstrapping), | 914 restored_key_for_bootstrapping(restored_key_for_bootstrapping), |
| 889 restored_keystore_key_for_bootstrapping( | 915 restored_keystore_key_for_bootstrapping( |
| 890 restored_keystore_key_for_bootstrapping), | 916 restored_keystore_key_for_bootstrapping), |
| 891 internal_components_factory(internal_components_factory), | 917 internal_components_factory(internal_components_factory), |
| 892 unrecoverable_error_handler(unrecoverable_error_handler), | 918 unrecoverable_error_handler(unrecoverable_error_handler), |
| 893 report_unrecoverable_error_function( | 919 report_unrecoverable_error_function( |
| 894 report_unrecoverable_error_function) { | 920 report_unrecoverable_error_function) { |
| 895 } | 921 } |
| 896 | 922 |
| 897 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} | 923 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} |
| 898 | 924 |
| 899 SyncBackendHost::Core::Core(const std::string& name, | 925 SyncBackendHost::Core::Core(const std::string& name, |
| 900 const FilePath& sync_data_folder_path, | 926 const FilePath& sync_data_folder_path, |
| 901 const base::WeakPtr<SyncBackendHost>& backend) | 927 const base::WeakPtr<SyncBackendHost>& backend) |
| 902 : name_(name), | 928 : name_(name), |
| 903 sync_data_folder_path_(sync_data_folder_path), | 929 sync_data_folder_path_(sync_data_folder_path), |
| 904 host_(backend), | 930 host_(backend), |
| 905 sync_loop_(NULL), | 931 sync_loop_(NULL), |
| 906 registrar_(NULL), | 932 registrar_(NULL), |
| 907 chrome_sync_notification_bridge_(NULL), | |
| 908 registered_as_invalidation_handler_(false) { | 933 registered_as_invalidation_handler_(false) { |
| 909 DCHECK(backend.get()); | 934 DCHECK(backend.get()); |
| 910 } | 935 } |
| 911 | 936 |
| 912 SyncBackendHost::Core::~Core() { | 937 SyncBackendHost::Core::~Core() { |
| 913 DCHECK(!sync_manager_.get()); | 938 DCHECK(!sync_manager_.get()); |
| 914 DCHECK(!sync_loop_); | 939 DCHECK(!sync_loop_); |
| 915 } | 940 } |
| 916 | 941 |
| 917 void SyncBackendHost::Core::OnSyncCycleCompleted( | 942 void SyncBackendHost::Core::OnSyncCycleCompleted( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 939 syncer::CONFIGURE_REASON_NEW_CLIENT, | 964 syncer::CONFIGURE_REASON_NEW_CLIENT, |
| 940 new_control_types, | 965 new_control_types, |
| 941 syncer::ModelTypeSet(), | 966 syncer::ModelTypeSet(), |
| 942 routing_info, | 967 routing_info, |
| 943 base::Bind(&SyncBackendHost::Core::DoInitialProcessControlTypes, | 968 base::Bind(&SyncBackendHost::Core::DoInitialProcessControlTypes, |
| 944 this), | 969 this), |
| 945 base::Bind(&SyncBackendHost::Core::OnControlTypesDownloadRetry, | 970 base::Bind(&SyncBackendHost::Core::OnControlTypesDownloadRetry, |
| 946 this)); | 971 this)); |
| 947 } | 972 } |
| 948 | 973 |
| 974 void SyncBackendHost::Core::DoRefreshTypes(syncer::ModelTypeSet types) { |
| 975 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 976 sync_manager_->RefreshTypes(types); |
| 977 } |
| 978 |
| 949 void SyncBackendHost::Core::OnControlTypesDownloadRetry() { | 979 void SyncBackendHost::Core::OnControlTypesDownloadRetry() { |
| 950 host_.Call(FROM_HERE, | 980 host_.Call(FROM_HERE, |
| 951 &SyncBackendHost::HandleControlTypesDownloadRetry); | 981 &SyncBackendHost::HandleControlTypesDownloadRetry); |
| 952 } | 982 } |
| 953 | 983 |
| 954 void SyncBackendHost::Core::OnInitializationComplete( | 984 void SyncBackendHost::Core::OnInitializationComplete( |
| 955 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 985 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 956 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 986 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 957 debug_info_listener, | 987 debug_info_listener, |
| 958 bool success, | 988 bool success, |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 // Make sure that the directory exists before initializing the backend. | 1157 // Make sure that the directory exists before initializing the backend. |
| 1128 // If it already exists, this will do no harm. | 1158 // If it already exists, this will do no harm. |
| 1129 if (!file_util::CreateDirectory(sync_data_folder_path_)) { | 1159 if (!file_util::CreateDirectory(sync_data_folder_path_)) { |
| 1130 DLOG(FATAL) << "Sync Data directory creation failed."; | 1160 DLOG(FATAL) << "Sync Data directory creation failed."; |
| 1131 } | 1161 } |
| 1132 | 1162 |
| 1133 DCHECK(!registrar_); | 1163 DCHECK(!registrar_); |
| 1134 registrar_ = options.registrar; | 1164 registrar_ = options.registrar; |
| 1135 DCHECK(registrar_); | 1165 DCHECK(registrar_); |
| 1136 | 1166 |
| 1137 DCHECK(!chrome_sync_notification_bridge_); | |
| 1138 chrome_sync_notification_bridge_ = options.chrome_sync_notification_bridge; | |
| 1139 DCHECK(chrome_sync_notification_bridge_); | |
| 1140 | |
| 1141 #if defined(OS_ANDROID) | |
| 1142 // Android uses ChromeSyncNotificationBridge exclusively. | |
| 1143 const syncer::InvalidatorState kDefaultInvalidatorState = | |
| 1144 syncer::INVALIDATIONS_ENABLED; | |
| 1145 #else | |
| 1146 const syncer::InvalidatorState kDefaultInvalidatorState = | |
| 1147 syncer::DEFAULT_INVALIDATION_ERROR; | |
| 1148 #endif | |
| 1149 | |
| 1150 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_); | 1167 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_); |
| 1151 sync_manager_->AddObserver(this); | 1168 sync_manager_->AddObserver(this); |
| 1152 sync_manager_->Init( | 1169 sync_manager_->Init( |
| 1153 sync_data_folder_path_, | 1170 sync_data_folder_path_, |
| 1154 options.event_handler, | 1171 options.event_handler, |
| 1155 options.service_url.host() + options.service_url.path(), | 1172 options.service_url.host() + options.service_url.path(), |
| 1156 options.service_url.EffectiveIntPort(), | 1173 options.service_url.EffectiveIntPort(), |
| 1157 options.service_url.SchemeIsSecure(), | 1174 options.service_url.SchemeIsSecure(), |
| 1158 options.make_http_bridge_factory_fn.Run().Pass(), | 1175 options.make_http_bridge_factory_fn.Run().Pass(), |
| 1159 options.workers, | 1176 options.workers, |
| 1160 options.extensions_activity_monitor, | 1177 options.extensions_activity_monitor, |
| 1161 options.registrar /* as SyncManager::ChangeDelegate */, | 1178 options.registrar /* as SyncManager::ChangeDelegate */, |
| 1162 options.credentials, | 1179 options.credentials, |
| 1163 scoped_ptr<syncer::Invalidator>(new BridgedInvalidator( | 1180 #if defined(OS_ANDROID) |
| 1164 options.chrome_sync_notification_bridge, | 1181 scoped_ptr<syncer::Invalidator>( |
| 1165 options.invalidator_factory->CreateInvalidator(), | 1182 new AndroidInvalidatorBridgeProxy( |
| 1166 kDefaultInvalidatorState)), | 1183 options.android_invalidator_bridge)), |
| 1184 #else |
| 1185 scoped_ptr<syncer::Invalidator>( |
| 1186 options.invalidator_factory->CreateInvalidator()), |
| 1187 #endif |
| 1167 options.restored_key_for_bootstrapping, | 1188 options.restored_key_for_bootstrapping, |
| 1168 options.restored_keystore_key_for_bootstrapping, | 1189 options.restored_keystore_key_for_bootstrapping, |
| 1169 scoped_ptr<InternalComponentsFactory>( | 1190 scoped_ptr<InternalComponentsFactory>( |
| 1170 options.internal_components_factory), | 1191 options.internal_components_factory), |
| 1171 &encryptor_, | 1192 &encryptor_, |
| 1172 options.unrecoverable_error_handler, | 1193 options.unrecoverable_error_handler, |
| 1173 options.report_unrecoverable_error_function); | 1194 options.report_unrecoverable_error_function); |
| 1174 | 1195 |
| 1175 // |sync_manager_| may end up being NULL here in tests (in | 1196 // |sync_manager_| may end up being NULL here in tests (in |
| 1176 // synchronous initialization mode). | 1197 // synchronous initialization mode). |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 } | 1327 } |
| 1307 | 1328 |
| 1308 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { | 1329 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { |
| 1309 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1330 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1310 // It's safe to do this even if the type was never activated. | 1331 // It's safe to do this even if the type was never activated. |
| 1311 registrar_->DeactivateDataType(syncer::DEVICE_INFO); | 1332 registrar_->DeactivateDataType(syncer::DEVICE_INFO); |
| 1312 synced_device_tracker_.reset(); | 1333 synced_device_tracker_.reset(); |
| 1313 | 1334 |
| 1314 DoDestroySyncManager(); | 1335 DoDestroySyncManager(); |
| 1315 | 1336 |
| 1316 chrome_sync_notification_bridge_ = NULL; | |
| 1317 registrar_ = NULL; | 1337 registrar_ = NULL; |
| 1318 | 1338 |
| 1319 if (sync_disabled) | 1339 if (sync_disabled) |
| 1320 DeleteSyncDataFolder(); | 1340 DeleteSyncDataFolder(); |
| 1321 | 1341 |
| 1322 sync_loop_ = NULL; | 1342 sync_loop_ = NULL; |
| 1323 | 1343 |
| 1324 host_.Reset(); | 1344 host_.Reset(); |
| 1325 } | 1345 } |
| 1326 | 1346 |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1613 DVLOG(1) << "Connection status changed: " | 1633 DVLOG(1) << "Connection status changed: " |
| 1614 << syncer::ConnectionStatusToString(status); | 1634 << syncer::ConnectionStatusToString(status); |
| 1615 frontend_->OnConnectionStatusChange(status); | 1635 frontend_->OnConnectionStatusChange(status); |
| 1616 } | 1636 } |
| 1617 | 1637 |
| 1618 #undef SDVLOG | 1638 #undef SDVLOG |
| 1619 | 1639 |
| 1620 #undef SLOG | 1640 #undef SLOG |
| 1621 | 1641 |
| 1622 } // namespace browser_sync | 1642 } // namespace browser_sync |
| OLD | NEW |