diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-04 06:45:43 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-04 06:45:43 +0000 |
commit | 4e600d6a8369367459477f9845f86d4fce16f69e (patch) | |
tree | 5e01487537a1fbf7c3cae46c23d201d3e58332cf | |
parent | b0544c44da65ac1a2b0654f97ec473c76176aea2 (diff) | |
download | chromium_src-4e600d6a8369367459477f9845f86d4fce16f69e.zip chromium_src-4e600d6a8369367459477f9845f86d4fce16f69e.tar.gz chromium_src-4e600d6a8369367459477f9845f86d4fce16f69e.tar.bz2 |
Refactor: Move the code that handles "chrome://net-internals/*" from the net module to the chrome module.
This is in preparation for making a javascript frontend to it, and merging in the functionality from about:network.
There is no behavior change here, just moving code around.
Review URL: http://codereview.chromium.org/668039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40608 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/dom_ui/chrome_url_data_manager.cc | 36 | ||||
-rw-r--r-- | chrome/browser/net/view_net_internals_job_factory.cc (renamed from net/url_request/url_request_view_net_internals_job.cc) | 89 | ||||
-rw-r--r-- | chrome/browser/net/view_net_internals_job_factory.h | 18 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | net/net.gyp | 2 | ||||
-rw-r--r-- | net/url_request/url_request_view_net_internals_job.h | 51 |
6 files changed, 92 insertions, 106 deletions
diff --git a/chrome/browser/dom_ui/chrome_url_data_manager.cc b/chrome/browser/dom_ui/chrome_url_data_manager.cc index 8a546127..d6b73ff 100644 --- a/chrome/browser/dom_ui/chrome_url_data_manager.cc +++ b/chrome/browser/dom_ui/chrome_url_data_manager.cc @@ -18,6 +18,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/net/chrome_url_request_context.h" +#include "chrome/browser/net/view_net_internals_job_factory.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/ref_counted_util.h" #include "chrome/common/url_constants.h" @@ -28,7 +29,6 @@ #include "net/url_request/url_request.h" #include "net/url_request/url_request_file_job.h" #include "net/url_request/url_request_job.h" -#include "net/url_request/url_request_view_net_internals_job.h" // URLRequestChromeJob is a URLRequestJob that manages running chrome-internal @@ -306,34 +306,6 @@ void ChromeURLDataManager::DataSource::SetFontAndTextDirection( L"rtl" : L"ltr"); } -// This class describes how to form chrome://net-internals/DESCRIPTION -// URLs, and conversely how to extract DESCRIPTION. -// -// This needs to be passed to URLRequestViewNetInternalsJob, which lives -// in the network module and doesn't know anything about what URL protocol -// it has been registered with. -class NetInternalsURLFormat : public URLRequestViewNetInternalsJob::URLFormat { - public: - virtual std::string GetDetails(const GURL& url) { - DCHECK(IsSupportedURL(url)); - size_t start = strlen(chrome::kNetworkViewInternalsURL); - if (start >= url.spec().size()) - return std::string(); - return url.spec().substr(start); - } - - virtual GURL MakeURL(const std::string& details) { - return GURL(std::string(chrome::kNetworkViewInternalsURL) + details); - } - - static bool IsSupportedURL(const GURL& url) { - // Note that kNetworkViewInternalsURL is terminated by a '/'. - return StartsWithASCII(url.spec(), - chrome::kNetworkViewInternalsURL, - true /*case_sensitive*/); - } -}; - URLRequestJob* ChromeURLDataManager::Factory(URLRequest* request, const std::string& scheme) { // Try first with a file handler @@ -342,10 +314,8 @@ URLRequestJob* ChromeURLDataManager::Factory(URLRequest* request, return new URLRequestChromeFileJob(request, path); // Next check for chrome://net-internals/, which uses its own job type. - if (NetInternalsURLFormat::IsSupportedURL(request->url())) { - static NetInternalsURLFormat url_format; - return new URLRequestViewNetInternalsJob(request, &url_format); - } + if (ViewNetInternalsJobFactory::IsSupportedURL(request->url())) + return ViewNetInternalsJobFactory::CreateJobForRequest(request); // Fall back to using a custom handler return new URLRequestChromeJob(request); diff --git a/net/url_request/url_request_view_net_internals_job.cc b/chrome/browser/net/view_net_internals_job_factory.cc index 38349a4..ab58dfcf 100644 --- a/net/url_request/url_request_view_net_internals_job.cc +++ b/chrome/browser/net/view_net_internals_job_factory.cc @@ -1,14 +1,15 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. -#include "net/url_request/url_request_view_net_internals_job.h" +#include "chrome/browser/net/view_net_internals_job_factory.h" #include <sstream> #include "base/format_macros.h" #include "base/stl_util-inl.h" #include "base/string_util.h" +#include "chrome/common/url_constants.h" #include "net/base/escape.h" #include "net/base/host_resolver_impl.h" #include "net/base/load_log_util.h" @@ -19,12 +20,49 @@ #include "net/socket_stream/socket_stream.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_context.h" +#include "net/url_request/url_request_simple_job.h" #include "net/url_request/view_cache_helper.h" namespace { const char kViewHttpCacheSubPath[] = "view-cache"; +std::string GetDetails(const GURL& url) { + DCHECK(ViewNetInternalsJobFactory::IsSupportedURL(url)); + size_t start = strlen(chrome::kNetworkViewInternalsURL); + if (start >= url.spec().size()) + return std::string(); + return url.spec().substr(start); +} + +GURL MakeURL(const std::string& details) { + return GURL(std::string(chrome::kNetworkViewInternalsURL) + details); +} + +// A job subclass that implements a protocol to inspect the internal +// state of the network stack. +class ViewNetInternalsJob : public URLRequestSimpleJob { + public: + + explicit ViewNetInternalsJob(URLRequest* request) + : URLRequestSimpleJob(request) {} + + // URLRequestSimpleJob methods: + virtual bool GetData(std::string* mime_type, + std::string* charset, + std::string* data) const; + + // Overridden methods from URLRequestJob: + virtual bool IsRedirectResponse(GURL* location, int* http_status_code); + + private: + ~ViewNetInternalsJob() {} + + // Returns true if the current request is for a "view-cache" URL. + // If it is, then |key| is assigned the particular cache URL of the request. + bool GetViewCacheKeyForRequest(std::string* key) const; +}; + //------------------------------------------------------------------------------ // Format helpers. //------------------------------------------------------------------------------ @@ -82,13 +120,10 @@ class SubSection { virtual void OutputBody(URLRequestContext* context, std::string* out) {} // Outputs this subsection, and all of its children. - void OutputRecursive(URLRequestContext* context, - URLRequestViewNetInternalsJob::URLFormat* url_format, - std::string* out) { + void OutputRecursive(URLRequestContext* context, std::string* out) { if (!is_root()) { // Canonicalizing the URL escapes characters which cause problems in HTML. - std::string section_url = - url_format->MakeURL(GetFullyQualifiedName()).spec(); + std::string section_url = MakeURL(GetFullyQualifiedName()).spec(); // Print the heading. StringAppendF( @@ -107,7 +142,7 @@ class SubSection { OutputBody(context, out); for (size_t i = 0; i < children_.size(); ++i) - children_[i]->OutputRecursive(context, url_format, out); + children_[i]->OutputRecursive(context, out); if (!is_root()) out->append("</div>"); @@ -662,11 +697,9 @@ void DrawControlsHeader(URLRequestContext* context, std::string* data) { data->append("</div>"); } -} // namespace - -bool URLRequestViewNetInternalsJob::GetData(std::string* mime_type, - std::string* charset, - std::string* data) const { +bool ViewNetInternalsJob::GetData(std::string* mime_type, + std::string* charset, + std::string* data) const { mime_type->assign("text/html"); charset->assign("UTF-8"); @@ -677,7 +710,7 @@ bool URLRequestViewNetInternalsJob::GetData(std::string* mime_type, // Use a different handler for "view-cache/*" subpaths. std::string cache_key; if (GetViewCacheKeyForRequest(&cache_key)) { - GURL url = url_format_->MakeURL(kViewHttpCacheSubPath + std::string("/")); + GURL url = MakeURL(kViewHttpCacheSubPath + std::string("/")); ViewCacheHelper::GetEntryInfoHTML(cache_key, context, url.spec(), data); return true; } @@ -690,7 +723,7 @@ bool URLRequestViewNetInternalsJob::GetData(std::string* mime_type, return true; } - std::string details = url_format_->GetDetails(request_->url()); + std::string details = GetDetails(request_->url()); data->append("<!DOCTYPE HTML>" "<html><head><title>Network internals</title>" @@ -731,7 +764,7 @@ bool URLRequestViewNetInternalsJob::GetData(std::string* mime_type, section = all->FindSubSectionByName(details); if (section) { - section->OutputRecursive(context, url_format_, data); + section->OutputRecursive(context, data); } else { data->append("<i>Nothing found for \""); data->append(EscapeForHTML(details)); @@ -743,8 +776,8 @@ bool URLRequestViewNetInternalsJob::GetData(std::string* mime_type, return true; } -bool URLRequestViewNetInternalsJob::IsRedirectResponse(GURL* location, - int* http_status_code) { +bool ViewNetInternalsJob::IsRedirectResponse(GURL* location, + int* http_status_code) { if (request_->url().has_query() && !GetViewCacheKeyForRequest(NULL)) { // Strip the query parameters. GURL::Replacements replacements; @@ -756,9 +789,9 @@ bool URLRequestViewNetInternalsJob::IsRedirectResponse(GURL* location, return false; } -bool URLRequestViewNetInternalsJob::GetViewCacheKeyForRequest( +bool ViewNetInternalsJob::GetViewCacheKeyForRequest( std::string* key) const { - std::string path = url_format_->GetDetails(request_->url()); + std::string path = GetDetails(request_->url()); if (!StartsWithASCII(path, kViewHttpCacheSubPath, true)) return false; @@ -771,3 +804,19 @@ bool URLRequestViewNetInternalsJob::GetViewCacheKeyForRequest( return true; } + +} // namespace + +// static +bool ViewNetInternalsJobFactory::IsSupportedURL(const GURL& url) { + // Note that kNetworkViewInternalsURL is terminated by a '/'. + return StartsWithASCII(url.spec(), + chrome::kNetworkViewInternalsURL, + true /*case_sensitive*/); +} + +// static +URLRequestJob* ViewNetInternalsJobFactory::CreateJobForRequest( + URLRequest* request) { + return new ViewNetInternalsJob(request); +} diff --git a/chrome/browser/net/view_net_internals_job_factory.h b/chrome/browser/net/view_net_internals_job_factory.h new file mode 100644 index 0000000..a694c93 --- /dev/null +++ b/chrome/browser/net/view_net_internals_job_factory.h @@ -0,0 +1,18 @@ +// Copyright (c) 2010 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 CHROME_BROWSER_NET_VIEW_NET_INTERNALS_JOB_FACTORY_H_ +#define CHROME_BROWSER_NET_VIEW_NET_INTERNALS_JOB_FACTORY_H_ + +class GURL; +class URLRequest; +class URLRequestJob; + +class ViewNetInternalsJobFactory { + public: + static bool IsSupportedURL(const GURL& url); + static URLRequestJob* CreateJobForRequest(URLRequest* request); +}; + +#endif // CHROME_BROWSER_NET_VIEW_NET_INTERNALS_JOB_FACTORY_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 8c54ce5..be72d21 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1463,6 +1463,8 @@ 'browser/net/url_request_slow_http_job.h', 'browser/net/url_request_tracking.cc', 'browser/net/url_request_tracking.h', + 'browser/net/view_net_internals_job_factory.cc', + 'browser/net/view_net_internals_job_factory.h', 'browser/net/websocket_experiment/websocket_experiment_runner.cc', 'browser/net/websocket_experiment/websocket_experiment_runner.h', 'browser/net/websocket_experiment/websocket_experiment_task.cc', diff --git a/net/net.gyp b/net/net.gyp index 1f89865..0addbbf 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -501,8 +501,6 @@ '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_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', 'websockets/websocket.cc', diff --git a/net/url_request/url_request_view_net_internals_job.h b/net/url_request/url_request_view_net_internals_job.h deleted file mode 100644 index 3d1eff3..0000000 --- a/net/url_request/url_request_view_net_internals_job.h +++ /dev/null @@ -1,51 +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_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) {} - - // URLRequestSimpleJob methods: - virtual bool GetData(std::string* mime_type, - std::string* charset, - std::string* data) const; - - // Overridden methods from URLRequestJob: - virtual bool IsRedirectResponse(GURL* location, int* http_status_code); - - private: - ~URLRequestViewNetInternalsJob() {} - - // Returns true if the current request is for a "view-cache" URL. - // If it is, then |key| is assigned the particular cache URL of the request. - bool GetViewCacheKeyForRequest(std::string* key) const; - - 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_ |