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

Side by Side Diff: chrome/browser/ui/webui/ntp/new_tab_ui.cc

Issue 8052028: NTP: Clean up of MetricsHandler class and namespacing chrome.send messages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/ntp/metrics_handler.cc ('k') | chrome/chrome_browser.gypi » ('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) 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 7 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
8 8
9 #include <set> 9 #include <set>
10 10
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/sessions/session_types.h" 23 #include "chrome/browser/sessions/session_types.h"
24 #include "chrome/browser/sync/profile_sync_service.h" 24 #include "chrome/browser/sync/profile_sync_service.h"
25 #include "chrome/browser/themes/theme_service.h" 25 #include "chrome/browser/themes/theme_service.h"
26 #include "chrome/browser/themes/theme_service_factory.h" 26 #include "chrome/browser/themes/theme_service_factory.h"
27 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 28 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
29 #include "chrome/browser/ui/webui/ntp/bookmarks_handler.h" 29 #include "chrome/browser/ui/webui/ntp/bookmarks_handler.h"
30 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" 30 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h"
31 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" 31 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h"
32 #include "chrome/browser/ui/webui/ntp/metrics_handler.h"
32 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" 33 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h"
33 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" 34 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h"
34 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" 35 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h"
35 #include "chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.h" 36 #include "chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.h"
36 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" 37 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h"
37 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" 38 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
38 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" 39 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
39 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" 40 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h"
40 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" 41 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h"
41 #include "chrome/browser/ui/webui/theme_source.h" 42 #include "chrome/browser/ui/webui/theme_source.h"
42 #include "chrome/common/chrome_notification_types.h" 43 #include "chrome/common/chrome_notification_types.h"
43 #include "chrome/common/chrome_switches.h" 44 #include "chrome/common/chrome_switches.h"
44 #include "chrome/common/extensions/extension.h" 45 #include "chrome/common/extensions/extension.h"
45 #include "chrome/common/pref_names.h" 46 #include "chrome/common/pref_names.h"
46 #include "chrome/common/url_constants.h" 47 #include "chrome/common/url_constants.h"
47 #include "content/browser/browser_thread.h" 48 #include "content/browser/browser_thread.h"
48 #include "content/browser/renderer_host/render_view_host.h" 49 #include "content/browser/renderer_host/render_view_host.h"
49 #include "content/browser/tab_contents/tab_contents.h" 50 #include "content/browser/tab_contents/tab_contents.h"
50 #include "content/browser/user_metrics.h" 51 #include "content/browser/user_metrics.h"
51 #include "content/common/notification_service.h" 52 #include "content/common/notification_service.h"
52 #include "grit/generated_resources.h" 53 #include "grit/generated_resources.h"
53 #include "grit/theme_resources.h" 54 #include "grit/theme_resources.h"
54 #include "ui/base/l10n/l10n_util.h" 55 #include "ui/base/l10n/l10n_util.h"
55 56
56 namespace { 57 namespace {
57 58
58 // The number of recent bookmarks we show.
59 const int kRecentBookmarks = 9;
60
61 // The number of search URLs to show.
62 const int kSearchURLs = 3;
63
Dan Beam 2011/09/28 03:12:10 As far as I can tell these were never used anywher
64 // The amount of time there must be no painting for us to consider painting 59 // The amount of time there must be no painting for us to consider painting
65 // finished. Observed times are in the ~1200ms range on Windows. 60 // finished. Observed times are in the ~1200ms range on Windows.
66 const int kTimeoutMs = 2000; 61 const int kTimeoutMs = 2000;
67 62
68 // Strings sent to the page via jstemplates used to set the direction of the 63 // Strings sent to the page via jstemplates used to set the direction of the
69 // HTML document based on locale. 64 // HTML document based on locale.
70 const char kRTLHtmlTextDirection[] = "rtl"; 65 const char kRTLHtmlTextDirection[] = "rtl";
71 const char kDefaultHtmlTextDirection[] = "ltr"; 66 const char kDefaultHtmlTextDirection[] = "ltr";
72 67
73 ///////////////////////////////////////////////////////////////////////////////
74 // MetricsHandler
75
76 // Let the page contents record UMA actions. Only use when you can't do it from
77 // C++. For example, we currently use it to let the NTP log the postion of the
78 // Most Visited or Bookmark the user clicked on, as we don't get that
79 // information through RequestOpenURL. You will need to update the metrics
80 // dashboard with the action names you use, as our processor won't catch that
81 // information (treat it as RecordComputedMetrics)
82 class MetricsHandler : public WebUIMessageHandler {
83 public:
84 MetricsHandler() {}
85 virtual ~MetricsHandler() {}
86
87 // WebUIMessageHandler implementation.
88 virtual void RegisterMessages() OVERRIDE;
89
90 // Callback which records a user action.
91 void HandleRecordAction(const ListValue* args);
92
93 // Callback which records into a histogram. |args| contains the histogram
94 // name, the value to record, and the maximum allowed value, which can be at
95 // most 4000. The histogram will use at most 100 buckets, one for each 1,
96 // 10, or 100 different values, depending on the maximum value.
97 void HandleRecordInHistogram(const ListValue* args);
98
99 // Callback for the "logEventTime" message.
100 void HandleLogEventTime(const ListValue* args);
101
102 private:
103
104 DISALLOW_COPY_AND_ASSIGN(MetricsHandler);
105 };
106
107 void MetricsHandler::RegisterMessages() {
108 web_ui_->RegisterMessageCallback("recordAction",
109 NewCallback(this, &MetricsHandler::HandleRecordAction));
110 web_ui_->RegisterMessageCallback("recordInHistogram",
111 NewCallback(this, &MetricsHandler::HandleRecordInHistogram));
112
113 web_ui_->RegisterMessageCallback("logEventTime",
114 NewCallback(this, &MetricsHandler::HandleLogEventTime));
115 }
116
117 void MetricsHandler::HandleRecordAction(const ListValue* args) {
118 std::string string_action = UTF16ToUTF8(ExtractStringValue(args));
119 UserMetrics::RecordComputedAction(string_action);
120 }
121
122 void MetricsHandler::HandleRecordInHistogram(const ListValue* args) {
123 std::string histogram_name;
124 double value;
125 double boundary_value;
126 if (!args->GetString(0, &histogram_name) ||
127 !args->GetDouble(1, &value) ||
128 !args->GetDouble(2, &boundary_value)) {
129 NOTREACHED();
130 return;
131 }
132
133 int int_value = static_cast<int>(value);
134 int int_boundary_value = static_cast<int>(boundary_value);
135 if (int_boundary_value >= 4000 ||
136 int_value > int_boundary_value ||
137 int_value < 0) {
138 NOTREACHED();
139 return;
140 }
141
142 int bucket_count = int_boundary_value;
143 while (bucket_count >= 100) {
144 bucket_count /= 10;
145 }
146
147 // As |histogram_name| may change between calls, the UMA_HISTOGRAM_ENUMERATION
148 // macro cannot be used here.
149 base::Histogram* counter =
150 base::LinearHistogram::FactoryGet(
151 histogram_name, 1, int_boundary_value, bucket_count + 1,
152 base::Histogram::kUmaTargetedHistogramFlag);
153 counter->Add(int_value);
154 }
155
156 void MetricsHandler::HandleLogEventTime(const ListValue* args) {
157 std::string event_name = UTF16ToUTF8(ExtractStringValue(args));
158 TabContents* tab = web_ui_->tab_contents();
159
160 // Not all new tab pages get timed. In those cases, we don't have a
161 // new_tab_start_time_.
162 if (tab->new_tab_start_time().is_null())
163 return;
164
165 base::TimeDelta duration = base::TimeTicks::Now() - tab->new_tab_start_time();
166 MetricEventDurationDetails details(event_name,
167 static_cast<int>(duration.InMilliseconds()));
168
169 if (event_name == "Tab.NewTabScriptStart") {
170 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
171 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
172 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
173 } else if (event_name == "Tab.NewTabOnload") {
174 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
175 // The new tab page has finished loading; reset it.
176 tab->set_new_tab_start_time(base::TimeTicks());
177 } else {
178 NOTREACHED();
179 }
180 NotificationService::current()->Notify(
181 chrome::NOTIFICATION_METRIC_EVENT_DURATION,
182 Source<TabContents>(tab),
183 Details<MetricEventDurationDetails>(&details));
184 }
185
186 } // namespace 68 } // namespace
187 69
188 /////////////////////////////////////////////////////////////////////////////// 70 ///////////////////////////////////////////////////////////////////////////////
189 // NewTabUI 71 // NewTabUI
190 72
191 NewTabUI::NewTabUI(TabContents* contents) 73 NewTabUI::NewTabUI(TabContents* contents)
192 : ChromeWebUI(contents) { 74 : ChromeWebUI(contents) {
193 // Override some options on the Web UI. 75 // Override some options on the Web UI.
194 hide_favicon_ = true; 76 hide_favicon_ = true;
195 77
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 SendResponse(request_id, html_bytes); 346 SendResponse(request_id, html_bytes);
465 } 347 }
466 348
467 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { 349 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const {
468 return "text/html"; 350 return "text/html";
469 } 351 }
470 352
471 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { 353 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const {
472 return false; 354 return false;
473 } 355 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/metrics_handler.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698