Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / histogram_internals_request_job.cc
blobd8640dd1a70cf284c6d1b1ffbe5b243c9d160f90
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"
13 #include "url/gurl.h"
15 namespace content {
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::Parsed& parsed = request->url().parsed_for_possibly_invalid_spec();
22 // + 1 to skip the slash at the beginning of the path.
23 int offset = parsed.CountCharactersBefore(url::Parsed::PATH, false) + 1;
25 if (offset < static_cast<int>(spec.size()))
26 path_.assign(spec.substr(offset));
29 void AboutHistogram(std::string* data, const std::string& path) {
30 HistogramSynchronizer::FetchHistograms();
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;
40 data->append("<!DOCTYPE html>\n<html>\n<head>\n");
41 data->append(
42 "<meta http-equiv=\"Content-Security-Policy\" "
43 "content=\"object-src 'none'; script-src 'none'\">");
44 data->append("<title>");
45 data->append(net::EscapeForHTML(unescaped_title));
46 data->append("</title>\n");
47 data->append("</head><body>");
49 // Display any stats for which we sent off requests the last time.
50 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");
52 data->append("<table width=\"100%\">\n");
54 base::StatisticsRecorder::WriteHTMLGraph(unescaped_query, data);
57 int HistogramInternalsRequestJob::GetData(
58 std::string* mime_type,
59 std::string* charset,
60 std::string* data,
61 const net::CompletionCallback& callback) const {
62 mime_type->assign("text/html");
63 charset->assign("UTF8");
65 data->clear();
66 AboutHistogram(data, path_);
67 return net::OK;
70 } // namespace content