summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-02 20:17:29 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-02 20:17:29 +0000
commit3b24ecf7ea2060bdb394ea249c24530f18a64578 (patch)
treecc1fe2fdf8af92a2f56c07598cea52f722113d6e /net
parent3b10a7515086465baab07296a30ba71797b455c8 (diff)
downloadchromium_src-3b24ecf7ea2060bdb394ea249c24530f18a64578.zip
chromium_src-3b24ecf7ea2060bdb394ea249c24530f18a64578.tar.gz
chromium_src-3b24ecf7ea2060bdb394ea249c24530f18a64578.tar.bz2
Add a visualizer for the HostCache (DNS cache) on the network internals page.
BUG=http://crbug.com/14478 Review URL: http://codereview.chromium.org/172100 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25227 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/host_cache.h17
-rw-r--r--net/base/host_resolver.h5
-rw-r--r--net/base/host_resolver_impl.cc4
-rw-r--r--net/base/host_resolver_impl.h1
-rw-r--r--net/base/mock_host_resolver.cc4
-rw-r--r--net/base/mock_host_resolver.h1
-rw-r--r--net/url_request/url_request_view_net_internal_job.cc63
7 files changed, 92 insertions, 3 deletions
diff --git a/net/base/host_cache.h b/net/base/host_cache.h
index d5b9511..ab01c86 100644
--- a/net/base/host_cache.h
+++ b/net/base/host_cache.h
@@ -31,6 +31,8 @@ class HostCache {
base::TimeTicks expiration;
};
+ typedef base::hash_map<std::string, scoped_refptr<Entry> > EntryMap;
+
// Constructs a HostCache whose entries are valid for |cache_duration_ms|
// milliseconds. The cache will store up to |max_entries|.
HostCache(size_t max_entries, size_t cache_duration_ms);
@@ -60,12 +62,23 @@ class HostCache {
return entries_.size();
}
+ size_t max_entries() const {
+ return max_entries_;
+ }
+
+ size_t cache_duration_ms() const {
+ return cache_duration_ms_;
+ }
+
+ // Note that this map may contain expired entries.
+ const EntryMap& entries() const {
+ return entries_;
+ }
+
private:
FRIEND_TEST(HostCacheTest, Compact);
FRIEND_TEST(HostCacheTest, NoCache);
- typedef base::hash_map<std::string, scoped_refptr<Entry> > EntryMap;
-
// Returns true if this cache entry's result is valid at time |now|.
static bool CanUseEntry(const Entry* entry, const base::TimeTicks now);
diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h
index eecf394..e5c46a3 100644
--- a/net/base/host_resolver.h
+++ b/net/base/host_resolver.h
@@ -16,6 +16,7 @@ class MessageLoop;
namespace net {
class AddressList;
+class HostCache;
class LoadLog;
// This class represents the task of resolving hostnames (or IP address
@@ -130,6 +131,10 @@ class HostResolver : public base::RefCounted<HostResolver> {
// Unregisters an observer previously added by AddObserver().
virtual void RemoveObserver(Observer* observer) = 0;
+ // Returns the host cache, or NULL if this implementation does not use
+ // a HostCache.
+ virtual HostCache* GetHostCache() = 0;
+
// TODO(eroman): temp hack for http://crbug.com/18373
virtual void Shutdown() = 0;
diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc
index eed116a..61f075e 100644
--- a/net/base/host_resolver_impl.cc
+++ b/net/base/host_resolver_impl.cc
@@ -414,6 +414,10 @@ void HostResolverImpl::RemoveObserver(Observer* observer) {
observers_.erase(it);
}
+HostCache* HostResolverImpl::GetHostCache() {
+ return &cache_;
+}
+
void HostResolverImpl::Shutdown() {
shutdown_ = true;
diff --git a/net/base/host_resolver_impl.h b/net/base/host_resolver_impl.h
index 45c8841..74dea08 100644
--- a/net/base/host_resolver_impl.h
+++ b/net/base/host_resolver_impl.h
@@ -65,6 +65,7 @@ class HostResolverImpl : public HostResolver {
virtual void CancelRequest(RequestHandle req);
virtual void AddObserver(Observer* observer);
virtual void RemoveObserver(Observer* observer);
+ virtual HostCache* GetHostCache();
// TODO(eroman): temp hack for http://crbug.com/15513
virtual void Shutdown();
diff --git a/net/base/mock_host_resolver.cc b/net/base/mock_host_resolver.cc
index 3c09e15..addccd0f 100644
--- a/net/base/mock_host_resolver.cc
+++ b/net/base/mock_host_resolver.cc
@@ -66,6 +66,10 @@ void MockHostResolverBase::RemoveObserver(Observer* observer) {
impl_->RemoveObserver(observer);
}
+HostCache* MockHostResolverBase::GetHostCache() {
+ return impl_->GetHostCache();
+}
+
void MockHostResolverBase::Shutdown() {
impl_->Shutdown();
}
diff --git a/net/base/mock_host_resolver.h b/net/base/mock_host_resolver.h
index 548cd0a..01a2eab 100644
--- a/net/base/mock_host_resolver.h
+++ b/net/base/mock_host_resolver.h
@@ -49,6 +49,7 @@ class MockHostResolverBase : public HostResolver {
virtual void CancelRequest(RequestHandle req);
virtual void AddObserver(Observer* observer);
virtual void RemoveObserver(Observer* observer);
+ virtual HostCache* GetHostCache();
// TODO(eroman): temp hack for http://crbug.com/18373
virtual void Shutdown();
diff --git a/net/url_request/url_request_view_net_internal_job.cc b/net/url_request/url_request_view_net_internal_job.cc
index dba83b1..d2185c4 100644
--- a/net/url_request/url_request_view_net_internal_job.cc
+++ b/net/url_request/url_request_view_net_internal_job.cc
@@ -9,8 +9,10 @@
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "net/base/escape.h"
+#include "net/base/host_cache.h"
#include "net/base/load_log_util.h"
#include "net/base/net_errors.h"
+#include "net/base/net_util.h"
#include "net/proxy/proxy_service.h"
#include "net/url_request/url_request_context.h"
@@ -189,7 +191,66 @@ class HostResolverCacheSubSection : public SubSection {
}
virtual void OutputBody(URLRequestContext* context, std::string* out) {
- out->append("TODO");
+ const net::HostCache* host_cache = context->host_resolver()->GetHostCache();
+
+ if (!host_cache || host_cache->caching_is_disabled()) {
+ out->append("<i>Caching is disabled.</i>");
+ return;
+ }
+
+ out->append(StringPrintf("<ul><li>Size: %u</li>"
+ "<li>Capacity: %u</li>"
+ "<li>Time to live (ms): %u</li></ul>",
+ host_cache->size(),
+ host_cache->max_entries(),
+ host_cache->cache_duration_ms()));
+
+ out->append("<table border=1>"
+ "<tr>"
+ "<th>Host</th>"
+ "<th>First address</th>"
+ "<th>Time to live (ms)</th>"
+ "</tr>");
+
+ for (net::HostCache::EntryMap::const_iterator it =
+ host_cache->entries().begin();
+ it != host_cache->entries().end();
+ ++it) {
+ const std::string& host = it->first;
+ const net::HostCache::Entry* entry = it->second.get();
+
+ if (entry->error == net::OK) {
+ // Note that ttl_ms may be negative, for the cases where entries have
+ // expired but not been garbage collected yet.
+ int ttl_ms = static_cast<int>(
+ (entry->expiration - base::TimeTicks::Now()).InMilliseconds());
+
+ // Color expired entries blue.
+ if (ttl_ms > 0) {
+ out->append("<tr>");
+ } else {
+ out->append("<tr style='color:blue'>");
+ }
+
+ std::string address_str =
+ net::NetAddressToString(entry->addrlist.head());
+
+ out->append(StringPrintf("<td>%s</td><td>%s</td><td>%d</td></tr>",
+ EscapeForHTML(host).c_str(),
+ EscapeForHTML(address_str).c_str(),
+ ttl_ms));
+ } else {
+ // This was an entry that failed to be resolved.
+ // Color negative entries red.
+ out->append(StringPrintf(
+ "<tr style='color:red'><td>%s</td>"
+ "<td colspan=2>%s</td></tr>",
+ EscapeForHTML(host).c_str(),
+ EscapeForHTML(net::ErrorToString(entry->error)).c_str()));
+ }
+ }
+
+ out->append("</table>");
}
};