0

[Code Health] Remove uses of Value::DeepCopy()

Uses have been replaced with Value::Clone(), wrapped with
base::Value::ToUniquePtrValue() when necessary.

Bug: 1187012
Change-Id: I1b52aa70f4f1e2a8e95dcd054db04b59f75cfad2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2873230
Commit-Queue: Austin Sullivan <asully@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#881291}
This commit is contained in:
Austin Sullivan
2021-05-10 23:00:32 +00:00
committed by Chromium LUCI CQ
parent 94d3270374
commit 12c5e9b91e
18 changed files with 38 additions and 33 deletions
ash/display
chrome
browser
test
chromedriver
chromeos
components
content

@ -476,8 +476,9 @@ void StoreDisplayLayoutPref(PrefService* pref_service,
std::unique_ptr<base::Value> layout_value(new base::DictionaryValue()); std::unique_ptr<base::Value> layout_value(new base::DictionaryValue());
if (pref_data->HasKey(name)) { if (pref_data->HasKey(name)) {
base::Value* value = nullptr; base::Value* value = nullptr;
if (pref_data->Get(name, &value) && value != nullptr) if (pref_data->Get(name, &value) && value != nullptr) {
layout_value.reset(value->DeepCopy()); layout_value = base::Value::ToUniquePtrValue(value->Clone());
}
} }
if (display::DisplayLayoutToJson(display_layout, layout_value.get())) if (display::DisplayLayoutToJson(display_layout, layout_value.get()))
pref_data->Set(name, std::move(layout_value)); pref_data->Set(name, std::move(layout_value));

@ -296,7 +296,7 @@ bool OwnerSettingsServiceAsh::Set(const std::string& setting,
if (!IsOwner() && !IsOwnerInTests(user_id_)) if (!IsOwner() && !IsOwnerInTests(user_id_))
return false; return false;
pending_changes_[setting] = base::WrapUnique(value.DeepCopy()); pending_changes_[setting] = base::Value::ToUniquePtrValue(value.Clone());
em::ChromeDeviceSettingsProto settings; em::ChromeDeviceSettingsProto settings;
if (tentative_settings_.get()) { if (tentative_settings_.get()) {

@ -408,10 +408,8 @@ std::unique_ptr<base::Value> ChromeosInfoPrivateGetFunction::GetValue(
return std::make_unique<base::Value>(timezone->GetValue()->Clone()); return std::make_unique<base::Value>(timezone->GetValue()->Clone());
} }
// TODO(crbug.com/697817): Convert CrosSettings::Get to take a unique_ptr. // TODO(crbug.com/697817): Convert CrosSettings::Get to take a unique_ptr.
return base::WrapUnique<base::Value>( return base::Value::ToUniquePtrValue(
ash::CrosSettings::Get() ash::CrosSettings::Get()->GetPref(chromeos::kSystemTimezone)->Clone());
->GetPref(chromeos::kSystemTimezone)
->DeepCopy());
} }
if (property_name == kPropertySupportedTimezones) { if (property_name == kPropertySupportedTimezones) {

@ -853,7 +853,7 @@ std::unique_ptr<settings_api::PrefObject> PrefsUtil::GetCrosSettingsPref(
} }
pref_object->key = name; pref_object->key = name;
pref_object->type = GetType(name, value->type()); pref_object->type = GetType(name, value->type());
pref_object->value.reset(value->DeepCopy()); pref_object->value = base::Value::ToUniquePtrValue(value->Clone());
#endif #endif
return pref_object; return pref_object;
@ -884,7 +884,8 @@ std::unique_ptr<settings_api::PrefObject> PrefsUtil::GetPref(
pref_object = std::make_unique<settings_api::PrefObject>(); pref_object = std::make_unique<settings_api::PrefObject>();
pref_object->key = pref->name(); pref_object->key = pref->name();
pref_object->type = GetType(name, pref->GetType()); pref_object->type = GetType(name, pref->GetType());
pref_object->value.reset(pref->GetValue()->DeepCopy()); pref_object->value =
base::Value::ToUniquePtrValue(pref->GetValue()->Clone());
} }
#if BUILDFLAG(IS_CHROMEOS_ASH) #if BUILDFLAG(IS_CHROMEOS_ASH)
@ -936,7 +937,8 @@ std::unique_ptr<settings_api::PrefObject> PrefsUtil::GetPref(
settings_api::ControlledBy::CONTROLLED_BY_USER_POLICY; settings_api::ControlledBy::CONTROLLED_BY_USER_POLICY;
pref_object->enforcement = pref_object->enforcement =
settings_api::Enforcement::ENFORCEMENT_RECOMMENDED; settings_api::Enforcement::ENFORCEMENT_RECOMMENDED;
pref_object->recommended_value.reset(recommended->DeepCopy()); pref_object->recommended_value =
base::Value::ToUniquePtrValue(recommended->Clone());
return pref_object; return pref_object;
} }

