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