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

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: Update with OAuth2 support 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "chrome/common/pref_names.h" 61 #include "chrome/common/pref_names.h"
62 #include "chrome/common/time_format.h" 62 #include "chrome/common/time_format.h"
63 #include "chrome/common/url_constants.h" 63 #include "chrome/common/url_constants.h"
64 #include "components/user_prefs/pref_registry_syncable.h" 64 #include "components/user_prefs/pref_registry_syncable.h"
65 #include "content/public/browser/notification_details.h" 65 #include "content/public/browser/notification_details.h"
66 #include "content/public/browser/notification_service.h" 66 #include "content/public/browser/notification_service.h"
67 #include "content/public/browser/notification_source.h" 67 #include "content/public/browser/notification_source.h"
68 #include "google_apis/gaia/gaia_constants.h" 68 #include "google_apis/gaia/gaia_constants.h"
69 #include "grit/generated_resources.h" 69 #include "grit/generated_resources.h"
70 #include "net/cookies/cookie_monster.h" 70 #include "net/cookies/cookie_monster.h"
71 #include "net/url_request/url_request_context_getter.h"
71 #include "sync/api/sync_error.h" 72 #include "sync/api/sync_error.h"
72 #include "sync/internal_api/public/configure_reason.h" 73 #include "sync/internal_api/public/configure_reason.h"
73 #include "sync/internal_api/public/sync_encryption_handler.h" 74 #include "sync/internal_api/public/sync_encryption_handler.h"
74 #include "sync/internal_api/public/util/experiments.h" 75 #include "sync/internal_api/public/util/experiments.h"
75 #include "sync/internal_api/public/util/sync_string_conversions.h" 76 #include "sync/internal_api/public/util/sync_string_conversions.h"
76 #include "sync/js/js_arg_list.h" 77 #include "sync/js/js_arg_list.h"
77 #include "sync/js/js_event_details.h" 78 #include "sync/js/js_event_details.h"
78 #include "sync/notifier/invalidator_registrar.h"
79 #include "sync/notifier/invalidator_state.h"
80 #include "sync/util/cryptographer.h" 79 #include "sync/util/cryptographer.h"
81 #include "ui/base/l10n/l10n_util.h" 80 #include "ui/base/l10n/l10n_util.h"
82 81
83 #if defined(ENABLE_MANAGED_USERS) 82 #if defined(ENABLE_MANAGED_USERS)
84 #include "chrome/browser/managed_mode/managed_user_service.h" 83 #include "chrome/browser/managed_mode/managed_user_service.h"
85 #endif 84 #endif
86 85
87 #if defined(OS_ANDROID) 86 #if defined(OS_ANDROID)
88 #include "sync/internal_api/public/read_transaction.h" 87 #include "sync/internal_api/public/read_transaction.h"
89 #endif 88 #endif
(...skipping 19 matching lines...) Expand all
109 const char* ProfileSyncService::kSyncServerUrl = 108 const char* ProfileSyncService::kSyncServerUrl =
110 "https://clients4.google.com/chrome-sync"; 109 "https://clients4.google.com/chrome-sync";
111 110
112 const char* ProfileSyncService::kDevServerUrl = 111 const char* ProfileSyncService::kDevServerUrl =
113 "https://clients4.google.com/chrome-sync/dev"; 112 "https://clients4.google.com/chrome-sync/dev";
114 113
115 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. 114 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute.
116 115
117 static const char* kOAuth2Scopes[] = { 116 static const char* kOAuth2Scopes[] = {
118 GaiaConstants::kChromeSyncOAuth2Scope, 117 GaiaConstants::kChromeSyncOAuth2Scope,
119 // GoogleTalk scope is needed for notifications.
120 GaiaConstants::kGoogleTalkOAuth2Scope
121 }; 118 };
122 119
123 120
124 static const char* kSyncUnrecoverableErrorHistogram = 121 static const char* kSyncUnrecoverableErrorHistogram =
125 "Sync.UnrecoverableErrors"; 122 "Sync.UnrecoverableErrors";
126 123
127 const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = { 124 const net::BackoffEntry::Policy kRequestAccessTokenBackoffPolicy = {
128 // Number of initial errors (in sequence) to ignore before applying 125 // Number of initial errors (in sequence) to ignore before applying
129 // exponential back-off rules. 126 // exponential back-off rules.
130 0, 127 0,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, 159 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory,
163 Profile* profile, 160 Profile* profile,
164 SigninManagerBase* signin_manager, 161 SigninManagerBase* signin_manager,
165 StartBehavior start_behavior) 162 StartBehavior start_behavior)
166 : last_auth_error_(AuthError::AuthErrorNone()), 163 : last_auth_error_(AuthError::AuthErrorNone()),
167 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), 164 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED),
168 factory_(factory), 165 factory_(factory),
169 profile_(profile), 166 profile_(profile),
170 // |profile| may be NULL in unit tests. 167 // |profile| may be NULL in unit tests.
171 sync_prefs_(profile_ ? profile_->GetPrefs() : NULL), 168 sync_prefs_(profile_ ? profile_->GetPrefs() : NULL),
172 invalidator_storage_(profile_ ? profile_->GetPrefs(): NULL),
173 sync_service_url_(kDevServerUrl), 169 sync_service_url_(kDevServerUrl),
174 data_type_requested_sync_startup_(false), 170 data_type_requested_sync_startup_(false),
175 is_first_time_sync_configure_(false), 171 is_first_time_sync_configure_(false),
176 backend_initialized_(false), 172 backend_initialized_(false),
177 sync_disabled_by_admin_(false), 173 sync_disabled_by_admin_(false),
178 is_auth_in_progress_(false), 174 is_auth_in_progress_(false),
179 signin_(signin_manager), 175 signin_(signin_manager),
180 unrecoverable_error_reason_(ERROR_REASON_UNSET), 176 unrecoverable_error_reason_(ERROR_REASON_UNSET),
181 weak_factory_(this), 177 weak_factory_(this),
182 expect_sync_configuration_aborted_(false), 178 expect_sync_configuration_aborted_(false),
183 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), 179 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()),
184 encrypt_everything_(false), 180 encrypt_everything_(false),
185 encryption_pending_(false), 181 encryption_pending_(false),
186 auto_start_enabled_(start_behavior == AUTO_START), 182 auto_start_enabled_(start_behavior == AUTO_START),
187 configure_status_(DataTypeManager::UNKNOWN), 183 configure_status_(DataTypeManager::UNKNOWN),
188 setup_in_progress_(false), 184 setup_in_progress_(false),
189 invalidator_state_(syncer::DEFAULT_INVALIDATION_ERROR),
190 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy) { 185 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy) {
191 // By default, dev, canary, and unbranded Chromium users will go to the 186 // By default, dev, canary, and unbranded Chromium users will go to the
192 // development servers. Development servers have more features than standard 187 // development servers. Development servers have more features than standard
193 // sync servers. Users with officially-branded Chrome stable and beta builds 188 // sync servers. Users with officially-branded Chrome stable and beta builds
194 // will go to the standard sync servers. 189 // will go to the standard sync servers.
195 // 190 //
196 // GetChannel hits the registry on Windows. See http://crbug.com/70380. 191 // GetChannel hits the registry on Windows. See http://crbug.com/70380.
197 base::ThreadRestrictions::ScopedAllowIO allow_io; 192 base::ThreadRestrictions::ScopedAllowIO allow_io;
198 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); 193 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
199 if (channel == chrome::VersionInfo::CHANNEL_STABLE || 194 if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 return token_service->RefreshTokenIsAvailable(); 227 return token_service->RefreshTokenIsAvailable();
233 } else { 228 } else {
234 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 229 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
235 if (!token_service) 230 if (!token_service)
236 return false; 231 return false;
237 return token_service->HasTokenForService(GaiaConstants::kSyncService); 232 return token_service->HasTokenForService(GaiaConstants::kSyncService);
238 } 233 }
239 } 234 }
240 235
241 void ProfileSyncService::Initialize() { 236 void ProfileSyncService::Initialize() {
242 DCHECK(!invalidator_registrar_.get());
243 invalidator_registrar_.reset(new syncer::InvalidatorRegistrar());
244
245 InitSettings(); 237 InitSettings();
246 238
247 // We clear this here (vs Shutdown) because we want to remember that an error 239 // We clear this here (vs Shutdown) because we want to remember that an error
248 // happened on shutdown so we can display details (message, location) about it 240 // happened on shutdown so we can display details (message, location) about it
249 // in about:sync. 241 // in about:sync.
250 ClearStaleErrors(); 242 ClearStaleErrors();
251 243
252 sync_prefs_.AddSyncPrefObserver(this); 244 sync_prefs_.AddSyncPrefObserver(this);
253 245
254 // For now, the only thing we can do through policy is to turn sync off. 246 // For now, the only thing we can do through policy is to turn sync off.
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 credentials, 491 credentials,
500 delete_stale_data, 492 delete_stale_data,
501 &sync_manager_factory_, 493 &sync_manager_factory_,
502 backend_unrecoverable_error_handler_.get(), 494 backend_unrecoverable_error_handler_.get(),
503 &browser_sync::ChromeReportUnrecoverableError); 495 &browser_sync::ChromeReportUnrecoverableError);
504 } 496 }
505 497
506 void ProfileSyncService::CreateBackend() { 498 void ProfileSyncService::CreateBackend() {
507 backend_.reset( 499 backend_.reset(
508 new SyncBackendHost(profile_->GetDebugName(), 500 new SyncBackendHost(profile_->GetDebugName(),
509 profile_, sync_prefs_.AsWeakPtr(), 501 profile_, sync_prefs_.AsWeakPtr()));
510 invalidator_storage_.AsWeakPtr()));
511 } 502 }
512 503
513 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { 504 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const {
514 if (encryption_pending()) 505 if (encryption_pending())
515 return true; 506 return true;
516 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); 507 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes();
517 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); 508 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes();
518 DCHECK(encrypted_types.Has(syncer::PASSWORDS)); 509 DCHECK(encrypted_types.Has(syncer::PASSWORDS));
519 return !Intersection(preferred_types, encrypted_types).Empty(); 510 return !Intersection(preferred_types, encrypted_types).Empty();
520 } 511 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 return; 617 return;
627 } 618 }
628 619
629 DCHECK(IsSyncEnabledAndLoggedIn()); 620 DCHECK(IsSyncEnabledAndLoggedIn());
630 CreateBackend(); 621 CreateBackend();
631 622
632 // Initialize the backend. Every time we start up a new SyncBackendHost, 623 // Initialize the backend. Every time we start up a new SyncBackendHost,
633 // we'll want to start from a fresh SyncDB, so delete any old one that might 624 // we'll want to start from a fresh SyncDB, so delete any old one that might
634 // be there. 625 // be there.
635 InitializeBackend(!HasSyncSetupCompleted()); 626 InitializeBackend(!HasSyncSetupCompleted());
636
637 // |backend_| may end up being NULL here in tests (in synchronous
638 // initialization mode).
639 //
640 // TODO(akalin): Fix this horribly non-intuitive behavior (see
641 // http://crbug.com/140354).
642 if (backend_) {
643 backend_->UpdateRegisteredInvalidationIds(
644 invalidator_registrar_->GetAllRegisteredIds());
645 for (AckHandleReplayQueue::const_iterator it = ack_replay_queue_.begin();
646 it != ack_replay_queue_.end(); ++it) {
647 backend_->AcknowledgeInvalidation(it->first, it->second);
648 }
649 ack_replay_queue_.clear();
650 }
651 }
652
653 void ProfileSyncService::RegisterInvalidationHandler(
654 syncer::InvalidationHandler* handler) {
655 invalidator_registrar_->RegisterHandler(handler);
656 }
657
658 void ProfileSyncService::UpdateRegisteredInvalidationIds(
659 syncer::InvalidationHandler* handler,
660 const syncer::ObjectIdSet& ids) {
661 invalidator_registrar_->UpdateRegisteredIds(handler, ids);
662
663 // If |backend_| is NULL, its registered IDs will be updated when
664 // it's created and initialized.
665 if (backend_) {
666 backend_->UpdateRegisteredInvalidationIds(
667 invalidator_registrar_->GetAllRegisteredIds());
668 }
669 }
670
671 void ProfileSyncService::UnregisterInvalidationHandler(
672 syncer::InvalidationHandler* handler) {
673 invalidator_registrar_->UnregisterHandler(handler);
674 }
675
676 void ProfileSyncService::AcknowledgeInvalidation(
677 const invalidation::ObjectId& id,
678 const syncer::AckHandle& ack_handle) {
679 if (backend_) {
680 backend_->AcknowledgeInvalidation(id, ack_handle);
681 } else {
682 // If |backend_| is NULL, save the acknowledgements to replay when
683 // it's created and initialized.
684 ack_replay_queue_.push_back(std::make_pair(id, ack_handle));
685 }
686 }
687
688 syncer::InvalidatorState ProfileSyncService::GetInvalidatorState() const {
689 return invalidator_registrar_->GetInvalidatorState();
690 } 627 }
691 628
692 void ProfileSyncService::OnGetTokenSuccess( 629 void ProfileSyncService::OnGetTokenSuccess(
693 const OAuth2TokenService::Request* request, 630 const OAuth2TokenService::Request* request,
694 const std::string& access_token, 631 const std::string& access_token,
695 const base::Time& expiration_time) { 632 const base::Time& expiration_time) {
696 DCHECK_EQ(access_token_request_, request); 633 DCHECK_EQ(access_token_request_, request);
697 access_token_request_.reset(); 634 access_token_request_.reset();
698 // Reset backoff time after successful response. 635 // Reset backoff time after successful response.
699 request_access_token_backoff_.Reset(); 636 request_access_token_backoff_.Reset();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 } 680 }
744 // Fallthrough. 681 // Fallthrough.
745 } 682 }
746 default: { 683 default: {
747 // Show error to user. 684 // Show error to user.
748 UpdateAuthErrorState(error); 685 UpdateAuthErrorState(error);
749 } 686 }
750 } 687 }
751 } 688 }
752 689
753 void ProfileSyncService::EmitInvalidationForTest(
754 const invalidation::ObjectId& id,
755 const std::string& payload) {
756 syncer::ObjectIdSet notify_ids;
757 notify_ids.insert(id);
758
759 const syncer::ObjectIdInvalidationMap& invalidation_map =
760 ObjectIdSetToInvalidationMap(notify_ids, payload);
761 OnIncomingInvalidation(invalidation_map);
762 }
763
764 void ProfileSyncService::Shutdown() { 690 void ProfileSyncService::Shutdown() {
765 DCHECK(invalidator_registrar_.get());
766 // Reset |invalidator_registrar_| first so that ShutdownImpl cannot
767 // use it.
768 invalidator_registrar_.reset();
769
770 if (signin_) 691 if (signin_)
771 signin_->signin_global_error()->RemoveProvider(this); 692 signin_->signin_global_error()->RemoveProvider(this);
772 693
773 ShutdownImpl(false); 694 ShutdownImpl(false);
774 } 695 }
775 696
776 void ProfileSyncService::ShutdownImpl(bool sync_disabled) { 697 void ProfileSyncService::ShutdownImpl(bool sync_disabled) {
777 // First, we spin down the backend and wait for it to stop syncing completely 698 // First, we spin down the backend and wait for it to stop syncing completely
778 // before we Stop the data type manager. This is to avoid a late sync cycle 699 // before we Stop the data type manager. This is to avoid a late sync cycle
779 // applying changes to the sync db that wouldn't get applied via 700 // applying changes to the sync db that wouldn't get applied via
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; 735 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time;
815 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); 736 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time);
816 737
817 weak_factory_.InvalidateWeakPtrs(); 738 weak_factory_.InvalidateWeakPtrs();
818 739
819 // Clear various flags. 740 // Clear various flags.
820 start_up_time_ = base::Time(); 741 start_up_time_ = base::Time();
821 expect_sync_configuration_aborted_ = false; 742 expect_sync_configuration_aborted_ = false;
822 is_auth_in_progress_ = false; 743 is_auth_in_progress_ = false;
823 backend_initialized_ = false; 744 backend_initialized_ = false;
824 // NULL if we're called from Shutdown().
825 if (invalidator_registrar_)
826 UpdateInvalidatorRegistrarState();
827 cached_passphrase_.clear(); 745 cached_passphrase_.clear();
828 encryption_pending_ = false; 746 encryption_pending_ = false;
829 encrypt_everything_ = false; 747 encrypt_everything_ = false;
830 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes(); 748 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes();
831 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; 749 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED;
832 request_access_token_retry_timer_.Stop(); 750 request_access_token_retry_timer_.Stop();
833 // Revert to "no auth error". 751 // Revert to "no auth error".
834 if (last_auth_error_.state() != GoogleServiceAuthError::NONE) 752 if (last_auth_error_.state() != GoogleServiceAuthError::NONE)
835 UpdateAuthErrorState(GoogleServiceAuthError::AuthErrorNone()); 753 UpdateAuthErrorState(GoogleServiceAuthError::AuthErrorNone());
836 754
837 if (sync_global_error_) { 755 if (sync_global_error_) {
838 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( 756 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(
839 sync_global_error_.get()); 757 sync_global_error_.get());
840 RemoveObserver(sync_global_error_.get()); 758 RemoveObserver(sync_global_error_.get());
841 sync_global_error_.reset(NULL); 759 sync_global_error_.reset(NULL);
842 } 760 }
843 761
844 NotifyObservers(); 762 NotifyObservers();
845 } 763 }
846 764
847 void ProfileSyncService::DisableForUser() { 765 void ProfileSyncService::DisableForUser() {
848 // Clear prefs (including SyncSetupHasCompleted) before shutting down so 766 // Clear prefs (including SyncSetupHasCompleted) before shutting down so
849 // PSS clients don't think we're set up while we're shutting down. 767 // PSS clients don't think we're set up while we're shutting down.
850 sync_prefs_.ClearPreferences(); 768 sync_prefs_.ClearPreferences();
851 invalidator_storage_.Clear();
852 ClearUnrecoverableError(); 769 ClearUnrecoverableError();
853 ShutdownImpl(true); 770 ShutdownImpl(true);
854 } 771 }
855 772
856 bool ProfileSyncService::HasSyncSetupCompleted() const { 773 bool ProfileSyncService::HasSyncSetupCompleted() const {
857 return sync_prefs_.HasSyncSetupCompleted(); 774 return sync_prefs_.HasSyncSetupCompleted();
858 } 775 }
859 776
860 void ProfileSyncService::SetSyncSetupCompleted() { 777 void ProfileSyncService::SetSyncSetupCompleted() {
861 sync_prefs_.SetSyncSetupCompleted(); 778 sync_prefs_.SetSyncSetupCompleted();
862 } 779 }
863 780
864 void ProfileSyncService::UpdateLastSyncedTime() { 781 void ProfileSyncService::UpdateLastSyncedTime() {
865 last_synced_time_ = base::Time::Now(); 782 last_synced_time_ = base::Time::Now();
866 sync_prefs_.SetLastSyncedTime(last_synced_time_); 783 sync_prefs_.SetLastSyncedTime(last_synced_time_);
867 } 784 }
868 785
869 void ProfileSyncService::NotifyObservers() { 786 void ProfileSyncService::NotifyObservers() {
870 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); 787 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
871 // TODO(akalin): Make an Observer subclass that listens and does the 788 // TODO(akalin): Make an Observer subclass that listens and does the
872 // event routing. 789 // event routing.
790 sync_js_controller_.HandleJsEvent("onServiceStateChanged", JsEventDetails());
791 }
792
793 void ProfileSyncService::NotifySyncCycleCompleted() {
794 FOR_EACH_OBSERVER(Observer, observers_, OnSyncCycleCompleted());
873 sync_js_controller_.HandleJsEvent( 795 sync_js_controller_.HandleJsEvent(
874 "onServiceStateChanged", JsEventDetails()); 796 "onServiceStateChanged", JsEventDetails());
875 } 797 }
876 798
877 void ProfileSyncService::ClearStaleErrors() { 799 void ProfileSyncService::ClearStaleErrors() {
878 ClearUnrecoverableError(); 800 ClearUnrecoverableError();
879 last_actionable_error_ = SyncProtocolError(); 801 last_actionable_error_ = SyncProtocolError();
880 // Clear the data type errors as well. 802 // Clear the data type errors as well.
881 failed_data_types_handler_.Reset(); 803 failed_data_types_handler_.Reset();
882 } 804 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 // the task that we are going to post, this type would still be disabled. 876 // the task that we are going to post, this type would still be disabled.
955 failed_data_types_handler_.UpdateFailedDataTypes( 877 failed_data_types_handler_.UpdateFailedDataTypes(
956 errors, 878 errors,
957 FailedDataTypesHandler::RUNTIME); 879 FailedDataTypesHandler::RUNTIME);
958 880
959 base::MessageLoop::current()->PostTask(FROM_HERE, 881 base::MessageLoop::current()->PostTask(FROM_HERE,
960 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, 882 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager,
961 weak_factory_.GetWeakPtr())); 883 weak_factory_.GetWeakPtr()));
962 } 884 }
963 885
964 void ProfileSyncService::OnInvalidatorStateChange(
965 syncer::InvalidatorState state) {
966 invalidator_state_ = state;
967 UpdateInvalidatorRegistrarState();
968 }
969
970 void ProfileSyncService::OnIncomingInvalidation(
971 const syncer::ObjectIdInvalidationMap& invalidation_map) {
972 invalidator_registrar_->DispatchInvalidationsToHandlers(invalidation_map);
973 }
974
975 void ProfileSyncService::OnBackendInitialized( 886 void ProfileSyncService::OnBackendInitialized(
976 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 887 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
977 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 888 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
978 debug_info_listener, 889 debug_info_listener,
979 bool success) { 890 bool success) {
980 is_first_time_sync_configure_ = !HasSyncSetupCompleted(); 891 is_first_time_sync_configure_ = !HasSyncSetupCompleted();
981 892
982 if (is_first_time_sync_configure_) { 893 if (is_first_time_sync_configure_) {
983 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); 894 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success);
984 } else { 895 } else {
(...skipping 23 matching lines...) Expand all
1008 // we get here, we will have already tried and failed to delete the 919 // we get here, we will have already tried and failed to delete the
1009 // directory. It would be no big deal if we tried to delete it again. 920 // directory. It would be no big deal if we tried to delete it again.
1010 OnInternalUnrecoverableError(FROM_HERE, 921 OnInternalUnrecoverableError(FROM_HERE,
1011 "BackendInitialize failure", 922 "BackendInitialize failure",
1012 false, 923 false,
1013 ERROR_REASON_BACKEND_INIT_FAILURE); 924 ERROR_REASON_BACKEND_INIT_FAILURE);
1014 return; 925 return;
1015 } 926 }
1016 927
1017 backend_initialized_ = true; 928 backend_initialized_ = true;
1018 UpdateInvalidatorRegistrarState();
1019 929
1020 sync_js_controller_.AttachJsBackend(js_backend); 930 sync_js_controller_.AttachJsBackend(js_backend);
1021 debug_info_listener_ = debug_info_listener; 931 debug_info_listener_ = debug_info_listener;
1022 932
1023 // If we have a cached passphrase use it to decrypt/encrypt data now that the 933 // If we have a cached passphrase use it to decrypt/encrypt data now that the
1024 // backend is initialized. We want to call this before notifying observers in 934 // backend is initialized. We want to call this before notifying observers in
1025 // case this operation affects the "passphrase required" status. 935 // case this operation affects the "passphrase required" status.
1026 ConsumeCachedPassphraseIfPossible(); 936 ConsumeCachedPassphraseIfPossible();
1027 937
1028 // The very first time the backend initializes is effectively the first time 938 // The very first time the backend initializes is effectively the first time
(...skipping 28 matching lines...) Expand all
1057 // Trigger garbage collection of old sessions now that we've downloaded 967 // Trigger garbage collection of old sessions now that we've downloaded
1058 // any new session data. TODO(zea): Have this be a notification the session 968 // any new session data. TODO(zea): Have this be a notification the session
1059 // model associator listens too. Also consider somehow plumbing the current 969 // model associator listens too. Also consider somehow plumbing the current
1060 // server time as last reported by CheckServerReachable, so we don't have to 970 // server time as last reported by CheckServerReachable, so we don't have to
1061 // rely on the local clock, which may be off significantly. 971 // rely on the local clock, which may be off significantly.
1062 base::MessageLoop::current()->PostTask(FROM_HERE, 972 base::MessageLoop::current()->PostTask(FROM_HERE,
1063 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, 973 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions,
1064 GetSessionModelAssociator()->AsWeakPtr())); 974 GetSessionModelAssociator()->AsWeakPtr()));
1065 } 975 }
1066 DVLOG(2) << "Notifying observers sync cycle completed"; 976 DVLOG(2) << "Notifying observers sync cycle completed";
1067 NotifyObservers(); 977 NotifySyncCycleCompleted();
1068 } 978 }
1069 979
1070 void ProfileSyncService::OnExperimentsChanged( 980 void ProfileSyncService::OnExperimentsChanged(
1071 const syncer::Experiments& experiments) { 981 const syncer::Experiments& experiments) {
1072 if (current_experiments_.Matches(experiments)) 982 if (current_experiments_.Matches(experiments))
1073 return; 983 return;
1074 984
1075 // If this is a first time sync for a client, this will be called before 985 // If this is a first time sync for a client, this will be called before
1076 // OnBackendInitialized() to ensure the new datatypes are available at sync 986 // OnBackendInitialized() to ensure the new datatypes are available at sync
1077 // setup. As a result, the migrator won't exist yet. This is fine because for 987 // setup. As a result, the migrator won't exist yet. This is fine because for
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 NOTREACHED(); 1086 NOTREACHED();
1177 return AuthError(AuthError::CONNECTION_FAILED); 1087 return AuthError(AuthError::CONNECTION_FAILED);
1178 } 1088 }
1179 } 1089 }
1180 1090
1181 } // namespace 1091 } // namespace
1182 1092
1183 void ProfileSyncService::OnConnectionStatusChange( 1093 void ProfileSyncService::OnConnectionStatusChange(
1184 syncer::ConnectionStatus status) { 1094 syncer::ConnectionStatus status) {
1185 if (use_oauth2_token_ && status == syncer::CONNECTION_AUTH_ERROR) { 1095 if (use_oauth2_token_ && status == syncer::CONNECTION_AUTH_ERROR) {
1186 // Sync or Tango server returned error indicating that access token is 1096 // Sync server returned error indicating that access token is invalid. It
1187 // invalid. It could be either expired or access is revoked. Let's request 1097 // could be either expired or access is revoked. Let's request another
1188 // another access token and if access is revoked then request for token will 1098 // access token and if access is revoked then request for token will fail
1189 // fail with corresponding error. 1099 // with corresponding error.
1190 RequestAccessToken(); 1100 RequestAccessToken();
1191 } else { 1101 } else {
1192 const GoogleServiceAuthError auth_error = 1102 const GoogleServiceAuthError auth_error =
1193 ConnectionStatusToAuthError(status); 1103 ConnectionStatusToAuthError(status);
1194 DVLOG(1) << "Connection status change: " << auth_error.ToString(); 1104 DVLOG(1) << "Connection status change: " << auth_error.ToString();
1195 UpdateAuthErrorState(auth_error); 1105 UpdateAuthErrorState(auth_error);
1196 } 1106 }
1197 } 1107 }
1198 1108
1199 void ProfileSyncService::OnStopSyncingPermanently() { 1109 void ProfileSyncService::OnStopSyncingPermanently() {
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after
2194 void ProfileSyncService::OnInternalUnrecoverableError( 2104 void ProfileSyncService::OnInternalUnrecoverableError(
2195 const tracked_objects::Location& from_here, 2105 const tracked_objects::Location& from_here,
2196 const std::string& message, 2106 const std::string& message,
2197 bool delete_sync_database, 2107 bool delete_sync_database,
2198 UnrecoverableErrorReason reason) { 2108 UnrecoverableErrorReason reason) {
2199 DCHECK(!HasUnrecoverableError()); 2109 DCHECK(!HasUnrecoverableError());
2200 unrecoverable_error_reason_ = reason; 2110 unrecoverable_error_reason_ = reason;
2201 OnUnrecoverableErrorImpl(from_here, message, delete_sync_database); 2111 OnUnrecoverableErrorImpl(from_here, message, delete_sync_database);
2202 } 2112 }
2203 2113
2204 void ProfileSyncService::UpdateInvalidatorRegistrarState() {
2205 const syncer::InvalidatorState effective_state =
2206 backend_initialized_ ?
2207 invalidator_state_ : syncer::TRANSIENT_INVALIDATION_ERROR;
2208 DVLOG(1) << "New invalidator state: "
2209 << syncer::InvalidatorStateToString(invalidator_state_)
2210 << ", effective state: "
2211 << syncer::InvalidatorStateToString(effective_state);
2212 invalidator_registrar_->UpdateInvalidatorState(effective_state);
2213 }
2214
2215 std::string ProfileSyncService::GetEffectiveUsername() { 2114 std::string ProfileSyncService::GetEffectiveUsername() {
2216 #if defined(ENABLE_MANAGED_USERS) 2115 #if defined(ENABLE_MANAGED_USERS)
2217 if (ManagedUserService::ProfileIsManaged(profile_)) { 2116 if (ManagedUserService::ProfileIsManaged(profile_)) {
2218 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername()); 2117 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername());
2219 return ManagedUserService::GetManagedUserPseudoEmail(); 2118 return ManagedUserService::GetManagedUserPseudoEmail();
2220 } 2119 }
2221 #endif 2120 #endif
2222 2121
2223 return signin_->GetAuthenticatedUsername(); 2122 return signin_->GetAuthenticatedUsername();
2224 } 2123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698