OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/histogram_internals_request_job.h" |
| 6 |
| 7 #include "base/metrics/histogram.h" |
| 8 #include "content/browser/histogram_synchronizer.h" |
| 9 #include "googleurl/src/gurl.h" |
| 10 #include "net/base/escape.h" |
| 11 #include "net/url_request/url_request.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 HistogramInternalsRequestJob::HistogramInternalsRequestJob( |
| 16 net::URLRequest* request) : net::URLRequestSimpleJob(request) { |
| 17 const std::string& spec = request->url().possibly_invalid_spec(); |
| 18 const url_parse::Parsed& parsed = |
| 19 request->url().parsed_for_possibly_invalid_spec(); |
| 20 // + 1 to skip the slash at the beginning of the path. |
| 21 int offset = parsed.CountCharactersBefore(url_parse::Parsed::PATH, false) + 1; |
| 22 |
| 23 if (offset < static_cast<int>(spec.size())) |
| 24 path_.assign(spec.substr(offset)); |
| 25 } |
| 26 |
| 27 void AboutHistogram(std::string* data, const std::string& path) { |
| 28 #ifndef NDEBUG |
| 29 base::StatisticsRecorder::CollectHistogramStats("Browser"); |
| 30 #endif |
| 31 content::HistogramSynchronizer::FetchHistograms(); |
| 32 |
| 33 std::string unescaped_query; |
| 34 std::string unescaped_title("About Histograms"); |
| 35 if (!path.empty()) { |
| 36 unescaped_query = net::UnescapeURLComponent(path, |
| 37 net::UnescapeRule::NORMAL); |
| 38 unescaped_title += " - " + unescaped_query; |
| 39 } |
| 40 |
| 41 data->append("<!DOCTYPE html>\n<html>\n<head>\n"); |
| 42 data->append( |
| 43 "<meta http-equiv=\"X-WebKit-CSP\" content=\"object-src 'none'; " |
| 44 "script-src 'none' 'unsafe-eval'\">"); |
| 45 data->append("<title>"); |
| 46 data->append(net::EscapeForHTML(unescaped_title)); |
| 47 data->append("</title>\n"); |
| 48 data->append("</head><body>"); |
| 49 |
| 50 // Display any stats for which we sent off requests the last time. |
| 51 data->append("<p>Stats as of last page load;"); |
| 52 data->append("reload to get stats as of this page load.</p>\n"); |
| 53 data->append("<table width=\"100%\">\n"); |
| 54 |
| 55 base::StatisticsRecorder::WriteHTMLGraph(unescaped_query, data); |
| 56 } |
| 57 |
| 58 bool HistogramInternalsRequestJob::GetData(std::string* mime_type, |
| 59 std::string* charset, |
| 60 std::string* data) const { |
| 61 mime_type->assign("text/html"); |
| 62 charset->assign("UTF8"); |
| 63 |
| 64 data->clear(); |
| 65 AboutHistogram(data, path_); |
| 66 return true; |
| 67 } |
| 68 |
| 69 } // namespace content |
OLD | NEW |