| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "chrome/grit/generated_resources.h" | 44 #include "chrome/grit/generated_resources.h" |
| 45 #include "components/browser_sync/profile_sync_service.h" | 45 #include "components/browser_sync/profile_sync_service.h" |
| 46 #include "components/pref_registry/pref_registry_syncable.h" | 46 #include "components/pref_registry/pref_registry_syncable.h" |
| 47 #include "components/prefs/pref_service.h" | 47 #include "components/prefs/pref_service.h" |
| 48 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 48 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 49 #include "components/signin/core/browser/signin_manager.h" | 49 #include "components/signin/core/browser/signin_manager.h" |
| 50 #include "components/signin/core/browser/signin_manager_base.h" | 50 #include "components/signin/core/browser/signin_manager_base.h" |
| 51 #include "components/signin/core/common/signin_switches.h" | 51 #include "components/signin/core/common/signin_switches.h" |
| 52 #include "content/public/browser/browser_thread.h" | 52 #include "content/public/browser/browser_thread.h" |
| 53 #include "content/public/browser/user_metrics.h" | 53 #include "content/public/browser/user_metrics.h" |
| 54 #include "extensions/features/features.h" |
| 54 #include "ui/base/l10n/l10n_util.h" | 55 #include "ui/base/l10n/l10n_util.h" |
| 55 | 56 |
| 56 #if !defined(OS_ANDROID) | 57 #if !defined(OS_ANDROID) |
| 57 #include "chrome/browser/supervised_user/legacy/custodian_profile_downloader_ser
vice.h" | 58 #include "chrome/browser/supervised_user/legacy/custodian_profile_downloader_ser
vice.h" |
| 58 #include "chrome/browser/supervised_user/legacy/custodian_profile_downloader_ser
vice_factory.h" | 59 #include "chrome/browser/supervised_user/legacy/custodian_profile_downloader_ser
vice_factory.h" |
| 59 #include "chrome/browser/supervised_user/legacy/permission_request_creator_sync.
h" | 60 #include "chrome/browser/supervised_user/legacy/permission_request_creator_sync.
h" |
| 60 #include "chrome/browser/supervised_user/legacy/supervised_user_pref_mapping_ser
vice.h" | 61 #include "chrome/browser/supervised_user/legacy/supervised_user_pref_mapping_ser
vice.h" |
| 61 #include "chrome/browser/supervised_user/legacy/supervised_user_pref_mapping_ser
vice_factory.h" | 62 #include "chrome/browser/supervised_user/legacy/supervised_user_pref_mapping_ser
vice_factory.h" |
| 62 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti
lity.h" | 63 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti
lity.h" |
| 63 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_
service_factory.h" | 64 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_
service_factory.h" |
| 64 #endif | 65 #endif |
| 65 | 66 |
| 66 #if defined(OS_CHROMEOS) | 67 #if defined(OS_CHROMEOS) |
| 67 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 68 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 68 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" | 69 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" |
| 69 #include "components/user_manager/user_manager.h" | 70 #include "components/user_manager/user_manager.h" |
| 70 #endif | 71 #endif |
| 71 | 72 |
| 72 #if defined(ENABLE_EXTENSIONS) | 73 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 73 #include "chrome/browser/extensions/extension_service.h" | 74 #include "chrome/browser/extensions/extension_service.h" |
| 74 #include "chrome/browser/extensions/extension_util.h" | 75 #include "chrome/browser/extensions/extension_util.h" |
| 75 #include "extensions/browser/extension_prefs.h" | 76 #include "extensions/browser/extension_prefs.h" |
| 76 #include "extensions/browser/extension_registry.h" | 77 #include "extensions/browser/extension_registry.h" |
| 77 #include "extensions/browser/extension_system.h" | 78 #include "extensions/browser/extension_system.h" |
| 78 #endif | 79 #endif |
| 79 | 80 |
| 80 #if defined(ENABLE_THEMES) | 81 #if defined(ENABLE_THEMES) |
| 81 #include "chrome/browser/themes/theme_service.h" | 82 #include "chrome/browser/themes/theme_service.h" |
| 82 #include "chrome/browser/themes/theme_service_factory.h" | 83 #include "chrome/browser/themes/theme_service_factory.h" |
| 83 #endif | 84 #endif |
| 84 | 85 |
| 85 using base::DictionaryValue; | 86 using base::DictionaryValue; |
| 86 using base::UserMetricsAction; | 87 using base::UserMetricsAction; |
| 87 using content::BrowserThread; | 88 using content::BrowserThread; |
| 88 | 89 |
| 89 #if defined(ENABLE_EXTENSIONS) | 90 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 90 using extensions::Extension; | 91 using extensions::Extension; |
| 91 using extensions::ExtensionPrefs; | 92 using extensions::ExtensionPrefs; |
| 92 using extensions::ExtensionRegistry; | 93 using extensions::ExtensionRegistry; |
| 93 using extensions::ExtensionSystem; | 94 using extensions::ExtensionSystem; |
| 94 #endif | 95 #endif |
| 95 | 96 |
| 96 #if defined(ENABLE_EXTENSIONS) | 97 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 97 using extensions::ExtensionPrefs; | 98 using extensions::ExtensionPrefs; |
| 98 #endif | 99 #endif |
| 99 | 100 |
| 100 namespace { | 101 namespace { |
| 101 | 102 |
| 102 // The URL from which to download a host blacklist if no local one exists yet. | 103 // The URL from which to download a host blacklist if no local one exists yet. |
| 103 const char kBlacklistURL[] = | 104 const char kBlacklistURL[] = |
| 104 "https://www.gstatic.com/chrome/supervised_user/blacklist-20141001-1k.bin"; | 105 "https://www.gstatic.com/chrome/supervised_user/blacklist-20141001-1k.bin"; |
| 105 // The filename under which we'll store the blacklist (in the user data dir). | 106 // The filename under which we'll store the blacklist (in the user data dir). |
| 106 const char kBlacklistFilename[] = "su-blacklist.bin"; | 107 const char kBlacklistFilename[] = "su-blacklist.bin"; |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 SupervisedUserService::SupervisedUserService(Profile* profile) | 531 SupervisedUserService::SupervisedUserService(Profile* profile) |
| 531 : includes_sync_sessions_type_(true), | 532 : includes_sync_sessions_type_(true), |
| 532 profile_(profile), | 533 profile_(profile), |
| 533 active_(false), | 534 active_(false), |
| 534 delegate_(NULL), | 535 delegate_(NULL), |
| 535 waiting_for_sync_initialization_(false), | 536 waiting_for_sync_initialization_(false), |
| 536 is_profile_active_(false), | 537 is_profile_active_(false), |
| 537 did_init_(false), | 538 did_init_(false), |
| 538 did_shutdown_(false), | 539 did_shutdown_(false), |
| 539 blacklist_state_(BlacklistLoadState::NOT_LOADED), | 540 blacklist_state_(BlacklistLoadState::NOT_LOADED), |
| 540 #if defined(ENABLE_EXTENSIONS) | 541 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 541 registry_observer_(this), | 542 registry_observer_(this), |
| 542 #endif | 543 #endif |
| 543 weak_ptr_factory_(this) { | 544 weak_ptr_factory_(this) { |
| 544 url_filter_context_.ui_url_filter()->AddObserver(this); | 545 url_filter_context_.ui_url_filter()->AddObserver(this); |
| 545 #if defined(ENABLE_EXTENSIONS) | 546 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 546 registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); | 547 registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); |
| 547 #endif | 548 #endif |
| 548 } | 549 } |
| 549 | 550 |
| 550 void SupervisedUserService::SetActive(bool active) { | 551 void SupervisedUserService::SetActive(bool active) { |
| 551 if (active_ == active) | 552 if (active_ == active) |
| 552 return; | 553 return; |
| 553 active_ = active; | 554 active_ = active; |
| 554 | 555 |
| 555 if (!delegate_ || !delegate_->SetActive(active_)) { | 556 if (!delegate_ || !delegate_->SetActive(active_)) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 if (theme_service->UsingDefaultTheme() || theme_service->UsingSystemTheme()) | 594 if (theme_service->UsingDefaultTheme() || theme_service->UsingSystemTheme()) |
| 594 theme_service->UseDefaultTheme(); | 595 theme_service->UseDefaultTheme(); |
| 595 #endif | 596 #endif |
| 596 | 597 |
| 597 browser_sync::ProfileSyncService* sync_service = | 598 browser_sync::ProfileSyncService* sync_service = |
| 598 ProfileSyncServiceFactory::GetForProfile(profile_); | 599 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 599 sync_service->SetEncryptEverythingAllowed(!active_); | 600 sync_service->SetEncryptEverythingAllowed(!active_); |
| 600 | 601 |
| 601 GetSettingsService()->SetActive(active_); | 602 GetSettingsService()->SetActive(active_); |
| 602 | 603 |
| 603 #if defined(ENABLE_EXTENSIONS) | 604 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 604 SetExtensionsActive(); | 605 SetExtensionsActive(); |
| 605 #endif | 606 #endif |
| 606 | 607 |
| 607 if (active_) { | 608 if (active_) { |
| 608 pref_change_registrar_.Add( | 609 pref_change_registrar_.Add( |
| 609 prefs::kDefaultSupervisedUserFilteringBehavior, | 610 prefs::kDefaultSupervisedUserFilteringBehavior, |
| 610 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, | 611 base::Bind(&SupervisedUserService::OnDefaultFilteringBehaviorChanged, |
| 611 base::Unretained(this))); | 612 base::Unretained(this))); |
| 612 #if defined(ENABLE_EXTENSIONS) | 613 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 613 pref_change_registrar_.Add( | 614 pref_change_registrar_.Add( |
| 614 prefs::kSupervisedUserApprovedExtensions, | 615 prefs::kSupervisedUserApprovedExtensions, |
| 615 base::Bind(&SupervisedUserService::UpdateApprovedExtensions, | 616 base::Bind(&SupervisedUserService::UpdateApprovedExtensions, |
| 616 base::Unretained(this))); | 617 base::Unretained(this))); |
| 617 #endif | 618 #endif |
| 618 pref_change_registrar_.Add(prefs::kSupervisedUserSafeSites, | 619 pref_change_registrar_.Add(prefs::kSupervisedUserSafeSites, |
| 619 base::Bind(&SupervisedUserService::OnSafeSitesSettingChanged, | 620 base::Bind(&SupervisedUserService::OnSafeSitesSettingChanged, |
| 620 base::Unretained(this))); | 621 base::Unretained(this))); |
| 621 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, | 622 pref_change_registrar_.Add(prefs::kSupervisedUserManualHosts, |
| 622 base::Bind(&SupervisedUserService::UpdateManualHosts, | 623 base::Bind(&SupervisedUserService::UpdateManualHosts, |
| 623 base::Unretained(this))); | 624 base::Unretained(this))); |
| 624 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, | 625 pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs, |
| 625 base::Bind(&SupervisedUserService::UpdateManualURLs, | 626 base::Bind(&SupervisedUserService::UpdateManualURLs, |
| 626 base::Unretained(this))); | 627 base::Unretained(this))); |
| 627 for (const char* pref : kCustodianInfoPrefs) { | 628 for (const char* pref : kCustodianInfoPrefs) { |
| 628 pref_change_registrar_.Add(pref, | 629 pref_change_registrar_.Add(pref, |
| 629 base::Bind(&SupervisedUserService::OnCustodianInfoChanged, | 630 base::Bind(&SupervisedUserService::OnCustodianInfoChanged, |
| 630 base::Unretained(this))); | 631 base::Unretained(this))); |
| 631 } | 632 } |
| 632 | 633 |
| 633 // Initialize the filter. | 634 // Initialize the filter. |
| 634 OnDefaultFilteringBehaviorChanged(); | 635 OnDefaultFilteringBehaviorChanged(); |
| 635 OnSafeSitesSettingChanged(); | 636 OnSafeSitesSettingChanged(); |
| 636 whitelist_service_->Init(); | 637 whitelist_service_->Init(); |
| 637 UpdateManualHosts(); | 638 UpdateManualHosts(); |
| 638 UpdateManualURLs(); | 639 UpdateManualURLs(); |
| 639 | 640 |
| 640 #if defined(ENABLE_EXTENSIONS) | 641 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 641 UpdateApprovedExtensions(); | 642 UpdateApprovedExtensions(); |
| 642 #endif | 643 #endif |
| 643 | 644 |
| 644 #if !defined(OS_ANDROID) | 645 #if !defined(OS_ANDROID) |
| 645 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 646 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
| 646 // http://crbug.com/313377 | 647 // http://crbug.com/313377 |
| 647 BrowserList::AddObserver(this); | 648 BrowserList::AddObserver(this); |
| 648 #endif | 649 #endif |
| 649 } else { | 650 } else { |
| 650 permissions_creators_.clear(); | 651 permissions_creators_.clear(); |
| 651 url_reporter_.reset(); | 652 url_reporter_.reset(); |
| 652 | 653 |
| 653 pref_change_registrar_.Remove( | 654 pref_change_registrar_.Remove( |
| 654 prefs::kDefaultSupervisedUserFilteringBehavior); | 655 prefs::kDefaultSupervisedUserFilteringBehavior); |
| 655 #if defined(ENABLE_EXTENSIONS) | 656 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 656 pref_change_registrar_.Remove(prefs::kSupervisedUserApprovedExtensions); | 657 pref_change_registrar_.Remove(prefs::kSupervisedUserApprovedExtensions); |
| 657 #endif | 658 #endif |
| 658 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); | 659 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); |
| 659 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); | 660 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); |
| 660 for (const char* pref : kCustodianInfoPrefs) { | 661 for (const char* pref : kCustodianInfoPrefs) { |
| 661 pref_change_registrar_.Remove(pref); | 662 pref_change_registrar_.Remove(pref); |
| 662 } | 663 } |
| 663 | 664 |
| 664 url_filter_context_.Clear(); | 665 url_filter_context_.Clear(); |
| 665 for (SupervisedUserServiceObserver& observer : observer_list_) | 666 for (SupervisedUserServiceObserver& observer : observer_list_) |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 sync_blocker_.reset(); | 984 sync_blocker_.reset(); |
| 984 | 985 |
| 985 browser_sync::ProfileSyncService* sync_service = | 986 browser_sync::ProfileSyncService* sync_service = |
| 986 ProfileSyncServiceFactory::GetForProfile(profile_); | 987 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 987 | 988 |
| 988 // Can be null in tests. | 989 // Can be null in tests. |
| 989 if (sync_service) | 990 if (sync_service) |
| 990 sync_service->RemovePreferenceProvider(this); | 991 sync_service->RemovePreferenceProvider(this); |
| 991 } | 992 } |
| 992 | 993 |
| 993 #if defined(ENABLE_EXTENSIONS) | 994 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 994 SupervisedUserService::ExtensionState SupervisedUserService::GetExtensionState( | 995 SupervisedUserService::ExtensionState SupervisedUserService::GetExtensionState( |
| 995 const Extension& extension) const { | 996 const Extension& extension) const { |
| 996 bool was_installed_by_default = extension.was_installed_by_default(); | 997 bool was_installed_by_default = extension.was_installed_by_default(); |
| 997 #if defined(OS_CHROMEOS) | 998 #if defined(OS_CHROMEOS) |
| 998 // On Chrome OS all external sources are controlled by us so it means that | 999 // On Chrome OS all external sources are controlled by us so it means that |
| 999 // they are "default". Method was_installed_by_default returns false because | 1000 // they are "default". Method was_installed_by_default returns false because |
| 1000 // extensions creation flags are ignored in case of default extensions with | 1001 // extensions creation flags are ignored in case of default extensions with |
| 1001 // update URL(the flags aren't passed to OnExternalExtensionUpdateUrlFound). | 1002 // update URL(the flags aren't passed to OnExternalExtensionUpdateUrlFound). |
| 1002 // TODO(dpolukhin): remove this Chrome OS specific code as soon as creation | 1003 // TODO(dpolukhin): remove this Chrome OS specific code as soon as creation |
| 1003 // flags are not ignored. | 1004 // flags are not ignored. |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 if (management_policy) { | 1234 if (management_policy) { |
| 1234 if (active_) | 1235 if (active_) |
| 1235 management_policy->RegisterProvider(this); | 1236 management_policy->RegisterProvider(this); |
| 1236 else | 1237 else |
| 1237 management_policy->UnregisterProvider(this); | 1238 management_policy->UnregisterProvider(this); |
| 1238 | 1239 |
| 1239 // Re-check the policy to make sure any new settings get applied. | 1240 // Re-check the policy to make sure any new settings get applied. |
| 1240 extension_system->extension_service()->CheckManagementPolicy(); | 1241 extension_system->extension_service()->CheckManagementPolicy(); |
| 1241 } | 1242 } |
| 1242 } | 1243 } |
| 1243 #endif // defined(ENABLE_EXTENSIONS) | 1244 #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 1244 | 1245 |
| 1245 syncer::ModelTypeSet SupervisedUserService::GetPreferredDataTypes() const { | 1246 syncer::ModelTypeSet SupervisedUserService::GetPreferredDataTypes() const { |
| 1246 if (!ProfileIsSupervised()) | 1247 if (!ProfileIsSupervised()) |
| 1247 return syncer::ModelTypeSet(); | 1248 return syncer::ModelTypeSet(); |
| 1248 | 1249 |
| 1249 syncer::ModelTypeSet result; | 1250 syncer::ModelTypeSet result; |
| 1250 if (IncludesSyncSessionsType()) | 1251 if (IncludesSyncSessionsType()) |
| 1251 result.Put(syncer::SESSIONS); | 1252 result.Put(syncer::SESSIONS); |
| 1252 result.Put(syncer::EXTENSIONS); | 1253 result.Put(syncer::EXTENSIONS); |
| 1253 result.Put(syncer::EXTENSION_SETTINGS); | 1254 result.Put(syncer::EXTENSION_SETTINGS); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1282 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); | 1283 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); |
| 1283 | 1284 |
| 1284 is_profile_active_ = profile_became_active; | 1285 is_profile_active_ = profile_became_active; |
| 1285 } | 1286 } |
| 1286 #endif // !defined(OS_ANDROID) | 1287 #endif // !defined(OS_ANDROID) |
| 1287 | 1288 |
| 1288 void SupervisedUserService::OnSiteListUpdated() { | 1289 void SupervisedUserService::OnSiteListUpdated() { |
| 1289 for (SupervisedUserServiceObserver& observer : observer_list_) | 1290 for (SupervisedUserServiceObserver& observer : observer_list_) |
| 1290 observer.OnURLFilterChanged(); | 1291 observer.OnURLFilterChanged(); |
| 1291 } | 1292 } |
| OLD | NEW |