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

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

Issue 2011009: Add the http cache info to chrome://net2. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 7 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/httpcacheview.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 46639)
+++ chrome/browser/dom_ui/net_internals_ui.cc (working copy)
@@ -33,6 +33,8 @@
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "net/base/sys_addrinfo.h"
+#include "net/disk_cache/disk_cache.h"
+#include "net/http/http_cache.h"
#include "net/proxy/proxy_service.h"
#include "net/url_request/url_request_context.h"
@@ -55,6 +57,18 @@
return host_resolver_impl->cache();
}
+// Returns the disk cache backend for |context| if there is one, or NULL.
+disk_cache::Backend* GetDiskCacheBackend(URLRequestContext* context) {
+ if (!context->http_transaction_factory())
+ return NULL;
+
+ net::HttpCache* http_cache = context->http_transaction_factory()->GetCache();
+ if (!http_cache)
+ return NULL;
+
+ return http_cache->GetBackend();
+}
+
// Serializes the specified event to a DictionaryValue.
Value* EntryToDictionaryValue(net::NetLog::EventType type,
const base::TimeTicks& time,
@@ -200,6 +214,7 @@
void OnClearHostResolverCache(const Value* value);
void OnGetPassiveLogEntries(const Value* value);
void OnStartConnectionTests(const Value* value);
+ void OnGetHttpCacheInfo(const Value* value);
// ChromeNetLog::Observer implementation:
virtual void OnAddEntry(net::NetLog::EventType type,
@@ -380,6 +395,9 @@
dom_ui_->RegisterMessageCallback(
"startConnectionTests",
proxy_->CreateCallback(&IOThreadImpl::OnStartConnectionTests));
+ dom_ui_->RegisterMessageCallback(
+ "getHttpCacheInfo",
+ proxy_->CreateCallback(&IOThreadImpl::OnGetHttpCacheInfo));
}
void NetInternalsMessageHandler::CallJavascriptFunction(
@@ -685,6 +703,40 @@
connection_tester_->RunAllTests(url);
}
+void NetInternalsMessageHandler::IOThreadImpl::OnGetHttpCacheInfo(
+ const Value* value) {
+ DictionaryValue* info_dict = new DictionaryValue();
+ ListValue* entry_keys = new ListValue();
+ DictionaryValue* stats_dict = new DictionaryValue();
+
+ disk_cache::Backend* disk_cache = GetDiskCacheBackend(
+ context_getter_->GetURLRequestContext());
+
+ if (disk_cache) {
+ // Iterate over all the entries in the cache, to discover the keys.
+ // WARNING: this can be slow! (and will block the IO thread).
+ void* iter = NULL;
+ disk_cache::Entry* entry;
+ while (disk_cache->OpenNextEntry(&iter, &entry)) {
+ entry_keys->Append(Value::CreateStringValue(entry->GetKey()));
+ entry->Close();
+ }
+
+ // Extract the statistics key/value pairs from the backend.
+ std::vector<std::pair<std::string, std::string> > stats;
+ disk_cache->GetStats(&stats);
+ for (size_t i = 0; i < stats.size(); ++i) {
+ stats_dict->Set(ASCIIToWide(stats[i].first),
+ Value::CreateStringValue(stats[i].second));
+ }
+ }
+
+ info_dict->Set(L"keys", entry_keys);
+ info_dict->Set(L"stats", stats_dict);
+
+ CallJavascriptFunction(L"g_browser.receivedHttpCacheInfo", info_dict);
+}
+
void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry(
net::NetLog::EventType type,
const base::TimeTicks& time,
« no previous file with comments | « no previous file | chrome/browser/resources/net_internals/httpcacheview.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698