diff options
-rw-r--r-- | chrome/browser/resources/net_internals/dns_view.html | 18 | ||||
-rw-r--r-- | chrome/browser/resources/net_internals/dns_view.js | 82 | ||||
-rw-r--r-- | chrome/browser/ui/webui/net_internals/net_internals_ui.cc | 4 | ||||
-rw-r--r-- | net/base/host_resolver.cc | 6 | ||||
-rw-r--r-- | net/base/host_resolver.h | 9 | ||||
-rw-r--r-- | net/base/host_resolver_impl.cc | 46 | ||||
-rw-r--r-- | net/base/host_resolver_impl.h | 1 | ||||
-rw-r--r-- | net/dns/dns_config_service.cc | 25 | ||||
-rw-r--r-- | net/dns/dns_config_service.h | 10 |
9 files changed, 161 insertions, 40 deletions
diff --git a/chrome/browser/resources/net_internals/dns_view.html b/chrome/browser/resources/net_internals/dns_view.html index 4a5aa2b3..776665f 100644 --- a/chrome/browser/resources/net_internals/dns_view.html +++ b/chrome/browser/resources/net_internals/dns_view.html @@ -11,6 +11,20 @@ </li> </ul> + <div> + <h4>Async DNS Configuration</h4> + <ul> + <li>Internal DNS client enabled: + <span id=dns-view-internal-dns-enabled></span> + <span id=dns-view-internal-dns-invalid-config class=warning-text style="display: none;"> + (No valid configuration found)</span> + </li> + </ul> + <table class="styled-table"> + <tbody id=dns-view-internal-dns-config-tbody></tbody> + </table> + </div> + <h4> Host resolver cache <input type=button value="Clear host cache" id=dns-view-clear-cache class="hide-when-not-capturing" /> @@ -18,9 +32,7 @@ <ul> <li>Capacity: <span id=dns-view-cache-capacity></span></li> </ul> - <h4> - Current State - </h4> + <h4>Current State</h4> <ul> <li>Active entries: <span id=dns-view-cache-active></span></li> <li>Expired entries: <span id=dns-view-cache-expired></span></li> diff --git a/chrome/browser/resources/net_internals/dns_view.js b/chrome/browser/resources/net_internals/dns_view.js index 14954b1d..6e9038e 100644 --- a/chrome/browser/resources/net_internals/dns_view.js +++ b/chrome/browser/resources/net_internals/dns_view.js @@ -46,16 +46,21 @@ var DnsView = (function() { // IDs for special HTML elements in dns_view.html DnsView.MAIN_BOX_ID = 'dns-view-tab-content'; - DnsView.CACHE_TBODY_ID = 'dns-view-cache-tbody'; - DnsView.CLEAR_CACHE_BUTTON_ID = 'dns-view-clear-cache'; DnsView.DEFAULT_FAMILY_SPAN_ID = 'dns-view-default-family'; DnsView.IPV6_DISABLED_SPAN_ID = 'dns-view-ipv6-disabled'; DnsView.ENABLE_IPV6_BUTTON_ID = 'dns-view-enable-ipv6'; + + DnsView.INTERNAL_DNS_ENABLED_SPAN_ID = 'dns-view-internal-dns-enabled'; + DnsView.INTERNAL_DNS_INVALID_CONFIG_SPAN_ID = + 'dns-view-internal-dns-invalid-config'; + DnsView.INTERNAL_DNS_CONFIG_TBODY_ID = 'dns-view-internal-dns-config-tbody'; + + DnsView.CLEAR_CACHE_BUTTON_ID = 'dns-view-clear-cache'; DnsView.CAPACITY_SPAN_ID = 'dns-view-cache-capacity'; + DnsView.ACTIVE_SPAN_ID = 'dns-view-cache-active'; DnsView.EXPIRED_SPAN_ID = 'dns-view-cache-expired'; - DnsView.TTL_SUCCESS_SPAN_ID = 'dns-view-cache-ttl-success'; - DnsView.TTL_FAILURE_SPAN_ID = 'dns-view-cache-ttl-failure'; + DnsView.CACHE_TBODY_ID = 'dns-view-cache-tbody'; cr.addSingletonGetter(DnsView); @@ -75,6 +80,9 @@ var DnsView = (function() { $(DnsView.ACTIVE_SPAN_ID).innerHTML = '0'; $(DnsView.EXPIRED_SPAN_ID).innerHTML = '0'; + // Update fields containing async DNS configuration information. + displayAsyncDnsConfig_(hostResolverInfo); + // No info. if (!hostResolverInfo || !hostResolverInfo.cache) return false; @@ -120,12 +128,7 @@ var DnsView = (function() { var errorNode = addTextNode(addressesCell, 'error: ' + errorText); addressesCell.classList.add('warning-text'); } else { - for (var j = 0; j < e.addresses.length; ++j) { - var address = e.addresses[j]; - if (j != 0) - addNode(addressesCell, 'br'); - addTextNode(addressesCell, address); - } + addListToNode_(addNode(addressesCell, 'div'), e.addresses); } var expiresDate = timeutil.convertTimeTicksToDate(e.expiration); @@ -146,5 +149,64 @@ var DnsView = (function() { } }; + /** + * Displays information corresponding to the current async DNS configuration. + * @param {Object} hostResolverInfo The host resolver information. + */ + function displayAsyncDnsConfig_(hostResolverInfo) { + // Clear the table. + $(DnsView.INTERNAL_DNS_CONFIG_TBODY_ID).innerHTML = ''; + + // Figure out if the internal DNS resolver is disabled or has no valid + // configuration information, and update display accordingly. + var enabled = hostResolverInfo && + hostResolverInfo.dns_config !== undefined; + var noConfig = enabled && + hostResolverInfo.dns_config.nameservers === undefined; + $(DnsView.INTERNAL_DNS_ENABLED_SPAN_ID).innerText = enabled; + setNodeDisplay($(DnsView.INTERNAL_DNS_INVALID_CONFIG_SPAN_ID), noConfig); + + // If the internal DNS resolver is disabled or has no valid configuration, + // we're done. + if (!enabled || noConfig) + return; + + var dnsConfig = hostResolverInfo.dns_config; + + // Display nameservers first. + var nameserverRow = addNode($(DnsView.INTERNAL_DNS_CONFIG_TBODY_ID), 'tr'); + addNodeWithText(nameserverRow, 'th', 'nameservers'); + addListToNode_(addNode(nameserverRow, 'td'), dnsConfig.nameservers); + + // Add everything else in |dnsConfig| to the table. + for (var key in dnsConfig) { + if (key == 'nameservers') + continue; + var tr = addNode($(DnsView.INTERNAL_DNS_CONFIG_TBODY_ID), 'tr'); + addNodeWithText(tr, 'th', key); + var td = addNode(tr, 'td'); + + // For lists, display each list entry on a separate line. + if (typeof dnsConfig[key] == 'object' && + dnsConfig[key].constructor == Array) { + addListToNode_(td, dnsConfig[key]); + continue; + } + + addTextNode(td, dnsConfig[key]); + } + } + + /** + * Takes a last of strings and adds them all to a DOM node, displaying them + * on separate lines. + * @param {DomNode} node The parent node. + * @param {Array.<String>} list List of strings to add to the node. + */ + function addListToNode_(node, list) { + for (var i = 0; i < list.length; ++i) + addNodeWithText(node, 'div', list[i]); + } + return DnsView; })(); diff --git a/chrome/browser/ui/webui/net_internals/net_internals_ui.cc b/chrome/browser/ui/webui/net_internals/net_internals_ui.cc index 5ecc2d2..6acd13c 100644 --- a/chrome/browser/ui/webui/net_internals/net_internals_ui.cc +++ b/chrome/browser/ui/webui/net_internals/net_internals_ui.cc @@ -867,6 +867,10 @@ void NetInternalsMessageHandler::IOThreadImpl::OnGetHostResolverInfo( DictionaryValue* dict = new DictionaryValue(); + base::Value* dns_config = context->host_resolver()->GetDnsConfigAsValue(); + if (dns_config) + dict->Set("dns_config", dns_config); + dict->SetInteger( "default_address_family", static_cast<int>(context->host_resolver()->GetDefaultAddressFamily())); diff --git a/net/base/host_resolver.cc b/net/base/host_resolver.cc index ab789aa..3e86aff 100644 --- a/net/base/host_resolver.cc +++ b/net/base/host_resolver.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -29,6 +29,10 @@ HostCache* HostResolver::GetHostCache() { return NULL; } +base::Value* HostResolver::GetDnsConfigAsValue() const { + return NULL; +} + HostResolver::HostResolver() { } diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h index a282701..300bd34 100644 --- a/net/base/host_resolver.h +++ b/net/base/host_resolver.h @@ -16,6 +16,10 @@ #include "net/base/net_util.h" #include "net/base/request_priority.h" +namespace base { +class Value; +} + namespace net { class AddressList; @@ -161,6 +165,11 @@ class NET_EXPORT HostResolver { // Used primarily to clear the cache and for getting debug information. virtual HostCache* GetHostCache(); + // Returns the current DNS configuration |this| is using, as a Value, or NULL + // if it's configured to always use the system host resolver. Caller takes + // ownership of the returned Value. + virtual base::Value* GetDnsConfigAsValue() const; + protected: HostResolver(); diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc index 5c202ed..4e1c5ac 100644 --- a/net/base/host_resolver_impl.cc +++ b/net/base/host_resolver_impl.cc @@ -316,31 +316,13 @@ class DnsConfigParameters : public NetLog::EventParameters { } virtual Value* ToValue() const OVERRIDE { - DictionaryValue* dict = new DictionaryValue(); - - ListValue* list = new ListValue(); - for (size_t i = 0; i < config_.nameservers.size(); ++i) { - list->Append(Value::CreateStringValue( - config_.nameservers[i].ToString())); - } - dict->Set("nameservers", list); - - list = new ListValue(); - for (size_t i = 0; i < config_.search.size(); ++i) { - list->Append(Value::CreateStringValue(config_.search[i])); - } - dict->Set("search", list); - - dict->SetBoolean("append_to_multi_label_name", - config_.append_to_multi_label_name); - dict->SetInteger("ndots", config_.ndots); - dict->SetDouble("timeout", config_.timeout.InSecondsF()); - dict->SetInteger("attempts", config_.attempts); - dict->SetBoolean("rotate", config_.rotate); - dict->SetBoolean("edns0", config_.edns0); - dict->SetInteger("num_hosts", num_hosts_); - - return dict; + Value* value = config_.ToValue(); + if (!value) + return NULL; + DictionaryValue* dict; + if (value->GetAsDictionary(&dict)) + dict->SetInteger("num_hosts", num_hosts_); + return value; } private: @@ -1718,6 +1700,20 @@ HostCache* HostResolverImpl::GetHostCache() { return cache_.get(); } +base::Value* HostResolverImpl::GetDnsConfigAsValue() const { + // Check if async DNS is disabled. + if (!dns_client_.get()) + return NULL; + + // Check if async DNS is enabled, but we currently have no configuration + // for it. + const DnsConfig* dns_config = dns_client_->GetConfig(); + if (dns_config == NULL) + return new DictionaryValue(); + + return dns_config->ToValue(); +} + bool HostResolverImpl::ResolveAsIP(const Key& key, const RequestInfo& info, int* net_error, diff --git a/net/base/host_resolver_impl.h b/net/base/host_resolver_impl.h index 65b25c1..467b837 100644 --- a/net/base/host_resolver_impl.h +++ b/net/base/host_resolver_impl.h @@ -143,6 +143,7 @@ class NET_EXPORT HostResolverImpl virtual AddressFamily GetDefaultAddressFamily() const OVERRIDE; virtual void ProbeIPv6Support() OVERRIDE; virtual HostCache* GetHostCache() OVERRIDE; + virtual base::Value* GetDnsConfigAsValue() const OVERRIDE; private: FRIEND_TEST_ALL_PREFIXES(HostResolverImplTest, diff --git a/net/dns/dns_config_service.cc b/net/dns/dns_config_service.cc index bd42b64..ffd5fe9 100644 --- a/net/dns/dns_config_service.cc +++ b/net/dns/dns_config_service.cc @@ -5,6 +5,7 @@ #include "net/dns/dns_config_service.h" #include "base/logging.h" +#include "base/values.h" #include "net/base/ip_endpoint.h" namespace net { @@ -46,6 +47,30 @@ void DnsConfig::CopyIgnoreHosts(const DnsConfig& d) { edns0 = d.edns0; } +base::Value* DnsConfig::ToValue() const { + DictionaryValue* dict = new DictionaryValue(); + + ListValue* list = new ListValue(); + for (size_t i = 0; i < nameservers.size(); ++i) + list->Append(Value::CreateStringValue(nameservers[i].ToString())); + dict->Set("nameservers", list); + + list = new ListValue(); + for (size_t i = 0; i < search.size(); ++i) + list->Append(Value::CreateStringValue(search[i])); + dict->Set("search", list); + + dict->SetBoolean("append_to_multi_label_name", append_to_multi_label_name); + dict->SetInteger("ndots", ndots); + dict->SetDouble("timeout", timeout.InSecondsF()); + dict->SetInteger("attempts", attempts); + dict->SetBoolean("rotate", rotate); + dict->SetBoolean("edns0", edns0); + dict->SetInteger("num_hosts", hosts.size()); + + return dict; +} + DnsConfigService::DnsConfigService() : have_config_(false), diff --git a/net/dns/dns_config_service.h b/net/dns/dns_config_service.h index e5794c2..8e7597d 100644 --- a/net/dns/dns_config_service.h +++ b/net/dns/dns_config_service.h @@ -19,6 +19,10 @@ #include "net/base/net_export.h" #include "net/dns/dns_hosts.h" +namespace base { +class Value; +} + namespace net { // DnsConfig stores configuration of the system resolver. @@ -32,6 +36,11 @@ struct NET_EXPORT_PRIVATE DnsConfig { void CopyIgnoreHosts(const DnsConfig& src); + // Returns a Value representation of |this|. Caller takes ownership of the + // returned Value. For performance reasons, the Value only contains the + // number of hosts rather than the full list. + base::Value* ToValue() const; + bool IsValid() const { return !nameservers.empty(); } @@ -123,7 +132,6 @@ class NET_EXPORT_PRIVATE DnsConfigService DISALLOW_COPY_AND_ASSIGN(DnsConfigService); }; - } // namespace net #endif // NET_DNS_DNS_CONFIG_SERVICE_H_ |