Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 const std::string name_; 262 const std::string name_;
263 263
264 // Path of the folder that stores the sync data files. 264 // Path of the folder that stores the sync data files.
265 const base::FilePath sync_data_folder_path_; 265 const base::FilePath sync_data_folder_path_;
266 266
267 // Our parent SyncBackendHost. 267 // Our parent SyncBackendHost.
268 syncer::WeakHandle<SyncBackendHost> host_; 268 syncer::WeakHandle<SyncBackendHost> host_;
269 269
270 // The loop where all the sync backend operations happen. 270 // The loop where all the sync backend operations happen.
271 // Non-NULL only between calls to DoInitialize() and DoShutdown(). 271 // Non-NULL only between calls to DoInitialize() and DoShutdown().
272 MessageLoop* sync_loop_; 272 base::MessageLoop* sync_loop_;
273 273
274 // Our parent's registrar (not owned). Non-NULL only between 274 // Our parent's registrar (not owned). Non-NULL only between
275 // calls to DoInitialize() and DoShutdown(). 275 // calls to DoInitialize() and DoShutdown().
276 SyncBackendRegistrar* registrar_; 276 SyncBackendRegistrar* registrar_;
277 277
278 // The timer used to periodically call SaveChanges. 278 // The timer used to periodically call SaveChanges.
279 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_; 279 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_;
280 280
281 // Our encryptor, which uses Chrome's encryption functions. 281 // Our encryptor, which uses Chrome's encryption functions.
282 ChromeEncryptor encryptor_; 282 ChromeEncryptor encryptor_;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 343
344 } // namespace 344 } // namespace
345 345
346 SyncBackendHost::SyncBackendHost( 346 SyncBackendHost::SyncBackendHost(
347 const std::string& name, 347 const std::string& name,
348 Profile* profile, 348 Profile* profile,
349 const base::WeakPtr<SyncPrefs>& sync_prefs, 349 const base::WeakPtr<SyncPrefs>& sync_prefs,
350 const base::WeakPtr<InvalidatorStorage>& invalidator_storage) 350 const base::WeakPtr<InvalidatorStorage>& invalidator_storage)
351 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 351 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
352 sync_thread_("Chrome_SyncThread"), 352 sync_thread_("Chrome_SyncThread"),
353 frontend_loop_(MessageLoop::current()), 353 frontend_loop_(base::MessageLoop::current()),
354 profile_(profile), 354 profile_(profile),
355 name_(name), 355 name_(name),
356 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), 356 core_(new Core(name,
357 profile_->GetPath().Append(kSyncDataFolderName),
357 weak_ptr_factory_.GetWeakPtr())), 358 weak_ptr_factory_.GetWeakPtr())),
358 initialization_state_(NOT_ATTEMPTED), 359 initialization_state_(NOT_ATTEMPTED),
359 sync_prefs_(sync_prefs), 360 sync_prefs_(sync_prefs),
360 invalidator_factory_( 361 invalidator_factory_(
361 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), 362 ParseNotifierOptions(*CommandLine::ForCurrentProcess(),
362 profile_->GetRequestContext()), 363 profile_->GetRequestContext()),
363 content::GetUserAgent(GURL()), 364 content::GetUserAgent(GURL()),
364 invalidator_storage), 365 invalidator_storage),
365 frontend_(NULL), 366 frontend_(NULL),
366 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { 367 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) {}
367 }
368 368
369 SyncBackendHost::SyncBackendHost(Profile* profile) 369 SyncBackendHost::SyncBackendHost(Profile* profile)
370 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 370 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
371 sync_thread_("Chrome_SyncThread"), 371 sync_thread_("Chrome_SyncThread"),
372 frontend_loop_(MessageLoop::current()), 372 frontend_loop_(base::MessageLoop::current()),
373 profile_(profile), 373 profile_(profile),
374 name_("Unknown"), 374 name_("Unknown"),
375 initialization_state_(NOT_ATTEMPTED), 375 initialization_state_(NOT_ATTEMPTED),
376 invalidator_factory_( 376 invalidator_factory_(
377 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), 377 ParseNotifierOptions(*CommandLine::ForCurrentProcess(),
378 profile_->GetRequestContext()), 378 profile_->GetRequestContext()),
379 content::GetUserAgent(GURL()), 379 content::GetUserAgent(GURL()),
380 base::WeakPtr<syncer::InvalidationStateTracker>()), 380 base::WeakPtr<syncer::InvalidationStateTracker>()),
381 frontend_(NULL), 381 frontend_(NULL),
382 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { 382 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) {}
383 }
384 383
385 SyncBackendHost::~SyncBackendHost() { 384 SyncBackendHost::~SyncBackendHost() {
386 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; 385 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor.";
387 DCHECK(!android_invalidator_bridge_.get()); 386 DCHECK(!android_invalidator_bridge_.get());
388 DCHECK(!registrar_.get()); 387 DCHECK(!registrar_.get());
389 } 388 }
390 389
391 namespace { 390 namespace {
392 391
393 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( 392 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 463
465 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { 464 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) {
466 DCHECK(sync_thread_.IsRunning()); 465 DCHECK(sync_thread_.IsRunning());
467 sync_thread_.message_loop()->PostTask(FROM_HERE, 466 sync_thread_.message_loop()->PostTask(FROM_HERE,
468 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), 467 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(),
469 credentials)); 468 credentials));
470 } 469 }
471 470
472 void SyncBackendHost::UpdateRegisteredInvalidationIds( 471 void SyncBackendHost::UpdateRegisteredInvalidationIds(
473 const syncer::ObjectIdSet& ids) { 472 const syncer::ObjectIdSet& ids) {
474 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 473 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
475 DCHECK(sync_thread_.IsRunning()); 474 DCHECK(sync_thread_.IsRunning());
476 sync_thread_.message_loop()->PostTask(FROM_HERE, 475 sync_thread_.message_loop()->PostTask(FROM_HERE,
477 base::Bind(&SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds, 476 base::Bind(&SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds,
478 core_.get(), ids)); 477 core_.get(), ids));
479 } 478 }
480 479
481 void SyncBackendHost::AcknowledgeInvalidation( 480 void SyncBackendHost::AcknowledgeInvalidation(
482 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { 481 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) {
483 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 482 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
484 DCHECK(sync_thread_.IsRunning()); 483 DCHECK(sync_thread_.IsRunning());
485 sync_thread_.message_loop()->PostTask(FROM_HERE, 484 sync_thread_.message_loop()->PostTask(FROM_HERE,
486 base::Bind(&SyncBackendHost::Core::DoAcknowledgeInvalidation, 485 base::Bind(&SyncBackendHost::Core::DoAcknowledgeInvalidation,
487 core_.get(), id, ack_handle)); 486 core_.get(), id, ack_handle));
488 } 487 }
489 488
490 void SyncBackendHost::StartSyncingWithServer() { 489 void SyncBackendHost::StartSyncingWithServer() {
491 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; 490 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called.";
492 491
493 syncer::ModelSafeRoutingInfo routing_info; 492 syncer::ModelSafeRoutingInfo routing_info;
(...skipping 10 matching lines...) Expand all
504 if (!IsNigoriEnabled()) { 503 if (!IsNigoriEnabled()) {
505 NOTREACHED() << "SetEncryptionPassphrase must never be called when nigori" 504 NOTREACHED() << "SetEncryptionPassphrase must never be called when nigori"
506 " is disabled."; 505 " is disabled.";
507 return; 506 return;
508 } 507 }
509 508
510 // We should never be called with an empty passphrase. 509 // We should never be called with an empty passphrase.
511 DCHECK(!passphrase.empty()); 510 DCHECK(!passphrase.empty());
512 511
513 // This should only be called by the frontend. 512 // This should only be called by the frontend.
514 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 513 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
515 514
516 // SetEncryptionPassphrase should never be called if we are currently 515 // SetEncryptionPassphrase should never be called if we are currently
517 // encrypted with an explicit passphrase. 516 // encrypted with an explicit passphrase.
518 DCHECK(cached_passphrase_type_ == syncer::KEYSTORE_PASSPHRASE || 517 DCHECK(cached_passphrase_type_ == syncer::KEYSTORE_PASSPHRASE ||
519 cached_passphrase_type_ == syncer::IMPLICIT_PASSPHRASE); 518 cached_passphrase_type_ == syncer::IMPLICIT_PASSPHRASE);
520 519
521 // Post an encryption task on the syncer thread. 520 // Post an encryption task on the syncer thread.
522 sync_thread_.message_loop()->PostTask(FROM_HERE, 521 sync_thread_.message_loop()->PostTask(FROM_HERE,
523 base::Bind(&SyncBackendHost::Core::DoSetEncryptionPassphrase, core_.get(), 522 base::Bind(&SyncBackendHost::Core::DoSetEncryptionPassphrase, core_.get(),
524 passphrase, is_explicit)); 523 passphrase, is_explicit));
525 } 524 }
526 525
527 bool SyncBackendHost::SetDecryptionPassphrase(const std::string& passphrase) { 526 bool SyncBackendHost::SetDecryptionPassphrase(const std::string& passphrase) {
528 if (!IsNigoriEnabled()) { 527 if (!IsNigoriEnabled()) {
529 NOTREACHED() << "SetDecryptionPassphrase must never be called when nigori" 528 NOTREACHED() << "SetDecryptionPassphrase must never be called when nigori"
530 " is disabled."; 529 " is disabled.";
531 return false; 530 return false;
532 } 531 }
533 532
534 // We should never be called with an empty passphrase. 533 // We should never be called with an empty passphrase.
535 DCHECK(!passphrase.empty()); 534 DCHECK(!passphrase.empty());
536 535
537 // This should only be called by the frontend. 536 // This should only be called by the frontend.
538 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 537 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
539 538
540 // This should only be called when we have cached pending keys. 539 // This should only be called when we have cached pending keys.
541 DCHECK(cached_pending_keys_.has_blob()); 540 DCHECK(cached_pending_keys_.has_blob());
542 541
543 // Check the passphrase that was provided against our local cache of the 542 // Check the passphrase that was provided against our local cache of the
544 // cryptographer's pending keys. If this was unsuccessful, the UI layer can 543 // cryptographer's pending keys. If this was unsuccessful, the UI layer can
545 // immediately call OnPassphraseRequired without showing the user a spinner. 544 // immediately call OnPassphraseRequired without showing the user a spinner.
546 if (!CheckPassphraseAgainstCachedPendingKeys(passphrase)) 545 if (!CheckPassphraseAgainstCachedPendingKeys(passphrase))
547 return false; 546 return false;
548 547
(...skipping 28 matching lines...) Expand all
577 base::Bind( 576 base::Bind(
578 &SyncBackendHost::Core::DoStopSyncManagerForShutdown, 577 &SyncBackendHost::Core::DoStopSyncManagerForShutdown,
579 core_.get(), 578 core_.get(),
580 closure)); 579 closure));
581 } else { 580 } else {
582 core_->DoStopSyncManagerForShutdown(closure); 581 core_->DoStopSyncManagerForShutdown(closure);
583 } 582 }
584 } 583 }
585 584
586 void SyncBackendHost::StopSyncingForShutdown() { 585 void SyncBackendHost::StopSyncingForShutdown() {
587 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 586 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
588 587
589 // Immediately stop sending messages to the frontend. 588 // Immediately stop sending messages to the frontend.
590 frontend_ = NULL; 589 frontend_ = NULL;
591 590
592 // Stop listening for and forwarding locally-triggered sync refresh requests. 591 // Stop listening for and forwarding locally-triggered sync refresh requests.
593 notification_registrar_.RemoveAll(); 592 notification_registrar_.RemoveAll();
594 593
595 // Thread shutdown should occur in the following order: 594 // Thread shutdown should occur in the following order:
596 // - Sync Thread 595 // - Sync Thread
597 // - UI Thread (stops some time after we return from this call). 596 // - UI Thread (stops some time after we return from this call).
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 routing_info, 829 routing_info,
831 ready_task, 830 ready_task,
832 retry_callback)); 831 retry_callback));
833 } 832 }
834 833
835 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop( 834 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop(
836 syncer::ModelTypeSet failed_configuration_types, 835 syncer::ModelTypeSet failed_configuration_types,
837 const base::Callback<void(syncer::ModelTypeSet)>& ready_task) { 836 const base::Callback<void(syncer::ModelTypeSet)>& ready_task) {
838 if (!frontend_) 837 if (!frontend_)
839 return; 838 return;
840 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 839 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
841 if (!ready_task.is_null()) 840 if (!ready_task.is_null())
842 ready_task.Run(failed_configuration_types); 841 ready_task.Run(failed_configuration_types);
843 } 842 }
844 843
845 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( 844 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop(
846 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 845 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
847 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 846 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
848 debug_info_listener, 847 debug_info_listener,
849 syncer::ModelTypeSet restored_types) { 848 syncer::ModelTypeSet restored_types) {
850 DCHECK_EQ(initialization_state_, CREATING_SYNC_MANAGER); 849 DCHECK_EQ(initialization_state_, CREATING_SYNC_MANAGER);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 state_details(details); 881 state_details(details);
883 const syncer::ModelTypeInvalidationMap& invalidation_map = 882 const syncer::ModelTypeInvalidationMap& invalidation_map =
884 *(state_details.ptr()); 883 *(state_details.ptr());
885 const syncer::ModelTypeSet types = 884 const syncer::ModelTypeSet types =
886 ModelTypeInvalidationMapToSet(invalidation_map); 885 ModelTypeInvalidationMapToSet(invalidation_map);
887 sync_thread_.message_loop()->PostTask(FROM_HERE, 886 sync_thread_.message_loop()->PostTask(FROM_HERE,
888 base::Bind(&SyncBackendHost::Core::DoRefreshTypes, core_.get(), types)); 887 base::Bind(&SyncBackendHost::Core::DoRefreshTypes, core_.get(), types));
889 } 888 }
890 889
891 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( 890 SyncBackendHost::DoInitializeOptions::DoInitializeOptions(
892 MessageLoop* sync_loop, 891 base::MessageLoop* sync_loop,
893 SyncBackendRegistrar* registrar, 892 SyncBackendRegistrar* registrar,
894 const syncer::ModelSafeRoutingInfo& routing_info, 893 const syncer::ModelSafeRoutingInfo& routing_info,
895 const std::vector<syncer::ModelSafeWorker*>& workers, 894 const std::vector<syncer::ModelSafeWorker*>& workers,
896 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 895 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
897 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 896 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
898 const GURL& service_url, 897 const GURL& service_url,
899 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, 898 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn,
900 const syncer::SyncCredentials& credentials, 899 const syncer::SyncCredentials& credentials,
901 AndroidInvalidatorBridge* android_invalidator_bridge, 900 AndroidInvalidatorBridge* android_invalidator_bridge,
902 syncer::InvalidatorFactory* invalidator_factory, 901 syncer::InvalidatorFactory* invalidator_factory,
(...skipping 16 matching lines...) Expand all
919 credentials(credentials), 918 credentials(credentials),
920 android_invalidator_bridge(android_invalidator_bridge), 919 android_invalidator_bridge(android_invalidator_bridge),
921 invalidator_factory(invalidator_factory), 920 invalidator_factory(invalidator_factory),
922 sync_manager_factory(sync_manager_factory), 921 sync_manager_factory(sync_manager_factory),
923 delete_sync_data_folder(delete_sync_data_folder), 922 delete_sync_data_folder(delete_sync_data_folder),
924 restored_key_for_bootstrapping(restored_key_for_bootstrapping), 923 restored_key_for_bootstrapping(restored_key_for_bootstrapping),
925 restored_keystore_key_for_bootstrapping( 924 restored_keystore_key_for_bootstrapping(
926 restored_keystore_key_for_bootstrapping), 925 restored_keystore_key_for_bootstrapping),
927 internal_components_factory(internal_components_factory), 926 internal_components_factory(internal_components_factory),
928 unrecoverable_error_handler(unrecoverable_error_handler), 927 unrecoverable_error_handler(unrecoverable_error_handler),
929 report_unrecoverable_error_function( 928 report_unrecoverable_error_function(report_unrecoverable_error_function) {
930 report_unrecoverable_error_function) {
931 } 929 }
932 930
933 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} 931 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {}
934 932
935 SyncBackendHost::Core::Core(const std::string& name, 933 SyncBackendHost::Core::Core(const std::string& name,
936 const base::FilePath& sync_data_folder_path, 934 const base::FilePath& sync_data_folder_path,
937 const base::WeakPtr<SyncBackendHost>& backend) 935 const base::WeakPtr<SyncBackendHost>& backend)
938 : name_(name), 936 : name_(name),
939 sync_data_folder_path_(sync_data_folder_path), 937 sync_data_folder_path_(sync_data_folder_path),
940 host_(backend), 938 host_(backend),
941 sync_loop_(NULL), 939 sync_loop_(NULL),
942 registrar_(NULL), 940 registrar_(NULL),
943 registered_as_invalidation_handler_(false) { 941 registered_as_invalidation_handler_(false) {
944 DCHECK(backend.get()); 942 DCHECK(backend.get());
945 } 943 }
946 944
947 SyncBackendHost::Core::~Core() { 945 SyncBackendHost::Core::~Core() {
948 DCHECK(!sync_manager_.get()); 946 DCHECK(!sync_manager_.get());
949 DCHECK(!sync_loop_); 947 DCHECK(!sync_loop_);
950 } 948 }
951 949
952 void SyncBackendHost::Core::OnSyncCycleCompleted( 950 void SyncBackendHost::Core::OnSyncCycleCompleted(
953 const SyncSessionSnapshot& snapshot) { 951 const SyncSessionSnapshot& snapshot) {
954 if (!sync_loop_) 952 if (!sync_loop_)
955 return; 953 return;
956 DCHECK_EQ(MessageLoop::current(), sync_loop_); 954 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
957 955
958 host_.Call( 956 host_.Call(
959 FROM_HERE, 957 FROM_HERE,
960 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop, 958 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop,
961 snapshot); 959 snapshot);
962 } 960 }
963 961
964 void SyncBackendHost::Core::DoDownloadControlTypes() { 962 void SyncBackendHost::Core::DoDownloadControlTypes() {
965 syncer::ModelTypeSet new_control_types = registrar_->ConfigureDataTypes( 963 syncer::ModelTypeSet new_control_types = registrar_->ConfigureDataTypes(
966 syncer::ControlTypes(), syncer::ModelTypeSet()); 964 syncer::ControlTypes(), syncer::ModelTypeSet());
967 syncer::ModelSafeRoutingInfo routing_info; 965 syncer::ModelSafeRoutingInfo routing_info;
968 registrar_->GetModelSafeRoutingInfo(&routing_info); 966 registrar_->GetModelSafeRoutingInfo(&routing_info);
969 SDVLOG(1) << "Control Types " 967 SDVLOG(1) << "Control Types "
970 << syncer::ModelTypeSetToString(new_control_types) 968 << syncer::ModelTypeSetToString(new_control_types)
971 << " added; calling DoConfigureSyncer"; 969 << " added; calling DoConfigureSyncer";
972 970
973 sync_manager_->ConfigureSyncer( 971 sync_manager_->ConfigureSyncer(
974 syncer::CONFIGURE_REASON_NEW_CLIENT, 972 syncer::CONFIGURE_REASON_NEW_CLIENT,
975 new_control_types, 973 new_control_types,
976 syncer::ModelTypeSet(), 974 syncer::ModelTypeSet(),
977 routing_info, 975 routing_info,
978 base::Bind(&SyncBackendHost::Core::DoInitialProcessControlTypes, 976 base::Bind(&SyncBackendHost::Core::DoInitialProcessControlTypes,
979 this), 977 this),
980 base::Bind(&SyncBackendHost::Core::OnControlTypesDownloadRetry, 978 base::Bind(&SyncBackendHost::Core::OnControlTypesDownloadRetry,
981 this)); 979 this));
982 } 980 }
983 981
984 void SyncBackendHost::Core::DoRefreshTypes(syncer::ModelTypeSet types) { 982 void SyncBackendHost::Core::DoRefreshTypes(syncer::ModelTypeSet types) {
985 DCHECK_EQ(MessageLoop::current(), sync_loop_); 983 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
986 sync_manager_->RefreshTypes(types); 984 sync_manager_->RefreshTypes(types);
987 } 985 }
988 986
989 void SyncBackendHost::Core::OnControlTypesDownloadRetry() { 987 void SyncBackendHost::Core::OnControlTypesDownloadRetry() {
990 host_.Call(FROM_HERE, 988 host_.Call(FROM_HERE,
991 &SyncBackendHost::HandleControlTypesDownloadRetry); 989 &SyncBackendHost::HandleControlTypesDownloadRetry);
992 } 990 }
993 991
994 void SyncBackendHost::Core::OnInitializationComplete( 992 void SyncBackendHost::Core::OnInitializationComplete(
995 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 993 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
996 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 994 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
997 debug_info_listener, 995 debug_info_listener,
998 bool success, 996 bool success,
999 const syncer::ModelTypeSet restored_types) { 997 const syncer::ModelTypeSet restored_types) {
1000 DCHECK_EQ(MessageLoop::current(), sync_loop_); 998 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1001 999
1002 if (!success) { 1000 if (!success) {
1003 DoDestroySyncManager(); 1001 DoDestroySyncManager();
1004 host_.Call(FROM_HERE, 1002 host_.Call(FROM_HERE,
1005 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, 1003 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop,
1006 false); 1004 false);
1007 return; 1005 return;
1008 } 1006 }
1009 1007
1010 // Register for encryption related changes now. We have to do this before 1008 // Register for encryption related changes now. We have to do this before
(...skipping 11 matching lines...) Expand all
1022 &SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop, 1020 &SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop,
1023 js_backend, 1021 js_backend,
1024 debug_info_listener, 1022 debug_info_listener,
1025 restored_types); 1023 restored_types);
1026 } 1024 }
1027 1025
1028 void SyncBackendHost::Core::OnConnectionStatusChange( 1026 void SyncBackendHost::Core::OnConnectionStatusChange(
1029 syncer::ConnectionStatus status) { 1027 syncer::ConnectionStatus status) {
1030 if (!sync_loop_) 1028 if (!sync_loop_)
1031 return; 1029 return;
1032 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1030 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1033 host_.Call( 1031 host_.Call(FROM_HERE,
1034 FROM_HERE, 1032 &SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop,
1035 &SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop, status); 1033 status);
1036 } 1034 }
1037 1035
1038 void SyncBackendHost::Core::OnPassphraseRequired( 1036 void SyncBackendHost::Core::OnPassphraseRequired(
1039 syncer::PassphraseRequiredReason reason, 1037 syncer::PassphraseRequiredReason reason,
1040 const sync_pb::EncryptedData& pending_keys) { 1038 const sync_pb::EncryptedData& pending_keys) {
1041 if (!sync_loop_) 1039 if (!sync_loop_)
1042 return; 1040 return;
1043 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1041 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1044 host_.Call( 1042 host_.Call(FROM_HERE,
1045 FROM_HERE, 1043 &SyncBackendHost::NotifyPassphraseRequired,
1046 &SyncBackendHost::NotifyPassphraseRequired, reason, pending_keys); 1044 reason,
1045 pending_keys);
1047 } 1046 }
1048 1047
1049 void SyncBackendHost::Core::OnPassphraseAccepted() { 1048 void SyncBackendHost::Core::OnPassphraseAccepted() {
1050 if (!sync_loop_) 1049 if (!sync_loop_)
1051 return; 1050 return;
1052 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1051 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1053 host_.Call( 1052 host_.Call(FROM_HERE, &SyncBackendHost::NotifyPassphraseAccepted);
1054 FROM_HERE,
1055 &SyncBackendHost::NotifyPassphraseAccepted);
1056 } 1053 }
1057 1054
1058 void SyncBackendHost::Core::OnBootstrapTokenUpdated( 1055 void SyncBackendHost::Core::OnBootstrapTokenUpdated(
1059 const std::string& bootstrap_token, 1056 const std::string& bootstrap_token,
1060 syncer::BootstrapTokenType type) { 1057 syncer::BootstrapTokenType type) {
1061 if (!sync_loop_) 1058 if (!sync_loop_)
1062 return; 1059 return;
1063 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1060 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1064 host_.Call(FROM_HERE, 1061 host_.Call(FROM_HERE,
1065 &SyncBackendHost::PersistEncryptionBootstrapToken, 1062 &SyncBackendHost::PersistEncryptionBootstrapToken,
1066 bootstrap_token, 1063 bootstrap_token,
1067 type); 1064 type);
1068 } 1065 }
1069 1066
1070 void SyncBackendHost::Core::OnStopSyncingPermanently() { 1067 void SyncBackendHost::Core::OnStopSyncingPermanently() {
1071 if (!sync_loop_) 1068 if (!sync_loop_)
1072 return; 1069 return;
1073 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1070 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1074 host_.Call( 1071 host_.Call(FROM_HERE,
1075 FROM_HERE, 1072 &SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop);
1076 &SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop);
1077 } 1073 }
1078 1074
1079 void SyncBackendHost::Core::OnUpdatedToken(const std::string& token) { 1075 void SyncBackendHost::Core::OnUpdatedToken(const std::string& token) {
1080 if (!sync_loop_) 1076 if (!sync_loop_)
1081 return; 1077 return;
1082 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1078 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1083 host_.Call( 1079 host_.Call(FROM_HERE, &SyncBackendHost::NotifyUpdatedToken, token);
1084 FROM_HERE,
1085 &SyncBackendHost::NotifyUpdatedToken, token);
1086 } 1080 }
1087 1081
1088 void SyncBackendHost::Core::OnEncryptedTypesChanged( 1082 void SyncBackendHost::Core::OnEncryptedTypesChanged(
1089 syncer::ModelTypeSet encrypted_types, 1083 syncer::ModelTypeSet encrypted_types,
1090 bool encrypt_everything) { 1084 bool encrypt_everything) {
1091 if (!sync_loop_) 1085 if (!sync_loop_)
1092 return; 1086 return;
1093 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1087 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1094 // NOTE: We're in a transaction. 1088 // NOTE: We're in a transaction.
1095 host_.Call( 1089 host_.Call(
1096 FROM_HERE, 1090 FROM_HERE,
1097 &SyncBackendHost::NotifyEncryptedTypesChanged, 1091 &SyncBackendHost::NotifyEncryptedTypesChanged,
1098 encrypted_types, encrypt_everything); 1092 encrypted_types, encrypt_everything);
1099 } 1093 }
1100 1094
1101 void SyncBackendHost::Core::OnEncryptionComplete() { 1095 void SyncBackendHost::Core::OnEncryptionComplete() {
1102 if (!sync_loop_) 1096 if (!sync_loop_)
1103 return; 1097 return;
1104 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1098 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1105 // NOTE: We're in a transaction. 1099 // NOTE: We're in a transaction.
1106 host_.Call( 1100 host_.Call(
1107 FROM_HERE, 1101 FROM_HERE,
1108 &SyncBackendHost::NotifyEncryptionComplete); 1102 &SyncBackendHost::NotifyEncryptionComplete);
1109 } 1103 }
1110 1104
1111 void SyncBackendHost::Core::OnCryptographerStateChanged( 1105 void SyncBackendHost::Core::OnCryptographerStateChanged(
1112 syncer::Cryptographer* cryptographer) { 1106 syncer::Cryptographer* cryptographer) {
1113 // Do nothing. 1107 // Do nothing.
1114 } 1108 }
1115 1109
1116 void SyncBackendHost::Core::OnPassphraseTypeChanged( 1110 void SyncBackendHost::Core::OnPassphraseTypeChanged(
1117 syncer::PassphraseType type, base::Time passphrase_time) { 1111 syncer::PassphraseType type, base::Time passphrase_time) {
1118 host_.Call( 1112 host_.Call(
1119 FROM_HERE, 1113 FROM_HERE,
1120 &SyncBackendHost::HandlePassphraseTypeChangedOnFrontendLoop, 1114 &SyncBackendHost::HandlePassphraseTypeChangedOnFrontendLoop,
1121 type, passphrase_time); 1115 type, passphrase_time);
1122 } 1116 }
1123 1117
1124 void SyncBackendHost::Core::OnActionableError( 1118 void SyncBackendHost::Core::OnActionableError(
1125 const syncer::SyncProtocolError& sync_error) { 1119 const syncer::SyncProtocolError& sync_error) {
1126 if (!sync_loop_) 1120 if (!sync_loop_)
1127 return; 1121 return;
1128 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1122 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1129 host_.Call( 1123 host_.Call(FROM_HERE,
1130 FROM_HERE, 1124 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop,
1131 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, 1125 sync_error);
1132 sync_error);
1133 } 1126 }
1134 1127
1135 void SyncBackendHost::Core::OnInvalidatorStateChange( 1128 void SyncBackendHost::Core::OnInvalidatorStateChange(
1136 syncer::InvalidatorState state) { 1129 syncer::InvalidatorState state) {
1137 if (!sync_loop_) 1130 if (!sync_loop_)
1138 return; 1131 return;
1139 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1132 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1140 host_.Call(FROM_HERE, 1133 host_.Call(FROM_HERE,
1141 &SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop, 1134 &SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop,
1142 state); 1135 state);
1143 } 1136 }
1144 1137
1145 void SyncBackendHost::Core::OnIncomingInvalidation( 1138 void SyncBackendHost::Core::OnIncomingInvalidation(
1146 const syncer::ObjectIdInvalidationMap& invalidation_map) { 1139 const syncer::ObjectIdInvalidationMap& invalidation_map) {
1147 if (!sync_loop_) 1140 if (!sync_loop_)
1148 return; 1141 return;
1149 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1142 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1150 host_.Call(FROM_HERE, 1143 host_.Call(FROM_HERE,
1151 &SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop, 1144 &SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop,
1152 invalidation_map); 1145 invalidation_map);
1153 } 1146 }
1154 1147
1155 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { 1148 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) {
1156 DCHECK(!sync_loop_); 1149 DCHECK(!sync_loop_);
1157 sync_loop_ = options.sync_loop; 1150 sync_loop_ = options.sync_loop;
1158 DCHECK(sync_loop_); 1151 DCHECK(sync_loop_);
1159 1152
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 // would be encountered. 1212 // would be encountered.
1220 if (CommandLine::ForCurrentProcess()->HasSwitch( 1213 if (CommandLine::ForCurrentProcess()->HasSwitch(
1221 switches::kSyncThrowUnrecoverableError)) { 1214 switches::kSyncThrowUnrecoverableError)) {
1222 sync_manager_->ThrowUnrecoverableError(); 1215 sync_manager_->ThrowUnrecoverableError();
1223 } 1216 }
1224 } 1217 }
1225 } 1218 }
1226 1219
1227 void SyncBackendHost::Core::DoUpdateCredentials( 1220 void SyncBackendHost::Core::DoUpdateCredentials(
1228 const SyncCredentials& credentials) { 1221 const SyncCredentials& credentials) {
1229 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1222 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1230 // UpdateCredentials can be called during backend initialization, possibly 1223 // UpdateCredentials can be called during backend initialization, possibly
1231 // when backend initialization has failed but hasn't notified the UI thread 1224 // when backend initialization has failed but hasn't notified the UI thread
1232 // yet. In that case, the sync manager may have been destroyed on the sync 1225 // yet. In that case, the sync manager may have been destroyed on the sync
1233 // thread before this task was executed, so we do nothing. 1226 // thread before this task was executed, so we do nothing.
1234 if (sync_manager_.get()) { 1227 if (sync_manager_.get()) {
1235 sync_manager_->UpdateCredentials(credentials); 1228 sync_manager_->UpdateCredentials(credentials);
1236 } 1229 }
1237 } 1230 }
1238 1231
1239 void SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds( 1232 void SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds(
1240 const syncer::ObjectIdSet& ids) { 1233 const syncer::ObjectIdSet& ids) {
1241 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1234 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1242 // |sync_manager_| may end up being NULL here in tests (in 1235 // |sync_manager_| may end up being NULL here in tests (in
1243 // synchronous initialization mode) since this is called during 1236 // synchronous initialization mode) since this is called during
1244 // shutdown. 1237 // shutdown.
1245 // 1238 //
1246 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). 1239 // TODO(akalin): Fix this behavior (see http://crbug.com/140354).
1247 if (sync_manager_.get()) { 1240 if (sync_manager_.get()) {
1248 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); 1241 sync_manager_->UpdateRegisteredInvalidationIds(this, ids);
1249 } 1242 }
1250 } 1243 }
1251 1244
1252 void SyncBackendHost::Core::DoAcknowledgeInvalidation( 1245 void SyncBackendHost::Core::DoAcknowledgeInvalidation(
1253 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { 1246 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) {
1254 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1247 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1255 // |sync_manager_| may end up being NULL here in tests (in 1248 // |sync_manager_| may end up being NULL here in tests (in
1256 // synchronous initialization mode). 1249 // synchronous initialization mode).
1257 // 1250 //
1258 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). 1251 // TODO(akalin): Fix this behavior (see http://crbug.com/140354).
1259 if (sync_manager_.get()) { 1252 if (sync_manager_.get()) {
1260 sync_manager_->AcknowledgeInvalidation(id, ack_handle); 1253 sync_manager_->AcknowledgeInvalidation(id, ack_handle);
1261 } 1254 }
1262 } 1255 }
1263 1256
1264 void SyncBackendHost::Core::DoStartSyncing( 1257 void SyncBackendHost::Core::DoStartSyncing(
1265 const syncer::ModelSafeRoutingInfo& routing_info) { 1258 const syncer::ModelSafeRoutingInfo& routing_info) {
1266 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1259 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1267 sync_manager_->StartSyncingNormally(routing_info); 1260 sync_manager_->StartSyncingNormally(routing_info);
1268 } 1261 }
1269 1262
1270 void SyncBackendHost::Core::DoSetEncryptionPassphrase( 1263 void SyncBackendHost::Core::DoSetEncryptionPassphrase(
1271 const std::string& passphrase, 1264 const std::string& passphrase,
1272 bool is_explicit) { 1265 bool is_explicit) {
1273 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1266 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1274 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase( 1267 sync_manager_->GetEncryptionHandler()
1275 passphrase, is_explicit); 1268 ->SetEncryptionPassphrase(passphrase, is_explicit);
1276 } 1269 }
1277 1270
1278 void SyncBackendHost::Core::DoInitialProcessControlTypes() { 1271 void SyncBackendHost::Core::DoInitialProcessControlTypes() {
1279 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1272 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1280 1273
1281 DVLOG(1) << "Initilalizing Control Types"; 1274 DVLOG(1) << "Initilalizing Control Types";
1282 1275
1283 // Initialize encryption. 1276 // Initialize encryption.
1284 sync_manager_->GetEncryptionHandler()->Init(); 1277 sync_manager_->GetEncryptionHandler()->Init();
1285 1278
1286 // Note: experiments are currently handled via SBH::AddExperimentalTypes, 1279 // Note: experiments are currently handled via SBH::AddExperimentalTypes,
1287 // which is called at the end of every sync cycle. 1280 // which is called at the end of every sync cycle.
1288 // TODO(zea): eventually add an experiment handler and initialize it here. 1281 // TODO(zea): eventually add an experiment handler and initialize it here.
1289 1282
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 sync_manager_->GetUserShare()); 1315 sync_manager_->GetUserShare());
1323 1316
1324 host_.Call( 1317 host_.Call(
1325 FROM_HERE, 1318 FROM_HERE,
1326 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, 1319 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop,
1327 true); 1320 true);
1328 } 1321 }
1329 1322
1330 void SyncBackendHost::Core::DoSetDecryptionPassphrase( 1323 void SyncBackendHost::Core::DoSetDecryptionPassphrase(
1331 const std::string& passphrase) { 1324 const std::string& passphrase) {
1332 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1325 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1333 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( 1326 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase(passphrase);
1334 passphrase);
1335 } 1327 }
1336 1328
1337 void SyncBackendHost::Core::DoEnableEncryptEverything() { 1329 void SyncBackendHost::Core::DoEnableEncryptEverything() {
1338 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1330 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1339 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); 1331 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything();
1340 } 1332 }
1341 1333
1342 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( 1334 void SyncBackendHost::Core::DoStopSyncManagerForShutdown(
1343 const base::Closure& closure) { 1335 const base::Closure& closure) {
1344 if (sync_manager_.get()) { 1336 if (sync_manager_.get()) {
1345 sync_manager_->StopSyncingForShutdown(closure); 1337 sync_manager_->StopSyncingForShutdown(closure);
1346 } else { 1338 } else {
1347 sync_loop_->PostTask(FROM_HERE, closure); 1339 sync_loop_->PostTask(FROM_HERE, closure);
1348 } 1340 }
1349 } 1341 }
1350 1342
1351 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { 1343 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) {
1352 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1344 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1353 // It's safe to do this even if the type was never activated. 1345 // It's safe to do this even if the type was never activated.
1354 registrar_->DeactivateDataType(syncer::DEVICE_INFO); 1346 registrar_->DeactivateDataType(syncer::DEVICE_INFO);
1355 synced_device_tracker_.reset(); 1347 synced_device_tracker_.reset();
1356 1348
1357 DoDestroySyncManager(); 1349 DoDestroySyncManager();
1358 1350
1359 registrar_ = NULL; 1351 registrar_ = NULL;
1360 1352
1361 if (sync_disabled) 1353 if (sync_disabled)
1362 DeleteSyncDataFolder(); 1354 DeleteSyncDataFolder();
1363 1355
1364 sync_loop_ = NULL; 1356 sync_loop_ = NULL;
1365 1357
1366 host_.Reset(); 1358 host_.Reset();
1367 } 1359 }
1368 1360
1369 void SyncBackendHost::Core::DoDestroySyncManager() { 1361 void SyncBackendHost::Core::DoDestroySyncManager() {
1370 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1362 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1371 if (sync_manager_.get()) { 1363 if (sync_manager_.get()) {
1372 save_changes_timer_.reset(); 1364 save_changes_timer_.reset();
1373 if (registered_as_invalidation_handler_) { 1365 if (registered_as_invalidation_handler_) {
1374 sync_manager_->UnregisterInvalidationHandler(this); 1366 sync_manager_->UnregisterInvalidationHandler(this);
1375 registered_as_invalidation_handler_ = false; 1367 registered_as_invalidation_handler_ = false;
1376 } 1368 }
1377 sync_manager_->RemoveObserver(this); 1369 sync_manager_->RemoveObserver(this);
1378 sync_manager_->ShutdownOnSyncThread(); 1370 sync_manager_->ShutdownOnSyncThread();
1379 sync_manager_.reset(); 1371 sync_manager_.reset();
1380 } 1372 }
1381 } 1373 }
1382 1374
1383 void SyncBackendHost::Core::DoConfigureSyncer( 1375 void SyncBackendHost::Core::DoConfigureSyncer(
1384 syncer::ConfigureReason reason, 1376 syncer::ConfigureReason reason,
1385 syncer::ModelTypeSet types_to_config, 1377 syncer::ModelTypeSet types_to_config,
1386 syncer::ModelTypeSet failed_types, 1378 syncer::ModelTypeSet failed_types,
1387 const syncer::ModelSafeRoutingInfo routing_info, 1379 const syncer::ModelSafeRoutingInfo routing_info,
1388 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, 1380 const base::Callback<void(syncer::ModelTypeSet)>& ready_task,
1389 const base::Closure& retry_callback) { 1381 const base::Closure& retry_callback) {
1390 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1382 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1391 sync_manager_->ConfigureSyncer( 1383 sync_manager_->ConfigureSyncer(
1392 reason, 1384 reason,
1393 types_to_config, 1385 types_to_config,
1394 failed_types, 1386 failed_types,
1395 routing_info, 1387 routing_info,
1396 base::Bind(&SyncBackendHost::Core::DoFinishConfigureDataTypes, 1388 base::Bind(&SyncBackendHost::Core::DoFinishConfigureDataTypes,
1397 this, 1389 this,
1398 types_to_config, 1390 types_to_config,
1399 ready_task), 1391 ready_task),
1400 base::Bind(&SyncBackendHost::Core::DoRetryConfiguration, 1392 base::Bind(
1401 this, 1393 &SyncBackendHost::Core::DoRetryConfiguration, this, retry_callback));
1402 retry_callback));
1403 } 1394 }
1404 1395
1405 void SyncBackendHost::Core::DoFinishConfigureDataTypes( 1396 void SyncBackendHost::Core::DoFinishConfigureDataTypes(
1406 syncer::ModelTypeSet types_to_config, 1397 syncer::ModelTypeSet types_to_config,
1407 const base::Callback<void(syncer::ModelTypeSet)>& ready_task) { 1398 const base::Callback<void(syncer::ModelTypeSet)>& ready_task) {
1408 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1399 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1409 1400
1410 // Update the enabled types for the bridge and sync manager. 1401 // Update the enabled types for the bridge and sync manager.
1411 syncer::ModelSafeRoutingInfo routing_info; 1402 syncer::ModelSafeRoutingInfo routing_info;
1412 registrar_->GetModelSafeRoutingInfo(&routing_info); 1403 registrar_->GetModelSafeRoutingInfo(&routing_info);
1413 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); 1404 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
1414 enabled_types.RemoveAll(syncer::ProxyTypes()); 1405 enabled_types.RemoveAll(syncer::ProxyTypes());
1415 sync_manager_->UpdateEnabledTypes(enabled_types); 1406 sync_manager_->UpdateEnabledTypes(enabled_types);
1416 1407
1417 const syncer::ModelTypeSet failed_configuration_types = 1408 const syncer::ModelTypeSet failed_configuration_types =
1418 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); 1409 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes());
1419 host_.Call(FROM_HERE, 1410 host_.Call(FROM_HERE,
1420 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop, 1411 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop,
1421 failed_configuration_types, 1412 failed_configuration_types,
1422 ready_task); 1413 ready_task);
1423 } 1414 }
1424 1415
1425 void SyncBackendHost::Core::DoRetryConfiguration( 1416 void SyncBackendHost::Core::DoRetryConfiguration(
1426 const base::Closure& retry_callback) { 1417 const base::Closure& retry_callback) {
1427 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1418 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1428 host_.Call(FROM_HERE, 1419 host_.Call(FROM_HERE,
1429 &SyncBackendHost::RetryConfigurationOnFrontendLoop, 1420 &SyncBackendHost::RetryConfigurationOnFrontendLoop,
1430 retry_callback); 1421 retry_callback);
1431 } 1422 }
1432 1423
1433 void SyncBackendHost::Core::DeleteSyncDataFolder() { 1424 void SyncBackendHost::Core::DeleteSyncDataFolder() {
1434 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1425 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1435 if (file_util::DirectoryExists(sync_data_folder_path_)) { 1426 if (file_util::DirectoryExists(sync_data_folder_path_)) {
1436 if (!file_util::Delete(sync_data_folder_path_, true)) 1427 if (!file_util::Delete(sync_data_folder_path_, true))
1437 SLOG(DFATAL) << "Could not delete the Sync Data folder."; 1428 SLOG(DFATAL) << "Could not delete the Sync Data folder.";
1438 } 1429 }
1439 } 1430 }
1440 1431
1441 void SyncBackendHost::Core::StartSavingChanges() { 1432 void SyncBackendHost::Core::StartSavingChanges() {
1442 // We may already be shut down. 1433 // We may already be shut down.
1443 if (!sync_loop_) 1434 if (!sync_loop_)
1444 return; 1435 return;
1445 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1436 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1446 DCHECK(!save_changes_timer_.get()); 1437 DCHECK(!save_changes_timer_.get());
1447 save_changes_timer_.reset(new base::RepeatingTimer<Core>()); 1438 save_changes_timer_.reset(new base::RepeatingTimer<Core>());
1448 save_changes_timer_->Start(FROM_HERE, 1439 save_changes_timer_->Start(FROM_HERE,
1449 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), 1440 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds),
1450 this, &Core::SaveChanges); 1441 this, &Core::SaveChanges);
1451 } 1442 }
1452 1443
1453 void SyncBackendHost::Core::SaveChanges() { 1444 void SyncBackendHost::Core::SaveChanges() {
1454 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1445 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1455 sync_manager_->SaveChanges(); 1446 sync_manager_->SaveChanges();
1456 } 1447 }
1457 1448
1458 void SyncBackendHost::AddExperimentalTypes() { 1449 void SyncBackendHost::AddExperimentalTypes() {
1459 CHECK(initialized()); 1450 CHECK(initialized());
1460 syncer::Experiments experiments; 1451 syncer::Experiments experiments;
1461 if (core_->sync_manager()->ReceivedExperiment(&experiments)) 1452 if (core_->sync_manager()->ReceivedExperiment(&experiments))
1462 frontend_->OnExperimentsChanged(experiments); 1453 frontend_->OnExperimentsChanged(experiments);
1463 } 1454 }
1464 1455
1465 void SyncBackendHost::HandleControlTypesDownloadRetry() { 1456 void SyncBackendHost::HandleControlTypesDownloadRetry() {
1466 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1457 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1467 if (!frontend_) 1458 if (!frontend_)
1468 return; 1459 return;
1469 1460
1470 frontend_->OnSyncConfigureRetry(); 1461 frontend_->OnSyncConfigureRetry();
1471 } 1462 }
1472 1463
1473 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop( 1464 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop(
1474 bool success) { 1465 bool success) {
1475 DCHECK_NE(initialization_state_, NOT_ATTEMPTED); 1466 DCHECK_NE(initialization_state_, NOT_ATTEMPTED);
1476 if (!frontend_) 1467 if (!frontend_)
1477 return; 1468 return;
1478 1469
1479 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1470 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1480 if (!success) { 1471 if (!success) {
1481 js_backend_.Reset(); 1472 js_backend_.Reset();
1482 initialization_state_ = NOT_INITIALIZED; 1473 initialization_state_ = NOT_INITIALIZED;
1483 frontend_->OnBackendInitialized( 1474 frontend_->OnBackendInitialized(
1484 syncer::WeakHandle<syncer::JsBackend>(), 1475 syncer::WeakHandle<syncer::JsBackend>(),
1485 syncer::WeakHandle<syncer::DataTypeDebugInfoListener>(), 1476 syncer::WeakHandle<syncer::DataTypeDebugInfoListener>(),
1486 false); 1477 false);
1487 return; 1478 return;
1488 } 1479 }
1489 1480
1490 initialization_state_ = INITIALIZED; 1481 initialization_state_ = INITIALIZED;
1491 1482
1492 // Now that we've downloaded the control types, we can see if there are any 1483 // Now that we've downloaded the control types, we can see if there are any
1493 // experimental types to enable. This should be done before we inform 1484 // experimental types to enable. This should be done before we inform
1494 // the frontend to ensure they're visible in the customize screen. 1485 // the frontend to ensure they're visible in the customize screen.
1495 AddExperimentalTypes(); 1486 AddExperimentalTypes();
1496 frontend_->OnBackendInitialized(js_backend_, 1487 frontend_->OnBackendInitialized(js_backend_,
1497 debug_info_listener_, 1488 debug_info_listener_,
1498 true); 1489 true);
1499 js_backend_.Reset(); 1490 js_backend_.Reset();
1500 } 1491 }
1501 1492
1502 void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop( 1493 void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop(
1503 const SyncSessionSnapshot& snapshot) { 1494 const SyncSessionSnapshot& snapshot) {
1504 if (!frontend_) 1495 if (!frontend_)
1505 return; 1496 return;
1506 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1497 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1507 1498
1508 last_snapshot_ = snapshot; 1499 last_snapshot_ = snapshot;
1509 1500
1510 SDVLOG(1) << "Got snapshot " << snapshot.ToString(); 1501 SDVLOG(1) << "Got snapshot " << snapshot.ToString();
1511 1502
1512 const syncer::ModelTypeSet to_migrate = 1503 const syncer::ModelTypeSet to_migrate =
1513 snapshot.model_neutral_state().types_needing_local_migration; 1504 snapshot.model_neutral_state().types_needing_local_migration;
1514 if (!to_migrate.Empty()) 1505 if (!to_migrate.Empty())
1515 frontend_->OnMigrationNeededForTypes(to_migrate); 1506 frontend_->OnMigrationNeededForTypes(to_migrate);
1516 1507
(...skipping 20 matching lines...) Expand all
1537 if (token_type == syncer::PASSPHRASE_BOOTSTRAP_TOKEN) 1528 if (token_type == syncer::PASSPHRASE_BOOTSTRAP_TOKEN)
1538 sync_prefs_->SetEncryptionBootstrapToken(token); 1529 sync_prefs_->SetEncryptionBootstrapToken(token);
1539 else 1530 else
1540 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token); 1531 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token);
1541 } 1532 }
1542 1533
1543 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( 1534 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop(
1544 const syncer::SyncProtocolError& sync_error) { 1535 const syncer::SyncProtocolError& sync_error) {
1545 if (!frontend_) 1536 if (!frontend_)
1546 return; 1537 return;
1547 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1538 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1548 frontend_->OnActionableError(sync_error); 1539 frontend_->OnActionableError(sync_error);
1549 } 1540 }
1550 1541
1551 void SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop( 1542 void SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop(
1552 syncer::InvalidatorState state) { 1543 syncer::InvalidatorState state) {
1553 if (!frontend_) 1544 if (!frontend_)
1554 return; 1545 return;
1555 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1546 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1556 frontend_->OnInvalidatorStateChange(state); 1547 frontend_->OnInvalidatorStateChange(state);
1557 } 1548 }
1558 1549
1559 void SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop( 1550 void SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop(
1560 const syncer::ObjectIdInvalidationMap& invalidation_map) { 1551 const syncer::ObjectIdInvalidationMap& invalidation_map) {
1561 if (!frontend_) 1552 if (!frontend_)
1562 return; 1553 return;
1563 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1554 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1564 frontend_->OnIncomingInvalidation(invalidation_map); 1555 frontend_->OnIncomingInvalidation(invalidation_map);
1565 } 1556 }
1566 1557
1567 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( 1558 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys(
1568 const std::string& passphrase) const { 1559 const std::string& passphrase) const {
1569 DCHECK(cached_pending_keys_.has_blob()); 1560 DCHECK(cached_pending_keys_.has_blob());
1570 DCHECK(!passphrase.empty()); 1561 DCHECK(!passphrase.empty());
1571 syncer::Nigori nigori; 1562 syncer::Nigori nigori;
1572 nigori.InitByDerivation("localhost", "dummy", passphrase); 1563 nigori.InitByDerivation("localhost", "dummy", passphrase);
1573 std::string plaintext; 1564 std::string plaintext;
1574 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); 1565 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext);
1575 DVLOG_IF(1, result) << "Passphrase failed to decrypt pending keys."; 1566 DVLOG_IF(1, result) << "Passphrase failed to decrypt pending keys.";
1576 return result; 1567 return result;
1577 } 1568 }
1578 1569
1579 void SyncBackendHost::NotifyPassphraseRequired( 1570 void SyncBackendHost::NotifyPassphraseRequired(
1580 syncer::PassphraseRequiredReason reason, 1571 syncer::PassphraseRequiredReason reason,
1581 sync_pb::EncryptedData pending_keys) { 1572 sync_pb::EncryptedData pending_keys) {
1582 if (!frontend_) 1573 if (!frontend_)
1583 return; 1574 return;
1584 1575
1585 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1576 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1586 1577
1587 // Update our cache of the cryptographer's pending keys. 1578 // Update our cache of the cryptographer's pending keys.
1588 cached_pending_keys_ = pending_keys; 1579 cached_pending_keys_ = pending_keys;
1589 1580
1590 frontend_->OnPassphraseRequired(reason, pending_keys); 1581 frontend_->OnPassphraseRequired(reason, pending_keys);
1591 } 1582 }
1592 1583
1593 void SyncBackendHost::NotifyPassphraseAccepted() { 1584 void SyncBackendHost::NotifyPassphraseAccepted() {
1594 if (!frontend_) 1585 if (!frontend_)
1595 return; 1586 return;
1596 1587
1597 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1588 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1598 1589
1599 // Clear our cache of the cryptographer's pending keys. 1590 // Clear our cache of the cryptographer's pending keys.
1600 cached_pending_keys_.clear_blob(); 1591 cached_pending_keys_.clear_blob();
1601 frontend_->OnPassphraseAccepted(); 1592 frontend_->OnPassphraseAccepted();
1602 } 1593 }
1603 1594
1604 void SyncBackendHost::NotifyUpdatedToken(const std::string& token) { 1595 void SyncBackendHost::NotifyUpdatedToken(const std::string& token) {
1605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1596 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1606 TokenAvailableDetails details(GaiaConstants::kSyncService, token); 1597 TokenAvailableDetails details(GaiaConstants::kSyncService, token);
1607 1598
1608 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 1599 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
1609 CHECK(token_service); 1600 CHECK(token_service);
1610 token_service->AddAuthTokenManually(details.service(), details.token()); 1601 token_service->AddAuthTokenManually(details.service(), details.token());
1611 } 1602 }
1612 1603
1613 void SyncBackendHost::NotifyEncryptedTypesChanged( 1604 void SyncBackendHost::NotifyEncryptedTypesChanged(
1614 syncer::ModelTypeSet encrypted_types, 1605 syncer::ModelTypeSet encrypted_types,
1615 bool encrypt_everything) { 1606 bool encrypt_everything) {
1616 if (!frontend_) 1607 if (!frontend_)
1617 return; 1608 return;
1618 1609
1619 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1610 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1620 frontend_->OnEncryptedTypesChanged( 1611 frontend_->OnEncryptedTypesChanged(encrypted_types, encrypt_everything);
1621 encrypted_types, encrypt_everything);
1622 } 1612 }
1623 1613
1624 void SyncBackendHost::NotifyEncryptionComplete() { 1614 void SyncBackendHost::NotifyEncryptionComplete() {
1625 if (!frontend_) 1615 if (!frontend_)
1626 return; 1616 return;
1627 1617
1628 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1618 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1629 frontend_->OnEncryptionComplete(); 1619 frontend_->OnEncryptionComplete();
1630 } 1620 }
1631 1621
1632 void SyncBackendHost::HandlePassphraseTypeChangedOnFrontendLoop( 1622 void SyncBackendHost::HandlePassphraseTypeChangedOnFrontendLoop(
1633 syncer::PassphraseType type, 1623 syncer::PassphraseType type,
1634 base::Time explicit_passphrase_time) { 1624 base::Time explicit_passphrase_time) {
1635 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1625 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1636 DVLOG(1) << "Passphrase type changed to " 1626 DVLOG(1) << "Passphrase type changed to "
1637 << syncer::PassphraseTypeToString(type); 1627 << syncer::PassphraseTypeToString(type);
1638 cached_passphrase_type_ = type; 1628 cached_passphrase_type_ = type;
1639 cached_explicit_passphrase_time_ = explicit_passphrase_time; 1629 cached_explicit_passphrase_time_ = explicit_passphrase_time;
1640 } 1630 }
1641 1631
1642 void SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop() { 1632 void SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop() {
1643 if (!frontend_) 1633 if (!frontend_)
1644 return; 1634 return;
1645 frontend_->OnStopSyncingPermanently(); 1635 frontend_->OnStopSyncingPermanently();
1646 } 1636 }
1647 1637
1648 void SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop( 1638 void SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop(
1649 syncer::ConnectionStatus status) { 1639 syncer::ConnectionStatus status) {
1650 if (!frontend_) 1640 if (!frontend_)
1651 return; 1641 return;
1652 1642
1653 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1643 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1654 1644
1655 DVLOG(1) << "Connection status changed: " 1645 DVLOG(1) << "Connection status changed: "
1656 << syncer::ConnectionStatusToString(status); 1646 << syncer::ConnectionStatusToString(status);
1657 frontend_->OnConnectionStatusChange(status); 1647 frontend_->OnConnectionStatusChange(status);
1658 } 1648 }
1659 1649
1660 #undef SDVLOG 1650 #undef SDVLOG
1661 1651
1662 #undef SLOG 1652 #undef SLOG
1663 1653
1664 } // namespace browser_sync 1654 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698