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

Side by Side Diff: chrome/browser/ui/webui/metrics_handler.cc

Issue 2203263002: History: Add load-time metric for non-MD and MD History WebUI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: isherman@ review Created 4 years, 4 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 | « chrome/browser/ui/webui/metrics_handler.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | 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 "chrome/browser/ui/webui/metrics_handler.h" 5 #include "chrome/browser/ui/webui/metrics_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 16 matching lines...) Expand all
27 27
28 void MetricsHandler::RegisterMessages() { 28 void MetricsHandler::RegisterMessages() {
29 web_ui()->RegisterMessageCallback( 29 web_ui()->RegisterMessageCallback(
30 "metricsHandler:recordAction", 30 "metricsHandler:recordAction",
31 base::Bind(&MetricsHandler::HandleRecordAction, base::Unretained(this))); 31 base::Bind(&MetricsHandler::HandleRecordAction, base::Unretained(this)));
32 web_ui()->RegisterMessageCallback( 32 web_ui()->RegisterMessageCallback(
33 "metricsHandler:recordInHistogram", 33 "metricsHandler:recordInHistogram",
34 base::Bind(&MetricsHandler::HandleRecordInHistogram, 34 base::Bind(&MetricsHandler::HandleRecordInHistogram,
35 base::Unretained(this))); 35 base::Unretained(this)));
36 web_ui()->RegisterMessageCallback( 36 web_ui()->RegisterMessageCallback(
37 "metricsHandler:recordTime",
38 base::Bind(&MetricsHandler::HandleRecordTime, base::Unretained(this)));
39 web_ui()->RegisterMessageCallback(
37 "metricsHandler:logEventTime", 40 "metricsHandler:logEventTime",
38 base::Bind(&MetricsHandler::HandleLogEventTime, base::Unretained(this))); 41 base::Bind(&MetricsHandler::HandleLogEventTime, base::Unretained(this)));
39 } 42 }
40 43
41 void MetricsHandler::HandleRecordAction(const base::ListValue* args) { 44 void MetricsHandler::HandleRecordAction(const base::ListValue* args) {
42 std::string string_action = base::UTF16ToUTF8(ExtractStringValue(args)); 45 std::string string_action = base::UTF16ToUTF8(ExtractStringValue(args));
43 content::RecordComputedAction(string_action); 46 content::RecordComputedAction(string_action);
44 } 47 }
45 48
46 void MetricsHandler::HandleRecordInHistogram(const base::ListValue* args) { 49 void MetricsHandler::HandleRecordInHistogram(const base::ListValue* args) {
(...skipping 23 matching lines...) Expand all
70 73
71 // As |histogram_name| may change between calls, the UMA_HISTOGRAM_ENUMERATION 74 // As |histogram_name| may change between calls, the UMA_HISTOGRAM_ENUMERATION
72 // macro cannot be used here. 75 // macro cannot be used here.
73 base::HistogramBase* counter = 76 base::HistogramBase* counter =
74 base::LinearHistogram::FactoryGet( 77 base::LinearHistogram::FactoryGet(
75 histogram_name, 1, int_boundary_value, bucket_count + 1, 78 histogram_name, 1, int_boundary_value, bucket_count + 1,
76 base::HistogramBase::kUmaTargetedHistogramFlag); 79 base::HistogramBase::kUmaTargetedHistogramFlag);
77 counter->Add(int_value); 80 counter->Add(int_value);
78 } 81 }
79 82
83 void MetricsHandler::HandleRecordTime(const base::ListValue* args) {
84 std::string histogram_name;
85 double value;
86
87 if (!args->GetString(0, &histogram_name) ||
88 !args->GetDouble(1, &value) ||
89 value < 0) {
90 NOTREACHED();
91 return;
92 }
93
94 base::TimeDelta time_value = base::TimeDelta::FromMilliseconds(value);
95
96 base::HistogramBase* counter = base::Histogram::FactoryTimeGet(
97 histogram_name, base::TimeDelta::FromMilliseconds(1),
98 base::TimeDelta::FromSeconds(10), 50,
99 base::HistogramBase::kUmaTargetedHistogramFlag);
100 counter->AddTime(time_value);
101 }
102
80 void MetricsHandler::HandleLogEventTime(const base::ListValue* args) { 103 void MetricsHandler::HandleLogEventTime(const base::ListValue* args) {
81 std::string event_name = base::UTF16ToUTF8(ExtractStringValue(args)); 104 std::string event_name = base::UTF16ToUTF8(ExtractStringValue(args));
82 WebContents* tab = web_ui()->GetWebContents(); 105 WebContents* tab = web_ui()->GetWebContents();
83 106
84 // Not all new tab pages get timed. In those cases, we don't have a 107 // Not all new tab pages get timed. In those cases, we don't have a
85 // new_tab_start_time_. 108 // new_tab_start_time_.
86 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(tab); 109 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(tab);
87 if (core_tab_helper->new_tab_start_time().is_null()) 110 if (core_tab_helper->new_tab_start_time().is_null())
88 return; 111 return;
89 112
90 base::TimeDelta duration = 113 base::TimeDelta duration =
91 base::TimeTicks::Now() - core_tab_helper->new_tab_start_time(); 114 base::TimeTicks::Now() - core_tab_helper->new_tab_start_time();
92 115
93 if (event_name == "Tab.NewTabScriptStart") { 116 if (event_name == "Tab.NewTabScriptStart") {
94 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration); 117 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
95 } else if (event_name == "Tab.NewTabDOMContentLoaded") { 118 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
96 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration); 119 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
97 } else if (event_name == "Tab.NewTabOnload") { 120 } else if (event_name == "Tab.NewTabOnload") {
98 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); 121 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
99 // The new tab page has finished loading; reset it. 122 // The new tab page has finished loading; reset it.
100 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(tab); 123 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(tab);
101 core_tab_helper->set_new_tab_start_time(base::TimeTicks()); 124 core_tab_helper->set_new_tab_start_time(base::TimeTicks());
102 } else { 125 } else {
103 NOTREACHED(); 126 NOTREACHED();
104 } 127 }
105 } 128 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/metrics_handler.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698