blob: d8640dd1a70cf284c6d1b1ffbe5b243c9d160f90 [file] [log] [blame]
[email protected]83ab4a282012-07-12 18:19:451// 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"
[email protected]567d30e2012-07-13 21:48:298#include "base/metrics/statistics_recorder.h"
[email protected]83ab4a282012-07-12 18:19:459#include "content/browser/histogram_synchronizer.h"
[email protected]83ab4a282012-07-12 18:19:4510#include "net/base/escape.h"
[email protected]36ffc7342012-07-23 17:15:1011#include "net/base/net_errors.h"
[email protected]83ab4a282012-07-12 18:19:4512#include "net/url_request/url_request.h"
[email protected]707e1c42013-07-09 21:18:5813#include "url/gurl.h"
[email protected]83ab4a282012-07-12 18:19:4514
15namespace content {
16
17HistogramInternalsRequestJob::HistogramInternalsRequestJob(
[email protected]9f170462012-08-24 01:06:5818 net::URLRequest* request, net::NetworkDelegate* network_delegate)
19 : net::URLRequestSimpleJob(request, network_delegate) {
[email protected]83ab4a282012-07-12 18:19:4520 const std::string& spec = request->url().possibly_invalid_spec();
[email protected]ea0c7a82014-05-01 06:12:2721 const url::Parsed& parsed = request->url().parsed_for_possibly_invalid_spec();
[email protected]83ab4a282012-07-12 18:19:4522 // + 1 to skip the slash at the beginning of the path.
[email protected]ea0c7a82014-05-01 06:12:2723 int offset = parsed.CountCharactersBefore(url::Parsed::PATH, false) + 1;
[email protected]83ab4a282012-07-12 18:19:4524
25 if (offset < static_cast<int>(spec.size()))
26 path_.assign(spec.substr(offset));
27}
28
29void AboutHistogram(std::string* data, const std::string& path) {
[email protected]46488322012-10-30 03:22:2030 HistogramSynchronizer::FetchHistograms();
[email protected]83ab4a282012-07-12 18:19:4531
32 std::string unescaped_query;
33 std::string unescaped_title("About Histograms");
34 if (!path.empty()) {
35 unescaped_query = net::UnescapeURLComponent(path,
36 net::UnescapeRule::NORMAL);
37 unescaped_title += " - " + unescaped_query;
38 }
39
40 data->append("<!DOCTYPE html>\n<html>\n<head>\n");
41 data->append(
[email protected]4db72872012-11-07 15:34:5042 "<meta http-equiv=\"Content-Security-Policy\" "
[email protected]6ed944a2013-05-31 22:41:5843 "content=\"object-src 'none'; script-src 'none'\">");
[email protected]83ab4a282012-07-12 18:19:4544 data->append("<title>");
45 data->append(net::EscapeForHTML(unescaped_title));
46 data->append("</title>\n");
47 data->append("</head><body>");
48
49 // Display any stats for which we sent off requests the last time.
[email protected]f2175b42014-07-30 07:49:3550 data->append("<p>Stats accumulated from browser startup to previous ");
51 data->append("page load; reload to get stats as of this page load.</p>\n");
[email protected]83ab4a282012-07-12 18:19:4552 data->append("<table width=\"100%\">\n");
53
54 base::StatisticsRecorder::WriteHTMLGraph(unescaped_query, data);
55}
56
[email protected]36ffc7342012-07-23 17:15:1057int HistogramInternalsRequestJob::GetData(
58 std::string* mime_type,
59 std::string* charset,
60 std::string* data,
61 const net::CompletionCallback& callback) const {
[email protected]83ab4a282012-07-12 18:19:4562 mime_type->assign("text/html");
63 charset->assign("UTF8");
64
65 data->clear();
66 AboutHistogram(data, path_);
[email protected]36ffc7342012-07-23 17:15:1067 return net::OK;
[email protected]83ab4a282012-07-12 18:19:4568}
69
70} // namespace content