OLD | NEW |
---|---|
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" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/chrome_notification_types.h" | |
14 #include "chrome/browser/metrics/metric_event_duration_details.h" | 13 #include "chrome/browser/metrics/metric_event_duration_details.h" |
15 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 14 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
16 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" | 15 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" |
17 #include "chrome/common/ntp_logging_events.h" | 16 #include "chrome/common/ntp_logging_events.h" |
18 #include "content/public/browser/notification_service.h" | |
19 #include "content/public/browser/user_metrics.h" | 17 #include "content/public/browser/user_metrics.h" |
20 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
21 #include "content/public/browser/web_ui.h" | 19 #include "content/public/browser/web_ui.h" |
22 | 20 |
23 using base::ListValue; | 21 using base::ListValue; |
24 using base::UserMetricsAction; | 22 using base::UserMetricsAction; |
25 using content::WebContents; | 23 using content::WebContents; |
26 | 24 |
27 MetricsHandler::MetricsHandler() {} | 25 MetricsHandler::MetricsHandler() {} |
28 MetricsHandler::~MetricsHandler() {} | 26 MetricsHandler::~MetricsHandler() {} |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 WebContents* tab = web_ui()->GetWebContents(); | 85 WebContents* tab = web_ui()->GetWebContents(); |
88 | 86 |
89 // Not all new tab pages get timed. In those cases, we don't have a | 87 // Not all new tab pages get timed. In those cases, we don't have a |
90 // new_tab_start_time_. | 88 // new_tab_start_time_. |
91 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(tab); | 89 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(tab); |
92 if (core_tab_helper->new_tab_start_time().is_null()) | 90 if (core_tab_helper->new_tab_start_time().is_null()) |
93 return; | 91 return; |
94 | 92 |
95 base::TimeDelta duration = | 93 base::TimeDelta duration = |
96 base::TimeTicks::Now() - core_tab_helper->new_tab_start_time(); | 94 base::TimeTicks::Now() - core_tab_helper->new_tab_start_time(); |
97 MetricEventDurationDetails details(event_name, | 95 MetricEventDurationDetails details(event_name, |
msw
2014/10/23 21:26:42
This is now unused and can be removed; the type is
oshima
2014/10/23 21:42:39
Ah, makes sense. Done.
| |
98 static_cast<int>(duration.InMilliseconds())); | 96 static_cast<int>(duration.InMilliseconds())); |
99 | 97 |
100 if (event_name == "Tab.NewTabScriptStart") { | 98 if (event_name == "Tab.NewTabScriptStart") { |
101 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration); | 99 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration); |
102 } else if (event_name == "Tab.NewTabDOMContentLoaded") { | 100 } else if (event_name == "Tab.NewTabDOMContentLoaded") { |
103 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration); | 101 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration); |
104 } else if (event_name == "Tab.NewTabOnload") { | 102 } else if (event_name == "Tab.NewTabOnload") { |
105 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); | 103 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); |
106 // The new tab page has finished loading; reset it. | 104 // The new tab page has finished loading; reset it. |
107 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(tab); | 105 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(tab); |
108 core_tab_helper->set_new_tab_start_time(base::TimeTicks()); | 106 core_tab_helper->set_new_tab_start_time(base::TimeTicks()); |
109 } else { | 107 } else { |
110 NOTREACHED(); | 108 NOTREACHED(); |
111 } | 109 } |
112 content::NotificationService::current()->Notify( | |
113 chrome::NOTIFICATION_METRIC_EVENT_DURATION, | |
114 content::Source<WebContents>(tab), | |
115 content::Details<MetricEventDurationDetails>(&details)); | |
116 } | 110 } |
117 | 111 |
118 void MetricsHandler::HandleLogMouseover(const base::ListValue* args) { | 112 void MetricsHandler::HandleLogMouseover(const base::ListValue* args) { |
119 #if !defined(OS_ANDROID) | 113 #if !defined(OS_ANDROID) |
120 // Android uses native UI for NTP. | 114 // Android uses native UI for NTP. |
121 NTPUserDataLogger::GetOrCreateFromWebContents( | 115 NTPUserDataLogger::GetOrCreateFromWebContents( |
122 web_ui()->GetWebContents())->LogEvent(NTP_MOUSEOVER); | 116 web_ui()->GetWebContents())->LogEvent(NTP_MOUSEOVER); |
123 #endif // !defined(OS_ANDROID) | 117 #endif // !defined(OS_ANDROID) |
124 } | 118 } |
OLD | NEW |