| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/net/view_net_internals_job_factory.h" | 5 #include "chrome/browser/net/view_net_internals_job_factory.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "net/socket_stream/socket_stream.h" | 23 #include "net/socket_stream/socket_stream.h" |
| 24 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
| 25 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
| 26 #include "net/url_request/url_request_simple_job.h" | 26 #include "net/url_request/url_request_simple_job.h" |
| 27 #include "net/url_request/view_cache_helper.h" | 27 #include "net/url_request/view_cache_helper.h" |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 const char kViewHttpCacheSubPath[] = "view-cache"; | 31 const char kViewHttpCacheSubPath[] = "view-cache"; |
| 32 | 32 |
| 33 // TODO(eroman): Delete this file. It should be replaced by |
| 34 // chrome/browser/dom_ui/net_internals_ui.cc once the porting is |
| 35 // complete. |
| 36 |
| 33 PassiveLogCollector* GetPassiveLogCollector(URLRequestContext* context) { | 37 PassiveLogCollector* GetPassiveLogCollector(URLRequestContext* context) { |
| 34 // Really this is the same as: | 38 // Really this is the same as: |
| 35 // g_browser_process->io_thread()->globals()-> | 39 // g_browser_process->io_thread()->globals()-> |
| 36 // net_log.get() | 40 // net_log.get() |
| 37 // (But we can't access g_browser_process from the IO thread). | 41 // (But we can't access g_browser_process from the IO thread). |
| 38 ChromeNetLog* chrome_net_log = static_cast<ChromeNetLog*>( | 42 ChromeNetLog* chrome_net_log = static_cast<ChromeNetLog*>( |
| 39 static_cast<ChromeURLRequestContext*>(context)->net_log()); | 43 static_cast<ChromeURLRequestContext*>(context)->net_log()); |
| 40 return chrome_net_log->passive_collector(); | 44 return chrome_net_log->passive_collector(); |
| 41 } | 45 } |
| 42 | 46 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 60 size_t start = strlen(chrome::kNetworkViewInternalsURL); | 64 size_t start = strlen(chrome::kNetworkViewInternalsURL); |
| 61 if (start >= url.spec().size()) | 65 if (start >= url.spec().size()) |
| 62 return std::string(); | 66 return std::string(); |
| 63 return url.spec().substr(start); | 67 return url.spec().substr(start); |
| 64 } | 68 } |
| 65 | 69 |
| 66 GURL MakeURL(const std::string& details) { | 70 GURL MakeURL(const std::string& details) { |
| 67 return GURL(std::string(chrome::kNetworkViewInternalsURL) + details); | 71 return GURL(std::string(chrome::kNetworkViewInternalsURL) + details); |
| 68 } | 72 } |
| 69 | 73 |
| 74 // Converts a PassiveLogCollector::EntryList to a CapturingNetLog::EntryList. |
| 75 // |
| 76 // They are basically the same thing, except PassiveLogCollector has an extra |
| 77 // "order" field which we will drop. |
| 78 net::CapturingNetLog::EntryList ConvertEntryList( |
| 79 const PassiveLogCollector::EntryList& input) { |
| 80 net::CapturingNetLog::EntryList result; |
| 81 for (size_t i = 0; i < input.size(); ++i) { |
| 82 result.push_back( |
| 83 net::CapturingNetLog::Entry( |
| 84 input[i].type, |
| 85 input[i].time, |
| 86 input[i].source, |
| 87 input[i].phase, |
| 88 input[i].extra_parameters)); |
| 89 } |
| 90 return result; |
| 91 } |
| 92 |
| 70 // A job subclass that implements a protocol to inspect the internal | 93 // A job subclass that implements a protocol to inspect the internal |
| 71 // state of the network stack. | 94 // state of the network stack. |
| 72 class ViewNetInternalsJob : public URLRequestSimpleJob { | 95 class ViewNetInternalsJob : public URLRequestSimpleJob { |
| 73 public: | 96 public: |
| 74 | 97 |
| 75 explicit ViewNetInternalsJob(URLRequest* request) | 98 explicit ViewNetInternalsJob(URLRequest* request) |
| 76 : URLRequestSimpleJob(request) {} | 99 : URLRequestSimpleJob(request) {} |
| 77 | 100 |
| 78 // URLRequestSimpleJob methods: | 101 // URLRequestSimpleJob methods: |
| 79 virtual bool GetData(std::string* mime_type, | 102 virtual bool GetData(std::string* mime_type, |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 } | 275 } |
| 253 }; | 276 }; |
| 254 | 277 |
| 255 class ProxyServiceLastInitLogSubSection : public SubSection { | 278 class ProxyServiceLastInitLogSubSection : public SubSection { |
| 256 public: | 279 public: |
| 257 explicit ProxyServiceLastInitLogSubSection(SubSection* parent) | 280 explicit ProxyServiceLastInitLogSubSection(SubSection* parent) |
| 258 : SubSection(parent, "init_log", "Last initialized load log") { | 281 : SubSection(parent, "init_log", "Last initialized load log") { |
| 259 } | 282 } |
| 260 | 283 |
| 261 virtual void OutputBody(URLRequestContext* context, std::string* out) { | 284 virtual void OutputBody(URLRequestContext* context, std::string* out) { |
| 262 OutputTextInPre(net::NetLogUtil::PrettyPrintAsEventTree( | 285 OutputTextInPre( |
| 263 GetInitProxyResolverTracker(context)->entries(), 0), out); | 286 net::NetLogUtil::PrettyPrintAsEventTree( |
| 287 ConvertEntryList(GetInitProxyResolverTracker(context)->entries()), |
| 288 0), |
| 289 out); |
| 264 } | 290 } |
| 265 }; | 291 }; |
| 266 | 292 |
| 267 class ProxyServiceBadProxiesSubSection : public SubSection { | 293 class ProxyServiceBadProxiesSubSection : public SubSection { |
| 268 public: | 294 public: |
| 269 explicit ProxyServiceBadProxiesSubSection(SubSection* parent) | 295 explicit ProxyServiceBadProxiesSubSection(SubSection* parent) |
| 270 : SubSection(parent, "bad_proxies", "Bad Proxies") { | 296 : SubSection(parent, "bad_proxies", "Bad Proxies") { |
| 271 } | 297 } |
| 272 | 298 |
| 273 virtual void OutputBody(URLRequestContext* context, std::string* out) { | 299 virtual void OutputBody(URLRequestContext* context, std::string* out) { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 499 |
| 474 // Helper for the URLRequest "outstanding" and "live" sections. | 500 // Helper for the URLRequest "outstanding" and "live" sections. |
| 475 void OutputURLAndLoadLog(const PassiveLogCollector::RequestInfo& request, | 501 void OutputURLAndLoadLog(const PassiveLogCollector::RequestInfo& request, |
| 476 std::string* out) { | 502 std::string* out) { |
| 477 out->append("<li>"); | 503 out->append("<li>"); |
| 478 out->append("<nobr>"); | 504 out->append("<nobr>"); |
| 479 out->append(EscapeForHTML(request.url)); | 505 out->append(EscapeForHTML(request.url)); |
| 480 out->append("</nobr>"); | 506 out->append("</nobr>"); |
| 481 OutputTextInPre( | 507 OutputTextInPre( |
| 482 net::NetLogUtil::PrettyPrintAsEventTree( | 508 net::NetLogUtil::PrettyPrintAsEventTree( |
| 483 request.entries, | 509 ConvertEntryList(request.entries), |
| 484 request.num_entries_truncated), | 510 request.num_entries_truncated), |
| 485 out); | 511 out); |
| 486 out->append("</li>"); | 512 out->append("</li>"); |
| 487 } | 513 } |
| 488 | 514 |
| 489 class URLRequestLiveSubSection : public SubSection { | 515 class URLRequestLiveSubSection : public SubSection { |
| 490 public: | 516 public: |
| 491 explicit URLRequestLiveSubSection(SubSection* parent) | 517 explicit URLRequestLiveSubSection(SubSection* parent) |
| 492 : SubSection(parent, "outstanding", "Outstanding requests") { | 518 : SubSection(parent, "outstanding", "Outstanding requests") { |
| 493 } | 519 } |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 return StartsWithASCII(url.spec(), | 866 return StartsWithASCII(url.spec(), |
| 841 chrome::kNetworkViewInternalsURL, | 867 chrome::kNetworkViewInternalsURL, |
| 842 true /*case_sensitive*/); | 868 true /*case_sensitive*/); |
| 843 } | 869 } |
| 844 | 870 |
| 845 // static | 871 // static |
| 846 URLRequestJob* ViewNetInternalsJobFactory::CreateJobForRequest( | 872 URLRequestJob* ViewNetInternalsJobFactory::CreateJobForRequest( |
| 847 URLRequest* request) { | 873 URLRequest* request) { |
| 848 return new ViewNetInternalsJob(request); | 874 return new ViewNetInternalsJob(request); |
| 849 } | 875 } |
| OLD | NEW |