OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/metrics/metric_event_duration_details.h" | 13 #include "chrome/browser/metrics/metric_event_duration_details.h" |
14 #include "chrome/browser/ui/webui/chrome_web_ui.h" | 14 #include "chrome/browser/ui/webui/chrome_web_ui.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "content/browser/tab_contents/tab_contents.h" | |
17 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/user_metrics.h" | 17 #include "content/public/browser/user_metrics.h" |
| 18 #include "content/public/browser/web_contents.h" |
19 | 19 |
20 using base::ListValue; | 20 using base::ListValue; |
21 using content::UserMetricsAction; | 21 using content::UserMetricsAction; |
| 22 using content::WebContents; |
22 | 23 |
23 MetricsHandler::MetricsHandler() {} | 24 MetricsHandler::MetricsHandler() {} |
24 MetricsHandler::~MetricsHandler() {} | 25 MetricsHandler::~MetricsHandler() {} |
25 | 26 |
26 void MetricsHandler::RegisterMessages() { | 27 void MetricsHandler::RegisterMessages() { |
27 web_ui()->RegisterMessageCallback( | 28 web_ui()->RegisterMessageCallback( |
28 "metricsHandler:recordAction", | 29 "metricsHandler:recordAction", |
29 base::Bind(&MetricsHandler::HandleRecordAction, base::Unretained(this))); | 30 base::Bind(&MetricsHandler::HandleRecordAction, base::Unretained(this))); |
30 web_ui()->RegisterMessageCallback( | 31 web_ui()->RegisterMessageCallback( |
31 "metricsHandler:recordInHistogram", | 32 "metricsHandler:recordInHistogram", |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // macro cannot be used here. | 71 // macro cannot be used here. |
71 base::Histogram* counter = | 72 base::Histogram* counter = |
72 base::LinearHistogram::FactoryGet( | 73 base::LinearHistogram::FactoryGet( |
73 histogram_name, 1, int_boundary_value, bucket_count + 1, | 74 histogram_name, 1, int_boundary_value, bucket_count + 1, |
74 base::Histogram::kUmaTargetedHistogramFlag); | 75 base::Histogram::kUmaTargetedHistogramFlag); |
75 counter->Add(int_value); | 76 counter->Add(int_value); |
76 } | 77 } |
77 | 78 |
78 void MetricsHandler::HandleLogEventTime(const ListValue* args) { | 79 void MetricsHandler::HandleLogEventTime(const ListValue* args) { |
79 std::string event_name = UTF16ToUTF8(ExtractStringValue(args)); | 80 std::string event_name = UTF16ToUTF8(ExtractStringValue(args)); |
80 TabContents* tab = web_ui()->tab_contents(); | 81 WebContents* tab = web_ui()->web_contents(); |
81 | 82 |
82 // Not all new tab pages get timed. In those cases, we don't have a | 83 // Not all new tab pages get timed. In those cases, we don't have a |
83 // new_tab_start_time_. | 84 // new_tab_start_time_. |
84 if (tab->GetNewTabStartTime().is_null()) | 85 if (tab->GetNewTabStartTime().is_null()) |
85 return; | 86 return; |
86 | 87 |
87 base::TimeDelta duration = base::TimeTicks::Now() - tab->GetNewTabStartTime(); | 88 base::TimeDelta duration = base::TimeTicks::Now() - tab->GetNewTabStartTime(); |
88 MetricEventDurationDetails details(event_name, | 89 MetricEventDurationDetails details(event_name, |
89 static_cast<int>(duration.InMilliseconds())); | 90 static_cast<int>(duration.InMilliseconds())); |
90 | 91 |
91 if (event_name == "Tab.NewTabScriptStart") { | 92 if (event_name == "Tab.NewTabScriptStart") { |
92 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration); | 93 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration); |
93 } else if (event_name == "Tab.NewTabDOMContentLoaded") { | 94 } else if (event_name == "Tab.NewTabDOMContentLoaded") { |
94 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration); | 95 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration); |
95 } else if (event_name == "Tab.NewTabOnload") { | 96 } else if (event_name == "Tab.NewTabOnload") { |
96 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); | 97 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); |
97 // The new tab page has finished loading; reset it. | 98 // The new tab page has finished loading; reset it. |
98 tab->SetNewTabStartTime(base::TimeTicks()); | 99 tab->SetNewTabStartTime(base::TimeTicks()); |
99 } else { | 100 } else { |
100 NOTREACHED(); | 101 NOTREACHED(); |
101 } | 102 } |
102 content::NotificationService::current()->Notify( | 103 content::NotificationService::current()->Notify( |
103 chrome::NOTIFICATION_METRIC_EVENT_DURATION, | 104 chrome::NOTIFICATION_METRIC_EVENT_DURATION, |
104 content::Source<TabContents>(tab), | 105 content::Source<WebContents>(tab), |
105 content::Details<MetricEventDurationDetails>(&details)); | 106 content::Details<MetricEventDurationDetails>(&details)); |
106 } | 107 } |
OLD | NEW |