Chromium Code Reviews| Index: chrome/browser/supervised_user/supervised_user_service.cc |
| diff --git a/chrome/browser/supervised_user/supervised_user_service.cc b/chrome/browser/supervised_user/supervised_user_service.cc |
| index 316af32ac82554b2ed19d0640ba9730f00f905ab..2923f440fe35320b15aaeb6b67468d638e918243 100644 |
| --- a/chrome/browser/supervised_user/supervised_user_service.cc |
| +++ b/chrome/browser/supervised_user/supervised_user_service.cc |
| @@ -217,11 +217,8 @@ void SupervisedUserService::Shutdown() { |
| } |
| SetActive(false); |
| - ProfileSyncService* sync_service = |
| - ProfileSyncServiceFactory::GetForProfile(profile_); |
| - // Can be null in tests. |
| - if (sync_service) |
| - sync_service->RemovePreferenceProvider(this); |
| + if (profile_sync_service_) |
| + profile_sync_service_->RemovePreferenceProvider(this); |
| } |
| bool SupervisedUserService::ProfileIsSupervised() const { |
| @@ -412,8 +409,9 @@ void SupervisedUserService::OnHistoryRecordingStateChanged() { |
| bool record_history = |
| profile_->GetPrefs()->GetBoolean(prefs::kRecordHistory); |
| includes_sync_sessions_type_ = record_history; |
| - ProfileSyncServiceFactory::GetForProfile(profile_) |
| - ->ReconfigureDatatypeManager(); |
| + |
| + if (profile_sync_service_) |
| + profile_sync_service_->ReconfigureDatatypeManager(); |
| } |
| bool SupervisedUserService::IncludesSyncSessionsType() const { |
| @@ -421,17 +419,17 @@ bool SupervisedUserService::IncludesSyncSessionsType() const { |
| } |
| void SupervisedUserService::OnStateChanged() { |
| - ProfileSyncService* service = |
| - ProfileSyncServiceFactory::GetForProfile(profile_); |
| - if (waiting_for_sync_initialization_ && service->backend_initialized() && |
| - service->backend_mode() == ProfileSyncService::SYNC) { |
| + if (waiting_for_sync_initialization_ && |
| + profile_sync_service_ && |
| + profile_sync_service_->backend_initialized() && |
| + profile_sync_service_->backend_mode() == ProfileSyncService::SYNC) { |
| waiting_for_sync_initialization_ = false; |
| - service->RemoveObserver(this); |
| + profile_sync_service_->RemoveObserver(this); |
| FinishSetupSync(); |
| return; |
| } |
| - DLOG_IF(ERROR, service->GetAuthError().state() == |
| + DLOG_IF(ERROR, profile_sync_service_->GetAuthError().state() == |
| GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS) |
| << "Credentials rejected"; |
| } |
| @@ -444,40 +442,41 @@ void SupervisedUserService::SetupSync() { |
| void SupervisedUserService::StartSetupSync() { |
| // Tell the sync service that setup is in progress so we don't start syncing |
| // until we've finished configuration. |
| - ProfileSyncServiceFactory::GetForProfile(profile_)->SetSetupInProgress(true); |
| + if (profile_sync_service_) |
| + profile_sync_service_->SetSetupInProgress(true); |
| } |
| void SupervisedUserService::FinishSetupSyncWhenReady() { |
| // If we're already waiting for the Sync backend, there's nothing to do here. |
| - if (waiting_for_sync_initialization_) |
| + if (waiting_for_sync_initialization_ || !profile_sync_service_) |
| return; |
| // Continue in FinishSetupSync() once the Sync backend has been initialized. |
| - ProfileSyncService* service = |
| - ProfileSyncServiceFactory::GetForProfile(profile_); |
| - if (service->backend_initialized() && |
| - service->backend_mode() == ProfileSyncService::SYNC) { |
| + if (profile_sync_service_->backend_initialized() && |
| + profile_sync_service_->backend_mode() == ProfileSyncService::SYNC) { |
| FinishSetupSync(); |
| } else { |
| - service->AddObserver(this); |
| + profile_sync_service_->AddObserver(this); |
| waiting_for_sync_initialization_ = true; |
| } |
| } |
| void SupervisedUserService::FinishSetupSync() { |
| - ProfileSyncService* service = |
| - ProfileSyncServiceFactory::GetForProfile(profile_); |
| - DCHECK(service->backend_initialized()); |
| - DCHECK(service->backend_mode() == ProfileSyncService::SYNC); |
| + if (!profile_sync_service_) |
| + return; |
| + |
| + DCHECK(profile_sync_service_->backend_initialized()); |
| + DCHECK(profile_sync_service_->backend_mode() == ProfileSyncService::SYNC); |
| // Sync nothing (except types which are set via GetPreferredDataTypes). |
| bool sync_everything = false; |
| syncer::ModelTypeSet synced_datatypes; |
| - service->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| + profile_sync_service_->OnUserChoseDatatypes(sync_everything, |
| + synced_datatypes); |
| // Notify ProfileSyncService that we are done with configuration. |
| - service->SetSetupInProgress(false); |
| - service->SetSyncSetupCompleted(); |
| + profile_sync_service_->SetSetupInProgress(false); |
| + profile_sync_service_->SetSyncSetupCompleted(); |
| } |
| #if defined(ENABLE_EXTENSIONS) |
| @@ -642,6 +641,8 @@ void SupervisedUserService::Init() { |
| DCHECK(!did_init_); |
| did_init_ = true; |
| DCHECK(GetSettingsService()->IsReady()); |
| + profile_sync_service_ = |
|
Alexei Svitkine (slow)
2015/02/19 22:04:08
Initialize this in the ctor too, or some bots will
Mike Lerman
2015/02/20 16:38:01
Done.
|
| + ProfileSyncServiceFactory::GetForProfile(profile_); |
| pref_change_registrar_.Init(profile_->GetPrefs()); |
| pref_change_registrar_.Add( |
| @@ -653,11 +654,8 @@ void SupervisedUserService::Init() { |
| base::Bind(&SupervisedUserService::OnHistoryRecordingStateChanged, |
| base::Unretained(this))); |
| - ProfileSyncService* sync_service = |
| - ProfileSyncServiceFactory::GetForProfile(profile_); |
| - // Can be null in tests. |
| - if (sync_service) |
| - sync_service->AddPreferenceProvider(this); |
| + if (profile_sync_service_) |
| + profile_sync_service_->AddPreferenceProvider(this); |
| std::string client_id = component_updater::SupervisedUserWhitelistInstaller:: |
| ClientIdForProfilePath(profile_->GetPath()); |
| @@ -697,11 +695,12 @@ void SupervisedUserService::SetActive(bool active) { |
| GetSettingsService(), |
| SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( |
| profile_), |
| - ProfileSyncServiceFactory::GetForProfile(profile_), |
| + profile_sync_service_, |
| GetSupervisedUserName(), |
| profile_->GetPrefs()->GetString(prefs::kSupervisedUserId))); |
| - SetupSync(); |
| + if (profile_sync_service_) |
| + SetupSync(); |
| } |
| } |
| @@ -715,9 +714,8 @@ void SupervisedUserService::SetActive(bool active) { |
| } |
| #endif |
| - ProfileSyncService* sync_service = |
| - ProfileSyncServiceFactory::GetForProfile(profile_); |
| - sync_service->SetEncryptEverythingAllowed(!active_); |
| + if (profile_sync_service_) |
| + profile_sync_service_->SetEncryptEverythingAllowed(!active_); |
| GetSettingsService()->SetActive(active_); |
| @@ -784,8 +782,8 @@ void SupervisedUserService::SetActive(bool active) { |
| FOR_EACH_OBSERVER( |
| SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
| - if (waiting_for_sync_initialization_) |
| - ProfileSyncServiceFactory::GetForProfile(profile_)->RemoveObserver(this); |
| + if (waiting_for_sync_initialization_ && profile_sync_service_) |
| + profile_sync_service_->RemoveObserver(this); |
| #if !defined(OS_ANDROID) |
| // TODO(bauerb): Get rid of the platform-specific #ifdef here. |