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_pref_store.h" | 5 #include "chrome/browser/supervised_user/supervised_user_pref_store.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/net/safe_search_util.h" |
14 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 15 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
15 #include "chrome/browser/supervised_user/supervised_user_bookmarks_handler.h" | 16 #include "chrome/browser/supervised_user/supervised_user_bookmarks_handler.h" |
16 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 17 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
17 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | 18 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
18 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" | 19 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" |
19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
21 #include "components/bookmarks/common/bookmark_pref_names.h" | 22 #include "components/bookmarks/common/bookmark_pref_names.h" |
22 #include "components/prefs/pref_value_map.h" | 23 #include "components/prefs/pref_value_map.h" |
23 #include "components/signin/core/common/signin_pref_names.h" | 24 #include "components/signin/core/common/signin_pref_names.h" |
(...skipping 20 matching lines...) Expand all Loading... |
44 prefs::kSupervisedUserManualHosts, | 45 prefs::kSupervisedUserManualHosts, |
45 }, | 46 }, |
46 { | 47 { |
47 supervised_users::kContentPackManualBehaviorURLs, | 48 supervised_users::kContentPackManualBehaviorURLs, |
48 prefs::kSupervisedUserManualURLs, | 49 prefs::kSupervisedUserManualURLs, |
49 }, | 50 }, |
50 { | 51 { |
51 supervised_users::kForceSafeSearch, prefs::kForceGoogleSafeSearch, | 52 supervised_users::kForceSafeSearch, prefs::kForceGoogleSafeSearch, |
52 }, | 53 }, |
53 { | 54 { |
54 supervised_users::kForceSafeSearch, prefs::kForceYouTubeSafetyMode, | |
55 }, | |
56 { | |
57 supervised_users::kSafeSitesEnabled, prefs::kSupervisedUserSafeSites, | 55 supervised_users::kSafeSitesEnabled, prefs::kSupervisedUserSafeSites, |
58 }, | 56 }, |
59 { | 57 { |
60 supervised_users::kSigninAllowed, prefs::kSigninAllowed, | 58 supervised_users::kSigninAllowed, prefs::kSigninAllowed, |
61 }, | 59 }, |
62 { | 60 { |
63 supervised_users::kUserName, prefs::kProfileName, | 61 supervised_users::kUserName, prefs::kProfileName, |
64 }, | 62 }, |
65 }; | 63 }; |
66 | 64 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 107 |
110 void SupervisedUserPrefStore::OnNewSettingsAvailable( | 108 void SupervisedUserPrefStore::OnNewSettingsAvailable( |
111 const base::DictionaryValue* settings) { | 109 const base::DictionaryValue* settings) { |
112 std::unique_ptr<PrefValueMap> old_prefs = std::move(prefs_); | 110 std::unique_ptr<PrefValueMap> old_prefs = std::move(prefs_); |
113 prefs_.reset(new PrefValueMap); | 111 prefs_.reset(new PrefValueMap); |
114 if (settings) { | 112 if (settings) { |
115 // Set hardcoded prefs and defaults. | 113 // Set hardcoded prefs and defaults. |
116 prefs_->SetInteger(prefs::kDefaultSupervisedUserFilteringBehavior, | 114 prefs_->SetInteger(prefs::kDefaultSupervisedUserFilteringBehavior, |
117 SupervisedUserURLFilter::ALLOW); | 115 SupervisedUserURLFilter::ALLOW); |
118 prefs_->SetBoolean(prefs::kForceGoogleSafeSearch, true); | 116 prefs_->SetBoolean(prefs::kForceGoogleSafeSearch, true); |
119 prefs_->SetBoolean(prefs::kForceYouTubeSafetyMode, true); | 117 prefs_->SetInteger(prefs::kForceYouTubeRestrict, |
| 118 safe_search_util::YOUTUBE_RESTRICT_MODERATE); |
120 prefs_->SetBoolean(prefs::kHideWebStoreIcon, true); | 119 prefs_->SetBoolean(prefs::kHideWebStoreIcon, true); |
121 prefs_->SetBoolean(prefs::kSigninAllowed, false); | 120 prefs_->SetBoolean(prefs::kSigninAllowed, false); |
122 | 121 |
123 // Copy supervised user settings to prefs. | 122 // Copy supervised user settings to prefs. |
124 for (const auto& entry : kSupervisedUserSettingsPrefMapping) { | 123 for (const auto& entry : kSupervisedUserSettingsPrefMapping) { |
125 const base::Value* value = NULL; | 124 const base::Value* value = NULL; |
126 if (settings->GetWithoutPathExpansion(entry.settings_name, &value)) | 125 if (settings->GetWithoutPathExpansion(entry.settings_name, &value)) |
127 prefs_->SetValue(entry.pref_name, value->CreateDeepCopy()); | 126 prefs_->SetValue(entry.pref_name, value->CreateDeepCopy()); |
128 } | 127 } |
129 | 128 |
130 // Manually set preferences that aren't direct copies of the settings value. | 129 // Manually set preferences that aren't direct copies of the settings value. |
| 130 { |
| 131 bool record_history = true; |
| 132 settings->GetBoolean(supervised_users::kRecordHistory, &record_history); |
| 133 prefs_->SetBoolean(prefs::kAllowDeletingBrowserHistory, !record_history); |
| 134 prefs_->SetInteger(prefs::kIncognitoModeAvailability, |
| 135 record_history ? IncognitoModePrefs::DISABLED |
| 136 : IncognitoModePrefs::ENABLED); |
131 | 137 |
132 bool record_history = true; | 138 bool record_history_includes_session_sync = true; |
133 settings->GetBoolean(supervised_users::kRecordHistory, &record_history); | 139 settings->GetBoolean(supervised_users::kRecordHistoryIncludesSessionSync, |
134 prefs_->SetBoolean(prefs::kAllowDeletingBrowserHistory, !record_history); | 140 &record_history_includes_session_sync); |
135 prefs_->SetInteger(prefs::kIncognitoModeAvailability, | 141 prefs_->SetBoolean( |
136 record_history ? IncognitoModePrefs::DISABLED | 142 prefs::kForceSessionSync, |
137 : IncognitoModePrefs::ENABLED); | 143 record_history && record_history_includes_session_sync); |
| 144 } |
138 | 145 |
139 bool record_history_includes_session_sync = true; | 146 { |
140 settings->GetBoolean(supervised_users::kRecordHistoryIncludesSessionSync, | 147 // Note that |prefs::kForceGoogleSafeSearch| is set automatically as part |
141 &record_history_includes_session_sync); | 148 // of |kSupervisedUserSettingsPrefMapping|, but this can't be done for |
142 prefs_->SetBoolean(prefs::kForceSessionSync, | 149 // |prefs::kForceYouTubeRestrict| because it is an int, not a bool. |
143 record_history && record_history_includes_session_sync); | 150 bool force_safe_search = true; |
| 151 settings->GetBoolean(supervised_users::kForceSafeSearch, |
| 152 &force_safe_search); |
| 153 prefs_->SetInteger( |
| 154 prefs::kForceYouTubeRestrict, |
| 155 force_safe_search ? safe_search_util::YOUTUBE_RESTRICT_MODERATE |
| 156 : safe_search_util::YOUTUBE_RESTRICT_OFF); |
| 157 } |
144 | 158 |
145 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 159 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
146 switches::kEnableSupervisedUserManagedBookmarksFolder)) { | 160 switches::kEnableSupervisedUserManagedBookmarksFolder)) { |
147 // Reconstruct bookmarks from split settings. | 161 // Reconstruct bookmarks from split settings. |
148 prefs_->SetValue( | 162 prefs_->SetValue( |
149 bookmarks::prefs::kSupervisedBookmarks, | 163 bookmarks::prefs::kSupervisedBookmarks, |
150 SupervisedUserBookmarksHandler::BuildBookmarksTree(*settings)); | 164 SupervisedUserBookmarksHandler::BuildBookmarksTree(*settings)); |
151 } | 165 } |
152 } | 166 } |
153 | 167 |
(...skipping 12 matching lines...) Expand all Loading... |
166 } | 180 } |
167 | 181 |
168 // Callback to unsubscribe from the supervised user settings service. | 182 // Callback to unsubscribe from the supervised user settings service. |
169 void SupervisedUserPrefStore::Observe( | 183 void SupervisedUserPrefStore::Observe( |
170 int type, | 184 int type, |
171 const content::NotificationSource& src, | 185 const content::NotificationSource& src, |
172 const content::NotificationDetails& details) { | 186 const content::NotificationDetails& details) { |
173 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 187 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
174 user_settings_subscription_.reset(); | 188 user_settings_subscription_.reset(); |
175 } | 189 } |
OLD | NEW |