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

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: rebase again Created 7 years, 6 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 const std::string name_; 265 const std::string name_;
266 266
267 // Path of the folder that stores the sync data files. 267 // Path of the folder that stores the sync data files.
268 const base::FilePath sync_data_folder_path_; 268 const base::FilePath sync_data_folder_path_;
269 269
270 // Our parent SyncBackendHost. 270 // Our parent SyncBackendHost.
271 syncer::WeakHandle<SyncBackendHost> host_; 271 syncer::WeakHandle<SyncBackendHost> host_;
272 272
273 // The loop where all the sync backend operations happen. 273 // The loop where all the sync backend operations happen.
274 // Non-NULL only between calls to DoInitialize() and DoShutdown(). 274 // Non-NULL only between calls to DoInitialize() and DoShutdown().
275 MessageLoop* sync_loop_; 275 base::MessageLoop* sync_loop_;
276 276
277 // Our parent's registrar (not owned). Non-NULL only between 277 // Our parent's registrar (not owned). Non-NULL only between
278 // calls to DoInitialize() and DoShutdown(). 278 // calls to DoInitialize() and DoShutdown().
279 SyncBackendRegistrar* registrar_; 279 SyncBackendRegistrar* registrar_;
280 280
281 // The timer used to periodically call SaveChanges. 281 // The timer used to periodically call SaveChanges.
282 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_; 282 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_;
283 283
284 // Our encryptor, which uses Chrome's encryption functions. 284 // Our encryptor, which uses Chrome's encryption functions.
285 ChromeEncryptor encryptor_; 285 ChromeEncryptor encryptor_;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 346
347 } // namespace 347 } // namespace
348 348
349 SyncBackendHost::SyncBackendHost( 349 SyncBackendHost::SyncBackendHost(
350 const std::string& name, 350 const std::string& name,
351 Profile* profile, 351 Profile* profile,
352 const base::WeakPtr<SyncPrefs>& sync_prefs, 352 const base::WeakPtr<SyncPrefs>& sync_prefs,
353 const base::WeakPtr<invalidation::InvalidatorStorage>& invalidator_storage) 353 const base::WeakPtr<invalidation::InvalidatorStorage>& invalidator_storage)
354 : weak_ptr_factory_(this), 354 : weak_ptr_factory_(this),
355 sync_thread_("Chrome_SyncThread"), 355 sync_thread_("Chrome_SyncThread"),
356 frontend_loop_(MessageLoop::current()), 356 frontend_loop_(base::MessageLoop::current()),
357 profile_(profile), 357 profile_(profile),
358 name_(name), 358 name_(name),
359 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName), 359 core_(new Core(name, profile_->GetPath().Append(kSyncDataFolderName),
360 weak_ptr_factory_.GetWeakPtr())), 360 weak_ptr_factory_.GetWeakPtr())),
361 initialization_state_(NOT_ATTEMPTED), 361 initialization_state_(NOT_ATTEMPTED),
362 sync_prefs_(sync_prefs), 362 sync_prefs_(sync_prefs),
363 invalidator_factory_( 363 invalidator_factory_(
364 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), 364 ParseNotifierOptions(*CommandLine::ForCurrentProcess(),
365 profile_->GetRequestContext()), 365 profile_->GetRequestContext()),
366 content::GetUserAgent(GURL()), 366 content::GetUserAgent(GURL()),
367 invalidator_storage), 367 invalidator_storage),
368 frontend_(NULL), 368 frontend_(NULL),
369 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { 369 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) {
370 } 370 }
371 371
372 SyncBackendHost::SyncBackendHost(Profile* profile) 372 SyncBackendHost::SyncBackendHost(Profile* profile)
373 : weak_ptr_factory_(this), 373 : weak_ptr_factory_(this),
374 sync_thread_("Chrome_SyncThread"), 374 sync_thread_("Chrome_SyncThread"),
375 frontend_loop_(MessageLoop::current()), 375 frontend_loop_(base::MessageLoop::current()),
376 profile_(profile), 376 profile_(profile),
377 name_("Unknown"), 377 name_("Unknown"),
378 initialization_state_(NOT_ATTEMPTED), 378 initialization_state_(NOT_ATTEMPTED),
379 invalidator_factory_( 379 invalidator_factory_(
380 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), 380 ParseNotifierOptions(*CommandLine::ForCurrentProcess(),
381 profile_->GetRequestContext()), 381 profile_->GetRequestContext()),
382 content::GetUserAgent(GURL()), 382 content::GetUserAgent(GURL()),
383 base::WeakPtr<syncer::InvalidationStateTracker>()), 383 base::WeakPtr<syncer::InvalidationStateTracker>()),
384 frontend_(NULL), 384 frontend_(NULL),
385 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { 385 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 471
472 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { 472 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) {
473 DCHECK(sync_thread_.IsRunning()); 473 DCHECK(sync_thread_.IsRunning());
474 sync_thread_.message_loop()->PostTask(FROM_HERE, 474 sync_thread_.message_loop()->PostTask(FROM_HERE,
475 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(), 475 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, core_.get(),
476 credentials)); 476 credentials));
477 } 477 }
478 478
479 void SyncBackendHost::UpdateRegisteredInvalidationIds( 479 void SyncBackendHost::UpdateRegisteredInvalidationIds(
480 const syncer::ObjectIdSet& ids) { 480 const syncer::ObjectIdSet& ids) {
481 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 481 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
482 DCHECK(sync_thread_.IsRunning()); 482 DCHECK(sync_thread_.IsRunning());
483 sync_thread_.message_loop()->PostTask(FROM_HERE, 483 sync_thread_.message_loop()->PostTask(FROM_HERE,
484 base::Bind(&SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds, 484 base::Bind(&SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds,
485 core_.get(), ids)); 485 core_.get(), ids));
486 } 486 }
487 487
488 void SyncBackendHost::AcknowledgeInvalidation( 488 void SyncBackendHost::AcknowledgeInvalidation(
489 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { 489 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) {
490 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 490 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
491 DCHECK(sync_thread_.IsRunning()); 491 DCHECK(sync_thread_.IsRunning());
492 sync_thread_.message_loop()->PostTask(FROM_HERE, 492 sync_thread_.message_loop()->PostTask(FROM_HERE,
493 base::Bind(&SyncBackendHost::Core::DoAcknowledgeInvalidation, 493 base::Bind(&SyncBackendHost::Core::DoAcknowledgeInvalidation,
494 core_.get(), id, ack_handle)); 494 core_.get(), id, ack_handle));
495 } 495 }
496 496
497 void SyncBackendHost::StartSyncingWithServer() { 497 void SyncBackendHost::StartSyncingWithServer() {
498 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; 498 SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called.";
499 499
500 syncer::ModelSafeRoutingInfo routing_info; 500 syncer::ModelSafeRoutingInfo routing_info;
(...skipping 10 matching lines...) Expand all
511 if (!IsNigoriEnabled()) { 511 if (!IsNigoriEnabled()) {
512 NOTREACHED() << "SetEncryptionPassphrase must never be called when nigori" 512 NOTREACHED() << "SetEncryptionPassphrase must never be called when nigori"
513 " is disabled."; 513 " is disabled.";
514 return; 514 return;
515 } 515 }
516 516
517 // We should never be called with an empty passphrase. 517 // We should never be called with an empty passphrase.
518 DCHECK(!passphrase.empty()); 518 DCHECK(!passphrase.empty());
519 519
520 // This should only be called by the frontend. 520 // This should only be called by the frontend.
521 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 521 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
522 522
523 // SetEncryptionPassphrase should never be called if we are currently 523 // SetEncryptionPassphrase should never be called if we are currently
524 // encrypted with an explicit passphrase. 524 // encrypted with an explicit passphrase.
525 DCHECK(cached_passphrase_type_ == syncer::KEYSTORE_PASSPHRASE || 525 DCHECK(cached_passphrase_type_ == syncer::KEYSTORE_PASSPHRASE ||
526 cached_passphrase_type_ == syncer::IMPLICIT_PASSPHRASE); 526 cached_passphrase_type_ == syncer::IMPLICIT_PASSPHRASE);
527 527
528 // Post an encryption task on the syncer thread. 528 // Post an encryption task on the syncer thread.
529 sync_thread_.message_loop()->PostTask(FROM_HERE, 529 sync_thread_.message_loop()->PostTask(FROM_HERE,
530 base::Bind(&SyncBackendHost::Core::DoSetEncryptionPassphrase, core_.get(), 530 base::Bind(&SyncBackendHost::Core::DoSetEncryptionPassphrase, core_.get(),
531 passphrase, is_explicit)); 531 passphrase, is_explicit));
532 } 532 }
533 533
534 bool SyncBackendHost::SetDecryptionPassphrase(const std::string& passphrase) { 534 bool SyncBackendHost::SetDecryptionPassphrase(const std::string& passphrase) {
535 if (!IsNigoriEnabled()) { 535 if (!IsNigoriEnabled()) {
536 NOTREACHED() << "SetDecryptionPassphrase must never be called when nigori" 536 NOTREACHED() << "SetDecryptionPassphrase must never be called when nigori"
537 " is disabled."; 537 " is disabled.";
538 return false; 538 return false;
539 } 539 }
540 540
541 // We should never be called with an empty passphrase. 541 // We should never be called with an empty passphrase.
542 DCHECK(!passphrase.empty()); 542 DCHECK(!passphrase.empty());
543 543
544 // This should only be called by the frontend. 544 // This should only be called by the frontend.
545 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 545 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
546 546
547 // This should only be called when we have cached pending keys. 547 // This should only be called when we have cached pending keys.
548 DCHECK(cached_pending_keys_.has_blob()); 548 DCHECK(cached_pending_keys_.has_blob());
549 549
550 // Check the passphrase that was provided against our local cache of the 550 // Check the passphrase that was provided against our local cache of the
551 // cryptographer's pending keys. If this was unsuccessful, the UI layer can 551 // cryptographer's pending keys. If this was unsuccessful, the UI layer can
552 // immediately call OnPassphraseRequired without showing the user a spinner. 552 // immediately call OnPassphraseRequired without showing the user a spinner.
553 if (!CheckPassphraseAgainstCachedPendingKeys(passphrase)) 553 if (!CheckPassphraseAgainstCachedPendingKeys(passphrase))
554 return false; 554 return false;
555 555
(...skipping 28 matching lines...) Expand all
584 base::Bind( 584 base::Bind(
585 &SyncBackendHost::Core::DoStopSyncManagerForShutdown, 585 &SyncBackendHost::Core::DoStopSyncManagerForShutdown,
586 core_.get(), 586 core_.get(),
587 closure)); 587 closure));
588 } else { 588 } else {
589 core_->DoStopSyncManagerForShutdown(closure); 589 core_->DoStopSyncManagerForShutdown(closure);
590 } 590 }
591 } 591 }
592 592
593 void SyncBackendHost::StopSyncingForShutdown() { 593 void SyncBackendHost::StopSyncingForShutdown() {
594 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 594 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
595 595
596 // Immediately stop sending messages to the frontend. 596 // Immediately stop sending messages to the frontend.
597 frontend_ = NULL; 597 frontend_ = NULL;
598 598
599 // Stop listening for and forwarding locally-triggered sync refresh requests. 599 // Stop listening for and forwarding locally-triggered sync refresh requests.
600 notification_registrar_.RemoveAll(); 600 notification_registrar_.RemoveAll();
601 601
602 // Thread shutdown should occur in the following order: 602 // Thread shutdown should occur in the following order:
603 // - Sync Thread 603 // - Sync Thread
604 // - UI Thread (stops some time after we return from this call). 604 // - UI Thread (stops some time after we return from this call).
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 retry_callback)); 841 retry_callback));
842 } 842 }
843 843
844 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop( 844 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop(
845 const syncer::ModelTypeSet succeeded_configuration_types, 845 const syncer::ModelTypeSet succeeded_configuration_types,
846 const syncer::ModelTypeSet failed_configuration_types, 846 const syncer::ModelTypeSet failed_configuration_types,
847 const base::Callback<void(syncer::ModelTypeSet, 847 const base::Callback<void(syncer::ModelTypeSet,
848 syncer::ModelTypeSet)>& ready_task) { 848 syncer::ModelTypeSet)>& ready_task) {
849 if (!frontend_) 849 if (!frontend_)
850 return; 850 return;
851 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 851 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
852 if (!ready_task.is_null()) 852 if (!ready_task.is_null())
853 ready_task.Run(succeeded_configuration_types, failed_configuration_types); 853 ready_task.Run(succeeded_configuration_types, failed_configuration_types);
854 } 854 }
855 855
856 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( 856 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop(
857 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 857 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
858 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 858 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
859 debug_info_listener, 859 debug_info_listener,
860 syncer::ModelTypeSet restored_types) { 860 syncer::ModelTypeSet restored_types) {
861 DCHECK_EQ(initialization_state_, CREATING_SYNC_MANAGER); 861 DCHECK_EQ(initialization_state_, CREATING_SYNC_MANAGER);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 state_details(details); 899 state_details(details);
900 const syncer::ModelTypeInvalidationMap& invalidation_map = 900 const syncer::ModelTypeInvalidationMap& invalidation_map =
901 *(state_details.ptr()); 901 *(state_details.ptr());
902 const syncer::ModelTypeSet types = 902 const syncer::ModelTypeSet types =
903 ModelTypeInvalidationMapToSet(invalidation_map); 903 ModelTypeInvalidationMapToSet(invalidation_map);
904 sync_thread_.message_loop()->PostTask(FROM_HERE, 904 sync_thread_.message_loop()->PostTask(FROM_HERE,
905 base::Bind(&SyncBackendHost::Core::DoRefreshTypes, core_.get(), types)); 905 base::Bind(&SyncBackendHost::Core::DoRefreshTypes, core_.get(), types));
906 } 906 }
907 907
908 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( 908 SyncBackendHost::DoInitializeOptions::DoInitializeOptions(
909 MessageLoop* sync_loop, 909 base::MessageLoop* sync_loop,
910 SyncBackendRegistrar* registrar, 910 SyncBackendRegistrar* registrar,
911 const syncer::ModelSafeRoutingInfo& routing_info, 911 const syncer::ModelSafeRoutingInfo& routing_info,
912 const std::vector<syncer::ModelSafeWorker*>& workers, 912 const std::vector<syncer::ModelSafeWorker*>& workers,
913 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 913 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
914 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 914 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
915 const GURL& service_url, 915 const GURL& service_url,
916 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, 916 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn,
917 const syncer::SyncCredentials& credentials, 917 const syncer::SyncCredentials& credentials,
918 AndroidInvalidatorBridge* android_invalidator_bridge, 918 AndroidInvalidatorBridge* android_invalidator_bridge,
919 syncer::InvalidatorFactory* invalidator_factory, 919 syncer::InvalidatorFactory* invalidator_factory,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 963
964 SyncBackendHost::Core::~Core() { 964 SyncBackendHost::Core::~Core() {
965 DCHECK(!sync_manager_.get()); 965 DCHECK(!sync_manager_.get());
966 DCHECK(!sync_loop_); 966 DCHECK(!sync_loop_);
967 } 967 }
968 968
969 void SyncBackendHost::Core::OnSyncCycleCompleted( 969 void SyncBackendHost::Core::OnSyncCycleCompleted(
970 const SyncSessionSnapshot& snapshot) { 970 const SyncSessionSnapshot& snapshot) {
971 if (!sync_loop_) 971 if (!sync_loop_)
972 return; 972 return;
973 DCHECK_EQ(MessageLoop::current(), sync_loop_); 973 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
974 974
975 host_.Call( 975 host_.Call(
976 FROM_HERE, 976 FROM_HERE,
977 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop, 977 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop,
978 snapshot); 978 snapshot);
979 } 979 }
980 980
981 void SyncBackendHost::Core::DoDownloadControlTypes( 981 void SyncBackendHost::Core::DoDownloadControlTypes(
982 syncer::ConfigureReason reason) { 982 syncer::ConfigureReason reason) {
983 syncer::ModelTypeSet new_control_types = registrar_->ConfigureDataTypes( 983 syncer::ModelTypeSet new_control_types = registrar_->ConfigureDataTypes(
984 syncer::ControlTypes(), syncer::ModelTypeSet()); 984 syncer::ControlTypes(), syncer::ModelTypeSet());
985 syncer::ModelSafeRoutingInfo routing_info; 985 syncer::ModelSafeRoutingInfo routing_info;
986 registrar_->GetModelSafeRoutingInfo(&routing_info); 986 registrar_->GetModelSafeRoutingInfo(&routing_info);
987 SDVLOG(1) << "Control Types " 987 SDVLOG(1) << "Control Types "
988 << syncer::ModelTypeSetToString(new_control_types) 988 << syncer::ModelTypeSetToString(new_control_types)
989 << " added; calling DoConfigureSyncer"; 989 << " added; calling DoConfigureSyncer";
990 990
991 sync_manager_->ConfigureSyncer( 991 sync_manager_->ConfigureSyncer(
992 reason, 992 reason,
993 new_control_types, 993 new_control_types,
994 syncer::ModelTypeSet(), 994 syncer::ModelTypeSet(),
995 routing_info, 995 routing_info,
996 base::Bind(&SyncBackendHost::Core::DoInitialProcessControlTypes, 996 base::Bind(&SyncBackendHost::Core::DoInitialProcessControlTypes,
997 this), 997 this),
998 base::Bind(&SyncBackendHost::Core::OnControlTypesDownloadRetry, 998 base::Bind(&SyncBackendHost::Core::OnControlTypesDownloadRetry,
999 this)); 999 this));
1000 } 1000 }
1001 1001
1002 void SyncBackendHost::Core::DoRefreshTypes(syncer::ModelTypeSet types) { 1002 void SyncBackendHost::Core::DoRefreshTypes(syncer::ModelTypeSet types) {
1003 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1003 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1004 sync_manager_->RefreshTypes(types); 1004 sync_manager_->RefreshTypes(types);
1005 } 1005 }
1006 1006
1007 void SyncBackendHost::Core::OnControlTypesDownloadRetry() { 1007 void SyncBackendHost::Core::OnControlTypesDownloadRetry() {
1008 host_.Call(FROM_HERE, 1008 host_.Call(FROM_HERE,
1009 &SyncBackendHost::HandleControlTypesDownloadRetry); 1009 &SyncBackendHost::HandleControlTypesDownloadRetry);
1010 } 1010 }
1011 1011
1012 void SyncBackendHost::Core::OnInitializationComplete( 1012 void SyncBackendHost::Core::OnInitializationComplete(
1013 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 1013 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
1014 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 1014 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
1015 debug_info_listener, 1015 debug_info_listener,
1016 bool success, 1016 bool success,
1017 const syncer::ModelTypeSet restored_types) { 1017 const syncer::ModelTypeSet restored_types) {
1018 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1018 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1019 1019
1020 if (!success) { 1020 if (!success) {
1021 DoDestroySyncManager(); 1021 DoDestroySyncManager();
1022 host_.Call(FROM_HERE, 1022 host_.Call(FROM_HERE,
1023 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, 1023 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop,
1024 false); 1024 false);
1025 return; 1025 return;
1026 } 1026 }
1027 1027
1028 // Register for encryption related changes now. We have to do this before 1028 // Register for encryption related changes now. We have to do this before
(...skipping 11 matching lines...) Expand all
1040 &SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop, 1040 &SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop,
1041 js_backend, 1041 js_backend,
1042 debug_info_listener, 1042 debug_info_listener,
1043 restored_types); 1043 restored_types);
1044 } 1044 }
1045 1045
1046 void SyncBackendHost::Core::OnConnectionStatusChange( 1046 void SyncBackendHost::Core::OnConnectionStatusChange(
1047 syncer::ConnectionStatus status) { 1047 syncer::ConnectionStatus status) {
1048 if (!sync_loop_) 1048 if (!sync_loop_)
1049 return; 1049 return;
1050 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1050 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1051 host_.Call( 1051 host_.Call(
1052 FROM_HERE, 1052 FROM_HERE,
1053 &SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop, status); 1053 &SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop, status);
1054 } 1054 }
1055 1055
1056 void SyncBackendHost::Core::OnPassphraseRequired( 1056 void SyncBackendHost::Core::OnPassphraseRequired(
1057 syncer::PassphraseRequiredReason reason, 1057 syncer::PassphraseRequiredReason reason,
1058 const sync_pb::EncryptedData& pending_keys) { 1058 const sync_pb::EncryptedData& pending_keys) {
1059 if (!sync_loop_) 1059 if (!sync_loop_)
1060 return; 1060 return;
1061 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1061 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1062 host_.Call( 1062 host_.Call(
1063 FROM_HERE, 1063 FROM_HERE,
1064 &SyncBackendHost::NotifyPassphraseRequired, reason, pending_keys); 1064 &SyncBackendHost::NotifyPassphraseRequired, reason, pending_keys);
1065 } 1065 }
1066 1066
1067 void SyncBackendHost::Core::OnPassphraseAccepted() { 1067 void SyncBackendHost::Core::OnPassphraseAccepted() {
1068 if (!sync_loop_) 1068 if (!sync_loop_)
1069 return; 1069 return;
1070 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1070 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1071 host_.Call( 1071 host_.Call(
1072 FROM_HERE, 1072 FROM_HERE,
1073 &SyncBackendHost::NotifyPassphraseAccepted); 1073 &SyncBackendHost::NotifyPassphraseAccepted);
1074 } 1074 }
1075 1075
1076 void SyncBackendHost::Core::OnBootstrapTokenUpdated( 1076 void SyncBackendHost::Core::OnBootstrapTokenUpdated(
1077 const std::string& bootstrap_token, 1077 const std::string& bootstrap_token,
1078 syncer::BootstrapTokenType type) { 1078 syncer::BootstrapTokenType type) {
1079 if (!sync_loop_) 1079 if (!sync_loop_)
1080 return; 1080 return;
1081 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1081 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1082 host_.Call(FROM_HERE, 1082 host_.Call(FROM_HERE,
1083 &SyncBackendHost::PersistEncryptionBootstrapToken, 1083 &SyncBackendHost::PersistEncryptionBootstrapToken,
1084 bootstrap_token, 1084 bootstrap_token,
1085 type); 1085 type);
1086 } 1086 }
1087 1087
1088 void SyncBackendHost::Core::OnStopSyncingPermanently() { 1088 void SyncBackendHost::Core::OnStopSyncingPermanently() {
1089 if (!sync_loop_) 1089 if (!sync_loop_)
1090 return; 1090 return;
1091 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1091 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1092 host_.Call( 1092 host_.Call(
1093 FROM_HERE, 1093 FROM_HERE,
1094 &SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop); 1094 &SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop);
1095 } 1095 }
1096 1096
1097 void SyncBackendHost::Core::OnUpdatedToken(const std::string& token) { 1097 void SyncBackendHost::Core::OnUpdatedToken(const std::string& token) {
1098 if (!sync_loop_) 1098 if (!sync_loop_)
1099 return; 1099 return;
1100 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1100 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1101 host_.Call( 1101 host_.Call(
1102 FROM_HERE, 1102 FROM_HERE,
1103 &SyncBackendHost::NotifyUpdatedToken, token); 1103 &SyncBackendHost::NotifyUpdatedToken, token);
1104 } 1104 }
1105 1105
1106 void SyncBackendHost::Core::OnEncryptedTypesChanged( 1106 void SyncBackendHost::Core::OnEncryptedTypesChanged(
1107 syncer::ModelTypeSet encrypted_types, 1107 syncer::ModelTypeSet encrypted_types,
1108 bool encrypt_everything) { 1108 bool encrypt_everything) {
1109 if (!sync_loop_) 1109 if (!sync_loop_)
1110 return; 1110 return;
1111 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1111 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1112 // NOTE: We're in a transaction. 1112 // NOTE: We're in a transaction.
1113 host_.Call( 1113 host_.Call(
1114 FROM_HERE, 1114 FROM_HERE,
1115 &SyncBackendHost::NotifyEncryptedTypesChanged, 1115 &SyncBackendHost::NotifyEncryptedTypesChanged,
1116 encrypted_types, encrypt_everything); 1116 encrypted_types, encrypt_everything);
1117 } 1117 }
1118 1118
1119 void SyncBackendHost::Core::OnEncryptionComplete() { 1119 void SyncBackendHost::Core::OnEncryptionComplete() {
1120 if (!sync_loop_) 1120 if (!sync_loop_)
1121 return; 1121 return;
1122 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1122 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1123 // NOTE: We're in a transaction. 1123 // NOTE: We're in a transaction.
1124 host_.Call( 1124 host_.Call(
1125 FROM_HERE, 1125 FROM_HERE,
1126 &SyncBackendHost::NotifyEncryptionComplete); 1126 &SyncBackendHost::NotifyEncryptionComplete);
1127 } 1127 }
1128 1128
1129 void SyncBackendHost::Core::OnCryptographerStateChanged( 1129 void SyncBackendHost::Core::OnCryptographerStateChanged(
1130 syncer::Cryptographer* cryptographer) { 1130 syncer::Cryptographer* cryptographer) {
1131 // Do nothing. 1131 // Do nothing.
1132 } 1132 }
1133 1133
1134 void SyncBackendHost::Core::OnPassphraseTypeChanged( 1134 void SyncBackendHost::Core::OnPassphraseTypeChanged(
1135 syncer::PassphraseType type, base::Time passphrase_time) { 1135 syncer::PassphraseType type, base::Time passphrase_time) {
1136 host_.Call( 1136 host_.Call(
1137 FROM_HERE, 1137 FROM_HERE,
1138 &SyncBackendHost::HandlePassphraseTypeChangedOnFrontendLoop, 1138 &SyncBackendHost::HandlePassphraseTypeChangedOnFrontendLoop,
1139 type, passphrase_time); 1139 type, passphrase_time);
1140 } 1140 }
1141 1141
1142 void SyncBackendHost::Core::OnActionableError( 1142 void SyncBackendHost::Core::OnActionableError(
1143 const syncer::SyncProtocolError& sync_error) { 1143 const syncer::SyncProtocolError& sync_error) {
1144 if (!sync_loop_) 1144 if (!sync_loop_)
1145 return; 1145 return;
1146 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1146 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1147 host_.Call( 1147 host_.Call(
1148 FROM_HERE, 1148 FROM_HERE,
1149 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, 1149 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop,
1150 sync_error); 1150 sync_error);
1151 } 1151 }
1152 1152
1153 void SyncBackendHost::Core::OnInvalidatorStateChange( 1153 void SyncBackendHost::Core::OnInvalidatorStateChange(
1154 syncer::InvalidatorState state) { 1154 syncer::InvalidatorState state) {
1155 if (!sync_loop_) 1155 if (!sync_loop_)
1156 return; 1156 return;
1157 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1157 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1158 host_.Call(FROM_HERE, 1158 host_.Call(FROM_HERE,
1159 &SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop, 1159 &SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop,
1160 state); 1160 state);
1161 } 1161 }
1162 1162
1163 void SyncBackendHost::Core::OnIncomingInvalidation( 1163 void SyncBackendHost::Core::OnIncomingInvalidation(
1164 const syncer::ObjectIdInvalidationMap& invalidation_map) { 1164 const syncer::ObjectIdInvalidationMap& invalidation_map) {
1165 if (!sync_loop_) 1165 if (!sync_loop_)
1166 return; 1166 return;
1167 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1167 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1168 host_.Call(FROM_HERE, 1168 host_.Call(FROM_HERE,
1169 &SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop, 1169 &SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop,
1170 invalidation_map); 1170 invalidation_map);
1171 } 1171 }
1172 1172
1173 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { 1173 void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) {
1174 DCHECK(!sync_loop_); 1174 DCHECK(!sync_loop_);
1175 sync_loop_ = options.sync_loop; 1175 sync_loop_ = options.sync_loop;
1176 DCHECK(sync_loop_); 1176 DCHECK(sync_loop_);
1177 1177
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 // would be encountered. 1237 // would be encountered.
1238 if (CommandLine::ForCurrentProcess()->HasSwitch( 1238 if (CommandLine::ForCurrentProcess()->HasSwitch(
1239 switches::kSyncThrowUnrecoverableError)) { 1239 switches::kSyncThrowUnrecoverableError)) {
1240 sync_manager_->ThrowUnrecoverableError(); 1240 sync_manager_->ThrowUnrecoverableError();
1241 } 1241 }
1242 } 1242 }
1243 } 1243 }
1244 1244
1245 void SyncBackendHost::Core::DoUpdateCredentials( 1245 void SyncBackendHost::Core::DoUpdateCredentials(
1246 const SyncCredentials& credentials) { 1246 const SyncCredentials& credentials) {
1247 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1247 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1248 // UpdateCredentials can be called during backend initialization, possibly 1248 // UpdateCredentials can be called during backend initialization, possibly
1249 // when backend initialization has failed but hasn't notified the UI thread 1249 // when backend initialization has failed but hasn't notified the UI thread
1250 // yet. In that case, the sync manager may have been destroyed on the sync 1250 // yet. In that case, the sync manager may have been destroyed on the sync
1251 // thread before this task was executed, so we do nothing. 1251 // thread before this task was executed, so we do nothing.
1252 if (sync_manager_) { 1252 if (sync_manager_) {
1253 sync_manager_->UpdateCredentials(credentials); 1253 sync_manager_->UpdateCredentials(credentials);
1254 } 1254 }
1255 } 1255 }
1256 1256
1257 void SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds( 1257 void SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds(
1258 const syncer::ObjectIdSet& ids) { 1258 const syncer::ObjectIdSet& ids) {
1259 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1259 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1260 // |sync_manager_| may end up being NULL here in tests (in 1260 // |sync_manager_| may end up being NULL here in tests (in
1261 // synchronous initialization mode) since this is called during 1261 // synchronous initialization mode) since this is called during
1262 // shutdown. 1262 // shutdown.
1263 // 1263 //
1264 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). 1264 // TODO(akalin): Fix this behavior (see http://crbug.com/140354).
1265 if (sync_manager_) { 1265 if (sync_manager_) {
1266 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); 1266 sync_manager_->UpdateRegisteredInvalidationIds(this, ids);
1267 } 1267 }
1268 } 1268 }
1269 1269
1270 void SyncBackendHost::Core::DoAcknowledgeInvalidation( 1270 void SyncBackendHost::Core::DoAcknowledgeInvalidation(
1271 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { 1271 const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) {
1272 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1272 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1273 // |sync_manager_| may end up being NULL here in tests (in 1273 // |sync_manager_| may end up being NULL here in tests (in
1274 // synchronous initialization mode). 1274 // synchronous initialization mode).
1275 // 1275 //
1276 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). 1276 // TODO(akalin): Fix this behavior (see http://crbug.com/140354).
1277 if (sync_manager_) { 1277 if (sync_manager_) {
1278 sync_manager_->AcknowledgeInvalidation(id, ack_handle); 1278 sync_manager_->AcknowledgeInvalidation(id, ack_handle);
1279 } 1279 }
1280 } 1280 }
1281 1281
1282 void SyncBackendHost::Core::DoStartSyncing( 1282 void SyncBackendHost::Core::DoStartSyncing(
1283 const syncer::ModelSafeRoutingInfo& routing_info) { 1283 const syncer::ModelSafeRoutingInfo& routing_info) {
1284 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1284 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1285 sync_manager_->StartSyncingNormally(routing_info); 1285 sync_manager_->StartSyncingNormally(routing_info);
1286 } 1286 }
1287 1287
1288 void SyncBackendHost::Core::DoSetEncryptionPassphrase( 1288 void SyncBackendHost::Core::DoSetEncryptionPassphrase(
1289 const std::string& passphrase, 1289 const std::string& passphrase,
1290 bool is_explicit) { 1290 bool is_explicit) {
1291 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1291 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1292 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase( 1292 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase(
1293 passphrase, is_explicit); 1293 passphrase, is_explicit);
1294 } 1294 }
1295 1295
1296 void SyncBackendHost::Core::DoInitialProcessControlTypes() { 1296 void SyncBackendHost::Core::DoInitialProcessControlTypes() {
1297 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1297 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1298 1298
1299 DVLOG(1) << "Initilalizing Control Types"; 1299 DVLOG(1) << "Initilalizing Control Types";
1300 1300
1301 // Initialize encryption. 1301 // Initialize encryption.
1302 sync_manager_->GetEncryptionHandler()->Init(); 1302 sync_manager_->GetEncryptionHandler()->Init();
1303 1303
1304 // Note: experiments are currently handled via SBH::AddExperimentalTypes, 1304 // Note: experiments are currently handled via SBH::AddExperimentalTypes,
1305 // which is called at the end of every sync cycle. 1305 // which is called at the end of every sync cycle.
1306 // TODO(zea): eventually add an experiment handler and initialize it here. 1306 // TODO(zea): eventually add an experiment handler and initialize it here.
1307 1307
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 sync_manager_->GetUserShare()); 1340 sync_manager_->GetUserShare());
1341 1341
1342 host_.Call( 1342 host_.Call(
1343 FROM_HERE, 1343 FROM_HERE,
1344 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, 1344 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop,
1345 true); 1345 true);
1346 } 1346 }
1347 1347
1348 void SyncBackendHost::Core::DoSetDecryptionPassphrase( 1348 void SyncBackendHost::Core::DoSetDecryptionPassphrase(
1349 const std::string& passphrase) { 1349 const std::string& passphrase) {
1350 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1350 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1351 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( 1351 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase(
1352 passphrase); 1352 passphrase);
1353 } 1353 }
1354 1354
1355 void SyncBackendHost::Core::DoEnableEncryptEverything() { 1355 void SyncBackendHost::Core::DoEnableEncryptEverything() {
1356 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1356 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1357 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); 1357 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything();
1358 } 1358 }
1359 1359
1360 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( 1360 void SyncBackendHost::Core::DoStopSyncManagerForShutdown(
1361 const base::Closure& closure) { 1361 const base::Closure& closure) {
1362 if (sync_manager_) { 1362 if (sync_manager_) {
1363 sync_manager_->StopSyncingForShutdown(closure); 1363 sync_manager_->StopSyncingForShutdown(closure);
1364 } else { 1364 } else {
1365 sync_loop_->PostTask(FROM_HERE, closure); 1365 sync_loop_->PostTask(FROM_HERE, closure);
1366 } 1366 }
1367 } 1367 }
1368 1368
1369 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { 1369 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) {
1370 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1370 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1371 // It's safe to do this even if the type was never activated. 1371 // It's safe to do this even if the type was never activated.
1372 registrar_->DeactivateDataType(syncer::DEVICE_INFO); 1372 registrar_->DeactivateDataType(syncer::DEVICE_INFO);
1373 synced_device_tracker_.reset(); 1373 synced_device_tracker_.reset();
1374 1374
1375 DoDestroySyncManager(); 1375 DoDestroySyncManager();
1376 1376
1377 registrar_ = NULL; 1377 registrar_ = NULL;
1378 1378
1379 if (sync_disabled) 1379 if (sync_disabled)
1380 DeleteSyncDataFolder(); 1380 DeleteSyncDataFolder();
1381 1381
1382 sync_loop_ = NULL; 1382 sync_loop_ = NULL;
1383 1383
1384 host_.Reset(); 1384 host_.Reset();
1385 } 1385 }
1386 1386
1387 void SyncBackendHost::Core::DoDestroySyncManager() { 1387 void SyncBackendHost::Core::DoDestroySyncManager() {
1388 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1388 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1389 if (sync_manager_) { 1389 if (sync_manager_) {
1390 save_changes_timer_.reset(); 1390 save_changes_timer_.reset();
1391 if (registered_as_invalidation_handler_) { 1391 if (registered_as_invalidation_handler_) {
1392 sync_manager_->UnregisterInvalidationHandler(this); 1392 sync_manager_->UnregisterInvalidationHandler(this);
1393 registered_as_invalidation_handler_ = false; 1393 registered_as_invalidation_handler_ = false;
1394 } 1394 }
1395 sync_manager_->RemoveObserver(this); 1395 sync_manager_->RemoveObserver(this);
1396 sync_manager_->ShutdownOnSyncThread(); 1396 sync_manager_->ShutdownOnSyncThread();
1397 sync_manager_.reset(); 1397 sync_manager_.reset();
1398 } 1398 }
1399 } 1399 }
1400 1400
1401 void SyncBackendHost::Core::DoConfigureSyncer( 1401 void SyncBackendHost::Core::DoConfigureSyncer(
1402 syncer::ConfigureReason reason, 1402 syncer::ConfigureReason reason,
1403 syncer::ModelTypeSet types_to_config, 1403 syncer::ModelTypeSet types_to_config,
1404 syncer::ModelTypeSet failed_types, 1404 syncer::ModelTypeSet failed_types,
1405 const syncer::ModelSafeRoutingInfo routing_info, 1405 const syncer::ModelSafeRoutingInfo routing_info,
1406 const base::Callback<void(syncer::ModelTypeSet, 1406 const base::Callback<void(syncer::ModelTypeSet,
1407 syncer::ModelTypeSet)>& ready_task, 1407 syncer::ModelTypeSet)>& ready_task,
1408 const base::Closure& retry_callback) { 1408 const base::Closure& retry_callback) {
1409 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1409 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1410 sync_manager_->ConfigureSyncer( 1410 sync_manager_->ConfigureSyncer(
1411 reason, 1411 reason,
1412 types_to_config, 1412 types_to_config,
1413 failed_types, 1413 failed_types,
1414 routing_info, 1414 routing_info,
1415 base::Bind(&SyncBackendHost::Core::DoFinishConfigureDataTypes, 1415 base::Bind(&SyncBackendHost::Core::DoFinishConfigureDataTypes,
1416 this, 1416 this,
1417 types_to_config, 1417 types_to_config,
1418 ready_task), 1418 ready_task),
1419 base::Bind(&SyncBackendHost::Core::DoRetryConfiguration, 1419 base::Bind(&SyncBackendHost::Core::DoRetryConfiguration,
1420 this, 1420 this,
1421 retry_callback)); 1421 retry_callback));
1422 } 1422 }
1423 1423
1424 void SyncBackendHost::Core::DoFinishConfigureDataTypes( 1424 void SyncBackendHost::Core::DoFinishConfigureDataTypes(
1425 syncer::ModelTypeSet types_to_config, 1425 syncer::ModelTypeSet types_to_config,
1426 const base::Callback<void(syncer::ModelTypeSet, 1426 const base::Callback<void(syncer::ModelTypeSet,
1427 syncer::ModelTypeSet)>& ready_task) { 1427 syncer::ModelTypeSet)>& ready_task) {
1428 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1428 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1429 1429
1430 // Update the enabled types for the bridge and sync manager. 1430 // Update the enabled types for the bridge and sync manager.
1431 syncer::ModelSafeRoutingInfo routing_info; 1431 syncer::ModelSafeRoutingInfo routing_info;
1432 registrar_->GetModelSafeRoutingInfo(&routing_info); 1432 registrar_->GetModelSafeRoutingInfo(&routing_info);
1433 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); 1433 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
1434 enabled_types.RemoveAll(syncer::ProxyTypes()); 1434 enabled_types.RemoveAll(syncer::ProxyTypes());
1435 sync_manager_->UpdateEnabledTypes(enabled_types); 1435 sync_manager_->UpdateEnabledTypes(enabled_types);
1436 1436
1437 const syncer::ModelTypeSet failed_configuration_types = 1437 const syncer::ModelTypeSet failed_configuration_types =
1438 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); 1438 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes());
1439 const syncer::ModelTypeSet succeeded_configuration_types = 1439 const syncer::ModelTypeSet succeeded_configuration_types =
1440 Difference(types_to_config, failed_configuration_types); 1440 Difference(types_to_config, failed_configuration_types);
1441 host_.Call(FROM_HERE, 1441 host_.Call(FROM_HERE,
1442 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop, 1442 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop,
1443 succeeded_configuration_types, failed_configuration_types, 1443 succeeded_configuration_types, failed_configuration_types,
1444 ready_task); 1444 ready_task);
1445 } 1445 }
1446 1446
1447 void SyncBackendHost::Core::DoRetryConfiguration( 1447 void SyncBackendHost::Core::DoRetryConfiguration(
1448 const base::Closure& retry_callback) { 1448 const base::Closure& retry_callback) {
1449 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1449 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1450 host_.Call(FROM_HERE, 1450 host_.Call(FROM_HERE,
1451 &SyncBackendHost::RetryConfigurationOnFrontendLoop, 1451 &SyncBackendHost::RetryConfigurationOnFrontendLoop,
1452 retry_callback); 1452 retry_callback);
1453 } 1453 }
1454 1454
1455 void SyncBackendHost::Core::DeleteSyncDataFolder() { 1455 void SyncBackendHost::Core::DeleteSyncDataFolder() {
1456 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1456 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1457 if (file_util::DirectoryExists(sync_data_folder_path_)) { 1457 if (file_util::DirectoryExists(sync_data_folder_path_)) {
1458 if (!file_util::Delete(sync_data_folder_path_, true)) 1458 if (!file_util::Delete(sync_data_folder_path_, true))
1459 SLOG(DFATAL) << "Could not delete the Sync Data folder."; 1459 SLOG(DFATAL) << "Could not delete the Sync Data folder.";
1460 } 1460 }
1461 } 1461 }
1462 1462
1463 void SyncBackendHost::Core::StartSavingChanges() { 1463 void SyncBackendHost::Core::StartSavingChanges() {
1464 // We may already be shut down. 1464 // We may already be shut down.
1465 if (!sync_loop_) 1465 if (!sync_loop_)
1466 return; 1466 return;
1467 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1467 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1468 DCHECK(!save_changes_timer_.get()); 1468 DCHECK(!save_changes_timer_.get());
1469 save_changes_timer_.reset(new base::RepeatingTimer<Core>()); 1469 save_changes_timer_.reset(new base::RepeatingTimer<Core>());
1470 save_changes_timer_->Start(FROM_HERE, 1470 save_changes_timer_->Start(FROM_HERE,
1471 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), 1471 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds),
1472 this, &Core::SaveChanges); 1472 this, &Core::SaveChanges);
1473 } 1473 }
1474 1474
1475 void SyncBackendHost::Core::SaveChanges() { 1475 void SyncBackendHost::Core::SaveChanges() {
1476 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1476 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1477 sync_manager_->SaveChanges(); 1477 sync_manager_->SaveChanges();
1478 } 1478 }
1479 1479
1480 void SyncBackendHost::AddExperimentalTypes() { 1480 void SyncBackendHost::AddExperimentalTypes() {
1481 CHECK(initialized()); 1481 CHECK(initialized());
1482 syncer::Experiments experiments; 1482 syncer::Experiments experiments;
1483 if (core_->sync_manager()->ReceivedExperiment(&experiments)) 1483 if (core_->sync_manager()->ReceivedExperiment(&experiments))
1484 frontend_->OnExperimentsChanged(experiments); 1484 frontend_->OnExperimentsChanged(experiments);
1485 } 1485 }
1486 1486
1487 void SyncBackendHost::HandleControlTypesDownloadRetry() { 1487 void SyncBackendHost::HandleControlTypesDownloadRetry() {
1488 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1488 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1489 if (!frontend_) 1489 if (!frontend_)
1490 return; 1490 return;
1491 1491
1492 frontend_->OnSyncConfigureRetry(); 1492 frontend_->OnSyncConfigureRetry();
1493 } 1493 }
1494 1494
1495 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop( 1495 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop(
1496 bool success) { 1496 bool success) {
1497 DCHECK_NE(initialization_state_, NOT_ATTEMPTED); 1497 DCHECK_NE(initialization_state_, NOT_ATTEMPTED);
1498 if (!frontend_) 1498 if (!frontend_)
1499 return; 1499 return;
1500 1500
1501 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1501 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1502 if (!success) { 1502 if (!success) {
1503 js_backend_.Reset(); 1503 js_backend_.Reset();
1504 initialization_state_ = NOT_INITIALIZED; 1504 initialization_state_ = NOT_INITIALIZED;
1505 frontend_->OnBackendInitialized( 1505 frontend_->OnBackendInitialized(
1506 syncer::WeakHandle<syncer::JsBackend>(), 1506 syncer::WeakHandle<syncer::JsBackend>(),
1507 syncer::WeakHandle<syncer::DataTypeDebugInfoListener>(), 1507 syncer::WeakHandle<syncer::DataTypeDebugInfoListener>(),
1508 false); 1508 false);
1509 return; 1509 return;
1510 } 1510 }
1511 1511
1512 initialization_state_ = INITIALIZED; 1512 initialization_state_ = INITIALIZED;
1513 1513
1514 // Now that we've downloaded the control types, we can see if there are any 1514 // Now that we've downloaded the control types, we can see if there are any
1515 // experimental types to enable. This should be done before we inform 1515 // experimental types to enable. This should be done before we inform
1516 // the frontend to ensure they're visible in the customize screen. 1516 // the frontend to ensure they're visible in the customize screen.
1517 AddExperimentalTypes(); 1517 AddExperimentalTypes();
1518 frontend_->OnBackendInitialized(js_backend_, 1518 frontend_->OnBackendInitialized(js_backend_,
1519 debug_info_listener_, 1519 debug_info_listener_,
1520 true); 1520 true);
1521 js_backend_.Reset(); 1521 js_backend_.Reset();
1522 } 1522 }
1523 1523
1524 void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop( 1524 void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop(
1525 const SyncSessionSnapshot& snapshot) { 1525 const SyncSessionSnapshot& snapshot) {
1526 if (!frontend_) 1526 if (!frontend_)
1527 return; 1527 return;
1528 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1528 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1529 1529
1530 last_snapshot_ = snapshot; 1530 last_snapshot_ = snapshot;
1531 1531
1532 SDVLOG(1) << "Got snapshot " << snapshot.ToString(); 1532 SDVLOG(1) << "Got snapshot " << snapshot.ToString();
1533 1533
1534 const syncer::ModelTypeSet to_migrate = 1534 const syncer::ModelTypeSet to_migrate =
1535 snapshot.model_neutral_state().types_needing_local_migration; 1535 snapshot.model_neutral_state().types_needing_local_migration;
1536 if (!to_migrate.Empty()) 1536 if (!to_migrate.Empty())
1537 frontend_->OnMigrationNeededForTypes(to_migrate); 1537 frontend_->OnMigrationNeededForTypes(to_migrate);
1538 1538
(...skipping 20 matching lines...) Expand all
1559 if (token_type == syncer::PASSPHRASE_BOOTSTRAP_TOKEN) 1559 if (token_type == syncer::PASSPHRASE_BOOTSTRAP_TOKEN)
1560 sync_prefs_->SetEncryptionBootstrapToken(token); 1560 sync_prefs_->SetEncryptionBootstrapToken(token);
1561 else 1561 else
1562 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token); 1562 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token);
1563 } 1563 }
1564 1564
1565 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( 1565 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop(
1566 const syncer::SyncProtocolError& sync_error) { 1566 const syncer::SyncProtocolError& sync_error) {
1567 if (!frontend_) 1567 if (!frontend_)
1568 return; 1568 return;
1569 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1569 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1570 frontend_->OnActionableError(sync_error); 1570 frontend_->OnActionableError(sync_error);
1571 } 1571 }
1572 1572
1573 void SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop( 1573 void SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop(
1574 syncer::InvalidatorState state) { 1574 syncer::InvalidatorState state) {
1575 if (!frontend_) 1575 if (!frontend_)
1576 return; 1576 return;
1577 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1577 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1578 frontend_->OnInvalidatorStateChange(state); 1578 frontend_->OnInvalidatorStateChange(state);
1579 } 1579 }
1580 1580
1581 void SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop( 1581 void SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop(
1582 const syncer::ObjectIdInvalidationMap& invalidation_map) { 1582 const syncer::ObjectIdInvalidationMap& invalidation_map) {
1583 if (!frontend_) 1583 if (!frontend_)
1584 return; 1584 return;
1585 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1585 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1586 frontend_->OnIncomingInvalidation(invalidation_map); 1586 frontend_->OnIncomingInvalidation(invalidation_map);
1587 } 1587 }
1588 1588
1589 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( 1589 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys(
1590 const std::string& passphrase) const { 1590 const std::string& passphrase) const {
1591 DCHECK(cached_pending_keys_.has_blob()); 1591 DCHECK(cached_pending_keys_.has_blob());
1592 DCHECK(!passphrase.empty()); 1592 DCHECK(!passphrase.empty());
1593 syncer::Nigori nigori; 1593 syncer::Nigori nigori;
1594 nigori.InitByDerivation("localhost", "dummy", passphrase); 1594 nigori.InitByDerivation("localhost", "dummy", passphrase);
1595 std::string plaintext; 1595 std::string plaintext;
1596 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); 1596 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext);
1597 DVLOG_IF(1, result) << "Passphrase failed to decrypt pending keys."; 1597 DVLOG_IF(1, result) << "Passphrase failed to decrypt pending keys.";
1598 return result; 1598 return result;
1599 } 1599 }
1600 1600
1601 void SyncBackendHost::NotifyPassphraseRequired( 1601 void SyncBackendHost::NotifyPassphraseRequired(
1602 syncer::PassphraseRequiredReason reason, 1602 syncer::PassphraseRequiredReason reason,
1603 sync_pb::EncryptedData pending_keys) { 1603 sync_pb::EncryptedData pending_keys) {
1604 if (!frontend_) 1604 if (!frontend_)
1605 return; 1605 return;
1606 1606
1607 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1607 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1608 1608
1609 // Update our cache of the cryptographer's pending keys. 1609 // Update our cache of the cryptographer's pending keys.
1610 cached_pending_keys_ = pending_keys; 1610 cached_pending_keys_ = pending_keys;
1611 1611
1612 frontend_->OnPassphraseRequired(reason, pending_keys); 1612 frontend_->OnPassphraseRequired(reason, pending_keys);
1613 } 1613 }
1614 1614
1615 void SyncBackendHost::NotifyPassphraseAccepted() { 1615 void SyncBackendHost::NotifyPassphraseAccepted() {
1616 if (!frontend_) 1616 if (!frontend_)
1617 return; 1617 return;
1618 1618
1619 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1619 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1620 1620
1621 // Clear our cache of the cryptographer's pending keys. 1621 // Clear our cache of the cryptographer's pending keys.
1622 cached_pending_keys_.clear_blob(); 1622 cached_pending_keys_.clear_blob();
1623 frontend_->OnPassphraseAccepted(); 1623 frontend_->OnPassphraseAccepted();
1624 } 1624 }
1625 1625
1626 void SyncBackendHost::NotifyUpdatedToken(const std::string& token) { 1626 void SyncBackendHost::NotifyUpdatedToken(const std::string& token) {
1627 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1627 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1628 TokenAvailableDetails details(GaiaConstants::kSyncService, token); 1628 TokenAvailableDetails details(GaiaConstants::kSyncService, token);
1629 1629
1630 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 1630 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
1631 CHECK(token_service); 1631 CHECK(token_service);
1632 token_service->AddAuthTokenManually(details.service(), details.token()); 1632 token_service->AddAuthTokenManually(details.service(), details.token());
1633 } 1633 }
1634 1634
1635 void SyncBackendHost::NotifyEncryptedTypesChanged( 1635 void SyncBackendHost::NotifyEncryptedTypesChanged(
1636 syncer::ModelTypeSet encrypted_types, 1636 syncer::ModelTypeSet encrypted_types,
1637 bool encrypt_everything) { 1637 bool encrypt_everything) {
1638 if (!frontend_) 1638 if (!frontend_)
1639 return; 1639 return;
1640 1640
1641 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1641 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1642 frontend_->OnEncryptedTypesChanged( 1642 frontend_->OnEncryptedTypesChanged(
1643 encrypted_types, encrypt_everything); 1643 encrypted_types, encrypt_everything);
1644 } 1644 }
1645 1645
1646 void SyncBackendHost::NotifyEncryptionComplete() { 1646 void SyncBackendHost::NotifyEncryptionComplete() {
1647 if (!frontend_) 1647 if (!frontend_)
1648 return; 1648 return;
1649 1649
1650 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1650 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1651 frontend_->OnEncryptionComplete(); 1651 frontend_->OnEncryptionComplete();
1652 } 1652 }
1653 1653
1654 void SyncBackendHost::HandlePassphraseTypeChangedOnFrontendLoop( 1654 void SyncBackendHost::HandlePassphraseTypeChangedOnFrontendLoop(
1655 syncer::PassphraseType type, 1655 syncer::PassphraseType type,
1656 base::Time explicit_passphrase_time) { 1656 base::Time explicit_passphrase_time) {
1657 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1657 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1658 DVLOG(1) << "Passphrase type changed to " 1658 DVLOG(1) << "Passphrase type changed to "
1659 << syncer::PassphraseTypeToString(type); 1659 << syncer::PassphraseTypeToString(type);
1660 cached_passphrase_type_ = type; 1660 cached_passphrase_type_ = type;
1661 cached_explicit_passphrase_time_ = explicit_passphrase_time; 1661 cached_explicit_passphrase_time_ = explicit_passphrase_time;
1662 } 1662 }
1663 1663
1664 void SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop() { 1664 void SyncBackendHost::HandleStopSyncingPermanentlyOnFrontendLoop() {
1665 if (!frontend_) 1665 if (!frontend_)
1666 return; 1666 return;
1667 frontend_->OnStopSyncingPermanently(); 1667 frontend_->OnStopSyncingPermanently();
1668 } 1668 }
1669 1669
1670 void SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop( 1670 void SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop(
1671 syncer::ConnectionStatus status) { 1671 syncer::ConnectionStatus status) {
1672 if (!frontend_) 1672 if (!frontend_)
1673 return; 1673 return;
1674 1674
1675 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1675 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
1676 1676
1677 DVLOG(1) << "Connection status changed: " 1677 DVLOG(1) << "Connection status changed: "
1678 << syncer::ConnectionStatusToString(status); 1678 << syncer::ConnectionStatusToString(status);
1679 frontend_->OnConnectionStatusChange(status); 1679 frontend_->OnConnectionStatusChange(status);
1680 } 1680 }
1681 1681
1682 #undef SDVLOG 1682 #undef SDVLOG
1683 1683
1684 #undef SLOG 1684 #undef SLOG
1685 1685
1686 } // namespace browser_sync 1686 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/shared_change_processor_unittest.cc ('k') | chrome/browser/sync/glue/sync_backend_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698