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/metrics/metric_event_duration_details.h" | 13 #include "chrome/browser/metrics/metric_event_duration_details.h" |
| 14 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
14 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
15 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
16 #include "content/public/browser/user_metrics.h" | 17 #include "content/public/browser/user_metrics.h" |
17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_ui.h" | 19 #include "content/public/browser/web_ui.h" |
19 | 20 |
20 using base::ListValue; | 21 using base::ListValue; |
21 using content::UserMetricsAction; | 22 using content::UserMetricsAction; |
22 using content::WebContents; | 23 using content::WebContents; |
23 | 24 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 base::HistogramBase::kUmaTargetedHistogramFlag); | 76 base::HistogramBase::kUmaTargetedHistogramFlag); |
76 counter->Add(int_value); | 77 counter->Add(int_value); |
77 } | 78 } |
78 | 79 |
79 void MetricsHandler::HandleLogEventTime(const ListValue* args) { | 80 void MetricsHandler::HandleLogEventTime(const ListValue* args) { |
80 std::string event_name = UTF16ToUTF8(ExtractStringValue(args)); | 81 std::string event_name = UTF16ToUTF8(ExtractStringValue(args)); |
81 WebContents* tab = web_ui()->GetWebContents(); | 82 WebContents* tab = web_ui()->GetWebContents(); |
82 | 83 |
83 // Not all new tab pages get timed. In those cases, we don't have a | 84 // Not all new tab pages get timed. In those cases, we don't have a |
84 // new_tab_start_time_. | 85 // new_tab_start_time_. |
85 if (tab->GetNewTabStartTime().is_null()) | 86 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(tab); |
| 87 if (core_tab_helper->new_tab_start_time().is_null()) |
86 return; | 88 return; |
87 | 89 |
88 base::TimeDelta duration = base::TimeTicks::Now() - tab->GetNewTabStartTime(); | 90 base::TimeDelta duration = |
| 91 base::TimeTicks::Now() - core_tab_helper->new_tab_start_time(); |
89 MetricEventDurationDetails details(event_name, | 92 MetricEventDurationDetails details(event_name, |
90 static_cast<int>(duration.InMilliseconds())); | 93 static_cast<int>(duration.InMilliseconds())); |
91 | 94 |
92 if (event_name == "Tab.NewTabScriptStart") { | 95 if (event_name == "Tab.NewTabScriptStart") { |
93 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration); | 96 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration); |
94 } else if (event_name == "Tab.NewTabDOMContentLoaded") { | 97 } else if (event_name == "Tab.NewTabDOMContentLoaded") { |
95 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration); | 98 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration); |
96 } else if (event_name == "Tab.NewTabOnload") { | 99 } else if (event_name == "Tab.NewTabOnload") { |
97 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); | 100 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); |
98 // The new tab page has finished loading; reset it. | 101 // The new tab page has finished loading; reset it. |
99 tab->SetNewTabStartTime(base::TimeTicks()); | 102 CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(tab); |
| 103 core_tab_helper->set_new_tab_start_time(base::TimeTicks()); |
100 } else { | 104 } else { |
101 NOTREACHED(); | 105 NOTREACHED(); |
102 } | 106 } |
103 content::NotificationService::current()->Notify( | 107 content::NotificationService::current()->Notify( |
104 chrome::NOTIFICATION_METRIC_EVENT_DURATION, | 108 chrome::NOTIFICATION_METRIC_EVENT_DURATION, |
105 content::Source<WebContents>(tab), | 109 content::Source<WebContents>(tab), |
106 content::Details<MetricEventDurationDetails>(&details)); | 110 content::Details<MetricEventDurationDetails>(&details)); |
107 } | 111 } |
OLD | NEW |