Commit 85bd28af authored by Panos Astithas's avatar Panos Astithas Committed by Commit Bot

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

Bug: 646113
Change-Id: Ib16b182766ec63175c49ba6dc27d5a4ae1d67677
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2256157
Commit-Queue: Panos Astithas <pastithas@google.com>
Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarZhongyi Shi <zhongyi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#783785}
parent fb79aaee
......@@ -676,7 +676,7 @@ void CronetURLRequestContext::NetworkTasks::StopNetLog() {
if (!net_log_file_observer_)
return;
net_log_file_observer_->StopObserving(
GetNetLogInfo(),
base::Value::ToUniquePtrValue(GetNetLogInfo()),
base::BindOnce(
&CronetURLRequestContext::NetworkTasks::StopNetLogCompleted,
base::Unretained(this)));
......@@ -688,13 +688,12 @@ void CronetURLRequestContext::NetworkTasks::StopNetLogCompleted() {
callback_->OnStopNetLogCompleted();
}
std::unique_ptr<base::DictionaryValue>
CronetURLRequestContext::NetworkTasks::GetNetLogInfo() const {
std::unique_ptr<base::DictionaryValue> net_info =
base::Value CronetURLRequestContext::NetworkTasks::GetNetLogInfo() const {
base::Value net_info =
net::GetNetInfo(context_.get(), net::NET_INFO_ALL_SOURCES);
if (effective_experimental_options_) {
net_info->Set("cronetExperimentalParams",
effective_experimental_options_->CreateDeepCopy());
net_info.SetKey("cronetExperimentalParams",
effective_experimental_options_->Clone());
}
return net_info;
}
......
......@@ -242,7 +242,7 @@ class CronetURLRequestContext {
private:
friend class TestUtil;
std::unique_ptr<base::DictionaryValue> GetNetLogInfo() const;
base::Value GetNetLogInfo() const;
std::unique_ptr<net::FileNetLogObserver> net_log_file_observer_;
......
......@@ -156,7 +156,7 @@ class CronetEnvironment {
void StartNetLogOnNetworkThread(const base::FilePath&, bool log_bytes);
void StopNetLogOnNetworkThread(base::WaitableEvent* log_stopped_event);
std::unique_ptr<base::DictionaryValue> GetNetLogInfo() const;
base::Value GetNetLogInfo() const;
// Returns the HttpNetworkSession object from the passed in
// URLRequestContext or NULL if none exists.
......
......@@ -201,20 +201,20 @@ void CronetEnvironment::StopNetLogOnNetworkThread(
if (file_net_log_observer_) {
DLOG(WARNING) << "Stopped NetLog.";
file_net_log_observer_->StopObserving(
GetNetLogInfo(), base::BindOnce(&SignalEvent, log_stopped_event));
base::Value::ToUniquePtrValue(GetNetLogInfo()),
base::BindOnce(&SignalEvent, log_stopped_event));
file_net_log_observer_.reset();
} else {
log_stopped_event->Signal();
}
}
std::unique_ptr<base::DictionaryValue> CronetEnvironment::GetNetLogInfo()
const {
std::unique_ptr<base::DictionaryValue> net_info =
base::Value CronetEnvironment::GetNetLogInfo() const {
base::Value net_info =
net::GetNetInfo(main_context_.get(), net::NET_INFO_ALL_SOURCES);
if (effective_experimental_options_) {
net_info->Set("cronetExperimentalParams",
effective_experimental_options_->CreateDeepCopy());
net_info.SetKey("cronetExperimentalParams",
effective_experimental_options_->Clone());
}
return net_info;
}
......
......@@ -353,13 +353,12 @@ base::Value GetNetConstants() {
return constants_dict;
}
NET_EXPORT std::unique_ptr<base::DictionaryValue> GetNetInfo(
URLRequestContext* context,
int info_sources) {
NET_EXPORT base::Value GetNetInfo(URLRequestContext* context,
int info_sources) {
// May only be called on the context's thread.
context->AssertCalledOnValidThread();
std::unique_ptr<base::DictionaryValue> net_info_dict =
base::Value net_info_dict =
context->proxy_resolution_service()->GetProxyNetLogValues(info_sources);
if (info_sources & NET_INFO_HOST_RESOLVER) {
......@@ -367,27 +366,29 @@ NET_EXPORT std::unique_ptr<base::DictionaryValue> GetNetInfo(
DCHECK(host_resolver);
HostCache* cache = host_resolver->GetHostCache();
if (cache) {
auto dict = std::make_unique<base::DictionaryValue>();
base::Value dict(base::Value::Type::DICTIONARY);
std::unique_ptr<base::Value> dns_config =
host_resolver->GetDnsConfigAsValue();
if (dns_config)
dict->Set("dns_config", std::move(dns_config));
dict.SetKey("dns_config",
base::Value::FromUniquePtrValue(std::move(dns_config)));
auto cache_info_dict = std::make_unique<base::DictionaryValue>();
auto cache_contents_list = std::make_unique<base::ListValue>();
base::Value cache_info_dict(base::Value::Type::DICTIONARY);
base::Value cache_contents_list(base::Value::Type::LIST);
cache_info_dict->SetInteger("capacity",
static_cast<int>(cache->max_entries()));
cache_info_dict->SetInteger("network_changes", cache->network_changes());
cache_info_dict.SetIntKey("capacity",
static_cast<int>(cache->max_entries()));
cache_info_dict.SetIntKey("network_changes", cache->network_changes());
cache->GetAsListValue(cache_contents_list.get(),
true /* include_staleness */,
HostCache::SerializationType::kDebug);
cache_info_dict->Set("entries", std::move(cache_contents_list));
base::ListValue* list_value = nullptr;
if (cache_contents_list.GetAsList(&list_value))
cache->GetAsListValue(list_value, true /* include_staleness */,
HostCache::SerializationType::kDebug);
cache_info_dict.SetKey("entries", std::move(cache_contents_list));
dict->Set("cache", std::move(cache_info_dict));
net_info_dict->Set(NetInfoSourceToString(NET_INFO_HOST_RESOLVER),
std::move(dict));
dict.SetKey("cache", std::move(cache_info_dict));
net_info_dict.SetKey(NetInfoSourceToString(NET_INFO_HOST_RESOLVER),
std::move(dict));
}
}
......@@ -395,20 +396,23 @@ NET_EXPORT std::unique_ptr<base::DictionaryValue> GetNetInfo(
context->http_transaction_factory()->GetSession();
if (info_sources & NET_INFO_SOCKET_POOL) {
net_info_dict->Set(NetInfoSourceToString(NET_INFO_SOCKET_POOL),
http_network_session->SocketPoolInfoToValue());
net_info_dict.SetKey(NetInfoSourceToString(NET_INFO_SOCKET_POOL),
base::Value::FromUniquePtrValue(
http_network_session->SocketPoolInfoToValue()));
}
if (info_sources & NET_INFO_SPDY_SESSIONS) {
net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_SESSIONS),
http_network_session->SpdySessionPoolInfoToValue());
net_info_dict.SetKey(
NetInfoSourceToString(NET_INFO_SPDY_SESSIONS),
base::Value::FromUniquePtrValue(
http_network_session->SpdySessionPoolInfoToValue()));
}
if (info_sources & NET_INFO_SPDY_STATUS) {
auto status_dict = std::make_unique<base::DictionaryValue>();
base::Value status_dict(base::Value::Type::DICTIONARY);
status_dict->SetBoolean("enable_http2",
http_network_session->params().enable_http2);
status_dict.SetBoolKey("enable_http2",
http_network_session->params().enable_http2);
NextProtoVector alpn_protos;
http_network_session->GetAlpnProtos(&alpn_protos);
......@@ -419,29 +423,31 @@ NET_EXPORT std::unique_ptr<base::DictionaryValue> GetNetInfo(
next_protos_string.append(",");
next_protos_string.append(NextProtoToString(proto));
}
status_dict->SetString("alpn_protos", next_protos_string);
status_dict.SetStringKey("alpn_protos", next_protos_string);
}
net_info_dict->Set(NetInfoSourceToString(NET_INFO_SPDY_STATUS),
std::move(status_dict));
net_info_dict.SetKey(NetInfoSourceToString(NET_INFO_SPDY_STATUS),
std::move(status_dict));
}
if (info_sources & NET_INFO_ALT_SVC_MAPPINGS) {
const HttpServerProperties& http_server_properties =
*context->http_server_properties();
net_info_dict->Set(
net_info_dict.SetKey(
NetInfoSourceToString(NET_INFO_ALT_SVC_MAPPINGS),
http_server_properties.GetAlternativeServiceInfoAsValue());
base::Value::FromUniquePtrValue(
http_server_properties.GetAlternativeServiceInfoAsValue()));
}
if (info_sources & NET_INFO_QUIC) {
net_info_dict->Set(NetInfoSourceToString(NET_INFO_QUIC),
http_network_session->QuicInfoToValue());
net_info_dict.SetKey(NetInfoSourceToString(NET_INFO_QUIC),
base::Value::FromUniquePtrValue(
http_network_session->QuicInfoToValue()));
}
if (info_sources & NET_INFO_HTTP_CACHE) {
auto info_dict = std::make_unique<base::DictionaryValue>();
auto stats_dict = std::make_unique<base::DictionaryValue>();
base::Value info_dict(base::Value::Type::DICTIONARY);
base::Value stats_dict(base::Value::Type::DICTIONARY);
disk_cache::Backend* disk_cache = GetDiskCacheBackend(context);
......@@ -449,14 +455,14 @@ NET_EXPORT std::unique_ptr<base::DictionaryValue> GetNetInfo(
// Extract the statistics key/value pairs from the backend.
base::StringPairs stats;
disk_cache->GetStats(&stats);
for (size_t i = 0; i < stats.size(); ++i) {
stats_dict->SetKey(stats[i].first, base::Value(stats[i].second));
for (auto& stat : stats) {
stats_dict.SetKey(stat.first, base::Value(std::move(stat.second)));
}
}
info_dict->Set("stats", std::move(stats_dict));
info_dict.SetKey("stats", std::move(stats_dict));
net_info_dict->Set(NetInfoSourceToString(NET_INFO_HTTP_CACHE),
std::move(info_dict));
net_info_dict.SetKey(NetInfoSourceToString(NET_INFO_HTTP_CACHE),
std::move(info_dict));
}
if (info_sources & NET_INFO_REPORTING) {
......@@ -470,20 +476,20 @@ NET_EXPORT std::unique_ptr<base::DictionaryValue> GetNetInfo(
reporting_dict.SetKey("networkErrorLogging",
network_error_logging_service->StatusAsValue());
}
net_info_dict->SetKey(NetInfoSourceToString(NET_INFO_REPORTING),
std::move(reporting_dict));
net_info_dict.SetKey(NetInfoSourceToString(NET_INFO_REPORTING),
std::move(reporting_dict));
} else {
base::Value reporting_dict(base::Value::Type::DICTIONARY);
reporting_dict.SetKey("reportingEnabled", base::Value(false));
net_info_dict->SetKey(NetInfoSourceToString(NET_INFO_REPORTING),
std::move(reporting_dict));
net_info_dict.SetKey(NetInfoSourceToString(NET_INFO_REPORTING),
std::move(reporting_dict));
}
#else // BUILDFLAG(ENABLE_REPORTING)
base::Value reporting_dict(base::Value::Type::DICTIONARY);
reporting_dict.SetKey("reportingEnabled", base::Value(false));
net_info_dict->SetKey(NetInfoSourceToString(NET_INFO_REPORTING),
std::move(reporting_dict));
net_info_dict.SetKey(NetInfoSourceToString(NET_INFO_REPORTING),
std::move(reporting_dict));
#endif // BUILDFLAG(ENABLE_REPORTING)
}
......
......@@ -11,10 +11,6 @@
#include "net/base/net_export.h"
#include "net/log/net_log.h"
namespace base {
class DictionaryValue;
}
namespace net {
class URLRequestContext;
......@@ -42,9 +38,7 @@ NET_EXPORT base::Value GetNetConstants();
// one top-level entry to the returned dictionary.
//
// May only be called on |context|'s thread.
NET_EXPORT std::unique_ptr<base::DictionaryValue> GetNetInfo(
URLRequestContext* context,
int info_sources);
NET_EXPORT base::Value GetNetInfo(URLRequestContext* context, int info_sources);
// Takes in a set of contexts and a NetLog::Observer, and passes in
// NetLog::Entries to the observer for certain NetLogSources with pending
......
......@@ -40,21 +40,20 @@ TEST(NetLogUtil, GetNetInfo) {
// Get NetInfo when there's no cache backend (It's only created on first use).
EXPECT_FALSE(http_cache->GetCurrentBackend());
std::unique_ptr<base::DictionaryValue> net_info_without_cache(
base::Value net_info_without_cache(
GetNetInfo(&context, NET_INFO_ALL_SOURCES));
EXPECT_FALSE(http_cache->GetCurrentBackend());
EXPECT_GT(net_info_without_cache->size(), 0u);
EXPECT_GT(net_info_without_cache.DictSize(), 0u);
// Fore creation of a cache backend, and get NetInfo again.
disk_cache::Backend* backend = nullptr;
EXPECT_EQ(OK, context.http_transaction_factory()->GetCache()->GetBackend(
&backend, TestCompletionCallback().callback()));
EXPECT_TRUE(http_cache->GetCurrentBackend());
std::unique_ptr<base::DictionaryValue> net_info_with_cache(
GetNetInfo(&context, NET_INFO_ALL_SOURCES));
EXPECT_GT(net_info_with_cache->size(), 0u);
base::Value net_info_with_cache = GetNetInfo(&context, NET_INFO_ALL_SOURCES);
EXPECT_GT(net_info_with_cache.DictSize(), 0u);
EXPECT_EQ(net_info_without_cache->size(), net_info_with_cache->size());
EXPECT_EQ(net_info_without_cache.DictSize(), net_info_with_cache.DictSize());
}
// Make sure CreateNetLogEntriesForActiveObjects works for requests from a
......
......@@ -1348,39 +1348,38 @@ void ConfiguredProxyResolutionService::ForceReloadProxyConfig() {
ApplyProxyConfigIfAvailable();
}
std::unique_ptr<base::DictionaryValue>
ConfiguredProxyResolutionService::GetProxyNetLogValues(int info_sources) {
std::unique_ptr<base::DictionaryValue> net_info_dict(
new base::DictionaryValue());
base::Value ConfiguredProxyResolutionService::GetProxyNetLogValues(
int info_sources) {
base::Value net_info_dict(base::Value::Type::DICTIONARY);
if (info_sources & NET_INFO_PROXY_SETTINGS) {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
base::Value dict(base::Value::Type::DICTIONARY);
if (fetched_config_)
dict->SetKey("original", fetched_config_->value().ToValue());
dict.SetKey("original", fetched_config_->value().ToValue());
if (config_)
dict->SetKey("effective", config_->value().ToValue());
dict.SetKey("effective", config_->value().ToValue());
net_info_dict->Set(NetInfoSourceToString(NET_INFO_PROXY_SETTINGS),
std::move(dict));
net_info_dict.SetKey(NetInfoSourceToString(NET_INFO_PROXY_SETTINGS),
std::move(dict));
}
if (info_sources & NET_INFO_BAD_PROXIES) {
auto list = std::make_unique<base::ListValue>();
base::Value list(base::Value::Type::LIST);
for (auto& it : proxy_retry_info_) {
for (const auto& it : proxy_retry_info_) {
const std::string& proxy_uri = it.first;
const ProxyRetryInfo& retry_info = it.second;
auto dict = std::make_unique<base::DictionaryValue>();
dict->SetString("proxy_uri", proxy_uri);
dict->SetString("bad_until",
NetLog::TickCountToString(retry_info.bad_until));
base::Value dict(base::Value::Type::DICTIONARY);
dict.SetStringKey("proxy_uri", proxy_uri);
dict.SetStringKey("bad_until",
NetLog::TickCountToString(retry_info.bad_until));
list->Append(std::move(dict));
list.Append(std::move(dict));
}
net_info_dict->Set(NetInfoSourceToString(NET_INFO_BAD_PROXIES),
std::move(list));
net_info_dict.SetKey(NetInfoSourceToString(NET_INFO_BAD_PROXIES),
std::move(list));
}
return net_info_dict;
......
......@@ -171,8 +171,7 @@ class NET_EXPORT ConfiguredProxyResolutionService
void ForceReloadProxyConfig();
// ProxyResolutionService
std::unique_ptr<base::DictionaryValue> GetProxyNetLogValues(
int info_sources) override;
base::Value GetProxyNetLogValues(int info_sources) override;
// ProxyResolutionService
bool CastToConfiguredProxyResolutionService(
......
......@@ -18,10 +18,6 @@
#include "net/proxy_resolution/proxy_info.h"
#include "url/gurl.h"
namespace base {
class DictionaryValue;
} // namespace base
namespace net {
class ConfiguredProxyResolutionService;
......@@ -99,8 +95,7 @@ class NET_EXPORT ProxyResolutionService {
// Returns proxy related debug information to be included in the NetLog. The
// data should be appropriate for any capture mode. |info_sources| is a bit
// field of NET_INFO_SOURCE.
virtual std::unique_ptr<base::DictionaryValue> GetProxyNetLogValues(
int info_sources) = 0;
virtual base::Value GetProxyNetLogValues(int info_sources) = 0;
// Returns true if |this| is an instance of ConfiguredProxyResolutionService
// and assigns |this| to the out parameter. Otherwise returns false and sets
......
......@@ -48,10 +48,9 @@ const ProxyRetryInfoMap& WindowsSystemProxyResolutionService::proxy_retry_info()
return proxy_retry_info_;
}
std::unique_ptr<base::DictionaryValue>
WindowsSystemProxyResolutionService::GetProxyNetLogValues(int info_sources) {
std::unique_ptr<base::DictionaryValue> net_info_dict(
new base::DictionaryValue());
base::Value WindowsSystemProxyResolutionService::GetProxyNetLogValues(
int info_sources) {
base::Value net_info_dict(base::Value::Type::DICTIONARY);
return net_info_dict;
}
......
......@@ -47,8 +47,7 @@ class NET_EXPORT WindowsSystemProxyResolutionService
const NetLogWithSource& net_log) override;
void ClearBadProxiesCache() override;
const ProxyRetryInfoMap& proxy_retry_info() const override;
std::unique_ptr<base::DictionaryValue> GetProxyNetLogValues(
int info_sources) override;
base::Value GetProxyNetLogValues(int info_sources) override;
bool CastToConfiguredProxyResolutionService(
ConfiguredProxyResolutionService** configured_proxy_resolution_service)
override WARN_UNUSED_RESULT;
......
......@@ -90,13 +90,13 @@ void NetLogExporter::Stop(base::Value polled_data_value,
return;
}
std::unique_ptr<base::DictionaryValue> net_info = net::GetNetInfo(
base::Value net_info = net::GetNetInfo(
network_context_->url_request_context(), net::NET_INFO_ALL_SOURCES);
if (polled_data)
net_info->MergeDictionary(polled_data);
net_info.MergeDictionary(polled_data);
file_net_observer_->StopObserving(
std::move(net_info),
base::Value::ToUniquePtrValue(std::move(net_info)),
base::BindOnce([](StopCallback sc) { std::move(sc).Run(net::OK); },
std::move(callback)));
file_net_observer_ = nullptr;
......
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