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() ...@@ -80,7 +80,7 @@ TestHarness::TestHarness()
POLICY_SOURCE_PLATFORM), POLICY_SOURCE_PLATFORM),
next_policy_file_index_(100) {} next_policy_file_index_(100) {}
TestHarness::~TestHarness() {} TestHarness::~TestHarness() = default;
void TestHarness::SetUp() { void TestHarness::SetUp() {
ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
...@@ -243,7 +243,7 @@ TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsMergePrefs) { ...@@ -243,7 +243,7 @@ TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsMergePrefs) {
.Get(kHomepageLocation) .Get(kHomepageLocation)
->DeepCopy(); ->DeepCopy();
conflict_policy.conflicts.clear(); 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())) expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
.GetMutable(kHomepageLocation) .GetMutable(kHomepageLocation)
->AddConflictingPolicy(std::move(conflict_policy)); ->AddConflictingPolicy(std::move(conflict_policy));
......
...@@ -54,11 +54,11 @@ void FilterSensitivePolicies(PolicyMap* policy) { ...@@ -54,11 +54,11 @@ void FilterSensitivePolicies(PolicyMap* policy) {
if (!map_entry->value()->GetAsList(&policy_list_value)) if (!map_entry->value()->GetAsList(&policy_list_value))
return; 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) { for (const auto& list_entry : *policy_list_value) {
std::string entry; if (!list_entry.is_string())
if (!list_entry.GetAsString(&entry))
continue; continue;
std::string entry = list_entry.GetString();
size_t pos = entry.find(';'); size_t pos = entry.find(';');
if (pos == std::string::npos) if (pos == std::string::npos)
continue; continue;
...@@ -69,7 +69,7 @@ void FilterSensitivePolicies(PolicyMap* policy) { ...@@ -69,7 +69,7 @@ void FilterSensitivePolicies(PolicyMap* policy) {
invalid_policies++; invalid_policies++;
} }
filtered_values->AppendString(entry); filtered_values.Append(entry);
} }
if (invalid_policies) { if (invalid_policies) {
PolicyMap::Entry filtered_entry = map_entry->DeepCopy(); PolicyMap::Entry filtered_entry = map_entry->DeepCopy();
......
...@@ -74,10 +74,6 @@ PolicyMap::Entry PolicyMap::Entry::DeepCopy() const { ...@@ -74,10 +74,6 @@ PolicyMap::Entry PolicyMap::Entry::DeepCopy() const {
return copy; 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) { void PolicyMap::Entry::set_value(base::Optional<base::Value> val) {
value_ = std::move(val); value_ = std::move(val);
} }
......
...@@ -61,11 +61,6 @@ class POLICY_EXPORT PolicyMap { ...@@ -61,11 +61,6 @@ class POLICY_EXPORT PolicyMap {
base::Value* value() { return base::OptionalOrNullptr(value_); } base::Value* value() { return base::OptionalOrNullptr(value_); }
const base::Value* value() const { 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); void set_value(base::Optional<base::Value> val);
// Returns true if |this| has higher priority than |other|. The priority of // Returns true if |this| has higher priority than |other|. The priority of
......
...@@ -913,10 +913,10 @@ TEST_F(PolicyMapTest, EntryAddConflict) { ...@@ -913,10 +913,10 @@ TEST_F(PolicyMapTest, EntryAddConflict) {
PolicyMap::Entry entry_a; PolicyMap::Entry entry_a;
entry_a.level = POLICY_LEVEL_MANDATORY; entry_a.level = POLICY_LEVEL_MANDATORY;
entry_a.source = POLICY_SOURCE_CLOUD; 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; entry_a.scope = POLICY_SCOPE_USER;
PolicyMap::Entry entry_b = entry_a.DeepCopy(); 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_b_no_conflicts = entry_b.DeepCopy();
PolicyMap::Entry entry_c = entry_a.DeepCopy(); PolicyMap::Entry entry_c = entry_a.DeepCopy();
entry_c.source = POLICY_SOURCE_PLATFORM; entry_c.source = POLICY_SOURCE_PLATFORM;
...@@ -937,9 +937,9 @@ TEST_F(PolicyMapTest, BlockedEntry) { ...@@ -937,9 +937,9 @@ TEST_F(PolicyMapTest, BlockedEntry) {
PolicyMap::Entry entry_a(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, PolicyMap::Entry entry_a(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
POLICY_SOURCE_CLOUD, base::Value("a"), nullptr); POLICY_SOURCE_CLOUD, base::Value("a"), nullptr);
PolicyMap::Entry entry_b = entry_a.DeepCopy(); 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(); 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(); entry_c_blocked.SetBlocked();
PolicyMap policies; PolicyMap policies;
...@@ -989,7 +989,7 @@ TEST_F(PolicyMapTest, InvalidEntry) { ...@@ -989,7 +989,7 @@ TEST_F(PolicyMapTest, InvalidEntry) {
PolicyMap::Entry entry_a(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, PolicyMap::Entry entry_a(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
POLICY_SOURCE_CLOUD, base::Value("a"), nullptr); POLICY_SOURCE_CLOUD, base::Value("a"), nullptr);
PolicyMap::Entry entry_b_invalid = entry_a.DeepCopy(); 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(); entry_b_invalid.SetInvalid();
PolicyMap policies; PolicyMap policies;
......
...@@ -119,7 +119,7 @@ void PolicyListMerger::DoMerge(PolicyMap::Entry* policy) const { ...@@ -119,7 +119,7 @@ void PolicyListMerger::DoMerge(PolicyMap::Entry* policy) const {
for (const base::Value* it : merged_values) for (const base::Value* it : merged_values)
new_value.Append(it->Clone()); 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->ClearConflicts();
policy->AddConflictingPolicy(std::move(new_conflict)); policy->AddConflictingPolicy(std::move(new_conflict));
...@@ -208,10 +208,9 @@ void PolicyDictionaryMerger::DoMerge(PolicyMap::Entry* policy) const { ...@@ -208,10 +208,9 @@ void PolicyDictionaryMerger::DoMerge(PolicyMap::Entry* policy) const {
} }
auto new_conflict = policy->DeepCopy(); auto new_conflict = policy->DeepCopy();
if (value_changed) { if (value_changed)
policy->set_value( policy->set_value(std::move(merged_dictionary));
base::Value::ToUniquePtrValue(std::move(merged_dictionary)));
}
policy->ClearConflicts(); policy->ClearConflicts();
policy->AddConflictingPolicy(std::move(new_conflict)); policy->AddConflictingPolicy(std::move(new_conflict));
policy->source = POLICY_SOURCE_MERGED; 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