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 a5cae02584aa041052631496eb6c15b6e5630bdd..91ab941e9a8d098d3c9ccbd6e134f459020a1e43 100644 |
| --- a/chrome/browser/supervised_user/supervised_user_service.cc |
| +++ b/chrome/browser/supervised_user/supervised_user_service.cc |
| @@ -141,21 +141,27 @@ SupervisedUserService::SupervisedUserService(Profile* profile) |
| waiting_for_sync_initialization_(false), |
| is_profile_active_(false), |
| elevated_for_testing_(false), |
| + did_init_(false), |
| did_shutdown_(false), |
| waiting_for_permissions_(false), |
| weak_ptr_factory_(this) { |
| } |
| SupervisedUserService::~SupervisedUserService() { |
| - DCHECK(did_shutdown_); |
| + DCHECK(!did_init_ || did_shutdown_); |
| } |
| void SupervisedUserService::Shutdown() { |
| + if (!did_init_ || did_shutdown_) |
|
Bernhard Bauer
2014/08/11 08:48:21
When would we call Shutdown() more than once?
Marc Treib
2014/08/11 08:57:09
Ah, that was unclear - actually I'm not sure if we
Bernhard Bauer
2014/08/11 09:07:13
I'm not sure what you mean by that -- right now yo
Marc Treib
2014/08/11 09:35:44
Done.
|
| + return; |
| did_shutdown_ = true; |
| if (ProfileIsSupervised()) { |
| content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); |
| } |
| SetActive(false); |
| + |
| + ProfileSyncServiceFactory::GetForProfile(profile_)->RemovePreferenceProvider( |
| + this); |
| } |
| bool SupervisedUserService::ProfileIsSupervised() const { |
| @@ -335,6 +341,21 @@ void SupervisedUserService::OnExtensionUnloaded( |
| } |
| #endif // defined(ENABLE_EXTENSIONS) |
| +syncer::ModelTypeSet SupervisedUserService::GetPreferredDataTypes() { |
| + if (!ProfileIsSupervised()) |
| + return syncer::ModelTypeSet(); |
| + |
| + syncer::ModelTypeSet result; |
| + result.Put(syncer::SESSIONS); |
| + result.Put(syncer::EXTENSIONS); |
| + result.Put(syncer::EXTENSION_SETTINGS); |
| + result.Put(syncer::APPS); |
| + result.Put(syncer::APP_SETTINGS); |
| + result.Put(syncer::APP_NOTIFICATIONS); |
| + result.Put(syncer::APP_LIST); |
| + return result; |
| +} |
| + |
| void SupervisedUserService::OnStateChanged() { |
| ProfileSyncService* service = |
| ProfileSyncServiceFactory::GetForProfile(profile_); |
| @@ -382,11 +403,9 @@ void SupervisedUserService::FinishSetupSync() { |
| ProfileSyncServiceFactory::GetForProfile(profile_); |
| DCHECK(service->sync_initialized()); |
| + // Sync nothing (except types which are set via GetPreferredDataTypes). |
| bool sync_everything = false; |
| syncer::ModelTypeSet synced_datatypes; |
| - synced_datatypes.Put(syncer::SESSIONS); |
| - synced_datatypes.Put(syncer::APPS); |
| - synced_datatypes.Put(syncer::EXTENSIONS); |
| service->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| // Notify ProfileSyncService that we are done with configuration. |
| @@ -567,6 +586,8 @@ void SupervisedUserService::InitSync(const std::string& refresh_token) { |
| } |
| void SupervisedUserService::Init() { |
| + DCHECK(!did_init_); |
| + did_init_ = true; |
| DCHECK(GetSettingsService()->IsReady()); |
| pref_change_registrar_.Init(profile_->GetPrefs()); |
| @@ -575,6 +596,9 @@ void SupervisedUserService::Init() { |
| base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, |
| base::Unretained(this))); |
| + ProfileSyncServiceFactory::GetForProfile(profile_)->AddPreferenceProvider( |
| + this); |
| + |
| SetActive(ProfileIsSupervised()); |
| } |
| @@ -666,11 +690,8 @@ void SupervisedUserService::SetActive(bool active) { |
| pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); |
| pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); |
| - if (waiting_for_sync_initialization_) { |
| - ProfileSyncService* sync_service = |
| - ProfileSyncServiceFactory::GetForProfile(profile_); |
| - sync_service->RemoveObserver(this); |
| - } |
| + if (waiting_for_sync_initialization_) |
| + ProfileSyncServiceFactory::GetForProfile(profile_)->RemoveObserver(this); |
| #if !defined(OS_ANDROID) |
| // TODO(bauerb): Get rid of the platform-specific #ifdef here. |