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