diff options
author | Ben Murdoch <benm@google.com> | 2013-07-10 11:40:50 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2013-07-10 11:40:50 +0100 |
commit | eb525c5499e34cc9c4b825d6d9e75bb07cc06ace (patch) | |
tree | d908ce4bfe1717d2cd53f41327d8b9ba8304355f /chrome/browser/sync/profile_sync_service.cc | |
parent | 3c54152607de4272b3da0c146b71dcba8a0e5610 (diff) | |
download | chromium_org-eb525c5499e34cc9c4b825d6d9e75bb07cc06ace.tar.gz |
Merge from Chromium at DEPS revision r210036
This commit was generated by merge_to_master.py.
Change-Id: Ib0e33a83ad5dfa541481e83d7acfc6970e68f471
Diffstat (limited to 'chrome/browser/sync/profile_sync_service.cc')
-rw-r--r-- | chrome/browser/sync/profile_sync_service.cc | 198 |
1 files changed, 41 insertions, 157 deletions
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index bbc69cf44c..26f26d14cb 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -22,11 +22,9 @@ #include "base/strings/stringprintf.h" #include "base/threading/thread_restrictions.h" #include "build/build_config.h" -#include "chrome/browser/about_flags.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/defaults.h" #include "chrome/browser/net/chrome_cookie_notification_details.h" -#include "chrome/browser/pref_service_flags_storage.h" #include "chrome/browser/prefs/pref_service_syncable.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/signin/about_signin_internals.h" @@ -68,6 +66,7 @@ #include "google_apis/gaia/gaia_constants.h" #include "grit/generated_resources.h" #include "net/cookies/cookie_monster.h" +#include "net/url_request/url_request_context_getter.h" #include "sync/api/sync_error.h" #include "sync/internal_api/public/configure_reason.h" #include "sync/internal_api/public/sync_encryption_handler.h" @@ -75,8 +74,6 @@ #include "sync/internal_api/public/util/sync_string_conversions.h" #include "sync/js/js_arg_list.h" #include "sync/js/js_event_details.h" -#include "sync/notifier/invalidator_registrar.h" -#include "sync/notifier/invalidator_state.h" #include "sync/util/cryptographer.h" #include "ui/base/l10n/l10n_util.h" @@ -116,10 +113,11 @@ static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. static const char* kOAuth2Scopes[] = { GaiaConstants::kChromeSyncOAuth2Scope, - // GoogleTalk scope is needed for notifications. - GaiaConstants::kGoogleTalkOAuth2Scope }; +static const char* kManagedOAuth2Scopes[] = { + GaiaConstants::kChromeSyncManagedOAuth2Scope +}; static const char* kSyncUnrecoverableErrorHistogram = "Sync.UnrecoverableErrors"; @@ -169,7 +167,6 @@ ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, profile_(profile), // |profile| may be NULL in unit tests. sync_prefs_(profile_ ? profile_->GetPrefs() : NULL), - invalidator_storage_(profile_ ? profile_->GetPrefs(): NULL), sync_service_url_(kDevServerUrl), data_type_requested_sync_startup_(false), is_first_time_sync_configure_(false), @@ -186,7 +183,6 @@ ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, auto_start_enabled_(start_behavior == AUTO_START), configure_status_(DataTypeManager::UNKNOWN), setup_in_progress_(false), - invalidator_state_(syncer::DEFAULT_INVALIDATION_ERROR), request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy) { // By default, dev, canary, and unbranded Chromium users will go to the // development servers. Development servers have more features than standard @@ -239,9 +235,6 @@ bool ProfileSyncService::IsOAuthRefreshTokenAvailable() { } void ProfileSyncService::Initialize() { - DCHECK(!invalidator_registrar_.get()); - invalidator_registrar_.reset(new syncer::InvalidatorRegistrar()); - InitSettings(); // We clear this here (vs Shutdown) because we want to remember that an error @@ -506,8 +499,7 @@ void ProfileSyncService::InitializeBackend(bool delete_stale_data) { void ProfileSyncService::CreateBackend() { backend_.reset( new SyncBackendHost(profile_->GetDebugName(), - profile_, sync_prefs_.AsWeakPtr(), - invalidator_storage_.AsWeakPtr())); + profile_, sync_prefs_.AsWeakPtr())); } bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { @@ -633,60 +625,6 @@ void ProfileSyncService::StartUpSlowBackendComponents() { // we'll want to start from a fresh SyncDB, so delete any old one that might // be there. InitializeBackend(!HasSyncSetupCompleted()); - - // |backend_| may end up being NULL here in tests (in synchronous - // initialization mode). - // - // TODO(akalin): Fix this horribly non-intuitive behavior (see - // http://crbug.com/140354). - if (backend_) { - backend_->UpdateRegisteredInvalidationIds( - invalidator_registrar_->GetAllRegisteredIds()); - for (AckHandleReplayQueue::const_iterator it = ack_replay_queue_.begin(); - it != ack_replay_queue_.end(); ++it) { - backend_->AcknowledgeInvalidation(it->first, it->second); - } - ack_replay_queue_.clear(); - } -} - -void ProfileSyncService::RegisterInvalidationHandler( - syncer::InvalidationHandler* handler) { - invalidator_registrar_->RegisterHandler(handler); -} - -void ProfileSyncService::UpdateRegisteredInvalidationIds( - syncer::InvalidationHandler* handler, - const syncer::ObjectIdSet& ids) { - invalidator_registrar_->UpdateRegisteredIds(handler, ids); - - // If |backend_| is NULL, its registered IDs will be updated when - // it's created and initialized. - if (backend_) { - backend_->UpdateRegisteredInvalidationIds( - invalidator_registrar_->GetAllRegisteredIds()); - } -} - -void ProfileSyncService::UnregisterInvalidationHandler( - syncer::InvalidationHandler* handler) { - invalidator_registrar_->UnregisterHandler(handler); -} - -void ProfileSyncService::AcknowledgeInvalidation( - const invalidation::ObjectId& id, - const syncer::AckHandle& ack_handle) { - if (backend_) { - backend_->AcknowledgeInvalidation(id, ack_handle); - } else { - // If |backend_| is NULL, save the acknowledgements to replay when - // it's created and initialized. - ack_replay_queue_.push_back(std::make_pair(id, ack_handle)); - } -} - -syncer::InvalidatorState ProfileSyncService::GetInvalidatorState() const { - return invalidator_registrar_->GetInvalidatorState(); } void ProfileSyncService::OnGetTokenSuccess( @@ -750,23 +688,7 @@ void ProfileSyncService::OnGetTokenFailure( } } -void ProfileSyncService::EmitInvalidationForTest( - const invalidation::ObjectId& id, - const std::string& payload) { - syncer::ObjectIdSet notify_ids; - notify_ids.insert(id); - - const syncer::ObjectIdInvalidationMap& invalidation_map = - ObjectIdSetToInvalidationMap(notify_ids, payload); - OnIncomingInvalidation(invalidation_map); -} - void ProfileSyncService::Shutdown() { - DCHECK(invalidator_registrar_.get()); - // Reset |invalidator_registrar_| first so that ShutdownImpl cannot - // use it. - invalidator_registrar_.reset(); - if (signin_) signin_->signin_global_error()->RemoveProvider(this); @@ -821,9 +743,6 @@ void ProfileSyncService::ShutdownImpl(bool sync_disabled) { expect_sync_configuration_aborted_ = false; is_auth_in_progress_ = false; backend_initialized_ = false; - // NULL if we're called from Shutdown(). - if (invalidator_registrar_) - UpdateInvalidatorRegistrarState(); cached_passphrase_.clear(); encryption_pending_ = false; encrypt_everything_ = false; @@ -848,7 +767,6 @@ void ProfileSyncService::DisableForUser() { // Clear prefs (including SyncSetupHasCompleted) before shutting down so // PSS clients don't think we're set up while we're shutting down. sync_prefs_.ClearPreferences(); - invalidator_storage_.Clear(); ClearUnrecoverableError(); ShutdownImpl(true); } @@ -870,6 +788,11 @@ void ProfileSyncService::NotifyObservers() { FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); // TODO(akalin): Make an Observer subclass that listens and does the // event routing. + sync_js_controller_.HandleJsEvent("onServiceStateChanged", JsEventDetails()); +} + +void ProfileSyncService::NotifySyncCycleCompleted() { + FOR_EACH_OBSERVER(Observer, observers_, OnSyncCycleCompleted()); sync_js_controller_.HandleJsEvent( "onServiceStateChanged", JsEventDetails()); } @@ -887,14 +810,6 @@ void ProfileSyncService::ClearUnrecoverableError() { unrecoverable_error_location_ = tracked_objects::Location(); } -// static -// TODO(sync): Consider having syncer::Experiments provide this. -std::string ProfileSyncService::GetExperimentNameForDataType( - syncer::ModelType data_type) { - NOTREACHED(); - return std::string(); -} - void ProfileSyncService::RegisterNewDataType(syncer::ModelType data_type) { if (data_type_controllers_.count(data_type) > 0) return; @@ -945,33 +860,23 @@ void ProfileSyncService::DisableBrokenDatatype( // passed onto the change processor. DeactivateDataType(type); - syncer::SyncError error(from_here, message, type); + syncer::SyncError error(from_here, + syncer::SyncError::DATATYPE_ERROR, + message, + type); std::map<syncer::ModelType, syncer::SyncError> errors; errors[type] = error; // Update this before posting a task. So if a configure happens before // the task that we are going to post, this type would still be disabled. - failed_data_types_handler_.UpdateFailedDataTypes( - errors, - FailedDataTypesHandler::RUNTIME); + failed_data_types_handler_.UpdateFailedDataTypes(errors); base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, weak_factory_.GetWeakPtr())); } -void ProfileSyncService::OnInvalidatorStateChange( - syncer::InvalidatorState state) { - invalidator_state_ = state; - UpdateInvalidatorRegistrarState(); -} - -void ProfileSyncService::OnIncomingInvalidation( - const syncer::ObjectIdInvalidationMap& invalidation_map) { - invalidator_registrar_->DispatchInvalidationsToHandlers(invalidation_map); -} - void ProfileSyncService::OnBackendInitialized( const syncer::WeakHandle<syncer::JsBackend>& js_backend, const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& @@ -1015,7 +920,6 @@ void ProfileSyncService::OnBackendInitialized( } backend_initialized_ = true; - UpdateInvalidatorRegistrarState(); sync_js_controller_.AttachJsBackend(js_backend); debug_info_listener_ = debug_info_listener; @@ -1064,7 +968,7 @@ void ProfileSyncService::OnSyncCycleCompleted() { GetSessionModelAssociator()->AsWeakPtr())); } DVLOG(2) << "Notifying observers sync cycle completed"; - NotifyObservers(); + NotifySyncCycleCompleted(); } void ProfileSyncService::OnExperimentsChanged( @@ -1091,24 +995,11 @@ void ProfileSyncService::OnExperimentsChanged( << syncer::ModelTypeSetToString(to_add); DVLOG(2) << "Enabling types: " << syncer::ModelTypeSetToString(to_register); - about_flags::PrefServiceFlagsStorage flags_storage_( - g_browser_process->local_state()); - for (syncer::ModelTypeSet::Iterator it = to_register.First(); it.Good(); it.Inc()) { // Received notice to enable experimental type. Check if the type is // registered, and if not register a new datatype controller. RegisterNewDataType(it.Get()); - // Enable the about:flags switch for the experimental type so we don't have - // to always perform this reconfiguration. Once we set this, the type will - // remain registered on restart, so we will no longer go down this code - // path. - std::string experiment_name = GetExperimentNameForDataType(it.Get()); - if (experiment_name.empty()) - continue; - about_flags::SetExperimentEnabled(&flags_storage_, - experiment_name, - true); } // Check if the user has "Keep Everything Synced" enabled. If so, we want @@ -1130,18 +1021,8 @@ void ProfileSyncService::OnExperimentsChanged( } } - // Now enable any non-datatype features. - if (experiments.keystore_encryption) { - about_flags::SetExperimentEnabled(&flags_storage_, - syncer::kKeystoreEncryptionFlag, - true); - } - - if (experiments.favicon_sync) { - about_flags::SetExperimentEnabled(&flags_storage_, - syncer::kFaviconSyncFlag, - true); - } + if (experiments.favicon_sync) + profile_->GetPrefs()->SetBoolean(prefs::kSyncFaviconsEnabled, true); current_experiments_ = experiments; } @@ -1183,10 +1064,10 @@ AuthError ConnectionStatusToAuthError( void ProfileSyncService::OnConnectionStatusChange( syncer::ConnectionStatus status) { if (use_oauth2_token_ && status == syncer::CONNECTION_AUTH_ERROR) { - // Sync or Tango server returned error indicating that access token is - // invalid. It could be either expired or access is revoked. Let's request - // another access token and if access is revoked then request for token will - // fail with corresponding error. + // Sync server returned error indicating that access token is invalid. It + // could be either expired or access is revoked. Let's request another + // access token and if access is revoked then request for token will fail + // with corresponding error. RequestAccessToken(); } else { const GoogleServiceAuthError auth_error = @@ -1321,8 +1202,12 @@ void ProfileSyncService::OnActionableError(const SyncProtocolError& error) { break; case syncer::DISABLE_SYNC_ON_CLIENT: OnStopSyncingPermanently(); - // TODO(rsimha): Re-evaluate whether to also sign out the user here after - // a dashboard clear. See http://crbug.com/240436. +#if !defined(OS_CHROMEOS) + // On desktop Chrome, sign out the user after a dashboard clear. + // TODO(rsimha): Revisit this for M30. See http://crbug.com/252049. + if (!auto_start_enabled_) // Skip sign out on ChromeOS/Android. + SigninManagerFactory::GetForProfile(profile_)->SignOut(); +#endif break; case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT: // Sync disabled by domain admin. we should stop syncing until next @@ -1393,7 +1278,7 @@ void ProfileSyncService::OnConfigureDone( std::string message = "Sync configuration failed with status " + DataTypeManager::ConfigureStatusToString(configure_status_) + - " during " + syncer::ModelTypeToString(error.type()) + + " during " + syncer::ModelTypeToString(error.model_type()) + ": " + error.message(); LOG(ERROR) << "ProfileSyncService error: " << message; OnInternalUnrecoverableError(error.location(), @@ -1923,8 +1808,18 @@ void ProfileSyncService::RequestAccessToken() { return; request_access_token_retry_timer_.Stop(); OAuth2TokenService::ScopeSet oauth2_scopes; - for (size_t i = 0; i < arraysize(kOAuth2Scopes); i++) - oauth2_scopes.insert(kOAuth2Scopes[i]); + bool is_managed = false; +#if defined(ENABLE_MANAGED_USERS) + is_managed = ManagedUserService::ProfileIsManaged(profile_); +#endif + if (is_managed) { + for (size_t i = 0; i < arraysize(kManagedOAuth2Scopes); i++) + oauth2_scopes.insert(kManagedOAuth2Scopes[i]); + } else { + for (size_t i = 0; i < arraysize(kOAuth2Scopes); i++) + oauth2_scopes.insert(kOAuth2Scopes[i]); + } + OAuth2TokenService* token_service = ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); // Invalidate previous token, otherwise token service will return the same @@ -2201,17 +2096,6 @@ void ProfileSyncService::OnInternalUnrecoverableError( OnUnrecoverableErrorImpl(from_here, message, delete_sync_database); } -void ProfileSyncService::UpdateInvalidatorRegistrarState() { - const syncer::InvalidatorState effective_state = - backend_initialized_ ? - invalidator_state_ : syncer::TRANSIENT_INVALIDATION_ERROR; - DVLOG(1) << "New invalidator state: " - << syncer::InvalidatorStateToString(invalidator_state_) - << ", effective state: " - << syncer::InvalidatorStateToString(effective_state); - invalidator_registrar_->UpdateInvalidatorState(effective_state); -} - std::string ProfileSyncService::GetEffectiveUsername() { #if defined(ENABLE_MANAGED_USERS) if (ManagedUserService::ProfileIsManaged(profile_)) { |