| 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 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 #if defined(ENABLE_EXTENSIONS) | 650 #if defined(ENABLE_EXTENSIONS) |
| 651 pref_change_registrar_.Remove(prefs::kSupervisedUserApprovedExtensions); | 651 pref_change_registrar_.Remove(prefs::kSupervisedUserApprovedExtensions); |
| 652 #endif | 652 #endif |
| 653 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); | 653 pref_change_registrar_.Remove(prefs::kSupervisedUserManualHosts); |
| 654 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); | 654 pref_change_registrar_.Remove(prefs::kSupervisedUserManualURLs); |
| 655 for (const char* pref : kCustodianInfoPrefs) { | 655 for (const char* pref : kCustodianInfoPrefs) { |
| 656 pref_change_registrar_.Remove(pref); | 656 pref_change_registrar_.Remove(pref); |
| 657 } | 657 } |
| 658 | 658 |
| 659 url_filter_context_.Clear(); | 659 url_filter_context_.Clear(); |
| 660 FOR_EACH_OBSERVER( | 660 for (SupervisedUserServiceObserver& observer : observer_list_) |
| 661 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 661 observer.OnURLFilterChanged(); |
| 662 | 662 |
| 663 #if !defined(OS_ANDROID) | 663 #if !defined(OS_ANDROID) |
| 664 if (waiting_for_sync_initialization_) | 664 if (waiting_for_sync_initialization_) |
| 665 ProfileSyncServiceFactory::GetForProfile(profile_)->RemoveObserver(this); | 665 ProfileSyncServiceFactory::GetForProfile(profile_)->RemoveObserver(this); |
| 666 | 666 |
| 667 // TODO(bauerb): Get rid of the platform-specific #ifdef here. | 667 // TODO(bauerb): Get rid of the platform-specific #ifdef here. |
| 668 // http://crbug.com/313377 | 668 // http://crbug.com/313377 |
| 669 BrowserList::RemoveObserver(this); | 669 BrowserList::RemoveObserver(this); |
| 670 #endif | 670 #endif |
| 671 } | 671 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 sync_blocker_.reset(); | 746 sync_blocker_.reset(); |
| 747 service->SetFirstSetupComplete(); | 747 service->SetFirstSetupComplete(); |
| 748 } | 748 } |
| 749 #endif | 749 #endif |
| 750 | 750 |
| 751 bool SupervisedUserService::ProfileIsSupervised() const { | 751 bool SupervisedUserService::ProfileIsSupervised() const { |
| 752 return profile_->IsSupervised(); | 752 return profile_->IsSupervised(); |
| 753 } | 753 } |
| 754 | 754 |
| 755 void SupervisedUserService::OnCustodianInfoChanged() { | 755 void SupervisedUserService::OnCustodianInfoChanged() { |
| 756 FOR_EACH_OBSERVER( | 756 for (SupervisedUserServiceObserver& observer : observer_list_) |
| 757 SupervisedUserServiceObserver, observer_list_, OnCustodianInfoChanged()); | 757 observer.OnCustodianInfoChanged(); |
| 758 } | 758 } |
| 759 | 759 |
| 760 SupervisedUserSettingsService* SupervisedUserService::GetSettingsService() { | 760 SupervisedUserSettingsService* SupervisedUserService::GetSettingsService() { |
| 761 return SupervisedUserSettingsServiceFactory::GetForProfile(profile_); | 761 return SupervisedUserSettingsServiceFactory::GetForProfile(profile_); |
| 762 } | 762 } |
| 763 | 763 |
| 764 size_t SupervisedUserService::FindEnabledPermissionRequestCreator( | 764 size_t SupervisedUserService::FindEnabledPermissionRequestCreator( |
| 765 size_t start) { | 765 size_t start) { |
| 766 for (size_t i = start; i < permissions_creators_.size(); ++i) { | 766 for (size_t i = start; i < permissions_creators_.size(); ++i) { |
| 767 if (permissions_creators_[i]->IsEnabled()) | 767 if (permissions_creators_[i]->IsEnabled()) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 SetActive(ProfileIsSupervised()); | 805 SetActive(ProfileIsSupervised()); |
| 806 } | 806 } |
| 807 | 807 |
| 808 void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { | 808 void SupervisedUserService::OnDefaultFilteringBehaviorChanged() { |
| 809 int behavior_value = profile_->GetPrefs()->GetInteger( | 809 int behavior_value = profile_->GetPrefs()->GetInteger( |
| 810 prefs::kDefaultSupervisedUserFilteringBehavior); | 810 prefs::kDefaultSupervisedUserFilteringBehavior); |
| 811 SupervisedUserURLFilter::FilteringBehavior behavior = | 811 SupervisedUserURLFilter::FilteringBehavior behavior = |
| 812 SupervisedUserURLFilter::BehaviorFromInt(behavior_value); | 812 SupervisedUserURLFilter::BehaviorFromInt(behavior_value); |
| 813 url_filter_context_.SetDefaultFilteringBehavior(behavior); | 813 url_filter_context_.SetDefaultFilteringBehavior(behavior); |
| 814 | 814 |
| 815 FOR_EACH_OBSERVER( | 815 for (SupervisedUserServiceObserver& observer : observer_list_) |
| 816 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 816 observer.OnURLFilterChanged(); |
| 817 } | 817 } |
| 818 | 818 |
| 819 void SupervisedUserService::OnSafeSitesSettingChanged() { | 819 void SupervisedUserService::OnSafeSitesSettingChanged() { |
| 820 bool use_blacklist = supervised_users::IsSafeSitesBlacklistEnabled(profile_); | 820 bool use_blacklist = supervised_users::IsSafeSitesBlacklistEnabled(profile_); |
| 821 if (use_blacklist != url_filter_context_.HasBlacklist()) { | 821 if (use_blacklist != url_filter_context_.HasBlacklist()) { |
| 822 if (use_blacklist && blacklist_state_ == BlacklistLoadState::NOT_LOADED) { | 822 if (use_blacklist && blacklist_state_ == BlacklistLoadState::NOT_LOADED) { |
| 823 LoadBlacklist(GetBlacklistPath(), GURL(kBlacklistURL)); | 823 LoadBlacklist(GetBlacklistPath(), GURL(kBlacklistURL)); |
| 824 } else if (!use_blacklist || | 824 } else if (!use_blacklist || |
| 825 blacklist_state_ == BlacklistLoadState::LOADED) { | 825 blacklist_state_ == BlacklistLoadState::LOADED) { |
| 826 // Either the blacklist was turned off, or it was turned on but has | 826 // Either the blacklist was turned off, or it was turned on but has |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 | 902 |
| 903 void SupervisedUserService::OnBlacklistLoaded() { | 903 void SupervisedUserService::OnBlacklistLoaded() { |
| 904 DCHECK(blacklist_state_ == BlacklistLoadState::LOAD_STARTED); | 904 DCHECK(blacklist_state_ == BlacklistLoadState::LOAD_STARTED); |
| 905 blacklist_state_ = BlacklistLoadState::LOADED; | 905 blacklist_state_ = BlacklistLoadState::LOADED; |
| 906 UpdateBlacklist(); | 906 UpdateBlacklist(); |
| 907 } | 907 } |
| 908 | 908 |
| 909 void SupervisedUserService::UpdateBlacklist() { | 909 void SupervisedUserService::UpdateBlacklist() { |
| 910 bool use_blacklist = supervised_users::IsSafeSitesBlacklistEnabled(profile_); | 910 bool use_blacklist = supervised_users::IsSafeSitesBlacklistEnabled(profile_); |
| 911 url_filter_context_.SetBlacklist(use_blacklist ? &blacklist_ : nullptr); | 911 url_filter_context_.SetBlacklist(use_blacklist ? &blacklist_ : nullptr); |
| 912 FOR_EACH_OBSERVER( | 912 for (SupervisedUserServiceObserver& observer : observer_list_) |
| 913 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 913 observer.OnURLFilterChanged(); |
| 914 } | 914 } |
| 915 | 915 |
| 916 void SupervisedUserService::UpdateManualHosts() { | 916 void SupervisedUserService::UpdateManualHosts() { |
| 917 const base::DictionaryValue* dict = | 917 const base::DictionaryValue* dict = |
| 918 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualHosts); | 918 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualHosts); |
| 919 std::unique_ptr<std::map<std::string, bool>> host_map( | 919 std::unique_ptr<std::map<std::string, bool>> host_map( |
| 920 new std::map<std::string, bool>()); | 920 new std::map<std::string, bool>()); |
| 921 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 921 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 922 bool allow = false; | 922 bool allow = false; |
| 923 bool result = it.value().GetAsBoolean(&allow); | 923 bool result = it.value().GetAsBoolean(&allow); |
| 924 DCHECK(result); | 924 DCHECK(result); |
| 925 (*host_map)[it.key()] = allow; | 925 (*host_map)[it.key()] = allow; |
| 926 } | 926 } |
| 927 url_filter_context_.SetManualHosts(std::move(host_map)); | 927 url_filter_context_.SetManualHosts(std::move(host_map)); |
| 928 | 928 |
| 929 FOR_EACH_OBSERVER( | 929 for (SupervisedUserServiceObserver& observer : observer_list_) |
| 930 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 930 observer.OnURLFilterChanged(); |
| 931 } | 931 } |
| 932 | 932 |
| 933 void SupervisedUserService::UpdateManualURLs() { | 933 void SupervisedUserService::UpdateManualURLs() { |
| 934 const base::DictionaryValue* dict = | 934 const base::DictionaryValue* dict = |
| 935 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); | 935 profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs); |
| 936 std::unique_ptr<std::map<GURL, bool>> url_map(new std::map<GURL, bool>()); | 936 std::unique_ptr<std::map<GURL, bool>> url_map(new std::map<GURL, bool>()); |
| 937 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 937 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 938 bool allow = false; | 938 bool allow = false; |
| 939 bool result = it.value().GetAsBoolean(&allow); | 939 bool result = it.value().GetAsBoolean(&allow); |
| 940 DCHECK(result); | 940 DCHECK(result); |
| 941 (*url_map)[GURL(it.key())] = allow; | 941 (*url_map)[GURL(it.key())] = allow; |
| 942 } | 942 } |
| 943 url_filter_context_.SetManualURLs(std::move(url_map)); | 943 url_filter_context_.SetManualURLs(std::move(url_map)); |
| 944 | 944 |
| 945 FOR_EACH_OBSERVER( | 945 for (SupervisedUserServiceObserver& observer : observer_list_) |
| 946 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 946 observer.OnURLFilterChanged(); |
| 947 } | 947 } |
| 948 | 948 |
| 949 std::string SupervisedUserService::GetSupervisedUserName() const { | 949 std::string SupervisedUserService::GetSupervisedUserName() const { |
| 950 #if defined(OS_CHROMEOS) | 950 #if defined(OS_CHROMEOS) |
| 951 // The active user can be NULL in unit tests. | 951 // The active user can be NULL in unit tests. |
| 952 if (user_manager::UserManager::Get()->GetActiveUser()) { | 952 if (user_manager::UserManager::Get()->GetActiveUser()) { |
| 953 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( | 953 return UTF16ToUTF8(user_manager::UserManager::Get()->GetUserDisplayName( |
| 954 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId())); | 954 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId())); |
| 955 } | 955 } |
| 956 return std::string(); | 956 return std::string(); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1274 if (!is_profile_active_ && profile_became_active) | 1274 if (!is_profile_active_ && profile_became_active) |
| 1275 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); | 1275 content::RecordAction(UserMetricsAction("ManagedUsers_OpenProfile")); |
| 1276 else if (is_profile_active_ && !profile_became_active) | 1276 else if (is_profile_active_ && !profile_became_active) |
| 1277 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); | 1277 content::RecordAction(UserMetricsAction("ManagedUsers_SwitchProfile")); |
| 1278 | 1278 |
| 1279 is_profile_active_ = profile_became_active; | 1279 is_profile_active_ = profile_became_active; |
| 1280 } | 1280 } |
| 1281 #endif // !defined(OS_ANDROID) | 1281 #endif // !defined(OS_ANDROID) |
| 1282 | 1282 |
| 1283 void SupervisedUserService::OnSiteListUpdated() { | 1283 void SupervisedUserService::OnSiteListUpdated() { |
| 1284 FOR_EACH_OBSERVER( | 1284 for (SupervisedUserServiceObserver& observer : observer_list_) |
| 1285 SupervisedUserServiceObserver, observer_list_, OnURLFilterChanged()); | 1285 observer.OnURLFilterChanged(); |
| 1286 } | 1286 } |
| OLD | NEW |