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

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: Responses to Fred's comments 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, 136 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory,
138 Profile* profile, 137 Profile* profile,
139 SigninManagerBase* signin_manager, 138 SigninManagerBase* signin_manager,
140 StartBehavior start_behavior) 139 StartBehavior start_behavior)
141 : last_auth_error_(AuthError::AuthErrorNone()), 140 : last_auth_error_(AuthError::AuthErrorNone()),
142 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), 141 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED),
143 factory_(factory), 142 factory_(factory),
144 profile_(profile), 143 profile_(profile),
145 // |profile| may be NULL in unit tests. 144 // |profile| may be NULL in unit tests.
146 sync_prefs_(profile_ ? profile_->GetPrefs() : NULL), 145 sync_prefs_(profile_ ? profile_->GetPrefs() : NULL),
147 invalidator_storage_(profile_ ? profile_->GetPrefs(): NULL),
148 sync_service_url_(kDevServerUrl), 146 sync_service_url_(kDevServerUrl),
149 data_type_requested_sync_startup_(false), 147 data_type_requested_sync_startup_(false),
150 is_first_time_sync_configure_(false), 148 is_first_time_sync_configure_(false),
151 backend_initialized_(false), 149 backend_initialized_(false),
152 is_auth_in_progress_(false), 150 is_auth_in_progress_(false),
153 signin_(signin_manager), 151 signin_(signin_manager),
154 unrecoverable_error_reason_(ERROR_REASON_UNSET), 152 unrecoverable_error_reason_(ERROR_REASON_UNSET),
155 weak_factory_(this), 153 weak_factory_(this),
156 expect_sync_configuration_aborted_(false), 154 expect_sync_configuration_aborted_(false),
157 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), 155 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()),
158 encrypt_everything_(false), 156 encrypt_everything_(false),
159 encryption_pending_(false), 157 encryption_pending_(false),
160 auto_start_enabled_(start_behavior == AUTO_START), 158 auto_start_enabled_(start_behavior == AUTO_START),
161 failed_datatypes_handler_(this), 159 failed_datatypes_handler_(this),
162 configure_status_(DataTypeManager::UNKNOWN), 160 configure_status_(DataTypeManager::UNKNOWN),
163 setup_in_progress_(false), 161 setup_in_progress_(false) {
164 invalidator_state_(syncer::DEFAULT_INVALIDATION_ERROR) {
165 // By default, dev, canary, and unbranded Chromium users will go to the 162 // By default, dev, canary, and unbranded Chromium users will go to the
166 // development servers. Development servers have more features than standard 163 // development servers. Development servers have more features than standard
167 // sync servers. Users with officially-branded Chrome stable and beta builds 164 // sync servers. Users with officially-branded Chrome stable and beta builds
168 // will go to the standard sync servers. 165 // will go to the standard sync servers.
169 // 166 //
170 // GetChannel hits the registry on Windows. See http://crbug.com/70380. 167 // GetChannel hits the registry on Windows. See http://crbug.com/70380.
171 base::ThreadRestrictions::ScopedAllowIO allow_io; 168 base::ThreadRestrictions::ScopedAllowIO allow_io;
172 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); 169 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
173 if (channel == chrome::VersionInfo::CHANNEL_STABLE || 170 if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
174 channel == chrome::VersionInfo::CHANNEL_BETA) { 171 channel == chrome::VersionInfo::CHANNEL_BETA) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 if (!sync_initialized()) 208 if (!sync_initialized())
212 return false; 209 return false;
213 // On Android we do not want to prompt user to enter a passphrase. If 210 // On Android we do not want to prompt user to enter a passphrase. If
214 // passwords cannot be decrypted we just disable them. 211 // passwords cannot be decrypted we just disable them.
215 syncer::ReadTransaction trans(FROM_HERE, GetUserShare()); 212 syncer::ReadTransaction trans(FROM_HERE, GetUserShare());
216 return IsCryptographerReady(&trans); 213 return IsCryptographerReady(&trans);
217 } 214 }
218 #endif 215 #endif
219 216
220 void ProfileSyncService::Initialize() { 217 void ProfileSyncService::Initialize() {
221 DCHECK(!invalidator_registrar_.get());
222 invalidator_registrar_.reset(new syncer::InvalidatorRegistrar());
223
224 InitSettings(); 218 InitSettings();
225 219
226 // We clear this here (vs Shutdown) because we want to remember that an error 220 // We clear this here (vs Shutdown) because we want to remember that an error
227 // happened on shutdown so we can display details (message, location) about it 221 // happened on shutdown so we can display details (message, location) about it
228 // in about:sync. 222 // in about:sync.
229 ClearStaleErrors(); 223 ClearStaleErrors();
230 224
231 sync_prefs_.AddSyncPrefObserver(this); 225 sync_prefs_.AddSyncPrefObserver(this);
232 226
233 // For now, the only thing we can do through policy is to turn sync off. 227 // 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
468 credentials, 462 credentials,
469 delete_stale_data, 463 delete_stale_data,
470 &sync_manager_factory_, 464 &sync_manager_factory_,
471 backend_unrecoverable_error_handler_.get(), 465 backend_unrecoverable_error_handler_.get(),
472 &browser_sync::ChromeReportUnrecoverableError); 466 &browser_sync::ChromeReportUnrecoverableError);
473 } 467 }
474 468
475 void ProfileSyncService::CreateBackend() { 469 void ProfileSyncService::CreateBackend() {
476 backend_.reset( 470 backend_.reset(
477 new SyncBackendHost(profile_->GetDebugName(), 471 new SyncBackendHost(profile_->GetDebugName(),
478 profile_, sync_prefs_.AsWeakPtr(), 472 profile_, sync_prefs_.AsWeakPtr()));
479 invalidator_storage_.AsWeakPtr()));
480 } 473 }
481 474
482 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { 475 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const {
483 if (encryption_pending()) 476 if (encryption_pending())
484 return true; 477 return true;
485 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); 478 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes();
486 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); 479 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes();
487 DCHECK(encrypted_types.Has(syncer::PASSWORDS)); 480 DCHECK(encrypted_types.Has(syncer::PASSWORDS));
488 return !Intersection(preferred_types, encrypted_types).Empty(); 481 return !Intersection(preferred_types, encrypted_types).Empty();
489 } 482 }
(...skipping 108 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.
783 sync_js_controller_.HandleJsEvent( 702 sync_js_controller_.HandleJsEvent(
784 "onServiceStateChanged", JsEventDetails()); 703 "onServiceStateChanged", JsEventDetails());
785 } 704 }
786 705
706 void ProfileSyncService::NotifySyncCycleCompleted() {
707 FOR_EACH_OBSERVER(Observer, observers_, OnSyncCycleCompleted());
708 sync_js_controller_.HandleJsEvent(
akalin 2013/06/04 19:23:54 one line?
rlarocque 2013/06/04 22:38:16 Done.
709 "onServiceStateChanged", JsEventDetails());
710 }
711
787 void ProfileSyncService::ClearStaleErrors() { 712 void ProfileSyncService::ClearStaleErrors() {
788 ClearUnrecoverableError(); 713 ClearUnrecoverableError();
789 last_actionable_error_ = SyncProtocolError(); 714 last_actionable_error_ = SyncProtocolError();
790 // Clear the data type errors as well. 715 // Clear the data type errors as well.
791 failed_datatypes_handler_.OnUserChoseDatatypes(); 716 failed_datatypes_handler_.OnUserChoseDatatypes();
792 } 717 }
793 718
794 void ProfileSyncService::ClearUnrecoverableError() { 719 void ProfileSyncService::ClearUnrecoverableError() {
795 unrecoverable_error_reason_ = ERROR_REASON_UNSET; 720 unrecoverable_error_reason_ = ERROR_REASON_UNSET;
796 unrecoverable_error_message_.clear(); 721 unrecoverable_error_message_.clear();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 // Update this before posting a task. So if a configure happens before 787 // Update this before posting a task. So if a configure happens before
863 // the task that we are going to post, this type would still be disabled. 788 // the task that we are going to post, this type would still be disabled.
864 failed_datatypes_handler_.UpdateFailedDatatypes(errors, 789 failed_datatypes_handler_.UpdateFailedDatatypes(errors,
865 FailedDatatypesHandler::RUNTIME); 790 FailedDatatypesHandler::RUNTIME);
866 791
867 MessageLoop::current()->PostTask(FROM_HERE, 792 MessageLoop::current()->PostTask(FROM_HERE,
868 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, 793 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager,
869 weak_factory_.GetWeakPtr())); 794 weak_factory_.GetWeakPtr()));
870 } 795 }
871 796
872 void ProfileSyncService::OnInvalidatorStateChange(
873 syncer::InvalidatorState state) {
874 invalidator_state_ = state;
875 UpdateInvalidatorRegistrarState();
876 }
877
878 void ProfileSyncService::OnIncomingInvalidation(
879 const syncer::ObjectIdInvalidationMap& invalidation_map) {
880 invalidator_registrar_->DispatchInvalidationsToHandlers(invalidation_map);
881 }
882
883 void ProfileSyncService::OnBackendInitialized( 797 void ProfileSyncService::OnBackendInitialized(
884 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 798 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
885 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 799 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
886 debug_info_listener, 800 debug_info_listener,
887 bool success) { 801 bool success) {
888 is_first_time_sync_configure_ = !HasSyncSetupCompleted(); 802 is_first_time_sync_configure_ = !HasSyncSetupCompleted();
889 803
890 if (is_first_time_sync_configure_) { 804 if (is_first_time_sync_configure_) {
891 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); 805 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success);
892 } else { 806 } else {
(...skipping 23 matching lines...) Expand all
916 // 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
917 // 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.
918 OnInternalUnrecoverableError(FROM_HERE, 832 OnInternalUnrecoverableError(FROM_HERE,
919 "BackendInitialize failure", 833 "BackendInitialize failure",
920 false, 834 false,
921 ERROR_REASON_BACKEND_INIT_FAILURE); 835 ERROR_REASON_BACKEND_INIT_FAILURE);
922 return; 836 return;
923 } 837 }
924 838
925 backend_initialized_ = true; 839 backend_initialized_ = true;
926 UpdateInvalidatorRegistrarState();
927 840
928 sync_js_controller_.AttachJsBackend(js_backend); 841 sync_js_controller_.AttachJsBackend(js_backend);
929 debug_info_listener_ = debug_info_listener; 842 debug_info_listener_ = debug_info_listener;
930 843
931 // 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
932 // 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
933 // case this operation affects the "passphrase required" status. 846 // case this operation affects the "passphrase required" status.
934 ConsumeCachedPassphraseIfPossible(); 847 ConsumeCachedPassphraseIfPossible();
935 848
936 // 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
965 // Trigger garbage collection of old sessions now that we've downloaded 878 // Trigger garbage collection of old sessions now that we've downloaded
966 // 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
967 // model associator listens too. Also consider somehow plumbing the current 880 // model associator listens too. Also consider somehow plumbing the current
968 // 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
969 // rely on the local clock, which may be off significantly. 882 // rely on the local clock, which may be off significantly.
970 MessageLoop::current()->PostTask(FROM_HERE, 883 MessageLoop::current()->PostTask(FROM_HERE,
971 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, 884 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions,
972 GetSessionModelAssociator()->AsWeakPtr())); 885 GetSessionModelAssociator()->AsWeakPtr()));
973 } 886 }
974 DVLOG(2) << "Notifying observers sync cycle completed"; 887 DVLOG(2) << "Notifying observers sync cycle completed";
975 NotifyObservers(); 888 NotifySyncCycleCompleted();
976 } 889 }
977 890
978 void ProfileSyncService::OnExperimentsChanged( 891 void ProfileSyncService::OnExperimentsChanged(
979 const syncer::Experiments& experiments) { 892 const syncer::Experiments& experiments) {
980 if (current_experiments_.Matches(experiments)) 893 if (current_experiments_.Matches(experiments))
981 return; 894 return;
982 895
983 // 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
984 // OnBackendInitialized() to ensure the new datatypes are available at sync 897 // OnBackendInitialized() to ensure the new datatypes are available at sync
985 // 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 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
2082 void ProfileSyncService::OnInternalUnrecoverableError( 1995 void ProfileSyncService::OnInternalUnrecoverableError(
2083 const tracked_objects::Location& from_here, 1996 const tracked_objects::Location& from_here,
2084 const std::string& message, 1997 const std::string& message,
2085 bool delete_sync_database, 1998 bool delete_sync_database,
2086 UnrecoverableErrorReason reason) { 1999 UnrecoverableErrorReason reason) {
2087 DCHECK(!HasUnrecoverableError()); 2000 DCHECK(!HasUnrecoverableError());
2088 unrecoverable_error_reason_ = reason; 2001 unrecoverable_error_reason_ = reason;
2089 OnUnrecoverableErrorImpl(from_here, message, delete_sync_database); 2002 OnUnrecoverableErrorImpl(from_here, message, delete_sync_database);
2090 } 2003 }
2091 2004
2092 void ProfileSyncService::UpdateInvalidatorRegistrarState() {
2093 const syncer::InvalidatorState effective_state =
2094 backend_initialized_ ?
2095 invalidator_state_ : syncer::TRANSIENT_INVALIDATION_ERROR;
2096 DVLOG(1) << "New invalidator state: "
2097 << syncer::InvalidatorStateToString(invalidator_state_)
2098 << ", effective state: "
2099 << syncer::InvalidatorStateToString(effective_state);
2100 invalidator_registrar_->UpdateInvalidatorState(effective_state);
2101 }
2102
2103 std::string ProfileSyncService::GetEffectiveUsername() { 2005 std::string ProfileSyncService::GetEffectiveUsername() {
2104 #if defined(ENABLE_MANAGED_USERS) 2006 #if defined(ENABLE_MANAGED_USERS)
2105 if (ManagedUserService::ProfileIsManaged(profile_)) { 2007 if (ManagedUserService::ProfileIsManaged(profile_)) {
2106 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername()); 2008 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername());
2107 return ManagedUserService::GetManagedUserPseudoEmail(); 2009 return ManagedUserService::GetManagedUserPseudoEmail();
2108 } 2010 }
2109 #endif 2011 #endif
2110 2012
2111 return signin_->GetAuthenticatedUsername(); 2013 return signin_->GetAuthenticatedUsername();
2112 } 2014 }
2113
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698