Chromium Code Reviews| 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 bc3a703e3073ba81d7e2185e2c388b7dba8c0be9..11600b57758e58652aabbc0cb965e71125e530a8 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 }, |
| @@ -615,17 +616,31 @@ 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 |
|
Thiemo Nagel
2016/10/05 17:38:14
Nit: Since you're continuing with small caps, the
ljusten (tachyonic)
2016/10/06 10:14:45
Done.
|
| + // ForceYouTubeSafetyMode, which has been replaced by |
|
Thiemo Nagel
2016/10/05 17:38:14
Nit: I'd suggest to not indent inside the comment,
ljusten (tachyonic)
2016/10/06 10:14:45
Done.
|
| + // ForceYouTubeRestrict. |
| if (policies.GetValue(key::kForceGoogleSafeSearch) || |
|
Thiemo Nagel
2016/10/05 17:38:14
As I read the code, the combination of ForceSafeSe
ljusten (tachyonic)
2016/10/06 10:14:45
This is correct, see crbug.com/476908. As soon as
Thiemo Nagel
2016/10/06 14:05:57
Alright. Thanks for updating the CL description t
|
| - 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, |
|
Thiemo Nagel
2016/10/05 17:38:14
Nit: Please wrap comments at 80 characters.
ljusten (tachyonic)
2016/10/06 10:14:45
Done.
|
| + // we cannot simply deep copy value, which is a boolean. |
| + if (value->GetAsBoolean(&enabled)) { |
| + prefs->SetValue( |
| + prefs::kForceYouTubeRestrict, |
| + base::MakeUnique<base::FundamentalValue>(static_cast<int>( |
| + enabled ? safe_search_util::YouTubeRestrictMode::kModerate |
| + : safe_search_util::YouTubeRestrictMode::kOff))); |
| + } |
| } |
| } |
| @@ -633,6 +648,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>(static_cast<int>( |
| + enabled ? safe_search_util::YouTubeRestrictMode::kModerate |
| + : safe_search_util::YouTubeRestrictMode::kOff))); |
| + } |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ForceYouTubeSafetyModePolicyHandler); |
| +}; |
| + |
| #if defined(ENABLE_EXTENSIONS) |
| void GetExtensionAllowedTypesMap( |
| ScopedVector<StringMappingListPolicyHandler::MappingEntry>* result) { |
| @@ -683,6 +728,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)); |