Commit 1dc52484 authored by Panos Astithas's avatar Panos Astithas Committed by Commit Bot

Remove base::DictionaryValue usage in net::GetNetConstants()

R=eroman@chromium.org

Bug: 646113
Change-Id: Ia62bfc2531336e289e315eb035fc0fcf15c81ebb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2225279
Commit-Queue: Panos Astithas <pastithas@google.com>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774968}
parent cdca6879
...@@ -13,17 +13,15 @@ ...@@ -13,17 +13,15 @@
namespace net_log { namespace net_log {
std::unique_ptr<base::Value> GetConstantsForNetLog( base::Value GetConstantsForNetLog(
const base::CommandLine::StringType& command_line_string, const base::CommandLine::StringType& command_line_string,
const std::string& channel_string) { const std::string& channel_string) {
std::unique_ptr<base::DictionaryValue> constants_dict = base::Value constants_dict = net::GetNetConstants();
net::GetNetConstants();
DCHECK(constants_dict);
auto platform_dict = auto platform_dict =
GetPlatformConstantsForNetLog(command_line_string, channel_string); GetPlatformConstantsForNetLog(command_line_string, channel_string);
if (platform_dict) if (platform_dict)
constants_dict->MergeDictionary(platform_dict.get()); constants_dict.MergeDictionary(platform_dict.get());
return constants_dict; return constants_dict;
} }
......
...@@ -24,7 +24,7 @@ namespace net_log { ...@@ -24,7 +24,7 @@ namespace net_log {
// names of error codes. // names of error codes.
// //
// Safe to call on any thread. // Safe to call on any thread.
std::unique_ptr<base::Value> GetConstantsForNetLog( base::Value GetConstantsForNetLog(
const base::CommandLine::StringType& command_line_string, const base::CommandLine::StringType& command_line_string,
const std::string& channel_string); const std::string& channel_string);
......
...@@ -29,13 +29,12 @@ namespace content { ...@@ -29,13 +29,12 @@ namespace content {
namespace { namespace {
std::unique_ptr<base::ListValue> GetNetworkErrorData() { std::unique_ptr<base::ListValue> GetNetworkErrorData() {
std::unique_ptr<base::DictionaryValue> error_codes = net::GetNetConstants(); base::Value error_codes = net::GetNetConstants();
const base::DictionaryValue* net_error_codes_dict = nullptr; const base::DictionaryValue* net_error_codes_dict = nullptr;
for (base::DictionaryValue::Iterator itr(*error_codes); !itr.IsAtEnd(); for (const auto& item : error_codes.DictItems()) {
itr.Advance()) { if (item.first == kNetworkErrorKey) {
if (itr.key() == kNetworkErrorKey) { item.second.GetAsDictionary(&net_error_codes_dict);
itr.value().GetAsDictionary(&net_error_codes_dict);
break; break;
} }
} }
......
...@@ -227,13 +227,12 @@ bool URLDataManagerBackend::CheckURLIsValid(const GURL& url) { ...@@ -227,13 +227,12 @@ bool URLDataManagerBackend::CheckURLIsValid(const GURL& url) {
} }
bool URLDataManagerBackend::IsValidNetworkErrorCode(int error_code) { bool URLDataManagerBackend::IsValidNetworkErrorCode(int error_code) {
std::unique_ptr<base::DictionaryValue> error_codes = net::GetNetConstants(); base::Value error_codes = net::GetNetConstants();
const base::DictionaryValue* net_error_codes_dict = nullptr; const base::DictionaryValue* net_error_codes_dict = nullptr;
for (base::DictionaryValue::Iterator itr(*error_codes); !itr.IsAtEnd(); for (const auto& item : error_codes.DictItems()) {
itr.Advance()) { if (item.first == kNetworkErrorKey) {
if (itr.key() == kNetworkErrorKey) { item.second.GetAsDictionary(&net_error_codes_dict);
itr.value().GetAsDictionary(&net_error_codes_dict);
break; break;
} }
} }
......
...@@ -20,7 +20,8 @@ namespace { ...@@ -20,7 +20,8 @@ namespace {
std::unique_ptr<base::DictionaryValue> GetWebEngineConstants() { std::unique_ptr<base::DictionaryValue> GetWebEngineConstants() {
std::unique_ptr<base::DictionaryValue> constants_dict = std::unique_ptr<base::DictionaryValue> constants_dict =
net::GetNetConstants(); base::DictionaryValue::From(
base::Value::ToUniquePtrValue(net::GetNetConstants()));
base::DictionaryValue dict; base::DictionaryValue dict;
dict.SetKey("name", base::Value("WebEngine")); dict.SetKey("name", base::Value("WebEngine"));
......
...@@ -481,7 +481,8 @@ FileNetLogObserver::FileNetLogObserver( ...@@ -481,7 +481,8 @@ FileNetLogObserver::FileNetLogObserver(
write_queue_(std::move(write_queue)), write_queue_(std::move(write_queue)),
file_writer_(std::move(file_writer)) { file_writer_(std::move(file_writer)) {
if (!constants) if (!constants)
constants = GetNetConstants(); constants = base::DictionaryValue::From(
base::Value::ToUniquePtrValue(GetNetConstants()));
file_task_runner_->PostTask( file_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&FileNetLogObserver::FileWriter::Initialize, FROM_HERE, base::BindOnce(&FileNetLogObserver::FileWriter::Initialize,
base::Unretained(file_writer_.get()), base::Unretained(file_writer_.get()),
......
...@@ -136,49 +136,48 @@ const char* NetInfoSourceToString(NetInfoSource source) { ...@@ -136,49 +136,48 @@ const char* NetInfoSourceToString(NetInfoSource source) {
return "?"; return "?";
} }
std::unique_ptr<base::DictionaryValue> GetNetConstants() { base::Value GetNetConstants() {
std::unique_ptr<base::DictionaryValue> constants_dict( base::Value constants_dict(base::Value::Type::DICTIONARY);
new base::DictionaryValue());
// Version of the file format. // Version of the file format.
constants_dict->SetInteger("logFormatVersion", kLogFormatVersion); constants_dict.SetIntKey("logFormatVersion", kLogFormatVersion);
// Add a dictionary with information on the relationship between event type // Add a dictionary with information on the relationship between event type
// enums and their symbolic names. // enums and their symbolic names.
constants_dict->SetKey("logEventTypes", NetLog::GetEventTypesAsValue()); constants_dict.SetKey("logEventTypes", NetLog::GetEventTypesAsValue());
// Add a dictionary with information about the relationship between CertStatus // Add a dictionary with information about the relationship between CertStatus
// flags and their symbolic names. // flags and their symbolic names.
{ {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); base::Value dict(base::Value::Type::DICTIONARY);
for (const auto& flag : kCertStatusFlags) for (const auto& flag : kCertStatusFlags)
dict->SetInteger(flag.name, flag.constant); dict.SetIntKey(flag.name, flag.constant);
constants_dict->Set("certStatusFlag", std::move(dict)); constants_dict.SetKey("certStatusFlag", std::move(dict));
} }
// Add a dictionary with information about the relationship between // Add a dictionary with information about the relationship between
// CertVerifier::VerifyFlags and their symbolic names. // CertVerifier::VerifyFlags and their symbolic names.
{ {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); base::Value dict(base::Value::Type::DICTIONARY);
dict->SetInteger("VERIFY_DISABLE_NETWORK_FETCHES", dict.SetIntKey("VERIFY_DISABLE_NETWORK_FETCHES",
CertVerifier::VERIFY_DISABLE_NETWORK_FETCHES); CertVerifier::VERIFY_DISABLE_NETWORK_FETCHES);
static_assert(CertVerifier::VERIFY_FLAGS_LAST == (1 << 0), static_assert(CertVerifier::VERIFY_FLAGS_LAST == (1 << 0),
"Update with new flags"); "Update with new flags");
constants_dict->Set("certVerifierFlags", std::move(dict)); constants_dict.SetKey("certVerifierFlags", std::move(dict));
} }
{ {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); base::Value dict(base::Value::Type::DICTIONARY);
dict->SetInteger( dict.SetIntKey(
"kStrong", "kStrong",
static_cast<int>(SimplePathBuilderDelegate::DigestPolicy::kStrong)); static_cast<int>(SimplePathBuilderDelegate::DigestPolicy::kStrong));
dict->SetInteger( dict.SetIntKey(
"kWeakAllowSha1", "kWeakAllowSha1",
static_cast<int>( static_cast<int>(
SimplePathBuilderDelegate::DigestPolicy::kWeakAllowSha1)); SimplePathBuilderDelegate::DigestPolicy::kWeakAllowSha1));
...@@ -187,20 +186,19 @@ std::unique_ptr<base::DictionaryValue> GetNetConstants() { ...@@ -187,20 +186,19 @@ std::unique_ptr<base::DictionaryValue> GetNetConstants() {
SimplePathBuilderDelegate::DigestPolicy::kWeakAllowSha1, SimplePathBuilderDelegate::DigestPolicy::kWeakAllowSha1,
"Update with new flags"); "Update with new flags");
constants_dict->Set("certPathBuilderDigestPolicy", std::move(dict)); constants_dict.SetKey("certPathBuilderDigestPolicy", std::move(dict));
} }
{ {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); base::Value dict(base::Value::Type::DICTIONARY);
dict->SetInteger("DISTRUSTED", dict.SetIntKey("DISTRUSTED",
static_cast<int>(CertificateTrustType::DISTRUSTED)); static_cast<int>(CertificateTrustType::DISTRUSTED));
dict->SetInteger("UNSPECIFIED", dict.SetIntKey("UNSPECIFIED",
static_cast<int>(CertificateTrustType::UNSPECIFIED)); static_cast<int>(CertificateTrustType::UNSPECIFIED));
dict->SetInteger("TRUSTED_ANCHOR", dict.SetIntKey("TRUSTED_ANCHOR",
static_cast<int>(CertificateTrustType::TRUSTED_ANCHOR)); static_cast<int>(CertificateTrustType::TRUSTED_ANCHOR));
dict->SetInteger( dict.SetIntKey("TRUSTED_ANCHOR_WITH_CONSTRAINTS",
"TRUSTED_ANCHOR_WITH_CONSTRAINTS",
static_cast<int>( static_cast<int>(
CertificateTrustType::TRUSTED_ANCHOR_WITH_CONSTRAINTS)); CertificateTrustType::TRUSTED_ANCHOR_WITH_CONSTRAINTS));
...@@ -208,106 +206,106 @@ std::unique_ptr<base::DictionaryValue> GetNetConstants() { ...@@ -208,106 +206,106 @@ std::unique_ptr<base::DictionaryValue> GetNetConstants() {
CertificateTrustType::TRUSTED_ANCHOR_WITH_CONSTRAINTS, CertificateTrustType::TRUSTED_ANCHOR_WITH_CONSTRAINTS,
"Update with new flags"); "Update with new flags");
constants_dict->Set("certificateTrustType", std::move(dict)); constants_dict.SetKey("certificateTrustType", std::move(dict));
} }
// Add a dictionary with information about the relationship between load flag // Add a dictionary with information about the relationship between load flag
// enums and their symbolic names. // enums and their symbolic names.
{ {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); base::Value dict(base::Value::Type::DICTIONARY);
for (const auto& flag : kLoadFlags) for (const auto& flag : kLoadFlags)
dict->SetInteger(flag.name, flag.constant); dict.SetIntKey(flag.name, flag.constant);
constants_dict->Set("loadFlag", std::move(dict)); constants_dict.SetKey("loadFlag", std::move(dict));
} }
// Add a dictionary with information about the relationship between load state // Add a dictionary with information about the relationship between load state
// enums and their symbolic names. // enums and their symbolic names.
{ {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); base::Value dict(base::Value::Type::DICTIONARY);
for (const auto& state : kLoadStateTable) for (const auto& state : kLoadStateTable)
dict->SetInteger(state.name, state.constant); dict.SetIntKey(state.name, state.constant);
constants_dict->Set("loadState", std::move(dict)); constants_dict.SetKey("loadState", std::move(dict));
} }
{ {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); base::Value dict(base::Value::Type::DICTIONARY);
#define NET_INFO_SOURCE(label, string, value) \ #define NET_INFO_SOURCE(label, string, value) \
dict->SetInteger(string, NET_INFO_##label); dict.SetIntKey(string, NET_INFO_##label);
#include "net/base/net_info_source_list.h" #include "net/base/net_info_source_list.h"
#undef NET_INFO_SOURCE #undef NET_INFO_SOURCE
constants_dict->Set("netInfoSources", std::move(dict)); constants_dict.SetKey("netInfoSources", std::move(dict));
} }
// Add information on the relationship between net error codes and their // Add information on the relationship between net error codes and their
// symbolic names. // symbolic names.
{ {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); base::Value dict(base::Value::Type::DICTIONARY);
for (const auto& error : kNetErrors) for (const auto& error : kNetErrors)
dict->SetInteger(ErrorToShortString(error), error); dict.SetIntKey(ErrorToShortString(error), error);
constants_dict->Set("netError", std::move(dict)); constants_dict.SetKey("netError", std::move(dict));
} }
// Add information on the relationship between QUIC error codes and their // Add information on the relationship between QUIC error codes and their
// symbolic names. // symbolic names.
{ {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); base::Value dict(base::Value::Type::DICTIONARY);
for (quic::QuicErrorCode error = quic::QUIC_NO_ERROR; for (quic::QuicErrorCode error = quic::QUIC_NO_ERROR;
error < quic::QUIC_LAST_ERROR; error < quic::QUIC_LAST_ERROR;
error = static_cast<quic::QuicErrorCode>(error + 1)) { error = static_cast<quic::QuicErrorCode>(error + 1)) {
dict->SetInteger(QuicErrorCodeToString(error), static_cast<int>(error)); dict.SetIntKey(QuicErrorCodeToString(error), static_cast<int>(error));
} }
constants_dict->Set("quicError", std::move(dict)); constants_dict.SetKey("quicError", std::move(dict));
} }
// Add information on the relationship between QUIC RST_STREAM error codes // Add information on the relationship between QUIC RST_STREAM error codes
// and their symbolic names. // and their symbolic names.
{ {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); base::Value dict(base::Value::Type::DICTIONARY);
for (quic::QuicRstStreamErrorCode error = quic::QUIC_STREAM_NO_ERROR; for (quic::QuicRstStreamErrorCode error = quic::QUIC_STREAM_NO_ERROR;
error < quic::QUIC_STREAM_LAST_ERROR; error < quic::QUIC_STREAM_LAST_ERROR;
error = static_cast<quic::QuicRstStreamErrorCode>(error + 1)) { error = static_cast<quic::QuicRstStreamErrorCode>(error + 1)) {
dict->SetInteger(QuicRstStreamErrorCodeToString(error), dict.SetIntKey(QuicRstStreamErrorCodeToString(error),
static_cast<int>(error)); static_cast<int>(error));
} }
constants_dict->Set("quicRstStreamError", std::move(dict)); constants_dict.SetKey("quicRstStreamError", std::move(dict));
} }
// Information about the relationship between event phase enums and their // Information about the relationship between event phase enums and their
// symbolic names. // symbolic names.
{ {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); base::Value dict(base::Value::Type::DICTIONARY);
dict->SetInteger("PHASE_BEGIN", static_cast<int>(NetLogEventPhase::BEGIN)); dict.SetIntKey("PHASE_BEGIN", static_cast<int>(NetLogEventPhase::BEGIN));
dict->SetInteger("PHASE_END", static_cast<int>(NetLogEventPhase::END)); dict.SetIntKey("PHASE_END", static_cast<int>(NetLogEventPhase::END));
dict->SetInteger("PHASE_NONE", static_cast<int>(NetLogEventPhase::NONE)); dict.SetIntKey("PHASE_NONE", static_cast<int>(NetLogEventPhase::NONE));
constants_dict->Set("logEventPhase", std::move(dict)); constants_dict.SetKey("logEventPhase", std::move(dict));
} }
// Information about the relationship between source type enums and // Information about the relationship between source type enums and
// their symbolic names. // their symbolic names.
constants_dict->SetKey("logSourceType", NetLog::GetSourceTypesAsValue()); constants_dict.SetKey("logSourceType", NetLog::GetSourceTypesAsValue());
// Information about the relationship between address family enums and // Information about the relationship between address family enums and
// their symbolic names. // their symbolic names.
{ {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); base::Value dict(base::Value::Type::DICTIONARY);
dict->SetInteger("ADDRESS_FAMILY_UNSPECIFIED", ADDRESS_FAMILY_UNSPECIFIED); dict.SetIntKey("ADDRESS_FAMILY_UNSPECIFIED", ADDRESS_FAMILY_UNSPECIFIED);
dict->SetInteger("ADDRESS_FAMILY_IPV4", ADDRESS_FAMILY_IPV4); dict.SetIntKey("ADDRESS_FAMILY_IPV4", ADDRESS_FAMILY_IPV4);
dict->SetInteger("ADDRESS_FAMILY_IPV6", ADDRESS_FAMILY_IPV6); dict.SetIntKey("ADDRESS_FAMILY_IPV6", ADDRESS_FAMILY_IPV6);
constants_dict->Set("addressFamily", std::move(dict)); constants_dict.SetKey("addressFamily", std::move(dict));
} }
// Information about how the "time ticks" values we have given it relate to // Information about how the "time ticks" values we have given it relate to
...@@ -327,14 +325,15 @@ std::unique_ptr<base::DictionaryValue> GetNetConstants() { ...@@ -327,14 +325,15 @@ std::unique_ptr<base::DictionaryValue> GetNetConstants() {
base::TimeTicks::Now() - base::TimeTicks(); base::TimeTicks::Now() - base::TimeTicks();
int64_t tick_to_unix_time_ms = int64_t tick_to_unix_time_ms =
(time_since_epoch - reference_time_ticks).InMilliseconds(); (time_since_epoch - reference_time_ticks).InMilliseconds();
constants_dict->SetKey("timeTickOffset", constants_dict.SetKey("timeTickOffset",
NetLogNumberValue(tick_to_unix_time_ms)); NetLogNumberValue(tick_to_unix_time_ms));
} }
// TODO(eroman): Is this needed? // TODO(eroman): Is this needed?
// "clientInfo" key is required for some log readers. Provide a default empty // "clientInfo" key is required for some log readers. Provide a default empty
// value for compatibility. // value for compatibility.
constants_dict->Set("clientInfo", std::make_unique<base::DictionaryValue>()); constants_dict.SetKey("clientInfo",
base::Value(base::Value::Type::DICTIONARY));
// Add a list of active field experiments. // Add a list of active field experiments.
{ {
...@@ -346,8 +345,9 @@ std::unique_ptr<base::DictionaryValue> GetNetConstants() { ...@@ -346,8 +345,9 @@ std::unique_ptr<base::DictionaryValue> GetNetConstants() {
it != active_groups.end(); ++it) { it != active_groups.end(); ++it) {
field_trial_groups->AppendString(it->trial_name + ":" + it->group_name); field_trial_groups->AppendString(it->trial_name + ":" + it->group_name);
} }
constants_dict->Set("activeFieldTrialGroups", constants_dict.SetKey(
std::move(field_trial_groups)); "activeFieldTrialGroups",
base::Value::FromUniquePtrValue(std::move(field_trial_groups)));
} }
return constants_dict; return constants_dict;
......
...@@ -33,8 +33,8 @@ enum NetInfoSource { ...@@ -33,8 +33,8 @@ enum NetInfoSource {
// Returns a friendly string to use for a given NetInfoSource in the net log. // Returns a friendly string to use for a given NetInfoSource in the net log.
NET_EXPORT const char* NetInfoSourceToString(NetInfoSource source); NET_EXPORT const char* NetInfoSourceToString(NetInfoSource source);
// Create a dictionary containing a legend for net/ constants. // Creates a dictionary containing a legend for net/ constants.
NET_EXPORT std::unique_ptr<base::DictionaryValue> GetNetConstants(); NET_EXPORT base::Value GetNetConstants();
// Retrieves a dictionary containing information about the current state of // Retrieves a dictionary containing information about the current state of
// |context|. |info_sources| is a set of NetInfoSources OR'd together, // |context|. |info_sources| is a set of NetInfoSources OR'd together,
......
...@@ -27,7 +27,7 @@ namespace { ...@@ -27,7 +27,7 @@ namespace {
// Make sure GetNetConstants doesn't crash. // Make sure GetNetConstants doesn't crash.
TEST(NetLogUtil, GetNetConstants) { TEST(NetLogUtil, GetNetConstants) {
std::unique_ptr<base::Value> constants(GetNetConstants()); base::Value constants(GetNetConstants());
} }
// Make sure GetNetInfo doesn't crash when called on contexts with and without // Make sure GetNetInfo doesn't crash when called on contexts with and without
......
...@@ -181,7 +181,9 @@ void NetLogExporter::StartWithScratchDir( ...@@ -181,7 +181,9 @@ void NetLogExporter::StartWithScratchDir(
state_ = STATE_RUNNING; state_ = STATE_RUNNING;
std::unique_ptr<base::DictionaryValue> constants = net::GetNetConstants(); std::unique_ptr<base::DictionaryValue> constants =
base::DictionaryValue::From(
base::Value::ToUniquePtrValue(net::GetNetConstants()));
if (extra_constants) if (extra_constants)
constants->MergeDictionary(extra_constants); constants->MergeDictionary(extra_constants);
......
...@@ -462,7 +462,9 @@ void NetworkService::StartNetLog(base::File file, ...@@ -462,7 +462,9 @@ void NetworkService::StartNetLog(base::File file,
net::NetLogCaptureMode capture_mode, net::NetLogCaptureMode capture_mode,
base::Value client_constants) { base::Value client_constants) {
DCHECK(client_constants.is_dict()); DCHECK(client_constants.is_dict());
std::unique_ptr<base::DictionaryValue> constants = net::GetNetConstants(); std::unique_ptr<base::DictionaryValue> constants =
base::DictionaryValue::From(
base::Value::ToUniquePtrValue(net::GetNetConstants()));
constants->MergeDictionary(&client_constants); constants->MergeDictionary(&client_constants);
file_net_log_observer_ = net::FileNetLogObserver::CreateUnboundedPreExisting( file_net_log_observer_ = net::FileNetLogObserver::CreateUnboundedPreExisting(
......
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