@ -73,7 +73,7 @@ void SetOriginStatus(Profile* profile,
->GetSettingsMap(profile) ->GetSettingsMap(profile)
->SetWebsiteSettingDefaultScope( ->SetWebsiteSettingDefaultScope(
origin, GURL(), ContentSettingsType::PERMISSION_AUTOREVOCATION_DATA, origin, GURL(), ContentSettingsType::PERMISSION_AUTOREVOCATION_DATA,
base::WrapUnique(dict.DeepCopy())); base::Value::ToUniquePtrValue(dict.Clone()));
} }
void RevokePermission(const GURL& origin, Profile* profile) { void RevokePermission(const GURL& origin, Profile* profile) {

@ -318,8 +318,8 @@ std::unique_ptr<base::ListValue> TtsExtensionEngine::BuildSpeakArgs(
// Pass through most options to the speech engine, but remove some // Pass through most options to the speech engine, but remove some
// that are handled internally. // that are handled internally.
std::unique_ptr<base::DictionaryValue> options( std::unique_ptr<base::DictionaryValue> options = base::DictionaryValue::From(
static_cast<base::DictionaryValue*>(utterance->GetOptions()->DeepCopy())); base::Value::ToUniquePtrValue(utterance->GetOptions()->Clone()));
if (options->FindKey(constants::kRequiredEventTypesKey)) if (options->FindKey(constants::kRequiredEventTypesKey))
options->Remove(constants::kRequiredEventTypesKey, NULL); options->Remove(constants::kRequiredEventTypesKey, NULL);
if (options->FindKey(constants::kDesiredEventTypesKey)) if (options->FindKey(constants::kDesiredEventTypesKey))

@ -74,7 +74,7 @@ std::unique_ptr<base::Value> SmartDeepCopy(const base::Value* value) {
TruncateString(&data); TruncateString(&data);
return std::make_unique<base::Value>(data); return std::make_unique<base::Value>(data);
} }
return std::unique_ptr<base::Value>(value->DeepCopy()); return base::Value::ToUniquePtrValue(value->Clone());
} }
} // namespace } // namespace

