Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: chrome/browser/dom_ui/net_internals_ui.cc

Issue 1558027: Add the host resolver cache to the new net internals page. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync with fragment changes Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/net_internals/dnsview.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/dom_ui/net_internals_ui.cc
===================================================================
--- chrome/browser/dom_ui/net_internals_ui.cc (revision 43861)
+++ chrome/browser/dom_ui/net_internals_ui.cc (working copy)
@@ -23,6 +23,10 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/url_constants.h"
#include "net/base/escape.h"
+#include "net/base/host_resolver_impl.h"
+#include "net/base/net_errors.h"
+#include "net/base/net_util.h"
+#include "net/base/sys_addrinfo.h"
#include "net/proxy/proxy_service.h"
#include "net/url_request/url_request_context.h"
@@ -33,6 +37,18 @@
return Int64ToString((t - base::TimeTicks()).InMilliseconds());
}
+// Returns the HostCache for |context|'s primary HostResolver, or NULL if
+// there is none.
+net::HostCache* GetHostResolverCache(URLRequestContext* context) {
+ net::HostResolverImpl* host_resolver_impl =
+ context->host_resolver()->GetAsHostResolverImpl();
+
+ if (!host_resolver_impl)
+ return NULL;
+
+ return host_resolver_impl->cache();
+}
+
// TODO(eroman): Bootstrap the net-internals page using the passively logged
// data.
@@ -132,6 +148,8 @@
void OnReloadProxySettings(const Value* value);
void OnGetBadProxies(const Value* value);
void OnClearBadProxies(const Value* value);
+ void OnGetHostResolverCache(const Value* value);
+ void OnClearHostResolverCache(const Value* value);
// ChromeNetLog::Observer implementation:
virtual void OnAddEntry(const net::NetLog::Entry& entry);
@@ -279,6 +297,10 @@
proxy_->CreateCallback(&IOThreadImpl::OnGetBadProxies));
dom_ui_->RegisterMessageCallback("clearBadProxies",
proxy_->CreateCallback(&IOThreadImpl::OnClearBadProxies));
+ dom_ui_->RegisterMessageCallback("getHostResolverCache",
+ proxy_->CreateCallback(&IOThreadImpl::OnGetHostResolverCache));
+ dom_ui_->RegisterMessageCallback("clearHostResolverCache",
+ proxy_->CreateCallback(&IOThreadImpl::OnClearHostResolverCache));
}
void NetInternalsMessageHandler::CallJavascriptFunction(
@@ -417,6 +439,7 @@
// Notify the client of the basic proxy data.
OnGetProxySettings(NULL);
OnGetBadProxies(NULL);
+ OnGetHostResolverCache(NULL);
}
void NetInternalsMessageHandler::IOThreadImpl::OnGetProxySettings(
@@ -481,6 +504,77 @@
OnGetBadProxies(NULL);
}
+void NetInternalsMessageHandler::IOThreadImpl::OnGetHostResolverCache(
+ const Value* value) {
+
+ net::HostCache* cache =
+ GetHostResolverCache(context_getter_->GetURLRequestContext());
+
+ if (!cache) {
+ CallJavascriptFunction(L"g_browser.receivedHostResolverCache", NULL);
+ return;
+ }
+
+ DictionaryValue* dict = new DictionaryValue();
+
+ dict->SetInteger(L"capacity", static_cast<int>(cache->max_entries()));
+ dict->SetInteger(
+ L"ttl_success_ms",
+ static_cast<int>(cache->success_entry_ttl().InMilliseconds()));
+ dict->SetInteger(
+ L"ttl_failure_ms",
+ static_cast<int>(cache->failure_entry_ttl().InMilliseconds()));
+
+ ListValue* entry_list = new ListValue();
+
+ for (net::HostCache::EntryMap::const_iterator it =
+ cache->entries().begin();
+ it != cache->entries().end();
+ ++it) {
+ const net::HostCache::Key& key = it->first;
+ const net::HostCache::Entry* entry = it->second.get();
+
+ DictionaryValue* entry_dict = new DictionaryValue();
+
+ entry_dict->SetString(L"hostname", key.hostname);
+ entry_dict->SetInteger(L"address_family",
+ static_cast<int>(key.address_family));
+ entry_dict->SetString(L"expiration", TickCountToString(entry->expiration));
+
+ if (entry->error != net::OK) {
+ entry_dict->SetInteger(L"error", entry->error);
+ } else {
+ // Append all of the resolved addresses.
+ ListValue* address_list = new ListValue();
+ const struct addrinfo* current_address = entry->addrlist.head();
+ while (current_address) {
+ address_list->Append(Value::CreateStringValue(
+ net::NetAddressToString(current_address)));
+ current_address = current_address->ai_next;
+ }
+ entry_dict->Set(L"addresses", address_list);
+ }
+
+ entry_list->Append(entry_dict);
+ }
+
+ dict->Set(L"entries", entry_list);
+
+ CallJavascriptFunction(L"g_browser.receivedHostResolverCache", dict);
+}
+
+void NetInternalsMessageHandler::IOThreadImpl::OnClearHostResolverCache(
+ const Value* value) {
+ net::HostCache* cache =
+ GetHostResolverCache(context_getter_->GetURLRequestContext());
+
+ if (cache)
+ cache->clear();
+
+ // Cause the renderer to be notified of the new values.
+ OnGetHostResolverCache(NULL);
+}
+
void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry(
const net::NetLog::Entry& entry) {
DCHECK(is_observing_log_);
« no previous file with comments | « no previous file | chrome/browser/resources/net_internals/dnsview.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698