Commit 69f85465 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Remove uses of deprecated override of PrefValueMap::SetValue

Convert client of the deprecated of PrefValueMap::SetValue taking
a std::unique_ptr<base::Value> to the recommended override taking
a base::Value directly.

The conversion is done using the following rules:

- If the value is built inline using std::make_unique<base::Value>
  then change to just construct a base::Value directly,

- If the value is built use base::Value::CreateDeepCopy(), then
  change to use base::Clone() which returns a base::Value instead
  of a std::unique_ptr<base::Value>,

- If the std::unique_ptr<base::Value> is just forwarded by the
  caller, dcheck it is not null (the check was present in the old
  method implementation) and use base::Value::FromUniquePtrValue
  to convert the std::unique_ptr<base::Value> to a base::Value.

This CL fixes uses in src/components/policy.

This CL was uploaded by git cl split.

Bug: 646113
Change-Id: Ief82c150539f913edd8f44f36caf566baaf39819
Reviewed-on: https://chromium-review.googlesource.com/c/1446360Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Auto-Submit: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#628485}
parent fd22eaa6
......@@ -228,8 +228,8 @@ void StringMappingListPolicyHandler::ApplyPolicySettings(
if (!pref_path_)
return;
const base::Value* value = policies.GetValue(policy_name());
std::unique_ptr<base::ListValue> list(new base::ListValue());
if (value && Convert(value, list.get(), nullptr))
base::ListValue list;
if (value && Convert(value, &list, nullptr))
prefs->SetValue(pref_path_, std::move(list));
}
......@@ -350,7 +350,7 @@ void SimplePolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
return;
const base::Value* value = policies.GetValue(policy_name());
if (value)
prefs->SetValue(pref_path_, value->CreateDeepCopy());
prefs->SetValue(pref_path_, value->Clone());
}
......@@ -456,7 +456,7 @@ void SimpleSchemaValidatingPolicyHandler::ApplyPolicySettings(
return;
const base::Value* value = policies.GetValue(policy_name());
if (value)
prefs->SetValue(pref_path_, value->CreateDeepCopy());
prefs->SetValue(pref_path_, value->Clone());
}
// SimpleJsonStringSchemaValidatingPolicyHandler implementation ----------------
......@@ -614,7 +614,7 @@ void SimpleJsonStringSchemaValidatingPolicyHandler::ApplyPolicySettings(
return;
const base::Value* value = policies.GetValue(policy_name_);
if (value)
prefs->SetValue(pref_path_, value->CreateDeepCopy());
prefs->SetValue(pref_path_, value->Clone());
}
void SimpleJsonStringSchemaValidatingPolicyHandler::RecordJsonError() {
......
......@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/values.h"
#include "components/policy/core/browser/policy_error_map.h"
#include "components/policy/core/common/policy_map.h"
......@@ -116,7 +117,9 @@ class StringListPolicyHandler : public ListPolicyHandler {
protected:
void ApplyList(std::unique_ptr<base::ListValue> filtered_list,
PrefValueMap* prefs) override {
prefs->SetValue(kTestPref, std::move(filtered_list));
DCHECK(filtered_list);
prefs->SetValue(kTestPref,
base::Value::FromUniquePtrValue(std::move(filtered_list)));
}
};
......
......@@ -173,22 +173,19 @@ void ProxyPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
switch (proxy_mode) {
case ProxyPrefs::MODE_DIRECT:
prefs->SetValue(
proxy_config::prefs::kProxy,
std::make_unique<base::Value>(ProxyConfigDictionary::CreateDirect()));
prefs->SetValue(proxy_config::prefs::kProxy,
ProxyConfigDictionary::CreateDirect());
break;
case ProxyPrefs::MODE_AUTO_DETECT:
prefs->SetValue(proxy_config::prefs::kProxy,
std::make_unique<base::Value>(
ProxyConfigDictionary::CreateAutoDetect()));
ProxyConfigDictionary::CreateAutoDetect());
break;
case ProxyPrefs::MODE_PAC_SCRIPT: {
std::string pac_url_string;
if (pac_url && pac_url->GetAsString(&pac_url_string)) {
prefs->SetValue(
proxy_config::prefs::kProxy,
std::make_unique<base::Value>(
ProxyConfigDictionary::CreatePacScript(pac_url_string, false)));
ProxyConfigDictionary::CreatePacScript(pac_url_string, false));
} else {
NOTREACHED();
}
......@@ -201,16 +198,14 @@ void ProxyPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
if (bypass_list)
bypass_list->GetAsString(&bypass_list_string);
prefs->SetValue(proxy_config::prefs::kProxy,
std::make_unique<base::Value>(
ProxyConfigDictionary::CreateFixedServers(
proxy_server, bypass_list_string)));
ProxyConfigDictionary::CreateFixedServers(
proxy_server, bypass_list_string));
}
break;
}
case ProxyPrefs::MODE_SYSTEM:
prefs->SetValue(
proxy_config::prefs::kProxy,
std::make_unique<base::Value>(ProxyConfigDictionary::CreateSystem()));
prefs->SetValue(proxy_config::prefs::kProxy,
ProxyConfigDictionary::CreateSystem());
break;
case ProxyPrefs::kModeCount:
NOTREACHED();
......
......@@ -6,6 +6,7 @@
#include <memory>
#include <utility>
#include <vector>
#include "base/values.h"
#include "components/policy/core/browser/policy_error_map.h"
......@@ -53,7 +54,7 @@ void URLBlacklistPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
if (disabled_schemes_policy)
disabled_schemes_policy->GetAsList(&disabled_schemes);
std::unique_ptr<base::ListValue> merged_url_blacklist(new base::ListValue());
std::vector<base::Value> merged_url_blacklist;
// We start with the DisabledSchemes because we have size limit when
// handling URLBlacklists.
......@@ -62,7 +63,7 @@ void URLBlacklistPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
std::string entry_value;
if (entry.GetAsString(&entry_value)) {
entry_value.append("://*");
merged_url_blacklist->AppendString(entry_value);
merged_url_blacklist.emplace_back(std::move(entry_value));
}
}
}
......@@ -70,13 +71,13 @@ void URLBlacklistPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
if (url_blacklist) {
for (const auto& entry : *url_blacklist) {
if (entry.is_string())
merged_url_blacklist->Append(entry.CreateDeepCopy());
merged_url_blacklist.push_back(entry.Clone());
}
}
if (disabled_schemes || url_blacklist) {
prefs->SetValue(policy_prefs::kUrlBlacklist,
std::move(merged_url_blacklist));
base::Value(std::move(merged_url_blacklist)));
}
}
......
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