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