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