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.
5 #include "content/browser/histogram_internals_request_job.h"
7 #include "base/metrics/histogram.h"
8 #include "base/metrics/statistics_recorder.h"
9 #include "content/browser/histogram_synchronizer.h"
10 #include "net/base/escape.h"
11 #include "net/base/net_errors.h"
12 #include "net/url_request/url_request.h"
17 HistogramInternalsRequestJob::HistogramInternalsRequestJob(
18 net::URLRequest
* request
, net::NetworkDelegate
* network_delegate
)
19 : net::URLRequestSimpleJob(request
, network_delegate
) {
20 const std::string
& spec
= request
->url().possibly_invalid_spec();
21 const url_parse::Parsed
& parsed
=
22 request
->url().parsed_for_possibly_invalid_spec();
23 // + 1 to skip the slash at the beginning of the path.
24 int offset
= parsed
.CountCharactersBefore(url_parse::Parsed::PATH
, false) + 1;
26 if (offset
< static_cast<int>(spec
.size()))
27 path_
.assign(spec
.substr(offset
));
30 void AboutHistogram(std::string
* data
, const std::string
& path
) {
31 HistogramSynchronizer::FetchHistograms();
33 std::string unescaped_query
;
34 std::string
unescaped_title("About Histograms");
36 unescaped_query
= net::UnescapeURLComponent(path
,
37 net::UnescapeRule::NORMAL
);
38 unescaped_title
+= " - " + unescaped_query
;
41 data
->append("<!DOCTYPE html>\n<html>\n<head>\n");
43 "<meta http-equiv=\"Content-Security-Policy\" "
44 "content=\"object-src 'none'; script-src 'none'\">");
45 data
->append("<title>");
46 data
->append(net::EscapeForHTML(unescaped_title
));
47 data
->append("</title>\n");
48 data
->append("</head><body>");
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");
55 base::StatisticsRecorder::WriteHTMLGraph(unescaped_query
, data
);
58 int HistogramInternalsRequestJob::GetData(
59 std::string
* mime_type
,
62 const net::CompletionCallback
& callback
) const {
63 mime_type
->assign("text/html");
64 charset
->assign("UTF8");
67 AboutHistogram(data
, path_
);
71 } // namespace content