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

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

Issue 2401743003: Recommit and fix of "Added a ForceYouTubeRestrict policy and deprecated the old ForceYouTubeSafetyM… (Closed)
Patch Set: Rebase Created 4 years, 2 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
« no previous file with comments | « chrome/browser/net/safe_search_util_unittest.cc ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3739445cce9664ca78d1ccc210b47035d92c54a8..b5c1210616fd30647e10aa711821f0ae80ff2cf4 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 },
@@ -618,17 +619,30 @@ 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)) {
+ prefs->SetValue(
+ prefs::kForceYouTubeRestrict,
+ base::MakeUnique<base::FundamentalValue>(
+ enabled ? safe_search_util::YOUTUBE_RESTRICT_MODERATE
+ : safe_search_util::YOUTUBE_RESTRICT_OFF));
+ }
}
}
@@ -636,6 +650,36 @@ 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)) {
+ prefs->SetValue(
+ prefs::kForceYouTubeRestrict,
+ base::MakeUnique<base::FundamentalValue>(
+ enabled ? safe_search_util::YOUTUBE_RESTRICT_MODERATE
+ : safe_search_util::YOUTUBE_RESTRICT_OFF));
+ }
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ForceYouTubeSafetyModePolicyHandler);
+};
+
#if defined(ENABLE_EXTENSIONS)
void GetExtensionAllowedTypesMap(
ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) {
@@ -686,6 +730,7 @@ std::unique_ptr<ConfigurationPolicyHandlerList> BuildHandlerList(
handlers->AddHandler(base::MakeUnique<AutofillPolicyHandler>());
handlers->AddHandler(base::MakeUnique<DefaultSearchPolicyHandler>());
handlers->AddHandler(base::MakeUnique<ForceSafeSearchPolicyHandler>());
+ handlers->AddHandler(base::MakeUnique<ForceYouTubeSafetyModePolicyHandler>());
handlers->AddHandler(base::MakeUnique<IncognitoModePolicyHandler>());
handlers->AddHandler(
base::MakeUnique<ManagedBookmarksPolicyHandler>(chrome_schema));
« no previous file with comments | « chrome/browser/net/safe_search_util_unittest.cc ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698