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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 15580002: Make use of InvalidationService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix PushMessagingApiTests 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
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 "chrome/browser/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #include "chrome/common/pref_names.h" 58 #include "chrome/common/pref_names.h"
59 #include "chrome/common/time_format.h" 59 #include "chrome/common/time_format.h"
60 #include "chrome/common/url_constants.h" 60 #include "chrome/common/url_constants.h"
61 #include "components/user_prefs/pref_registry_syncable.h" 61 #include "components/user_prefs/pref_registry_syncable.h"
62 #include "content/public/browser/notification_details.h" 62 #include "content/public/browser/notification_details.h"
63 #include "content/public/browser/notification_service.h" 63 #include "content/public/browser/notification_service.h"
64 #include "content/public/browser/notification_source.h" 64 #include "content/public/browser/notification_source.h"
65 #include "google_apis/gaia/gaia_constants.h" 65 #include "google_apis/gaia/gaia_constants.h"
66 #include "grit/generated_resources.h" 66 #include "grit/generated_resources.h"
67 #include "net/cookies/cookie_monster.h" 67 #include "net/cookies/cookie_monster.h"
68 #include "net/url_request/url_request_context_getter.h"
68 #include "sync/api/sync_error.h" 69 #include "sync/api/sync_error.h"
69 #include "sync/internal_api/public/configure_reason.h" 70 #include "sync/internal_api/public/configure_reason.h"
70 #include "sync/internal_api/public/sync_encryption_handler.h" 71 #include "sync/internal_api/public/sync_encryption_handler.h"
71 #include "sync/internal_api/public/util/experiments.h" 72 #include "sync/internal_api/public/util/experiments.h"
72 #include "sync/internal_api/public/util/sync_string_conversions.h" 73 #include "sync/internal_api/public/util/sync_string_conversions.h"
73 #include "sync/js/js_arg_list.h" 74 #include "sync/js/js_arg_list.h"
74 #include "sync/js/js_event_details.h" 75 #include "sync/js/js_event_details.h"
75 #include "sync/notifier/invalidator_registrar.h"
76 #include "sync/notifier/invalidator_state.h"
77 #include "sync/util/cryptographer.h" 76 #include "sync/util/cryptographer.h"
78 #include "ui/base/l10n/l10n_util.h" 77 #include "ui/base/l10n/l10n_util.h"
79 78
80 #if defined(ENABLE_MANAGED_USERS) 79 #if defined(ENABLE_MANAGED_USERS)
81 #include "chrome/browser/managed_mode/managed_user_service.h" 80 #include "chrome/browser/managed_mode/managed_user_service.h"
82 #endif 81 #endif
83 82
84 #if defined(OS_ANDROID) 83 #if defined(OS_ANDROID)
85 #include "sync/internal_api/public/read_transaction.h" 84 #include "sync/internal_api/public/read_transaction.h"
86 #endif 85 #endif
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, 138 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory,
140 Profile* profile, 139 Profile* profile,
141 SigninManagerBase* signin_manager, 140 SigninManagerBase* signin_manager,
142 StartBehavior start_behavior) 141 StartBehavior start_behavior)
143 : last_auth_error_(AuthError::AuthErrorNone()), 142 : last_auth_error_(AuthError::AuthErrorNone()),
144 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), 143 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED),
145 factory_(factory), 144 factory_(factory),
146 profile_(profile), 145 profile_(profile),
147 // |profile| may be NULL in unit tests. 146 // |profile| may be NULL in unit tests.
148 sync_prefs_(profile_ ? profile_->GetPrefs() : NULL), 147 sync_prefs_(profile_ ? profile_->GetPrefs() : NULL),
149 invalidator_storage_(profile_ ? profile_->GetPrefs(): NULL),
150 sync_service_url_(kDevServerUrl), 148 sync_service_url_(kDevServerUrl),
151 data_type_requested_sync_startup_(false), 149 data_type_requested_sync_startup_(false),
152 is_first_time_sync_configure_(false), 150 is_first_time_sync_configure_(false),
153 backend_initialized_(false), 151 backend_initialized_(false),
154 sync_disabled_by_admin_(false), 152 sync_disabled_by_admin_(false),
155 is_auth_in_progress_(false), 153 is_auth_in_progress_(false),
156 signin_(signin_manager), 154 signin_(signin_manager),
157 unrecoverable_error_reason_(ERROR_REASON_UNSET), 155 unrecoverable_error_reason_(ERROR_REASON_UNSET),
158 weak_factory_(this), 156 weak_factory_(this),
159 expect_sync_configuration_aborted_(false), 157 expect_sync_configuration_aborted_(false),
160 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), 158 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()),
161 encrypt_everything_(false), 159 encrypt_everything_(false),
162 encryption_pending_(false), 160 encryption_pending_(false),
163 auto_start_enabled_(start_behavior == AUTO_START), 161 auto_start_enabled_(start_behavior == AUTO_START),
164 configure_status_(DataTypeManager::UNKNOWN), 162 configure_status_(DataTypeManager::UNKNOWN),
165 setup_in_progress_(false), 163 setup_in_progress_(false) {
166 invalidator_state_(syncer::DEFAULT_INVALIDATION_ERROR) {
167 // By default, dev, canary, and unbranded Chromium users will go to the 164 // By default, dev, canary, and unbranded Chromium users will go to the
168 // development servers. Development servers have more features than standard 165 // development servers. Development servers have more features than standard
169 // sync servers. Users with officially-branded Chrome stable and beta builds 166 // sync servers. Users with officially-branded Chrome stable and beta builds
170 // will go to the standard sync servers. 167 // will go to the standard sync servers.
171 // 168 //
172 // GetChannel hits the registry on Windows. See http://crbug.com/70380. 169 // GetChannel hits the registry on Windows. See http://crbug.com/70380.
173 base::ThreadRestrictions::ScopedAllowIO allow_io; 170 base::ThreadRestrictions::ScopedAllowIO allow_io;
174 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); 171 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
175 if (channel == chrome::VersionInfo::CHANNEL_STABLE || 172 if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
176 channel == chrome::VersionInfo::CHANNEL_BETA) { 173 channel == chrome::VersionInfo::CHANNEL_BETA) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 if (!sync_initialized()) 207 if (!sync_initialized())
211 return false; 208 return false;
212 // On Android we do not want to prompt user to enter a passphrase. If 209 // On Android we do not want to prompt user to enter a passphrase. If
213 // passwords cannot be decrypted we just disable them. 210 // passwords cannot be decrypted we just disable them.
214 syncer::ReadTransaction trans(FROM_HERE, GetUserShare()); 211 syncer::ReadTransaction trans(FROM_HERE, GetUserShare());
215 return IsCryptographerReady(&trans); 212 return IsCryptographerReady(&trans);
216 } 213 }
217 #endif 214 #endif
218 215
219 void ProfileSyncService::Initialize() { 216 void ProfileSyncService::Initialize() {
220 DCHECK(!invalidator_registrar_.get());
221 invalidator_registrar_.reset(new syncer::InvalidatorRegistrar());
222
223 InitSettings(); 217 InitSettings();
224 218
225 // We clear this here (vs Shutdown) because we want to remember that an error 219 // We clear this here (vs Shutdown) because we want to remember that an error
226 // happened on shutdown so we can display details (message, location) about it 220 // happened on shutdown so we can display details (message, location) about it
227 // in about:sync. 221 // in about:sync.
228 ClearStaleErrors(); 222 ClearStaleErrors();
229 223
230 sync_prefs_.AddSyncPrefObserver(this); 224 sync_prefs_.AddSyncPrefObserver(this);
231 225
232 // For now, the only thing we can do through policy is to turn sync off. 226 // For now, the only thing we can do through policy is to turn sync off.
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 credentials, 461 credentials,
468 delete_stale_data, 462 delete_stale_data,
469 &sync_manager_factory_, 463 &sync_manager_factory_,
470 backend_unrecoverable_error_handler_.get(), 464 backend_unrecoverable_error_handler_.get(),
471 &browser_sync::ChromeReportUnrecoverableError); 465 &browser_sync::ChromeReportUnrecoverableError);
472 } 466 }
473 467
474 void ProfileSyncService::CreateBackend() { 468 void ProfileSyncService::CreateBackend() {
475 backend_.reset( 469 backend_.reset(
476 new SyncBackendHost(profile_->GetDebugName(), 470 new SyncBackendHost(profile_->GetDebugName(),
477 profile_, sync_prefs_.AsWeakPtr(), 471 profile_, sync_prefs_.AsWeakPtr()));
478 invalidator_storage_.AsWeakPtr()));
479 } 472 }
480 473
481 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { 474 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const {
482 if (encryption_pending()) 475 if (encryption_pending())
483 return true; 476 return true;
484 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); 477 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes();
485 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); 478 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes();
486 DCHECK(encrypted_types.Has(syncer::PASSWORDS)); 479 DCHECK(encrypted_types.Has(syncer::PASSWORDS));
487 return !Intersection(preferred_types, encrypted_types).Empty(); 480 return !Intersection(preferred_types, encrypted_types).Empty();
488 } 481 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 return; 591 return;
599 } 592 }
600 593
601 DCHECK(IsSyncEnabledAndLoggedIn()); 594 DCHECK(IsSyncEnabledAndLoggedIn());
602 CreateBackend(); 595 CreateBackend();
603 596
604 // Initialize the backend. Every time we start up a new SyncBackendHost, 597 // Initialize the backend. Every time we start up a new SyncBackendHost,
605 // we'll want to start from a fresh SyncDB, so delete any old one that might 598 // we'll want to start from a fresh SyncDB, so delete any old one that might
606 // be there. 599 // be there.
607 InitializeBackend(!HasSyncSetupCompleted()); 600 InitializeBackend(!HasSyncSetupCompleted());
608
609 // |backend_| may end up being NULL here in tests (in synchronous
610 // initialization mode).
611 //
612 // TODO(akalin): Fix this horribly non-intuitive behavior (see
613 // http://crbug.com/140354).
614 if (backend_) {
615 backend_->UpdateRegisteredInvalidationIds(
616 invalidator_registrar_->GetAllRegisteredIds());
617 for (AckHandleReplayQueue::const_iterator it = ack_replay_queue_.begin();
618 it != ack_replay_queue_.end(); ++it) {
619 backend_->AcknowledgeInvalidation(it->first, it->second);
620 }
621 ack_replay_queue_.clear();
622 }
623 }
624
625 void ProfileSyncService::RegisterInvalidationHandler(
626 syncer::InvalidationHandler* handler) {
627 invalidator_registrar_->RegisterHandler(handler);
628 }
629
630 void ProfileSyncService::UpdateRegisteredInvalidationIds(
631 syncer::InvalidationHandler* handler,
632 const syncer::ObjectIdSet& ids) {
633 invalidator_registrar_->UpdateRegisteredIds(handler, ids);
634
635 // If |backend_| is NULL, its registered IDs will be updated when
636 // it's created and initialized.
637 if (backend_) {
638 backend_->UpdateRegisteredInvalidationIds(
639 invalidator_registrar_->GetAllRegisteredIds());
640 }
641 }
642
643 void ProfileSyncService::UnregisterInvalidationHandler(
644 syncer::InvalidationHandler* handler) {
645 invalidator_registrar_->UnregisterHandler(handler);
646 }
647
648 void ProfileSyncService::AcknowledgeInvalidation(
649 const invalidation::ObjectId& id,
650 const syncer::AckHandle& ack_handle) {
651 if (backend_) {
652 backend_->AcknowledgeInvalidation(id, ack_handle);
653 } else {
654 // If |backend_| is NULL, save the acknowledgements to replay when
655 // it's created and initialized.
656 ack_replay_queue_.push_back(std::make_pair(id, ack_handle));
657 }
658 }
659
660 syncer::InvalidatorState ProfileSyncService::GetInvalidatorState() const {
661 return invalidator_registrar_->GetInvalidatorState();
662 }
663
664 void ProfileSyncService::EmitInvalidationForTest(
665 const invalidation::ObjectId& id,
666 const std::string& payload) {
667 syncer::ObjectIdSet notify_ids;
668 notify_ids.insert(id);
669
670 const syncer::ObjectIdInvalidationMap& invalidation_map =
671 ObjectIdSetToInvalidationMap(notify_ids, payload);
672 OnIncomingInvalidation(invalidation_map);
673 } 601 }
674 602
675 void ProfileSyncService::Shutdown() { 603 void ProfileSyncService::Shutdown() {
676 DCHECK(invalidator_registrar_.get());
677 // Reset |invalidator_registrar_| first so that ShutdownImpl cannot
678 // use it.
679 invalidator_registrar_.reset();
680
681 if (signin_) 604 if (signin_)
682 signin_->signin_global_error()->RemoveProvider(this); 605 signin_->signin_global_error()->RemoveProvider(this);
683 606
684 ShutdownImpl(false); 607 ShutdownImpl(false);
685 } 608 }
686 609
687 void ProfileSyncService::ShutdownImpl(bool sync_disabled) { 610 void ProfileSyncService::ShutdownImpl(bool sync_disabled) {
688 // First, we spin down the backend and wait for it to stop syncing completely 611 // First, we spin down the backend and wait for it to stop syncing completely
689 // before we Stop the data type manager. This is to avoid a late sync cycle 612 // before we Stop the data type manager. This is to avoid a late sync cycle
690 // applying changes to the sync db that wouldn't get applied via 613 // applying changes to the sync db that wouldn't get applied via
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; 648 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time;
726 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); 649 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time);
727 650
728 weak_factory_.InvalidateWeakPtrs(); 651 weak_factory_.InvalidateWeakPtrs();
729 652
730 // Clear various flags. 653 // Clear various flags.
731 start_up_time_ = base::Time(); 654 start_up_time_ = base::Time();
732 expect_sync_configuration_aborted_ = false; 655 expect_sync_configuration_aborted_ = false;
733 is_auth_in_progress_ = false; 656 is_auth_in_progress_ = false;
734 backend_initialized_ = false; 657 backend_initialized_ = false;
735 // NULL if we're called from Shutdown().
736 if (invalidator_registrar_)
737 UpdateInvalidatorRegistrarState();
738 cached_passphrase_.clear(); 658 cached_passphrase_.clear();
739 encryption_pending_ = false; 659 encryption_pending_ = false;
740 encrypt_everything_ = false; 660 encrypt_everything_ = false;
741 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes(); 661 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes();
742 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; 662 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED;
743 start_up_time_ = base::Time(); 663 start_up_time_ = base::Time();
744 // Revert to "no auth error". 664 // Revert to "no auth error".
745 if (last_auth_error_.state() != GoogleServiceAuthError::NONE) 665 if (last_auth_error_.state() != GoogleServiceAuthError::NONE)
746 UpdateAuthErrorState(GoogleServiceAuthError::AuthErrorNone()); 666 UpdateAuthErrorState(GoogleServiceAuthError::AuthErrorNone());
747 667
748 if (sync_global_error_) { 668 if (sync_global_error_) {
749 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( 669 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(
750 sync_global_error_.get()); 670 sync_global_error_.get());
751 RemoveObserver(sync_global_error_.get()); 671 RemoveObserver(sync_global_error_.get());
752 sync_global_error_.reset(NULL); 672 sync_global_error_.reset(NULL);
753 } 673 }
754 } 674 }
755 675
756 void ProfileSyncService::DisableForUser() { 676 void ProfileSyncService::DisableForUser() {
757 // Clear prefs (including SyncSetupHasCompleted) before shutting down so 677 // Clear prefs (including SyncSetupHasCompleted) before shutting down so
758 // PSS clients don't think we're set up while we're shutting down. 678 // PSS clients don't think we're set up while we're shutting down.
759 sync_prefs_.ClearPreferences(); 679 sync_prefs_.ClearPreferences();
760 invalidator_storage_.Clear();
761 ClearUnrecoverableError(); 680 ClearUnrecoverableError();
762 ShutdownImpl(true); 681 ShutdownImpl(true);
763 NotifyObservers(); 682 NotifyObservers();
764 } 683 }
765 684
766 bool ProfileSyncService::HasSyncSetupCompleted() const { 685 bool ProfileSyncService::HasSyncSetupCompleted() const {
767 return sync_prefs_.HasSyncSetupCompleted(); 686 return sync_prefs_.HasSyncSetupCompleted();
768 } 687 }
769 688
770 void ProfileSyncService::SetSyncSetupCompleted() { 689 void ProfileSyncService::SetSyncSetupCompleted() {
771 sync_prefs_.SetSyncSetupCompleted(); 690 sync_prefs_.SetSyncSetupCompleted();
772 } 691 }
773 692
774 void ProfileSyncService::UpdateLastSyncedTime() { 693 void ProfileSyncService::UpdateLastSyncedTime() {
775 last_synced_time_ = base::Time::Now(); 694 last_synced_time_ = base::Time::Now();
776 sync_prefs_.SetLastSyncedTime(last_synced_time_); 695 sync_prefs_.SetLastSyncedTime(last_synced_time_);
777 } 696 }
778 697
779 void ProfileSyncService::NotifyObservers() { 698 void ProfileSyncService::NotifyObservers() {
780 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); 699 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
781 // TODO(akalin): Make an Observer subclass that listens and does the 700 // TODO(akalin): Make an Observer subclass that listens and does the
782 // event routing. 701 // event routing.
702 sync_js_controller_.HandleJsEvent("onServiceStateChanged", JsEventDetails());
703 }
704
705 void ProfileSyncService::NotifySyncCycleCompleted() {
706 FOR_EACH_OBSERVER(Observer, observers_, OnSyncCycleCompleted());
783 sync_js_controller_.HandleJsEvent( 707 sync_js_controller_.HandleJsEvent(
784 "onServiceStateChanged", JsEventDetails()); 708 "onServiceStateChanged", JsEventDetails());
785 } 709 }
786 710
787 void ProfileSyncService::ClearStaleErrors() { 711 void ProfileSyncService::ClearStaleErrors() {
788 ClearUnrecoverableError(); 712 ClearUnrecoverableError();
789 last_actionable_error_ = SyncProtocolError(); 713 last_actionable_error_ = SyncProtocolError();
790 // Clear the data type errors as well. 714 // Clear the data type errors as well.
791 failed_data_types_handler_.Reset(); 715 failed_data_types_handler_.Reset();
792 } 716 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 // the task that we are going to post, this type would still be disabled. 787 // the task that we are going to post, this type would still be disabled.
864 failed_data_types_handler_.UpdateFailedDataTypes( 788 failed_data_types_handler_.UpdateFailedDataTypes(
865 errors, 789 errors,
866 FailedDataTypesHandler::RUNTIME); 790 FailedDataTypesHandler::RUNTIME);
867 791
868 base::MessageLoop::current()->PostTask(FROM_HERE, 792 base::MessageLoop::current()->PostTask(FROM_HERE,
869 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, 793 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager,
870 weak_factory_.GetWeakPtr())); 794 weak_factory_.GetWeakPtr()));
871 } 795 }
872 796
873 void ProfileSyncService::OnInvalidatorStateChange(
874 syncer::InvalidatorState state) {
875 invalidator_state_ = state;
876 UpdateInvalidatorRegistrarState();
877 }
878
879 void ProfileSyncService::OnIncomingInvalidation(
880 const syncer::ObjectIdInvalidationMap& invalidation_map) {
881 invalidator_registrar_->DispatchInvalidationsToHandlers(invalidation_map);
882 }
883
884 void ProfileSyncService::OnBackendInitialized( 797 void ProfileSyncService::OnBackendInitialized(
885 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 798 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
886 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 799 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
887 debug_info_listener, 800 debug_info_listener,
888 bool success) { 801 bool success) {
889 is_first_time_sync_configure_ = !HasSyncSetupCompleted(); 802 is_first_time_sync_configure_ = !HasSyncSetupCompleted();
890 803
891 if (is_first_time_sync_configure_) { 804 if (is_first_time_sync_configure_) {
892 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); 805 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success);
893 } else { 806 } else {
(...skipping 23 matching lines...) Expand all
917 // we get here, we will have already tried and failed to delete the 830 // we get here, we will have already tried and failed to delete the
918 // directory. It would be no big deal if we tried to delete it again. 831 // directory. It would be no big deal if we tried to delete it again.
919 OnInternalUnrecoverableError(FROM_HERE, 832 OnInternalUnrecoverableError(FROM_HERE,
920 "BackendInitialize failure", 833 "BackendInitialize failure",
921 false, 834 false,
922 ERROR_REASON_BACKEND_INIT_FAILURE); 835 ERROR_REASON_BACKEND_INIT_FAILURE);
923 return; 836 return;
924 } 837 }
925 838
926 backend_initialized_ = true; 839 backend_initialized_ = true;
927 UpdateInvalidatorRegistrarState();
928 840
929 sync_js_controller_.AttachJsBackend(js_backend); 841 sync_js_controller_.AttachJsBackend(js_backend);
930 debug_info_listener_ = debug_info_listener; 842 debug_info_listener_ = debug_info_listener;
931 843
932 // If we have a cached passphrase use it to decrypt/encrypt data now that the 844 // If we have a cached passphrase use it to decrypt/encrypt data now that the
933 // backend is initialized. We want to call this before notifying observers in 845 // backend is initialized. We want to call this before notifying observers in
934 // case this operation affects the "passphrase required" status. 846 // case this operation affects the "passphrase required" status.
935 ConsumeCachedPassphraseIfPossible(); 847 ConsumeCachedPassphraseIfPossible();
936 848
937 // The very first time the backend initializes is effectively the first time 849 // The very first time the backend initializes is effectively the first time
(...skipping 28 matching lines...) Expand all
966 // Trigger garbage collection of old sessions now that we've downloaded 878 // Trigger garbage collection of old sessions now that we've downloaded
967 // any new session data. TODO(zea): Have this be a notification the session 879 // any new session data. TODO(zea): Have this be a notification the session
968 // model associator listens too. Also consider somehow plumbing the current 880 // model associator listens too. Also consider somehow plumbing the current
969 // server time as last reported by CheckServerReachable, so we don't have to 881 // server time as last reported by CheckServerReachable, so we don't have to
970 // rely on the local clock, which may be off significantly. 882 // rely on the local clock, which may be off significantly.
971 base::MessageLoop::current()->PostTask(FROM_HERE, 883 base::MessageLoop::current()->PostTask(FROM_HERE,
972 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, 884 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions,
973 GetSessionModelAssociator()->AsWeakPtr())); 885 GetSessionModelAssociator()->AsWeakPtr()));
974 } 886 }
975 DVLOG(2) << "Notifying observers sync cycle completed"; 887 DVLOG(2) << "Notifying observers sync cycle completed";
976 NotifyObservers(); 888 NotifySyncCycleCompleted();
977 } 889 }
978 890
979 void ProfileSyncService::OnExperimentsChanged( 891 void ProfileSyncService::OnExperimentsChanged(
980 const syncer::Experiments& experiments) { 892 const syncer::Experiments& experiments) {
981 if (current_experiments_.Matches(experiments)) 893 if (current_experiments_.Matches(experiments))
982 return; 894 return;
983 895
984 // If this is a first time sync for a client, this will be called before 896 // If this is a first time sync for a client, this will be called before
985 // OnBackendInitialized() to ensure the new datatypes are available at sync 897 // OnBackendInitialized() to ensure the new datatypes are available at sync
986 // setup. As a result, the migrator won't exist yet. This is fine because for 898 // setup. As a result, the migrator won't exist yet. This is fine because for
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2088 void ProfileSyncService::OnInternalUnrecoverableError( 2000 void ProfileSyncService::OnInternalUnrecoverableError(
2089 const tracked_objects::Location& from_here, 2001 const tracked_objects::Location& from_here,
2090 const std::string& message, 2002 const std::string& message,
2091 bool delete_sync_database, 2003 bool delete_sync_database,
2092 UnrecoverableErrorReason reason) { 2004 UnrecoverableErrorReason reason) {
2093 DCHECK(!HasUnrecoverableError()); 2005 DCHECK(!HasUnrecoverableError());
2094 unrecoverable_error_reason_ = reason; 2006 unrecoverable_error_reason_ = reason;
2095 OnUnrecoverableErrorImpl(from_here, message, delete_sync_database); 2007 OnUnrecoverableErrorImpl(from_here, message, delete_sync_database);
2096 } 2008 }
2097 2009
2098 void ProfileSyncService::UpdateInvalidatorRegistrarState() {
2099 const syncer::InvalidatorState effective_state =
2100 backend_initialized_ ?
2101 invalidator_state_ : syncer::TRANSIENT_INVALIDATION_ERROR;
2102 DVLOG(1) << "New invalidator state: "
2103 << syncer::InvalidatorStateToString(invalidator_state_)
2104 << ", effective state: "
2105 << syncer::InvalidatorStateToString(effective_state);
2106 invalidator_registrar_->UpdateInvalidatorState(effective_state);
2107 }
2108
2109 std::string ProfileSyncService::GetEffectiveUsername() { 2010 std::string ProfileSyncService::GetEffectiveUsername() {
2110 #if defined(ENABLE_MANAGED_USERS) 2011 #if defined(ENABLE_MANAGED_USERS)
2111 if (ManagedUserService::ProfileIsManaged(profile_)) { 2012 if (ManagedUserService::ProfileIsManaged(profile_)) {
2112 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername()); 2013 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername());
2113 return ManagedUserService::GetManagedUserPseudoEmail(); 2014 return ManagedUserService::GetManagedUserPseudoEmail();
2114 } 2015 }
2115 #endif 2016 #endif
2116 2017
2117 return signin_->GetAuthenticatedUsername(); 2018 return signin_->GetAuthenticatedUsername();
2118 } 2019 }
2119
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698