Remove heap allocation of base::Value from NetLog.
This CL changes NetLogParametersCallback to return a "base::Value" rather than a "std::unique_ptr<base::Value>", and updates the affected callsites.
This is a step towards removing all the deprecated calls in base/values.h. This CL does not change the use of base::DictionaryValue.
Bug: 646113
Bug: 901525
TBR: [email protected],[email protected]
Change-Id: I27465cc27578de22575f4a441f571cdaa3eda4d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1590407
Commit-Queue: Eric Roman <[email protected]>
Reviewed-by: David Benjamin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#655454}
diff --git a/net/log/net_log.cc b/net/log/net_log.cc
index afb760e..88b3fa8 100644
--- a/net/log/net_log.cc
+++ b/net/log/net_log.cc
@@ -23,63 +23,51 @@
namespace {
-std::unique_ptr<base::Value> NetLogBoolCallback(
- const char* name,
- bool value,
- NetLogCaptureMode /* capture_mode */) {
- std::unique_ptr<base::DictionaryValue> event_params(
- new base::DictionaryValue());
- event_params->SetBoolean(name, value);
+base::Value NetLogBoolCallback(const char* name,
+ bool value,
+ NetLogCaptureMode /* capture_mode */) {
+ base::DictionaryValue event_params;
+ event_params.SetBoolean(name, value);
return std::move(event_params);
}
-std::unique_ptr<base::Value> NetLogIntCallback(
- const char* name,
- int value,
- NetLogCaptureMode /* capture_mode */) {
- std::unique_ptr<base::DictionaryValue> event_params(
- new base::DictionaryValue());
- event_params->SetInteger(name, value);
+base::Value NetLogIntCallback(const char* name,
+ int value,
+ NetLogCaptureMode /* capture_mode */) {
+ base::DictionaryValue event_params;
+ event_params.SetInteger(name, value);
return std::move(event_params);
}
-std::unique_ptr<base::Value> NetLogInt64Callback(
- const char* name,
- int64_t value,
- NetLogCaptureMode /* capture_mode */) {
- std::unique_ptr<base::DictionaryValue> event_params(
- new base::DictionaryValue());
- event_params->SetKey(name, NetLogNumberValue(value));
+base::Value NetLogInt64Callback(const char* name,
+ int64_t value,
+ NetLogCaptureMode /* capture_mode */) {
+ base::DictionaryValue event_params;
+ event_params.SetKey(name, NetLogNumberValue(value));
return std::move(event_params);
}
-std::unique_ptr<base::Value> NetLogStringCallback(
- const char* name,
- const std::string* value,
- NetLogCaptureMode /* capture_mode */) {
- std::unique_ptr<base::DictionaryValue> event_params(
- new base::DictionaryValue());
- event_params->SetString(name, *value);
+base::Value NetLogStringCallback(const char* name,
+ const std::string* value,
+ NetLogCaptureMode /* capture_mode */) {
+ base::DictionaryValue event_params;
+ event_params.SetString(name, *value);
return std::move(event_params);
}
-std::unique_ptr<base::Value> NetLogCharStringCallback(
- const char* name,
- const char* value,
- NetLogCaptureMode /* capture_mode */) {
- std::unique_ptr<base::DictionaryValue> event_params(
- new base::DictionaryValue());
- event_params->SetString(name, value);
+base::Value NetLogCharStringCallback(const char* name,
+ const char* value,
+ NetLogCaptureMode /* capture_mode */) {
+ base::DictionaryValue event_params;
+ event_params.SetString(name, value);
return std::move(event_params);
}
-std::unique_ptr<base::Value> NetLogString16Callback(
- const char* name,
- const base::string16* value,
- NetLogCaptureMode /* capture_mode */) {
- std::unique_ptr<base::DictionaryValue> event_params(
- new base::DictionaryValue());
- event_params->SetString(name, *value);
+base::Value NetLogString16Callback(const char* name,
+ const base::string16* value,
+ NetLogCaptureMode /* capture_mode */) {
+ base::DictionaryValue event_params;
+ event_params.SetString(name, *value);
return std::move(event_params);
}
@@ -236,10 +224,10 @@
}
// static
-std::unique_ptr<base::Value> NetLog::GetEventTypesAsValue() {
- auto dict = std::make_unique<base::DictionaryValue>();
+base::Value NetLog::GetEventTypesAsValue() {
+ base::DictionaryValue dict;
for (int i = 0; i < static_cast<int>(NetLogEventType::COUNT); ++i) {
- dict->SetInteger(EventTypeToString(static_cast<NetLogEventType>(i)), i);
+ dict.SetInteger(EventTypeToString(static_cast<NetLogEventType>(i)), i);
}
return std::move(dict);
}
@@ -259,10 +247,10 @@
}
// static
-std::unique_ptr<base::Value> NetLog::GetSourceTypesAsValue() {
- auto dict = std::make_unique<base::DictionaryValue>();
+base::Value NetLog::GetSourceTypesAsValue() {
+ base::DictionaryValue dict;
for (int i = 0; i < static_cast<int>(NetLogSourceType::COUNT); ++i) {
- dict->SetInteger(SourceTypeToString(static_cast<NetLogSourceType>(i)), i);
+ dict.SetInteger(SourceTypeToString(static_cast<NetLogSourceType>(i)), i);
}
return std::move(dict);
}