Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: content/browser/histogram_internals_request_job.cc

Issue 2658163002: Merge histograms from providers into StatisticsRecorder for display. (Closed)
Patch Set: rebased Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/histogram_internals_request_job.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/histogram_internals_request_job.h" 5 #include "content/browser/histogram_internals_request_job.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/metrics/statistics_recorder.h" 8 #include "base/metrics/statistics_recorder.h"
9 #include "content/browser/histogram_synchronizer.h" 9 #include "content/browser/histogram_synchronizer.h"
10 #include "content/public/browser/browser_thread.h"
10 #include "net/base/escape.h" 11 #include "net/base/escape.h"
11 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
12 #include "net/url_request/url_request.h" 13 #include "net/url_request/url_request.h"
13 #include "url/gurl.h" 14 #include "url/gurl.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 HistogramInternalsRequestJob::HistogramInternalsRequestJob( 18 HistogramInternalsRequestJob::HistogramInternalsRequestJob(
18 net::URLRequest* request, net::NetworkDelegate* network_delegate) 19 net::URLRequest* request,
19 : net::URLRequestSimpleJob(request, network_delegate) { 20 net::NetworkDelegate* network_delegate)
21 : net::URLRequestSimpleJob(request, network_delegate), weak_factory_(this) {
20 const std::string& spec = request->url().possibly_invalid_spec(); 22 const std::string& spec = request->url().possibly_invalid_spec();
21 const url::Parsed& parsed = request->url().parsed_for_possibly_invalid_spec(); 23 const url::Parsed& parsed = request->url().parsed_for_possibly_invalid_spec();
22 // + 1 to skip the slash at the beginning of the path. 24 // + 1 to skip the slash at the beginning of the path.
23 int offset = parsed.CountCharactersBefore(url::Parsed::PATH, false) + 1; 25 int offset = parsed.CountCharactersBefore(url::Parsed::PATH, false) + 1;
24 26
25 if (offset < static_cast<int>(spec.size())) 27 if (offset < static_cast<int>(spec.size()))
26 path_.assign(spec.substr(offset)); 28 path_.assign(spec.substr(offset));
27 } 29 }
28 30
31 HistogramInternalsRequestJob::~HistogramInternalsRequestJob() {}
32
29 void AboutHistogram(std::string* data, const std::string& path) { 33 void AboutHistogram(std::string* data, const std::string& path) {
30 HistogramSynchronizer::FetchHistograms(); 34 HistogramSynchronizer::FetchHistograms();
31 35
32 std::string unescaped_query; 36 std::string unescaped_query;
33 std::string unescaped_title("About Histograms"); 37 std::string unescaped_title("About Histograms");
34 if (!path.empty()) { 38 if (!path.empty()) {
35 unescaped_query = net::UnescapeURLComponent(path, 39 unescaped_query = net::UnescapeURLComponent(path,
36 net::UnescapeRule::NORMAL); 40 net::UnescapeRule::NORMAL);
37 unescaped_title += " - " + unescaped_query; 41 unescaped_title += " - " + unescaped_query;
38 } 42 }
39 43
40 data->append("<!DOCTYPE html>\n<html>\n<head>\n"); 44 data->append("<!DOCTYPE html>\n<html>\n<head>\n");
41 data->append( 45 data->append(
42 "<meta http-equiv=\"Content-Security-Policy\" " 46 "<meta http-equiv=\"Content-Security-Policy\" "
43 "content=\"object-src 'none'; script-src 'none'\">"); 47 "content=\"object-src 'none'; script-src 'none'\">");
44 data->append("<title>"); 48 data->append("<title>");
45 data->append(net::EscapeForHTML(unescaped_title)); 49 data->append(net::EscapeForHTML(unescaped_title));
46 data->append("</title>\n"); 50 data->append("</title>\n");
47 data->append("</head><body>"); 51 data->append("</head><body>");
48 52
49 // Display any stats for which we sent off requests the last time. 53 // Display any stats for which we sent off requests the last time.
50 data->append("<p>Stats accumulated from browser startup to previous "); 54 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"); 55 data->append("page load; reload to get stats as of this page load.</p>\n");
52 data->append("<table width=\"100%\">\n"); 56 data->append("<table width=\"100%\">\n");
53 57
54 base::StatisticsRecorder::WriteHTMLGraph(unescaped_query, data); 58 base::StatisticsRecorder::WriteHTMLGraph(unescaped_query, data);
55 } 59 }
56 60
61 void HistogramInternalsRequestJob::Start() {
62 // First import histograms from all providers and then start the URL fetch
63 // job. It's not possible to call URLRequestSimpleJob::Start through Bind,
64 // it ends up re-calling this method, so a small helper method is used.
65 content::BrowserThread::PostTaskAndReply(
66 content::BrowserThread::UI, FROM_HERE,
67 base::Bind(&base::StatisticsRecorder::ImportProvidedHistograms),
68 base::Bind(&HistogramInternalsRequestJob::StartUrlRequest,
69 weak_factory_.GetWeakPtr()));
70 }
71
57 int HistogramInternalsRequestJob::GetData( 72 int HistogramInternalsRequestJob::GetData(
58 std::string* mime_type, 73 std::string* mime_type,
59 std::string* charset, 74 std::string* charset,
60 std::string* data, 75 std::string* data,
61 const net::CompletionCallback& callback) const { 76 const net::CompletionCallback& callback) const {
62 mime_type->assign("text/html"); 77 mime_type->assign("text/html");
63 charset->assign("UTF8"); 78 charset->assign("UTF8");
64 79
65 data->clear(); 80 data->clear();
66 AboutHistogram(data, path_); 81 AboutHistogram(data, path_);
67 return net::OK; 82 return net::OK;
68 } 83 }
69 84
85 void HistogramInternalsRequestJob::StartUrlRequest() {
86 URLRequestSimpleJob::Start();
87 }
88
70 } // namespace content 89 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/histogram_internals_request_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698