Commit 10c94abf authored by Aya ElAttar's avatar Aya ElAttar Committed by Commit Bot

Remove old PolicyMap::Entry::get_value

1. Removed PolicyMap::Entry::get_value which accepts unique_ptr.
2. Changed all its references to use the new one with
base::Optional instead.

Bug: 1092471
Change-Id: Iaa1246f55e63bc3737e36141bb349905d48335e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2237974
Auto-Submit: Aya Elsayed <ayaelattar@google.com>
Commit-Queue: Aya Elsayed <ayaelattar@google.com>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776926}
parent 05dd8f93
......@@ -80,7 +80,7 @@ TestHarness::TestHarness()
POLICY_SOURCE_PLATFORM),
next_policy_file_index_(100) {}
TestHarness::~TestHarness() {}
TestHarness::~TestHarness() = default;
void TestHarness::SetUp() {
ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
......@@ -243,7 +243,7 @@ TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsMergePrefs) {
.Get(kHomepageLocation)
->DeepCopy();
conflict_policy.conflicts.clear();
conflict_policy.set_value(std::make_unique<base::Value>("http://bar.com"));
conflict_policy.set_value(base::Value("http://bar.com"));
expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
.GetMutable(kHomepageLocation)
->AddConflictingPolicy(std::move(conflict_policy));
......
......@@ -54,11 +54,11 @@ void FilterSensitivePolicies(PolicyMap* policy) {
if (!map_entry->value()->GetAsList(&policy_list_value))
return;
std::unique_ptr<base::ListValue> filtered_values(new base::ListValue);
base::Value filtered_values(base::Value::Type::LIST);
for (const auto& list_entry : *policy_list_value) {
std::string entry;
if (!list_entry.GetAsString(&entry))
if (!list_entry.is_string())
continue;
std::string entry = list_entry.GetString();
size_t pos = entry.find(';');
if (pos == std::string::npos)
continue;
......@@ -69,7 +69,7 @@ void FilterSensitivePolicies(PolicyMap* policy) {
invalid_policies++;
}
filtered_values->AppendString(entry);
filtered_values.Append(entry);
}
if (invalid_policies) {
PolicyMap::Entry filtered_entry = map_entry->DeepCopy();
......
......@@ -74,10 +74,6 @@ PolicyMap::Entry PolicyMap::Entry::DeepCopy() const {
return copy;
}
void PolicyMap::Entry::set_value(std::unique_ptr<base::Value> val) {
value_ = val ? base::make_optional(std::move(*val)) : base::nullopt;
}
void PolicyMap::Entry::set_value(base::Optional<base::Value> val) {
value_ = std::move(val);
}
......
......@@ -61,11 +61,6 @@ class POLICY_EXPORT PolicyMap {
base::Value* value() { return base::OptionalOrNullptr(value_); }
const base::Value* value() const { return base::OptionalOrNullptr(value_); }
// DEPRECATED: Use the other version that takes base::Optional<base::Value>
// below.
// TODO(crbug.com/1092471): Migrate the existing usages and delete this
// method.
void set_value(std::unique_ptr<base::Value> val);
void set_value(base::Optional<base::Value> val);
// Returns true if |this| has higher priority than |other|. The priority of
......
......@@ -913,10 +913,10 @@ TEST_F(PolicyMapTest, EntryAddConflict) {
PolicyMap::Entry entry_a;
entry_a.level = POLICY_LEVEL_MANDATORY;
entry_a.source = POLICY_SOURCE_CLOUD;
entry_a.set_value(std::make_unique<base::Value>(true));
entry_a.set_value(base::Value(true));
entry_a.scope = POLICY_SCOPE_USER;
PolicyMap::Entry entry_b = entry_a.DeepCopy();
entry_b.set_value(std::make_unique<base::Value>(false));
entry_b.set_value(base::Value(false));
PolicyMap::Entry entry_b_no_conflicts = entry_b.DeepCopy();
PolicyMap::Entry entry_c = entry_a.DeepCopy();
entry_c.source = POLICY_SOURCE_PLATFORM;
......@@ -937,9 +937,9 @@ TEST_F(PolicyMapTest, BlockedEntry) {
PolicyMap::Entry entry_a(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
POLICY_SOURCE_CLOUD, base::Value("a"), nullptr);
PolicyMap::Entry entry_b = entry_a.DeepCopy();
entry_b.set_value(std::make_unique<base::Value>("b"));
entry_b.set_value(base::Value("b"));
PolicyMap::Entry entry_c_blocked = entry_a.DeepCopy();
entry_c_blocked.set_value(std::make_unique<base::Value>("c"));
entry_c_blocked.set_value(base::Value("c"));
entry_c_blocked.SetBlocked();
PolicyMap policies;
......@@ -989,7 +989,7 @@ TEST_F(PolicyMapTest, InvalidEntry) {
PolicyMap::Entry entry_a(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
POLICY_SOURCE_CLOUD, base::Value("a"), nullptr);
PolicyMap::Entry entry_b_invalid = entry_a.DeepCopy();
entry_b_invalid.set_value(std::make_unique<base::Value>("b"));
entry_b_invalid.set_value(base::Value("b"));
entry_b_invalid.SetInvalid();
PolicyMap policies;
......
......@@ -119,7 +119,7 @@ void PolicyListMerger::DoMerge(PolicyMap::Entry* policy) const {
for (const base::Value* it : merged_values)
new_value.Append(it->Clone());
policy->set_value(base::Value::ToUniquePtrValue(std::move(new_value)));
policy->set_value(std::move(new_value));
}
policy->ClearConflicts();
policy->AddConflictingPolicy(std::move(new_conflict));
......@@ -208,10 +208,9 @@ void PolicyDictionaryMerger::DoMerge(PolicyMap::Entry* policy) const {
}
auto new_conflict = policy->DeepCopy();
if (value_changed) {
policy->set_value(
base::Value::ToUniquePtrValue(std::move(merged_dictionary)));
}
if (value_changed)
policy->set_value(std::move(merged_dictionary));
policy->ClearConflicts();
policy->AddConflictingPolicy(std::move(new_conflict));
policy->source = POLICY_SOURCE_MERGED;
......
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