| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/supervised_user/supervised_user_service.h" | 5 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 pref_change_registrar_.Init(profile_->GetPrefs()); | 183 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 184 pref_change_registrar_.Add( | 184 pref_change_registrar_.Add( |
| 185 prefs::kSupervisedUserId, | 185 prefs::kSupervisedUserId, |
| 186 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, | 186 base::Bind(&SupervisedUserService::OnSupervisedUserIdChanged, |
| 187 base::Unretained(this))); | 187 base::Unretained(this))); |
| 188 pref_change_registrar_.Add( | 188 pref_change_registrar_.Add( |
| 189 prefs::kForceSessionSync, | 189 prefs::kForceSessionSync, |
| 190 base::Bind(&SupervisedUserService::OnForceSessionSyncChanged, | 190 base::Bind(&SupervisedUserService::OnForceSessionSyncChanged, |
| 191 base::Unretained(this))); | 191 base::Unretained(this))); |
| 192 | 192 |
| 193 ProfileSyncService* sync_service = | 193 browser_sync::ProfileSyncService* sync_service = |
| 194 ProfileSyncServiceFactory::GetForProfile(profile_); | 194 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 195 // Can be null in tests. | 195 // Can be null in tests. |
| 196 if (sync_service) | 196 if (sync_service) |
| 197 sync_service->AddPreferenceProvider(this); | 197 sync_service->AddPreferenceProvider(this); |
| 198 | 198 |
| 199 std::string client_id = component_updater::SupervisedUserWhitelistInstaller:: | 199 std::string client_id = component_updater::SupervisedUserWhitelistInstaller:: |
| 200 ClientIdForProfilePath(profile_->GetPath()); | 200 ClientIdForProfilePath(profile_->GetPath()); |
| 201 whitelist_service_.reset(new SupervisedUserWhitelistService( | 201 whitelist_service_.reset(new SupervisedUserWhitelistService( |
| 202 profile_->GetPrefs(), | 202 profile_->GetPrefs(), |
| 203 g_browser_process->supervised_user_whitelist_installer(), client_id)); | 203 g_browser_process->supervised_user_whitelist_installer(), client_id)); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 | 579 |
| 580 // Now activate/deactivate anything not handled by the delegate yet. | 580 // Now activate/deactivate anything not handled by the delegate yet. |
| 581 | 581 |
| 582 #if defined(ENABLE_THEMES) | 582 #if defined(ENABLE_THEMES) |
| 583 // Re-set the default theme to turn the SU theme on/off. | 583 // Re-set the default theme to turn the SU theme on/off. |
| 584 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_); | 584 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_); |
| 585 if (theme_service->UsingDefaultTheme() || theme_service->UsingSystemTheme()) | 585 if (theme_service->UsingDefaultTheme() || theme_service->UsingSystemTheme()) |
| 586 theme_service->UseDefaultTheme(); | 586 theme_service->UseDefaultTheme(); |
| 587 #endif | 587 #endif |
| 588 | 588 |
| 589 ProfileSyncService* sync_service = | 589 browser_sync::ProfileSyncService* sync_service = |
| 590 ProfileSyncServiceFactory::GetForProfile(profile_); | 590 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 591 sync_service->SetEncryptEverythingAllowed(!active_); | 591 sync_service->SetEncryptEverythingAllowed(!active_); |
| 592 | 592 |
| 593 GetSettingsService()->SetActive(active_); | 593 GetSettingsService()->SetActive(active_); |
| 594 | 594 |
| 595 #if defined(ENABLE_EXTENSIONS) | 595 #if defined(ENABLE_EXTENSIONS) |
| 596 SetExtensionsActive(); | 596 SetExtensionsActive(); |
| 597 #endif | 597 #endif |
| 598 | 598 |
| 599 if (active_) { | 599 if (active_) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 sync_blocker_ = ProfileSyncServiceFactory::GetForProfile(profile_) | 712 sync_blocker_ = ProfileSyncServiceFactory::GetForProfile(profile_) |
| 713 ->GetSetupInProgressHandle(); | 713 ->GetSetupInProgressHandle(); |
| 714 } | 714 } |
| 715 | 715 |
| 716 void SupervisedUserService::FinishSetupSyncWhenReady() { | 716 void SupervisedUserService::FinishSetupSyncWhenReady() { |
| 717 // If we're already waiting for the Sync backend, there's nothing to do here. | 717 // If we're already waiting for the Sync backend, there's nothing to do here. |
| 718 if (waiting_for_sync_initialization_) | 718 if (waiting_for_sync_initialization_) |
| 719 return; | 719 return; |
| 720 | 720 |
| 721 // Continue in FinishSetupSync() once the Sync backend has been initialized. | 721 // Continue in FinishSetupSync() once the Sync backend has been initialized. |
| 722 ProfileSyncService* service = | 722 browser_sync::ProfileSyncService* service = |
| 723 ProfileSyncServiceFactory::GetForProfile(profile_); | 723 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 724 if (service->IsBackendInitialized()) { | 724 if (service->IsBackendInitialized()) { |
| 725 FinishSetupSync(); | 725 FinishSetupSync(); |
| 726 } else { | 726 } else { |
| 727 service->AddObserver(this); | 727 service->AddObserver(this); |
| 728 waiting_for_sync_initialization_ = true; | 728 waiting_for_sync_initialization_ = true; |
| 729 } | 729 } |
| 730 } | 730 } |
| 731 | 731 |
| 732 void SupervisedUserService::FinishSetupSync() { | 732 void SupervisedUserService::FinishSetupSync() { |
| 733 ProfileSyncService* service = | 733 browser_sync::ProfileSyncService* service = |
| 734 ProfileSyncServiceFactory::GetForProfile(profile_); | 734 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 735 DCHECK(service->IsBackendInitialized()); | 735 DCHECK(service->IsBackendInitialized()); |
| 736 | 736 |
| 737 // Sync nothing (except types which are set via GetPreferredDataTypes). | 737 // Sync nothing (except types which are set via GetPreferredDataTypes). |
| 738 bool sync_everything = false; | 738 bool sync_everything = false; |
| 739 syncer::ModelTypeSet synced_datatypes; | 739 syncer::ModelTypeSet synced_datatypes; |
| 740 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 740 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| 741 | 741 |
| 742 // Notify ProfileSyncService that we are done with configuration. | 742 // Notify ProfileSyncService that we are done with configuration. |
| 743 sync_blocker_.reset(); | 743 sync_blocker_.reset(); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 if (!did_init_) | 967 if (!did_init_) |
| 968 return; | 968 return; |
| 969 DCHECK(!did_shutdown_); | 969 DCHECK(!did_shutdown_); |
| 970 did_shutdown_ = true; | 970 did_shutdown_ = true; |
| 971 if (ProfileIsSupervised()) { | 971 if (ProfileIsSupervised()) { |
| 972 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); | 972 content::RecordAction(UserMetricsAction("ManagedUsers_QuitBrowser")); |
| 973 } | 973 } |
| 974 SetActive(false); | 974 SetActive(false); |
| 975 sync_blocker_.reset(); | 975 sync_blocker_.reset(); |
| 976 | 976 |
| 977 ProfileSyncService* sync_service = | 977 browser_sync::ProfileSyncService* sync_service = |
| 978 ProfileSyncServiceFactory::GetForProfile(profile_); | 978 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 979 | 979 |
| 980 // Can be null in tests. | 980 // Can be null in tests. |
| 981 if (sync_service) | 981 if (sync_service) |
| 982 sync_service->RemovePreferenceProvider(this); | 982 sync_service->RemovePreferenceProvider(this); |
| 983 } | 983 } |
| 984 | 984 |
| 985 #if defined(ENABLE_EXTENSIONS) | 985 #if defined(ENABLE_EXTENSIONS) |
| 986 SupervisedUserService::ExtensionState SupervisedUserService::GetExtensionState( | 986 SupervisedUserService::ExtensionState SupervisedUserService::GetExtensionState( |
| 987 const Extension& extension) const { | 987 const Extension& extension) const { |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 result.Put(syncer::EXTENSION_SETTINGS); | 1245 result.Put(syncer::EXTENSION_SETTINGS); |
| 1246 result.Put(syncer::APPS); | 1246 result.Put(syncer::APPS); |
| 1247 result.Put(syncer::APP_SETTINGS); | 1247 result.Put(syncer::APP_SETTINGS); |
| 1248 result.Put(syncer::APP_NOTIFICATIONS); | 1248 result.Put(syncer::APP_NOTIFICATIONS); |
| 1249 result.Put(syncer::APP_LIST); | 1249 result.Put(syncer::APP_LIST); |
| 1250 return result; | 1250 return result; |
| 1251 } | 1251 } |
| 1252 | 1252 |
| 1253 #if !defined(OS_ANDROID) | 1253 #if !defined(OS_ANDROID) |
| 1254 void SupervisedUserService::OnStateChanged() { | 1254 void SupervisedUserService::OnStateChanged() { |
| 1255 ProfileSyncService* service = | 1255 browser_sync::ProfileSyncService* service = |
| 1256 ProfileSyncServiceFactory::GetForProfile(profile_); | 1256 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 1257 if (waiting_for_sync_initialization_ && service->IsBackendInitialized()) { | 1257 if (waiting_for_sync_initialization_ && service->IsBackendInitialized()) { |
| 1258 waiting_for_sync_initialization_ = false; | 1258 waiting_for_sync_initialization_ = false; |
| 1259 service->RemoveObserver(this); | 1259 service->RemoveObserver(this); |
| 1260 FinishSetupSync(); | 1260 FinishSetupSync(); |
| 1261 return; | 1261 return; |
| 1262 } | 1262 } |
| 1263 | 1263 |
| 1264 DLOG_IF(ERROR, service->GetAuthError().state() == | 1264 DLOG_IF(ERROR, service->GetAuthError().state() == |
| 1265 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS) | 1265 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS) |
| 1266 << "Credentials rejected"; | 1266 << "Credentials rejected"; |
| 1267 } | 1267 } |
| 1268 | 1268 |
| 1269 void SupervisedUserService::OnBrowserSetLastActive(Browser* browser) { | 1269 void SupervisedUserService::OnBrowserSetLastActive(Browser* browser) { |
| 1270 bool profile_became_active = profile_->IsSameProfile(browser->profile()); | 1270 bool profile_became_active = profile_->IsSameProfile(browser->profile()); |
| 1271 if (!is_profile_active_ && profile_became_active) | 1271 if (!is_profile_active_ && profile_became_active) |
| 1272 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); | 1272 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); |
| 1273 else if (is_profile_active_ && !profile_became_active) | 1273 else if (is_profile_active_ && !profile_became_active) |
| 1274 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); | 1274 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); |
| 1275 | 1275 |
| 1276 is_profile_active_ = profile_became_active; | 1276 is_profile_active_ = profile_became_active; |
| 1277 } | 1277 } |
| 1278 #endif // !defined(OS_ANDROID) | 1278 #endif // !defined(OS_ANDROID) |
| 1279 | 1279 |
| 1280 void SupervisedUserService::OnSiteListUpdated() { | 1280 void SupervisedUserService::OnSiteListUpdated() { |
| 1281 FOR_EACH_OBSERVER( | 1281 FOR_EACH_OBSERVER( |
| 1282 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 1282 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); |
| 1283 } | 1283 } |
| OLD | NEW |