diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-14 20:51:04 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-14 20:51:04 +0000 |
commit | 13c34d1395636e081be2318e8ae12bc8fa71ca57 (patch) | |
tree | 4a719a69338f1cc14fe23db88e061c513cf122db /net | |
parent | 1364d8b89dd74afd35a5d9fe4bb4f3c66d09c3c4 (diff) | |
download | chromium_src-13c34d1395636e081be2318e8ae12bc8fa71ca57.zip chromium_src-13c34d1395636e081be2318e8ae12bc8fa71ca57.tar.gz chromium_src-13c34d1395636e081be2318e8ae12bc8fa71ca57.tar.bz2 |
Change the URLs used to access "view-cache:" and "view-net-internals:".
"net-internal:*" ==> "chrome://net-internals/*"
"view-cache:*" ==> "chrome://net-internals/view-cache/*"
"view-cache:stats" ==> "chrome://net-internals/httpcache.stats"
As before, there are also aliases from the "about:*" page:
"about:net-internal[/*]" aliases "chrome://net-internals/*"
"about:cache[/*]" aliases "chrome://net-internals/view-cache"
BUG=http://crbug.com/21551
Review URL: http://codereview.chromium.org/202067
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26158 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/net_util.h | 2 | ||||
-rw-r--r-- | net/base/net_util_unittest.cc | 2 | ||||
-rw-r--r-- | net/net.gyp | 8 | ||||
-rw-r--r-- | net/url_request/url_request_job_manager.cc | 4 | ||||
-rw-r--r-- | net/url_request/url_request_view_cache_job.h | 32 | ||||
-rw-r--r-- | net/url_request/url_request_view_net_internal_job.h | 26 | ||||
-rw-r--r-- | net/url_request/url_request_view_net_internals_job.cc (renamed from net/url_request/url_request_view_net_internal_job.cc) | 93 | ||||
-rw-r--r-- | net/url_request/url_request_view_net_internals_job.h | 42 | ||||
-rw-r--r-- | net/url_request/view_cache_helper.cc (renamed from net/url_request/url_request_view_cache_job.cc) | 78 | ||||
-rw-r--r-- | net/url_request/view_cache_helper.h | 24 |
10 files changed, 184 insertions, 127 deletions
diff --git a/net/base/net_util.h b/net/base/net_util.h index 60e5636..89386bf8 100644 --- a/net/base/net_util.h +++ b/net/base/net_util.h @@ -178,7 +178,7 @@ std::wstring StripWWW(const std::wstring& text); // Gets the filename from the raw Content-Disposition header (as read from the // network). Otherwise uses the last path component name or hostname from // |url|. Note: it's possible for the suggested filename to be empty (e.g., -// file:/// or view-cache:). referrer_charset is used as one of charsets +// file:///). referrer_charset is used as one of charsets // to interpret a raw 8bit string in C-D header (after interpreting // as UTF-8 fails). See the comment for GetFilenameFromCD for more details. std::wstring GetSuggestedFilename(const GURL& url, diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc index fed9c0d6..2047b14 100644 --- a/net/base/net_util_unittest.cc +++ b/net/base/net_util_unittest.cc @@ -802,7 +802,7 @@ TEST(NetUtilTest, GetSuggestedFilename) { "", L"", L"download"}, - {"view-cache:", + {"non-standard-scheme:", "", "", L"", diff --git a/net/net.gyp b/net/net.gyp index 34281d1..5fed81d 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -361,10 +361,10 @@ 'url_request/url_request_status.h', 'url_request/url_request_test_job.cc', 'url_request/url_request_test_job.h', - 'url_request/url_request_view_cache_job.cc', - 'url_request/url_request_view_cache_job.h', - 'url_request/url_request_view_net_internal_job.cc', - 'url_request/url_request_view_net_internal_job.h', + 'url_request/url_request_view_net_internals_job.cc', + 'url_request/url_request_view_net_internals_job.h', + 'url_request/view_cache_helper.cc', + 'url_request/view_cache_helper.h', ], 'export_dependent_settings': [ '../base/base.gyp:base', diff --git a/net/url_request/url_request_job_manager.cc b/net/url_request/url_request_job_manager.cc index 241edec..617a938 100644 --- a/net/url_request/url_request_job_manager.cc +++ b/net/url_request/url_request_job_manager.cc @@ -19,8 +19,6 @@ #include "net/url_request/url_request_new_ftp_job.h" #endif #include "net/url_request/url_request_http_job.h" -#include "net/url_request/url_request_view_cache_job.h" -#include "net/url_request/url_request_view_net_internal_job.h" // The built-in set of protocol factories namespace { @@ -42,8 +40,6 @@ static const SchemeToFactory kBuiltinFactories[] = { { "ftp", URLRequestNewFtpJob::Factory }, #endif { "about", URLRequestAboutJob::Factory }, - { "view-cache", URLRequestViewCacheJob::Factory }, - { "view-net-internal", URLRequestViewNetInternalJob::Factory }, }; URLRequestJobManager::URLRequestJobManager() { diff --git a/net/url_request/url_request_view_cache_job.h b/net/url_request/url_request_view_cache_job.h deleted file mode 100644 index e85d273..0000000 --- a/net/url_request/url_request_view_cache_job.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2006-2008 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. - -#ifndef NET_URL_REQUEST_URL_REQUEST_VIEW_CACHE_JOB_H_ -#define NET_URL_REQUEST_URL_REQUEST_VIEW_CACHE_JOB_H_ - -#include "net/url_request/url_request.h" -#include "net/url_request/url_request_simple_job.h" - -namespace disk_cache { -class Backend; -} - -// A job subclass that implements the view-cache: protocol, which simply -// provides a debug view of the cache or of a particular cache entry. -class URLRequestViewCacheJob : public URLRequestSimpleJob { - public: - URLRequestViewCacheJob(URLRequest* request) : URLRequestSimpleJob(request) {} - - static URLRequest::ProtocolFactory Factory; - - // override from URLRequestSimpleJob - virtual bool GetData(std::string* mime_type, - std::string* charset, - std::string* data) const; - - private: - disk_cache::Backend* GetDiskCache() const; -}; - -#endif // NET_URL_REQUEST_URL_REQUEST_VIEW_CACHE_JOB_H_ diff --git a/net/url_request/url_request_view_net_internal_job.h b/net/url_request/url_request_view_net_internal_job.h deleted file mode 100644 index 4044041..0000000 --- a/net/url_request/url_request_view_net_internal_job.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2009 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. - -#ifndef NET_URL_REQUEST_URL_REQUEST_VIEW_NET_INTERNAL_JOB_H_ -#define NET_URL_REQUEST_URL_REQUEST_VIEW_NET_INTERNAL_JOB_H_ - -#include "net/url_request/url_request.h" -#include "net/url_request/url_request_simple_job.h" - -// A job subclass that implements the view-net-internal: protocol, which simply -// provides a debug view of the various network components. -class URLRequestViewNetInternalJob : public URLRequestSimpleJob { - public: - URLRequestViewNetInternalJob(URLRequest* request) - : URLRequestSimpleJob(request) {} - - static URLRequest::ProtocolFactory Factory; - - // override from URLRequestSimpleJob - virtual bool GetData(std::string* mime_type, - std::string* charset, - std::string* data) const; -}; - -#endif // NET_URL_REQUEST_URL_REQUEST_VIEW_NET_INTERNAL_JOB_H_ diff --git a/net/url_request/url_request_view_net_internal_job.cc b/net/url_request/url_request_view_net_internals_job.cc index 1095ae4..eac53bc 100644 --- a/net/url_request/url_request_view_net_internal_job.cc +++ b/net/url_request/url_request_view_net_internals_job.cc @@ -4,7 +4,7 @@ #include <sstream> -#include "net/url_request/url_request_view_net_internal_job.h" +#include "net/url_request/url_request_view_net_internals_job.h" #include "base/stl_util-inl.h" #include "base/string_util.h" @@ -16,9 +16,12 @@ #include "net/proxy/proxy_service.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_context.h" +#include "net/url_request/view_cache_helper.h" namespace { +const char kViewHttpCacheSubPath[] = "view-cache"; + //------------------------------------------------------------------------------ // Format helpers. //------------------------------------------------------------------------------ @@ -51,12 +54,13 @@ class SubSection { virtual void OutputBody(URLRequestContext* context, std::string* out) {} // Outputs this subsection, and all of its children. - void OutputRecursive(URLRequestContext* context, std::string* out) { + void OutputRecursive(URLRequestContext* context, + URLRequestViewNetInternalsJob::URLFormat* url_format, + std::string* out) { if (!is_root()) { - std::string section_url = - std::string("view-net-internal:") + GetFullyQualifiedName(); // Canonicalizing the URL escapes characters which cause problems in HTML. - section_url = GURL(section_url).spec(); + std::string section_url = + url_format->MakeURL(GetFullyQualifiedName()).spec(); // Print the heading. out->append(StringPrintf("<div>" @@ -73,7 +77,7 @@ class SubSection { OutputBody(context, out); for (size_t i = 0; i < children_.size(); ++i) - children_[i]->OutputRecursive(context, out); + children_[i]->OutputRecursive(context, url_format, out); if (!is_root()) out->append("</div>"); @@ -339,35 +343,80 @@ class URLRequestSubSection : public SubSection { } }; +class HttpCacheStatsSubSection : public SubSection { + public: + HttpCacheStatsSubSection(SubSection* parent) + : SubSection(parent, "stats", "Statistics") { + } + + virtual void OutputBody(URLRequestContext* context, std::string* out) { + ViewCacheHelper::GetStatisticsHTML(context, out); + } +}; + +class HttpCacheSection : public SubSection { + public: + HttpCacheSection(SubSection* parent) + : SubSection(parent, "httpcache", "HttpCache") { + AddSubSection(new HttpCacheStatsSubSection(this)); + } + + virtual void OutputBody(URLRequestContext* context, std::string* out) { + // Advertise the view-cache URL (too much data to inline it). + out->append("<p><a href='/"); + out->append(kViewHttpCacheSubPath); + out->append("'>View all cache entries</a></p>"); + } +}; + class AllSubSections : public SubSection { public: AllSubSections() : SubSection(NULL, "", "") { AddSubSection(new ProxyServiceSubSection(this)); AddSubSection(new HostResolverSubSection(this)); AddSubSection(new URLRequestSubSection(this)); + AddSubSection(new HttpCacheSection(this)); } }; -} // namespace +// Returns true if |path| is a subpath for "view-cache". +// If it is, then |key| is assigned the subpath. +bool GetViewCacheKeyFromPath(const std::string path, + std::string* key) { + if (!StartsWithASCII(path, kViewHttpCacheSubPath, true)) + return false; + + if (path.size() > strlen(kViewHttpCacheSubPath) && + path[strlen(kViewHttpCacheSubPath)] != '/') + return false; -// static -URLRequestJob* URLRequestViewNetInternalJob::Factory( - URLRequest* request, const std::string& scheme) { - return new URLRequestViewNetInternalJob(request); + if (path.size() > strlen(kViewHttpCacheSubPath) + 1) + *key = path.substr(strlen(kViewHttpCacheSubPath) + 1); + + return true; } -bool URLRequestViewNetInternalJob::GetData(std::string* mime_type, - std::string* charset, - std::string* data) const { - DCHECK_EQ(std::string("view-net-internal"), request_->url().scheme()); +} // namespace +bool URLRequestViewNetInternalsJob::GetData(std::string* mime_type, + std::string* charset, + std::string* data) const { mime_type->assign("text/html"); charset->assign("UTF-8"); URLRequestContext* context = request_->context(); - std::string path = request_->url().path(); + std::string details = url_format_->GetDetails(request_->url()); data->clear(); + + // Use a different handler for "view-cache/*" subpaths. + std::string cache_key; + if (GetViewCacheKeyFromPath(details, &cache_key)) { + GURL url = url_format_->MakeURL(kViewHttpCacheSubPath + std::string("/")); + ViewCacheHelper::GetEntryInfoHTML(cache_key, context, url.spec(), data); + return true; + } + data->append("<html><head><title>Network internals</title>" "<style>" "body { font-family: sans-serif; }\n" @@ -376,22 +425,22 @@ bool URLRequestViewNetInternalJob::GetData(std::string* mime_type, ".subsection_name { font-size: 80%; }\n" "</style>" "</head><body>" - "<p><a href='http://sites.google.com/a/chromium.org/dev/" - "developers/design-documents/view-net-internal'>" + "<p><a href='http://dev.chromium.org/" + "developers/design-documents/view-net-internals'>" "Help: how do I use this?</a></p>"); SubSection* all = Singleton<AllSubSections>::get(); SubSection* section = all; // Display only the subsection tree asked for. - if (!path.empty()) - section = all->FindSubSectionByName(path); + if (!details.empty()) + section = all->FindSubSectionByName(details); if (section) { - section->OutputRecursive(context, data); + section->OutputRecursive(context, url_format_, data); } else { data->append("<i>Nothing found for \""); - data->append(EscapeForHTML(path)); + data->append(EscapeForHTML(details)); data->append("\"</i>"); } diff --git a/net/url_request/url_request_view_net_internals_job.h b/net/url_request/url_request_view_net_internals_job.h new file mode 100644 index 0000000..967d20c --- /dev/null +++ b/net/url_request/url_request_view_net_internals_job.h @@ -0,0 +1,42 @@ +// Copyright (c) 2009 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. + +#ifndef NET_URL_REQUEST_URL_REQUEST_VIEW_NET_INTERNALS_JOB_H_ +#define NET_URL_REQUEST_URL_REQUEST_VIEW_NET_INTERNALS_JOB_H_ + +#include "net/url_request/url_request.h" +#include "net/url_request/url_request_simple_job.h" + +// A job subclass that implements a protocol to inspect the internal +// state of the network stack. The exact format of the URLs is left up to +// the caller, and is described by a URLFormat instance passed into +// the constructor. +class URLRequestViewNetInternalsJob : public URLRequestSimpleJob { + public: + class URLFormat; + + // |url_format| must remain valid for the duration |this|'s lifespan. + URLRequestViewNetInternalsJob(URLRequest* request, + URLFormat* url_format) + : URLRequestSimpleJob(request), url_format_(url_format) {} + + // override from URLRequestSimpleJob + virtual bool GetData(std::string* mime_type, + std::string* charset, + std::string* data) const; + + private: + URLFormat* url_format_; +}; + +// Describes how to pack/unpack the filter string (details) +// from a URL. +class URLRequestViewNetInternalsJob::URLFormat { + public: + virtual ~URLFormat() {} + virtual std::string GetDetails(const GURL& url) = 0; + virtual GURL MakeURL(const std::string& details) = 0; +}; + +#endif // NET_URL_REQUEST_URL_REQUEST_VIEW_NET_INTERNALS_JOB_H_ diff --git a/net/url_request/url_request_view_cache_job.cc b/net/url_request/view_cache_helper.cc index 112f409..1e66d21 100644 --- a/net/url_request/url_request_view_cache_job.cc +++ b/net/url_request/view_cache_helper.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "net/url_request/url_request_view_cache_job.h" +#include "net/url_request/view_cache_helper.h" #include "base/string_util.h" #include "net/base/escape.h" @@ -10,6 +10,7 @@ #include "net/disk_cache/disk_cache.h" #include "net/http/http_cache.h" #include "net/http/http_response_headers.h" +#include "net/http/http_response_info.h" #include "net/url_request/url_request_context.h" #define VIEW_CACHE_HEAD \ @@ -55,10 +56,13 @@ static void HexDump(const char *buf, size_t buf_len, std::string* result) { } } -static std::string FormatEntryInfo(disk_cache::Entry* entry) { - std::string key = EscapeForHTML(entry->GetKey()); +static std::string FormatEntryInfo(disk_cache::Entry* entry, + const std::string& url_prefix) { + std::string key = entry->GetKey(); + GURL url = GURL(url_prefix + key); std::string row = - "<tr><td><a href=\"view-cache:" + key + "\">" + key + "</a></td></tr>"; + "<tr><td><a href=\"" + url.spec() + "\">" + EscapeForHTML(key) + + "</a></td></tr>"; return row; } @@ -101,6 +105,20 @@ static std::string FormatEntryDetails(disk_cache::Entry* entry) { return result; } +static disk_cache::Backend* GetDiskCache(URLRequestContext* context) { + if (!context) + return NULL; + + if (!context->http_transaction_factory()) + return NULL; + + net::HttpCache* http_cache = context->http_transaction_factory()->GetCache(); + if (!http_cache) + return NULL; + + return http_cache->disk_cache(); +} + static std::string FormatStatistics(disk_cache::Backend* disk_cache) { std::vector<std::pair<std::string, std::string> > stats; disk_cache->GetStats(&stats); @@ -117,57 +135,43 @@ static std::string FormatStatistics(disk_cache::Backend* disk_cache) { } // static -URLRequestJob* URLRequestViewCacheJob::Factory(URLRequest* request, - const std::string& scheme) { - return new URLRequestViewCacheJob(request); -} - -bool URLRequestViewCacheJob::GetData(std::string* mime_type, - std::string* charset, - std::string* data) const { - mime_type->assign("text/html"); - charset->assign("UTF-8"); - - disk_cache::Backend* disk_cache = GetDiskCache(); +void ViewCacheHelper::GetEntryInfoHTML(const std::string& key, + URLRequestContext* context, + const std::string& url_prefix, + std::string* data) { + disk_cache::Backend* disk_cache = GetDiskCache(context); if (!disk_cache) { data->assign("no disk cache"); - return true; + return; } - if (request_->url().spec() == "view-cache:") { + if (key.empty()) { data->assign(VIEW_CACHE_HEAD); void* iter = NULL; disk_cache::Entry* entry; while (disk_cache->OpenNextEntry(&iter, &entry)) { - data->append(FormatEntryInfo(entry)); + data->append(FormatEntryInfo(entry, url_prefix)); entry->Close(); } data->append(VIEW_CACHE_TAIL); - } else if (request_->url().spec() == "view-cache:stats") { - data->assign(FormatStatistics(disk_cache)); } else { disk_cache::Entry* entry; - if (disk_cache->OpenEntry(request_->url().path(), &entry)) { + if (disk_cache->OpenEntry(key, &entry)) { data->assign(FormatEntryDetails(entry)); entry->Close(); } else { - data->assign("no matching cache entry"); + data->assign("no matching cache entry for: " + key); } } - return true; } -disk_cache::Backend* URLRequestViewCacheJob::GetDiskCache() const { - if (!request_->context()) - return NULL; - - if (!request_->context()->http_transaction_factory()) - return NULL; - - net::HttpCache* http_cache = - request_->context()->http_transaction_factory()->GetCache(); - if (!http_cache) - return NULL; - - return http_cache->disk_cache(); +// static +void ViewCacheHelper::GetStatisticsHTML(URLRequestContext* context, + std::string* data) { + disk_cache::Backend* disk_cache = GetDiskCache(context); + if (!disk_cache) { + data->append("no disk cache"); + return; + } + data->append(FormatStatistics(disk_cache)); } diff --git a/net/url_request/view_cache_helper.h b/net/url_request/view_cache_helper.h new file mode 100644 index 0000000..2648699 --- /dev/null +++ b/net/url_request/view_cache_helper.h @@ -0,0 +1,24 @@ +// Copyright (c) 2006-2008 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. + +#ifndef NET_URL_REQUEST_VIEW_CACHE_HELPER_H_ +#define NET_URL_REQUEST_VIEW_CACHE_HELPER_H_ + +#include <string> + +class URLRequestContext; + +class ViewCacheHelper { + public: + // Formats the cache information for |key| as HTML. + static void GetEntryInfoHTML(const std::string& key, + URLRequestContext* context, + const std::string& url_prefix, + std::string* out); + + static void GetStatisticsHTML(URLRequestContext* context, + std::string* out); +}; + +#endif // NET_URL_REQUEST_VIEW_CACHE_HELPER_H_ |