OLD | NEW |
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // sync servers. Users with officially-branded Chrome stable and beta builds | 155 // sync servers. Users with officially-branded Chrome stable and beta builds |
156 // will go to the standard sync servers. | 156 // will go to the standard sync servers. |
157 // | 157 // |
158 // GetChannel hits the registry on Windows. See http://crbug.com/70380. | 158 // GetChannel hits the registry on Windows. See http://crbug.com/70380. |
159 base::ThreadRestrictions::ScopedAllowIO allow_io; | 159 base::ThreadRestrictions::ScopedAllowIO allow_io; |
160 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 160 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
161 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 161 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
162 channel == chrome::VersionInfo::CHANNEL_BETA) { | 162 channel == chrome::VersionInfo::CHANNEL_BETA) { |
163 sync_service_url_ = GURL(kSyncServerUrl); | 163 sync_service_url_ = GURL(kSyncServerUrl); |
164 } | 164 } |
165 if (signin_) | |
166 signin_->signin_global_error()->AddProvider(this); | |
167 } | 165 } |
168 | 166 |
169 ProfileSyncService::~ProfileSyncService() { | 167 ProfileSyncService::~ProfileSyncService() { |
170 sync_prefs_.RemoveSyncPrefObserver(this); | 168 sync_prefs_.RemoveSyncPrefObserver(this); |
171 // Shutdown() should have been called before destruction. | 169 // Shutdown() should have been called before destruction. |
172 CHECK(!backend_initialized_); | 170 CHECK(!backend_initialized_); |
173 } | 171 } |
174 | 172 |
175 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { | 173 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { |
176 // Exit if sync is disabled. | 174 // Exit if sync is disabled. |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 ObjectIdSetToInvalidationMap(notify_ids, payload); | 525 ObjectIdSetToInvalidationMap(notify_ids, payload); |
528 OnIncomingInvalidation(invalidation_map, syncer::REMOTE_INVALIDATION); | 526 OnIncomingInvalidation(invalidation_map, syncer::REMOTE_INVALIDATION); |
529 } | 527 } |
530 | 528 |
531 void ProfileSyncService::Shutdown() { | 529 void ProfileSyncService::Shutdown() { |
532 DCHECK(invalidator_registrar_.get()); | 530 DCHECK(invalidator_registrar_.get()); |
533 // Reset |invalidator_registrar_| first so that ShutdownImpl cannot | 531 // Reset |invalidator_registrar_| first so that ShutdownImpl cannot |
534 // use it. | 532 // use it. |
535 invalidator_registrar_.reset(); | 533 invalidator_registrar_.reset(); |
536 | 534 |
537 if (signin_) | |
538 signin_->signin_global_error()->RemoveProvider(this); | |
539 | |
540 ShutdownImpl(false); | 535 ShutdownImpl(false); |
541 } | 536 } |
542 | 537 |
543 void ProfileSyncService::ShutdownImpl(bool sync_disabled) { | 538 void ProfileSyncService::ShutdownImpl(bool sync_disabled) { |
544 // First, we spin down the backend and wait for it to stop syncing completely | 539 // First, we spin down the backend and wait for it to stop syncing completely |
545 // before we Stop the data type manager. This is to avoid a late sync cycle | 540 // before we Stop the data type manager. This is to avoid a late sync cycle |
546 // applying changes to the sync db that wouldn't get applied via | 541 // applying changes to the sync db that wouldn't get applied via |
547 // ChangeProcessors, leading to back-from-the-dead bugs. | 542 // ChangeProcessors, leading to back-from-the-dead bugs. |
548 base::Time shutdown_start_time = base::Time::Now(); | 543 base::Time shutdown_start_time = base::Time::Now(); |
549 if (backend_.get()) { | 544 if (backend_.get()) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 is_auth_in_progress_ = false; | 583 is_auth_in_progress_ = false; |
589 backend_initialized_ = false; | 584 backend_initialized_ = false; |
590 // NULL if we're called from Shutdown(). | 585 // NULL if we're called from Shutdown(). |
591 if (invalidator_registrar_.get()) | 586 if (invalidator_registrar_.get()) |
592 UpdateInvalidatorRegistrarState(); | 587 UpdateInvalidatorRegistrarState(); |
593 cached_passphrase_.clear(); | 588 cached_passphrase_.clear(); |
594 encryption_pending_ = false; | 589 encryption_pending_ = false; |
595 encrypt_everything_ = false; | 590 encrypt_everything_ = false; |
596 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes(); | 591 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes(); |
597 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; | 592 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; |
598 // Revert to "no auth error". | 593 last_auth_error_ = AuthError::None(); |
599 if (last_auth_error_.state() != GoogleServiceAuthError::NONE) | |
600 UpdateAuthErrorState(GoogleServiceAuthError::None()); | |
601 | 594 |
602 if (sync_global_error_.get()) { | 595 if (sync_global_error_.get()) { |
603 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( | 596 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( |
604 sync_global_error_.get()); | 597 sync_global_error_.get()); |
605 RemoveObserver(sync_global_error_.get()); | 598 RemoveObserver(sync_global_error_.get()); |
606 sync_global_error_.reset(NULL); | 599 sync_global_error_.reset(NULL); |
607 } | 600 } |
608 } | 601 } |
609 | 602 |
610 void ProfileSyncService::DisableForUser() { | 603 void ProfileSyncService::DisableForUser() { |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 | 909 |
917 current_experiments_ = experiments; | 910 current_experiments_ = experiments; |
918 } | 911 } |
919 | 912 |
920 void ProfileSyncService::UpdateAuthErrorState(const AuthError& error) { | 913 void ProfileSyncService::UpdateAuthErrorState(const AuthError& error) { |
921 is_auth_in_progress_ = false; | 914 is_auth_in_progress_ = false; |
922 last_auth_error_ = error; | 915 last_auth_error_ = error; |
923 | 916 |
924 // Fan the notification out to interested UI-thread components. | 917 // Fan the notification out to interested UI-thread components. |
925 NotifyObservers(); | 918 NotifyObservers(); |
926 if (signin()) | |
927 signin()->signin_global_error()->AuthStatusChanged(); | |
928 } | 919 } |
929 | 920 |
930 namespace { | 921 namespace { |
931 | 922 |
932 AuthError ConnectionStatusToAuthError( | 923 AuthError ConnectionStatusToAuthError( |
933 syncer::ConnectionStatus status) { | 924 syncer::ConnectionStatus status) { |
934 switch (status) { | 925 switch (status) { |
935 case syncer::CONNECTION_OK: | 926 case syncer::CONNECTION_OK: |
936 return AuthError::None(); | 927 return AuthError::None(); |
937 break; | 928 break; |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 status.sync_protocol_error = last_actionable_error_; | 1209 status.sync_protocol_error = last_actionable_error_; |
1219 *result = status; | 1210 *result = status; |
1220 return false; | 1211 return false; |
1221 } | 1212 } |
1222 } | 1213 } |
1223 | 1214 |
1224 const AuthError& ProfileSyncService::GetAuthError() const { | 1215 const AuthError& ProfileSyncService::GetAuthError() const { |
1225 return last_auth_error_; | 1216 return last_auth_error_; |
1226 } | 1217 } |
1227 | 1218 |
1228 GoogleServiceAuthError ProfileSyncService::GetAuthStatus() const { | |
1229 return GetAuthError(); | |
1230 } | |
1231 | |
1232 bool ProfileSyncService::FirstSetupInProgress() const { | 1219 bool ProfileSyncService::FirstSetupInProgress() const { |
1233 return !HasSyncSetupCompleted() && setup_in_progress_; | 1220 return !HasSyncSetupCompleted() && setup_in_progress_; |
1234 } | 1221 } |
1235 | 1222 |
1236 void ProfileSyncService::SetSetupInProgress(bool setup_in_progress) { | 1223 void ProfileSyncService::SetSetupInProgress(bool setup_in_progress) { |
1237 bool was_in_progress = setup_in_progress_; | 1224 bool was_in_progress = setup_in_progress_; |
1238 setup_in_progress_ = setup_in_progress; | 1225 setup_in_progress_ = setup_in_progress; |
1239 if (!setup_in_progress && was_in_progress) { | 1226 if (!setup_in_progress && was_in_progress) { |
1240 if (sync_initialized()) { | 1227 if (sync_initialized()) { |
1241 ReconfigureDatatypeManager(); | 1228 ReconfigureDatatypeManager(); |
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1926 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. | 1913 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. |
1927 ProfileSyncService* old_this = this; | 1914 ProfileSyncService* old_this = this; |
1928 this->~ProfileSyncService(); | 1915 this->~ProfileSyncService(); |
1929 new(old_this) ProfileSyncService( | 1916 new(old_this) ProfileSyncService( |
1930 new ProfileSyncComponentsFactoryImpl(profile, | 1917 new ProfileSyncComponentsFactoryImpl(profile, |
1931 CommandLine::ForCurrentProcess()), | 1918 CommandLine::ForCurrentProcess()), |
1932 profile, | 1919 profile, |
1933 signin, | 1920 signin, |
1934 behavior); | 1921 behavior); |
1935 } | 1922 } |
OLD | NEW |