| 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..1c941ae89952e223d5c1590aa9bcd43e10a30f72 100644
|
| --- a/chrome/browser/supervised_user/supervised_user_service.cc
|
| +++ b/chrome/browser/supervised_user/supervised_user_service.cc
|
| @@ -141,21 +141,31 @@ 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_)
|
| + return;
|
| + DCHECK(!did_shutdown_);
|
| did_shutdown_ = true;
|
| if (ProfileIsSupervised()) {
|
| content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser"));
|
| }
|
| SetActive(false);
|
| +
|
| + ProfileSyncService* sync_service =
|
| + ProfileSyncServiceFactory::GetForProfile(profile_);
|
| + // Can be null in tests.
|
| + if (sync_service)
|
| + sync_service->RemovePreferenceProvider(this);
|
| }
|
|
|
| bool SupervisedUserService::ProfileIsSupervised() const {
|
| @@ -335,6 +345,21 @@ void SupervisedUserService::OnExtensionUnloaded(
|
| }
|
| #endif // defined(ENABLE_EXTENSIONS)
|
|
|
| +syncer::ModelTypeSet SupervisedUserService::GetPreferredDataTypes() const {
|
| + 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 +407,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 +590,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 +600,12 @@ void SupervisedUserService::Init() {
|
| base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged,
|
| base::Unretained(this)));
|
|
|
| + ProfileSyncService* sync_service =
|
| + ProfileSyncServiceFactory::GetForProfile(profile_);
|
| + // Can be null in tests.
|
| + if (sync_service)
|
| + sync_service->AddPreferenceProvider(this);
|
| +
|
| SetActive(ProfileIsSupervised());
|
| }
|
|
|
| @@ -666,11 +697,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.
|
|
|