@ -1233,7 +1233,7 @@ Status WebViewImpl::CallAsyncFunctionInternal(
base::Value* value = NULL; base::Value* value = NULL;
if (result_info->Get("value", &value)) { if (result_info->Get("value", &value)) {
result->reset(value->DeepCopy()); *result = base::Value::ToUniquePtrValue(value->Clone());
return Status(kOk); return Status(kOk);
} }
@ -1324,14 +1324,14 @@ std::unique_ptr<base::Value> WebViewImpl::GetCastSinks() {
if (!cast_tracker_) if (!cast_tracker_)
cast_tracker_ = std::make_unique<CastTracker>(client_.get()); cast_tracker_ = std::make_unique<CastTracker>(client_.get());
HandleReceivedEvents(); HandleReceivedEvents();
return std::unique_ptr<base::Value>(cast_tracker_->sinks().DeepCopy()); return base::Value::ToUniquePtrValue(cast_tracker_->sinks().Clone());
} }
std::unique_ptr<base::Value> WebViewImpl::GetCastIssueMessage() { std::unique_ptr<base::Value> WebViewImpl::GetCastIssueMessage() {
if (!cast_tracker_) if (!cast_tracker_)
cast_tracker_ = std::make_unique<CastTracker>(client_.get()); cast_tracker_ = std::make_unique<CastTracker>(client_.get());
HandleReceivedEvents(); HandleReceivedEvents();
return std::unique_ptr<base::Value>(cast_tracker_->issue().DeepCopy()); return base::Value::ToUniquePtrValue(cast_tracker_->issue().Clone());
} }
WebViewImplHolder::WebViewImplHolder(WebViewImpl* web_view) { WebViewImplHolder::WebViewImplHolder(WebViewImpl* web_view) {
@ -1444,7 +1444,7 @@ Status EvaluateScriptAndGetValue(DevToolsClient* client,
base::Value* value; base::Value* value;
if (!temp_result->Get("value", &value)) if (!temp_result->Get("value", &value))
return Status(kUnknownError, "Runtime.evaluate missing 'value'"); return Status(kUnknownError, "Runtime.evaluate missing 'value'");
result->reset(value->DeepCopy()); *result = base::Value::ToUniquePtrValue(value->Clone());
} }
return Status(kOk); return Status(kOk);
} }
@ -1469,7 +1469,7 @@ Status ParseCallFunctionResult(const base::Value& temp_result,
// Missing 'value' indicates the JavaScript code didn't return a value. // Missing 'value' indicates the JavaScript code didn't return a value.
return Status(kOk); return Status(kOk);
} }
result->reset(unscoped_value->DeepCopy()); *result = base::Value::ToUniquePtrValue(unscoped_value->Clone());
return Status(kOk); return Status(kOk);
} }

@ -51,7 +51,7 @@ std::unique_ptr<base::Value> PopStringToStringDictionary(
} // namespace } // namespace
ValueMatcher::ValueMatcher(const base::Value& value) ValueMatcher::ValueMatcher(const base::Value& value)
: expected_value_(value.DeepCopy()) {} : expected_value_(base::Value::ToUniquePtrValue(value.Clone())) {}
bool ValueMatcher::MatchAndExplain(const base::Value& value, bool ValueMatcher::MatchAndExplain(const base::Value& value,
MatchResultListener* listener) const { MatchResultListener* listener) const {

@ -87,8 +87,10 @@ NetworkUIData::NetworkUIData(const base::Value& dict) {
const base::Value* user_settings_value = const base::Value* user_settings_value =
dict.FindKeyOfType(kKeyUserSettings, base::Value::Type::DICTIONARY); dict.FindKeyOfType(kKeyUserSettings, base::Value::Type::DICTIONARY);
if (user_settings_value) if (user_settings_value) {
user_settings_.reset(user_settings_value->DeepCopy()); user_settings_ =
base::Value::ToUniquePtrValue(user_settings_value->Clone());
}
} }
NetworkUIData::~NetworkUIData() = default; NetworkUIData::~NetworkUIData() = default;

@ -62,7 +62,7 @@ std::unique_ptr<base::Value> Mapper::MapPrimitive(
const OncValueSignature& signature, const OncValueSignature& signature,
const base::Value& onc_primitive, const base::Value& onc_primitive,
bool* error) { bool* error) {
return base::WrapUnique(onc_primitive.DeepCopy()); return base::Value::ToUniquePtrValue(onc_primitive.Clone());
} }
void Mapper::MapFields(const OncValueSignature& object_signature, void Mapper::MapFields(const OncValueSignature& object_signature,

@ -310,7 +310,7 @@ class MergeToEffective : public MergeSettingsAndPolicies {
// dictionaries contained a value for it. // dictionaries contained a value for it.
} }
if (result) if (result)
return base::WrapUnique(result->DeepCopy()); return base::Value::ToUniquePtrValue(result->Clone());
return nullptr; return nullptr;
} }
@ -380,7 +380,7 @@ class MergeToAugmented : public MergeToEffective {
// controlled by policy. Return the plain active value instead of an // controlled by policy. Return the plain active value instead of an
// augmented dictionary. // augmented dictionary.
if (values.active_setting) if (values.active_setting)
return base::WrapUnique(values.active_setting->DeepCopy()); return base::Value::ToUniquePtrValue(values.active_setting->Clone());
return nullptr; return nullptr;
} }
@ -402,7 +402,7 @@ class MergeToAugmented : public MergeToEffective {
} }
if (values.active_setting) { if (values.active_setting) {
// Unmanaged networks have assigned (active) values. // Unmanaged networks have assigned (active) values.
return base::WrapUnique(values.active_setting->DeepCopy()); return base::Value::ToUniquePtrValue(values.active_setting->Clone());
} }
LOG(ERROR) << "Field has no effective value: " << key; LOG(ERROR) << "Field has no effective value: " << key;
return nullptr; return nullptr;

