Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4851)

Unified Diff: chrome/browser/policy/configuration_policy_handler_list_factory.cc

Issue 2239753002: Added a ForceYouTubeRestrict policy and deprecated the old ForceYouTubeSafetyMode policy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Inc'ed id of new policy to 346 Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/configuration_policy_handler_list_factory.cc
diff --git a/chrome/browser/policy/configuration_policy_handler_list_factory.cc b/chrome/browser/policy/configuration_policy_handler_list_factory.cc
index 2be349187658d11c21556b5b3aca82c891afcf04..4b930dfc9dff1afed97f8373fcd22ec104084d64 100644
--- a/chrome/browser/policy/configuration_policy_handler_list_factory.cc
+++ b/chrome/browser/policy/configuration_policy_handler_list_factory.cc
@@ -16,6 +16,7 @@
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/net/disk_cache_dir_policy_handler.h"
+#include "chrome/browser/net/safe_search_util.h"
#include "chrome/browser/policy/file_selection_dialogs_policy_handler.h"
#include "chrome/browser/policy/javascript_policy_handler.h"
#include "chrome/browser/policy/managed_bookmarks_policy_handler.h"
@@ -119,9 +120,9 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = {
{ key::kForceGoogleSafeSearch,
prefs::kForceGoogleSafeSearch,
base::Value::TYPE_BOOLEAN },
- { key::kForceYouTubeSafetyMode,
- prefs::kForceYouTubeSafetyMode,
- base::Value::TYPE_BOOLEAN },
+ { key::kForceYouTubeRestrict,
+ prefs::kForceYouTubeRestrict,
+ base::Value::TYPE_INTEGER},
{ key::kPasswordManagerEnabled,
password_manager::prefs::kPasswordManagerSavingEnabled,
base::Value::TYPE_BOOLEAN },
@@ -612,17 +613,29 @@ class ForceSafeSearchPolicyHandler : public TypeCheckingPolicyHandler {
// ConfigurationPolicyHandler implementation:
void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) override {
- // If either of the new GoogleSafeSearch or YouTubeSafetyMode policies is
- // defined, then this one should be ignored. crbug.com/476908
- // Note: Those policies are declared in kSimplePolicyMap above.
+ // If either of the new ForceGoogleSafeSearch, ForceYouTubeSafetyMode or
+ // ForceYouTubeRestrict policies are defined, then this one should be
+ // ignored. crbug.com/476908, crbug.com/590478
+ // Note: Those policies are declared in kSimplePolicyMap above. except
+ // ForceYouTubeSafetyMode, which has been replaced by
+ // ForceYouTubeRestrict.
if (policies.GetValue(key::kForceGoogleSafeSearch) ||
- policies.GetValue(key::kForceYouTubeSafetyMode)) {
+ policies.GetValue(key::kForceYouTubeSafetyMode) ||
+ policies.GetValue(key::kForceYouTubeRestrict)) {
return;
}
const base::Value* value = policies.GetValue(policy_name());
if (value) {
+ bool enabled;
prefs->SetValue(prefs::kForceGoogleSafeSearch, value->CreateDeepCopy());
- prefs->SetValue(prefs::kForceYouTubeSafetyMode, value->CreateDeepCopy());
+
+ // Note that ForceYouTubeRestrict is an int policy,
+ // we cannot simply deep copy value, which is a boolean.
+ if (value->GetAsBoolean(&enabled))
Marc Treib 2016/09/05 09:58:10 Braces please if the body doesn't fit on one line.
ljusten (tachyonic) 2016/09/05 15:24:32 Done.
+ prefs->SetValue(prefs::kForceYouTubeRestrict,
+ base::MakeUnique<base::FundamentalValue>(
+ enabled ? safe_search_util::YOUTUBE_MODERATE
+ : safe_search_util::YOUTUBE_OFF));
}
}
@@ -630,6 +643,34 @@ class ForceSafeSearchPolicyHandler : public TypeCheckingPolicyHandler {
DISALLOW_COPY_AND_ASSIGN(ForceSafeSearchPolicyHandler);
};
+class ForceYouTubeSafetyModePolicyHandler : public TypeCheckingPolicyHandler {
+ public:
+ ForceYouTubeSafetyModePolicyHandler()
+ : TypeCheckingPolicyHandler(key::kForceYouTubeSafetyMode,
+ base::Value::TYPE_BOOLEAN) {}
+ ~ForceYouTubeSafetyModePolicyHandler() override {}
+
+ // ConfigurationPolicyHandler implementation:
+ void ApplyPolicySettings(const PolicyMap& policies,
+ PrefValueMap* prefs) override {
+ // If only the deprecated ForceYouTubeSafetyMode policy is set,
+ // but not ForceYouTubeRestrict, set ForceYouTubeRestrict to Moderate.
+ if (policies.GetValue(key::kForceYouTubeRestrict))
+ return;
+
+ const base::Value* value = policies.GetValue(policy_name());
+ bool enabled;
+ if (value && value->GetAsBoolean(&enabled))
Marc Treib 2016/09/05 09:58:10 Also here, braces please.
ljusten (tachyonic) 2016/09/05 15:24:32 Done.
+ prefs->SetValue(prefs::kForceYouTubeRestrict,
+ base::MakeUnique<base::FundamentalValue>(
+ enabled ? safe_search_util::YOUTUBE_MODERATE
+ : safe_search_util::YOUTUBE_OFF));
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ForceYouTubeSafetyModePolicyHandler);
+};
+
#if defined(ENABLE_EXTENSIONS)
void GetExtensionAllowedTypesMap(
ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) {
@@ -680,6 +721,8 @@ std::unique_ptr<ConfigurationPolicyHandlerList> BuildHandlerList(
handlers->AddHandler(base::WrapUnique(new AutofillPolicyHandler()));
handlers->AddHandler(base::WrapUnique(new DefaultSearchPolicyHandler()));
handlers->AddHandler(base::WrapUnique(new ForceSafeSearchPolicyHandler()));
+ handlers->AddHandler(
+ base::WrapUnique(new ForceYouTubeSafetyModePolicyHandler()));
handlers->AddHandler(base::WrapUnique(new IncognitoModePolicyHandler()));
handlers->AddHandler(
base::WrapUnique(new ManagedBookmarksPolicyHandler(chrome_schema)));

Powered by Google App Engine
This is Rietveld 408576698