Commit ecaf0275 authored by Julian Pastarmov's avatar Julian Pastarmov Committed by Commit Bot

Revert "Merge old and new list policies that were renamed"

This reverts commit b53e31ad.

Reason for revert: Crashes on Canary https://crbug.com/1148731

Original change's description:
> Merge old and new list policies that were renamed
>
> This change moves migrating of renamed policies from the PolicyHandler
> to a PolicyMigrator that happens right after the PolicyMerger has run.
> This guarantees that list policies can be properly merged between
> sources even if different sources provide different naming.
>
> BUG=1138572
> TEST=browser_tests:PolicyPrefsTest.PolicyToPrefsMapping
>
> Change-Id: Ibe335176ef52dabbe09c076ba57ae04d1c67c1c6
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2507771
> Commit-Queue: Julian Pastarmov <pastarmovj@chromium.org>
> Reviewed-by: Owen Min <zmin@chromium.org>
> Reviewed-by: Yann Dago <ydago@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#826903}

TBR=pastarmovj@chromium.org,zmin@chromium.org,ydago@chromium.org

Change-Id: I550446cbe736502003862ea9965b2277306b0890
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1138572
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536875Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Commit-Queue: Julian Pastarmov <pastarmovj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827231}
parent 804f0bbd
...@@ -138,7 +138,7 @@ std::string GetTestPolicy(const char* homepage, int key_version) { ...@@ -138,7 +138,7 @@ std::string GetTestPolicy(const char* homepage, int key_version) {
" \"mandatory\": {" " \"mandatory\": {"
" \"ShowHomeButton\": true," " \"ShowHomeButton\": true,"
" \"RestoreOnStartup\": 4," " \"RestoreOnStartup\": 4,"
" \"URLBlocklist\": [ \"dev.chromium.org\", \"youtube.com\" ]," " \"URLBlacklist\": [ \"dev.chromium.org\", \"youtube.com\" ],"
" \"MaxInvalidationFetchDelay\": 1000" " \"MaxInvalidationFetchDelay\": 1000"
" }," " },"
" \"recommended\": {" " \"recommended\": {"
...@@ -167,7 +167,7 @@ void GetExpectedTestPolicy(PolicyMap* expected, const char* homepage) { ...@@ -167,7 +167,7 @@ void GetExpectedTestPolicy(PolicyMap* expected, const char* homepage) {
base::ListValue list; base::ListValue list;
list.AppendString("dev.chromium.org"); list.AppendString("dev.chromium.org");
list.AppendString("youtube.com"); list.AppendString("youtube.com");
expected->Set(key::kURLBlocklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, expected->Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
POLICY_SOURCE_CLOUD, list.Clone(), nullptr); POLICY_SOURCE_CLOUD, list.Clone(), nullptr);
expected->Set(key::kMaxInvalidationFetchDelay, POLICY_LEVEL_MANDATORY, expected->Set(key::kMaxInvalidationFetchDelay, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, base::Value(1000), POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, base::Value(1000),
......
...@@ -125,7 +125,7 @@ class RestoreOnStartupPolicyTest : public PolicyTest, ...@@ -125,7 +125,7 @@ class RestoreOnStartupPolicyTest : public PolicyTest,
base::Value urls(base::Value::Type::LIST); base::Value urls(base::Value::Type::LIST);
for (const auto* url_string : kRestoredURLs) for (const auto* url_string : kRestoredURLs)
urls.Append(url_string); urls.Append(url_string);
policies.Set(key::kURLBlocklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
POLICY_SOURCE_CLOUD, std::move(urls), nullptr); POLICY_SOURCE_CLOUD, std::move(urls), nullptr);
provider_.UpdateChromePolicy(policies); provider_.UpdateChromePolicy(policies);
// This should restore the tabs opened at PRE_RunTest below, yet all should // This should restore the tabs opened at PRE_RunTest below, yet all should
......
...@@ -16,10 +16,8 @@ ...@@ -16,10 +16,8 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/values.h" #include "base/values.h"
#include "build/build_config.h"
#include "components/policy/core/common/features.h" #include "components/policy/core/common/features.h"
#include "components/policy/core/common/policy_bundle.h" #include "components/policy/core/common/policy_bundle.h"
#include "components/policy/core/common/policy_map.h" #include "components/policy/core/common/policy_map.h"
...@@ -27,9 +25,6 @@ ...@@ -27,9 +25,6 @@
#include "components/policy/core/common/policy_types.h" #include "components/policy/core/common/policy_types.h"
#include "components/policy/core/common/values_util.h" #include "components/policy/core/common/values_util.h"
#include "components/policy/policy_constants.h" #include "components/policy/policy_constants.h"
#include "components/strings/grit/components_strings.h"
#include "extensions/buildflags/buildflags.h"
#include "ui/base/l10n/l10n_util.h"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "components/policy/core/common/android/policy_service_android.h" #include "components/policy/core/common/android/policy_service_android.h"
...@@ -84,81 +79,6 @@ void RemapProxyPolicies(PolicyMap* policies) { ...@@ -84,81 +79,6 @@ void RemapProxyPolicies(PolicyMap* policies) {
} }
} }
// Maps the separate policies for proxy settings into a single Dictionary
// policy. This allows to keep the logic of merging policies from different
// sources simple, as all separate proxy policies should be considered as a
// single whole during merging.
void RemapRenamedPolicies(PolicyMap* policies) {
// For all renamed policies we need to explicitly merge the value of the
// old policy with the new one or else merging will not be carried over
// if desired.
base::Value* merge_list =
policies->GetMutableValue(key::kPolicyListMultipleSourceMergeList);
base::flat_set<std::string> policy_lists_to_merge =
policy::ValueToStringSet(merge_list);
const std::vector<std::pair<const char*, const char*>> renamed_policies = {{
{policy::key::kSafeBrowsingWhitelistDomains,
policy::key::kSafeBrowsingAllowlistDomains},
{policy::key::kSpellcheckLanguageBlacklist,
policy::key::kSpellcheckLanguageBlocklist},
{policy::key::kURLBlacklist, policy::key::kURLBlocklist},
{policy::key::kURLWhitelist, policy::key::kURLAllowlist},
#if !defined(OS_ANDROID)
{policy::key::kAutoplayWhitelist, policy::key::kAutoplayAllowlist},
#endif // !defined(OS_ANDROID)
#if BUILDFLAG(ENABLE_EXTENSIONS)
{policy::key::kExtensionInstallBlacklist,
policy::key::kExtensionInstallBlocklist},
{policy::key::kExtensionInstallWhitelist,
policy::key::kExtensionInstallAllowlist},
{policy::key::kNativeMessagingBlacklist,
policy::key::kNativeMessagingBlocklist},
{policy::key::kNativeMessagingWhitelist,
policy::key::kNativeMessagingAllowlist},
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
#if defined(OS_CHROMEOS)
{policy::key::kAttestationExtensionWhitelist,
policy::key::kAttestationExtensionAllowlist},
{policy::key::kExternalPrintServersWhitelist,
policy::key::kExternalPrintServersAllowlist},
{policy::key::kNativePrintersBulkBlacklist,
policy::key::kPrintersBulkBlocklist},
{policy::key::kNativePrintersBulkWhitelist,
policy::key::kPrintersBulkAllowlist},
{policy::key::kPerAppTimeLimitsWhitelist,
policy::key::kPerAppTimeLimitsAllowlist},
{policy::key::kQuickUnlockModeWhitelist,
policy::key::kQuickUnlockModeAllowlist},
{policy::key::kNoteTakingAppsLockScreenWhitelist,
policy::key::kNoteTakingAppsLockScreenAllowlist},
#if defined(USE_CUPS)
{policy::key::kPrintingAPIExtensionsWhitelist,
policy::key::kPrintingAPIExtensionsAllowlist},
#endif // defined(USE_CUPS)
#endif // defined(OS_CHROMEOS)
}};
for (const auto& policy_pair : renamed_policies) {
PolicyMap::Entry* old_policy = policies->GetMutable(policy_pair.first);
const PolicyMap::Entry* new_policy = policies->Get(policy_pair.second);
if (old_policy && !new_policy) {
PolicyMap::Entry policy_entry = old_policy->DeepCopy();
policy_entry.AddError(
l10n_util::GetStringFUTF8(IDS_POLICY_MIGRATED_NEW_POLICY,
base::UTF8ToUTF16(policy_pair.first)));
// TOTO(pastarmovj): Readd the old_policy error when the tast tests
// for chromeos have been updated.
// old_policy->AddError(
// l10n_util::GetStringFUTF8(IDS_POLICY_MIGRATED_OLD_POLICY,
// base::UTF8ToUTF16(policy_pair.second)));
policies->Set(policy_pair.second, std::move(policy_entry));
}
if (policy_lists_to_merge.contains(policy_pair.first) &&
!policy_lists_to_merge.contains(policy_pair.second)) {
merge_list->Append(base::Value(policy_pair.second));
}
}
}
// Returns the string values of |policy|. Returns an empty set if the values are // Returns the string values of |policy|. Returns an empty set if the values are
// not strings. // not strings.
base::flat_set<std::string> GetStringListPolicyItems( base::flat_set<std::string> GetStringListPolicyItems(
...@@ -359,7 +279,6 @@ void PolicyServiceImpl::MergeAndTriggerUpdates() { ...@@ -359,7 +279,6 @@ void PolicyServiceImpl::MergeAndTriggerUpdates() {
PolicyBundle provided_bundle; PolicyBundle provided_bundle;
provided_bundle.CopyFrom(provider->policies()); provided_bundle.CopyFrom(provider->policies());
RemapProxyPolicies(&provided_bundle.Get(chrome_namespace)); RemapProxyPolicies(&provided_bundle.Get(chrome_namespace));
RemapRenamedPolicies(&provided_bundle.Get(chrome_namespace));
bundle.MergeFrom(provided_bundle); bundle.MergeFrom(provided_bundle);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment