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 // We only rush the acquisition of Histogram meta-data (meta-histograms) in |
| 30 // Debug mode, so that developers don't damage our data that we upload to UMA |
| 31 // (in official builds). |
| 32 base::StatisticsRecorder::CollectHistogramStats("Browser"); |
| 33 #endif |
| 34 content::HistogramSynchronizer::FetchHistograms(); |
| 35 |
| 36 std::string unescaped_query; |
| 37 std::string unescaped_title("About Histograms"); |
| 38 if (!path.empty()) { |
| 39 unescaped_query = net::UnescapeURLComponent(path, |
| 40 net::UnescapeRule::NORMAL); |
| 41 unescaped_title += " - " + unescaped_query; |
| 42 } |
| 43 |
| 44 data->append("<!DOCTYPE html>\n<html>\n<head>\n"); |
| 45 data->append( |
| 46 "<meta http-equiv=\"X-WebKit-CSP\" content=\"object-src 'none'; " |
| 47 "script-src 'none' 'unsafe-eval'\">"); |
| 48 data->append("<title>"); |
| 49 data->append(net::EscapeForHTML(unescaped_title)); |
| 50 data->append("</title>\n"); |
| 51 data->append("</head><body>"); |
| 52 |
| 53 // Display any stats for which we sent off requests the last time. |
| 54 data->append("<p>Stats as of last page load;"); |
| 55 data->append("reload to get stats as of this page load.</p>\n"); |
| 56 data->append("<table width=\"100%\">\n"); |
| 57 |
| 58 base::StatisticsRecorder::WriteHTMLGraph(unescaped_query, data); |
| 59 } |
| 60 |
| 61 bool HistogramInternalsRequestJob::GetData(std::string* mime_type, |
| 62 std::string* charset, |
| 63 std::string* data) const { |
| 64 mime_type->assign("text/html"); |
| 65 charset->assign("UTF8"); |
| 66 |
| 67 data->clear(); |
| 68 AboutHistogram(data, path_); |
| 69 return true; |
| 70 } |
| 71 |
| 72 } // namespace content |
OLD | NEW |