@ -309,7 +309,7 @@ void DefaultProvider::ChangeSetting(ContentSettingsType content_type,
DCHECK(!info || !value || DCHECK(!info || !value ||
info->IsDefaultSettingValid(ValueToContentSetting(value))); info->IsDefaultSettingValid(ValueToContentSetting(value)));
default_settings_[content_type] = default_settings_[content_type] =
value ? base::WrapUnique(value->DeepCopy()) value ? base::Value::ToUniquePtrValue(value->Clone())
: ContentSettingToValue(GetDefaultValue(content_type)); : ContentSettingToValue(GetDefaultValue(content_type));
} }

@ -393,7 +393,7 @@ bool SchemaValidatingPolicyHandler::CheckAndGetValue(
if (!value) if (!value)
return true; return true;
output->reset(value->DeepCopy()); *output = base::Value::ToUniquePtrValue(value->Clone());
std::string error_path; std::string error_path;
std::string error; std::string error;
bool result = bool result =

@ -11,6 +11,7 @@
#include "base/location.h" #include "base/location.h"
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "base/util/values/values_util.h" #include "base/util/values/values_util.h"
#include "base/values.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
using base::SequencedTaskRunner; using base::SequencedTaskRunner;
@ -72,8 +73,9 @@ void PrefMemberBase::UpdateValueFromPref(base::OnceClosure callback) const {
DCHECK(pref); DCHECK(pref);
if (!internal()) if (!internal())
CreateInternal(); CreateInternal();
internal()->UpdateValue(pref->GetValue()->DeepCopy(), pref->IsManaged(), internal()->UpdateValue(
pref->IsUserModifiable(), std::move(callback)); base::Value::ToUniquePtrValue(pref->GetValue()->Clone()).release(),
pref->IsManaged(), pref->IsUserModifiable(), std::move(callback));
} }
void PrefMemberBase::VerifyPref() const { void PrefMemberBase::VerifyPref() const {

@ -280,7 +280,7 @@ std::unique_ptr<base::Value> PrefModelAssociator::MergePreference(
} }
// If this is not a specially handled preference, server wins. // If this is not a specially handled preference, server wins.
return base::WrapUnique(server_value.DeepCopy()); return base::Value::ToUniquePtrValue(server_value.Clone());
} }
bool PrefModelAssociator::CreatePrefSyncData( bool PrefModelAssociator::CreatePrefSyncData(

@ -106,7 +106,7 @@ const std::string& TtsUtteranceImpl::GetText() {
} }
void TtsUtteranceImpl::SetOptions(const base::Value* options) { void TtsUtteranceImpl::SetOptions(const base::Value* options) {
options_.reset(options->DeepCopy()); options_ = base::Value::ToUniquePtrValue(options->Clone());
} }
const base::Value* TtsUtteranceImpl::GetOptions() { const base::Value* TtsUtteranceImpl::GetOptions() {

@ -108,7 +108,7 @@ std::unique_ptr<base::Value> GinJavaBridgeDispatcher::InvokeJavaMethod(
base::Value* result; base::Value* result;
if (!result_wrapper.Get(0, &result)) if (!result_wrapper.Get(0, &result))
return nullptr; return nullptr;
return std::unique_ptr<base::Value>(result->DeepCopy()); return base::Value::ToUniquePtrValue(result->Clone());
} }
GinJavaBridgeObject* GinJavaBridgeDispatcher::GetObject(ObjectID object_id) { GinJavaBridgeObject* GinJavaBridgeDispatcher::GetObject(ObjectID object_id) {