[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:

committed by
Chromium LUCI CQ

parent
94d3270374
commit
12c5e9b91e
ash/display
chrome
browser
ash
ownership
chromeos
extensions
extensions
api
settings_private
permissions
speech
extension_api
test
chromedriver
chrome
chromeos
components
content_settings
core
policy
core
prefs
sync_preferences
content
@ -476,8 +476,9 @@ void StoreDisplayLayoutPref(PrefService* pref_service,
|
||||
std::unique_ptr<base::Value> layout_value(new base::DictionaryValue());
|
||||
if (pref_data->HasKey(name)) {
|
||||
base::Value* value = nullptr;
|
||||
if (pref_data->Get(name, &value) && value != nullptr)
|
||||
layout_value.reset(value->DeepCopy());
|
||||
if (pref_data->Get(name, &value) && value != nullptr) {
|
||||
layout_value = base::Value::ToUniquePtrValue(value->Clone());
|
||||
}
|
||||
}
|
||||
if (display::DisplayLayoutToJson(display_layout, layout_value.get()))
|
||||
pref_data->Set(name, std::move(layout_value));
|
||||
|
@ -296,7 +296,7 @@ bool OwnerSettingsServiceAsh::Set(const std::string& setting,
|
||||
if (!IsOwner() && !IsOwnerInTests(user_id_))
|
||||
return false;
|
||||
|
||||
pending_changes_[setting] = base::WrapUnique(value.DeepCopy());
|
||||
pending_changes_[setting] = base::Value::ToUniquePtrValue(value.Clone());
|
||||
|
||||
em::ChromeDeviceSettingsProto settings;
|
||||
if (tentative_settings_.get()) {
|
||||
|
@ -408,10 +408,8 @@ std::unique_ptr<base::Value> ChromeosInfoPrivateGetFunction::GetValue(
|
||||
return std::make_unique<base::Value>(timezone->GetValue()->Clone());
|
||||
}
|
||||
// TODO(crbug.com/697817): Convert CrosSettings::Get to take a unique_ptr.
|
||||
return base::WrapUnique<base::Value>(
|
||||
ash::CrosSettings::Get()
|
||||
->GetPref(chromeos::kSystemTimezone)
|
||||
->DeepCopy());
|
||||
return base::Value::ToUniquePtrValue(
|
||||
ash::CrosSettings::Get()->GetPref(chromeos::kSystemTimezone)->Clone());
|
||||
}
|
||||
|
||||
if (property_name == kPropertySupportedTimezones) {
|
||||
|
@ -853,7 +853,7 @@ std::unique_ptr<settings_api::PrefObject> PrefsUtil::GetCrosSettingsPref(
|
||||
}
|
||||
pref_object->key = name;
|
||||
pref_object->type = GetType(name, value->type());
|
||||
pref_object->value.reset(value->DeepCopy());
|
||||
pref_object->value = base::Value::ToUniquePtrValue(value->Clone());
|
||||
#endif
|
||||
|
||||
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->key = pref->name();
|
||||
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)
|
||||
@ -936,7 +937,8 @@ std::unique_ptr<settings_api::PrefObject> PrefsUtil::GetPref(
|
||||
settings_api::ControlledBy::CONTROLLED_BY_USER_POLICY;
|
||||
pref_object->enforcement =
|
||||
settings_api::Enforcement::ENFORCEMENT_RECOMMENDED;
|
||||
pref_object->recommended_value.reset(recommended->DeepCopy());
|
||||
pref_object->recommended_value =
|
||||
base::Value::ToUniquePtrValue(recommended->Clone());
|
||||
return pref_object;
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ void SetOriginStatus(Profile* profile,
|
||||
->GetSettingsMap(profile)
|
||||
->SetWebsiteSettingDefaultScope(
|
||||
origin, GURL(), ContentSettingsType::PERMISSION_AUTOREVOCATION_DATA,
|
||||
base::WrapUnique(dict.DeepCopy()));
|
||||
base::Value::ToUniquePtrValue(dict.Clone()));
|
||||
}
|
||||
|
||||
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
|
||||
// that are handled internally.
|
||||
std::unique_ptr<base::DictionaryValue> options(
|
||||
static_cast<base::DictionaryValue*>(utterance->GetOptions()->DeepCopy()));
|
||||
std::unique_ptr<base::DictionaryValue> options = base::DictionaryValue::From(
|
||||
base::Value::ToUniquePtrValue(utterance->GetOptions()->Clone()));
|
||||
if (options->FindKey(constants::kRequiredEventTypesKey))
|
||||
options->Remove(constants::kRequiredEventTypesKey, NULL);
|
||||
if (options->FindKey(constants::kDesiredEventTypesKey))
|
||||
|
@ -74,7 +74,7 @@ std::unique_ptr<base::Value> SmartDeepCopy(const base::Value* value) {
|
||||
TruncateString(&data);
|
||||
return std::make_unique<base::Value>(data);
|
||||
}
|
||||
return std::unique_ptr<base::Value>(value->DeepCopy());
|
||||
return base::Value::ToUniquePtrValue(value->Clone());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -1233,7 +1233,7 @@ Status WebViewImpl::CallAsyncFunctionInternal(
|
||||
|
||||
base::Value* value = NULL;
|
||||
if (result_info->Get("value", &value)) {
|
||||
result->reset(value->DeepCopy());
|
||||
*result = base::Value::ToUniquePtrValue(value->Clone());
|
||||
return Status(kOk);
|
||||
}
|
||||
|
||||
@ -1324,14 +1324,14 @@ std::unique_ptr<base::Value> WebViewImpl::GetCastSinks() {
|
||||
if (!cast_tracker_)
|
||||
cast_tracker_ = std::make_unique<CastTracker>(client_.get());
|
||||
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() {
|
||||
if (!cast_tracker_)
|
||||
cast_tracker_ = std::make_unique<CastTracker>(client_.get());
|
||||
HandleReceivedEvents();
|
||||
return std::unique_ptr<base::Value>(cast_tracker_->issue().DeepCopy());
|
||||
return base::Value::ToUniquePtrValue(cast_tracker_->issue().Clone());
|
||||
}
|
||||
|
||||
WebViewImplHolder::WebViewImplHolder(WebViewImpl* web_view) {
|
||||
@ -1444,7 +1444,7 @@ Status EvaluateScriptAndGetValue(DevToolsClient* client,
|
||||
base::Value* value;
|
||||
if (!temp_result->Get("value", &value))
|
||||
return Status(kUnknownError, "Runtime.evaluate missing 'value'");
|
||||
result->reset(value->DeepCopy());
|
||||
*result = base::Value::ToUniquePtrValue(value->Clone());
|
||||
}
|
||||
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.
|
||||
return Status(kOk);
|
||||
}
|
||||
result->reset(unscoped_value->DeepCopy());
|
||||
*result = base::Value::ToUniquePtrValue(unscoped_value->Clone());
|
||||
return Status(kOk);
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ std::unique_ptr<base::Value> PopStringToStringDictionary(
|
||||
} // namespace
|
||||
|
||||
ValueMatcher::ValueMatcher(const base::Value& value)
|
||||
: expected_value_(value.DeepCopy()) {}
|
||||
: expected_value_(base::Value::ToUniquePtrValue(value.Clone())) {}
|
||||
|
||||
bool ValueMatcher::MatchAndExplain(const base::Value& value,
|
||||
MatchResultListener* listener) const {
|
||||
|
@ -87,8 +87,10 @@ NetworkUIData::NetworkUIData(const base::Value& dict) {
|
||||
|
||||
const base::Value* user_settings_value =
|
||||
dict.FindKeyOfType(kKeyUserSettings, base::Value::Type::DICTIONARY);
|
||||
if (user_settings_value)
|
||||
user_settings_.reset(user_settings_value->DeepCopy());
|
||||
if (user_settings_value) {
|
||||
user_settings_ =
|
||||
base::Value::ToUniquePtrValue(user_settings_value->Clone());
|
||||
}
|
||||
}
|
||||
|
||||
NetworkUIData::~NetworkUIData() = default;
|
||||
|
@ -62,7 +62,7 @@ std::unique_ptr<base::Value> Mapper::MapPrimitive(
|
||||
const OncValueSignature& signature,
|
||||
const base::Value& onc_primitive,
|
||||
bool* error) {
|
||||
return base::WrapUnique(onc_primitive.DeepCopy());
|
||||
return base::Value::ToUniquePtrValue(onc_primitive.Clone());
|
||||
}
|
||||
|
||||
void Mapper::MapFields(const OncValueSignature& object_signature,
|
||||
|
@ -310,7 +310,7 @@ class MergeToEffective : public MergeSettingsAndPolicies {
|
||||
// dictionaries contained a value for it.
|
||||
}
|
||||
if (result)
|
||||
return base::WrapUnique(result->DeepCopy());
|
||||
return base::Value::ToUniquePtrValue(result->Clone());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -380,7 +380,7 @@ class MergeToAugmented : public MergeToEffective {
|
||||
// controlled by policy. Return the plain active value instead of an
|
||||
// augmented dictionary.
|
||||
if (values.active_setting)
|
||||
return base::WrapUnique(values.active_setting->DeepCopy());
|
||||
return base::Value::ToUniquePtrValue(values.active_setting->Clone());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -402,7 +402,7 @@ class MergeToAugmented : public MergeToEffective {
|
||||
}
|
||||
if (values.active_setting) {
|
||||
// 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;
|
||||
return nullptr;
|
||||
|
@ -309,7 +309,7 @@ void DefaultProvider::ChangeSetting(ContentSettingsType content_type,
|
||||
DCHECK(!info || !value ||
|
||||
info->IsDefaultSettingValid(ValueToContentSetting(value)));
|
||||
default_settings_[content_type] =
|
||||
value ? base::WrapUnique(value->DeepCopy())
|
||||
value ? base::Value::ToUniquePtrValue(value->Clone())
|
||||
: ContentSettingToValue(GetDefaultValue(content_type));
|
||||
}
|
||||
|
||||
|
@ -393,7 +393,7 @@ bool SchemaValidatingPolicyHandler::CheckAndGetValue(
|
||||
if (!value)
|
||||
return true;
|
||||
|
||||
output->reset(value->DeepCopy());
|
||||
*output = base::Value::ToUniquePtrValue(value->Clone());
|
||||
std::string error_path;
|
||||
std::string error;
|
||||
bool result =
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "base/location.h"
|
||||
#include "base/threading/sequenced_task_runner_handle.h"
|
||||
#include "base/util/values/values_util.h"
|
||||
#include "base/values.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
|
||||
using base::SequencedTaskRunner;
|
||||
@ -72,8 +73,9 @@ void PrefMemberBase::UpdateValueFromPref(base::OnceClosure callback) const {
|
||||
DCHECK(pref);
|
||||
if (!internal())
|
||||
CreateInternal();
|
||||
internal()->UpdateValue(pref->GetValue()->DeepCopy(), pref->IsManaged(),
|
||||
pref->IsUserModifiable(), std::move(callback));
|
||||
internal()->UpdateValue(
|
||||
base::Value::ToUniquePtrValue(pref->GetValue()->Clone()).release(),
|
||||
pref->IsManaged(), pref->IsUserModifiable(), std::move(callback));
|
||||
}
|
||||
|
||||
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.
|
||||
return base::WrapUnique(server_value.DeepCopy());
|
||||
return base::Value::ToUniquePtrValue(server_value.Clone());
|
||||
}
|
||||
|
||||
bool PrefModelAssociator::CreatePrefSyncData(
|
||||
|
@ -106,7 +106,7 @@ const std::string& TtsUtteranceImpl::GetText() {
|
||||
}
|
||||
|
||||
void TtsUtteranceImpl::SetOptions(const base::Value* options) {
|
||||
options_.reset(options->DeepCopy());
|
||||
options_ = base::Value::ToUniquePtrValue(options->Clone());
|
||||
}
|
||||
|
||||
const base::Value* TtsUtteranceImpl::GetOptions() {
|
||||
|
@ -108,7 +108,7 @@ std::unique_ptr<base::Value> GinJavaBridgeDispatcher::InvokeJavaMethod(
|
||||
base::Value* result;
|
||||
if (!result_wrapper.Get(0, &result))
|
||||
return nullptr;
|
||||
return std::unique_ptr<base::Value>(result->DeepCopy());
|
||||
return base::Value::ToUniquePtrValue(result->Clone());
|
||||
}
|
||||
|
||||
GinJavaBridgeObject* GinJavaBridgeDispatcher::GetObject(ObjectID object_id) {
|
||||
|
Reference in New Issue
Block a user