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

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

Issue 2127783002: Make EmitNtpStatistics() private. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ntp/ntp_user_data_logger.h" 5 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // originate from it. We use the NavigationController's URL since it might 102 // originate from it. We use the NavigationController's URL since it might
103 // differ from the WebContents URL which is usually chrome://newtab/. 103 // differ from the WebContents URL which is usually chrome://newtab/.
104 const content::NavigationEntry* entry = 104 const content::NavigationEntry* entry =
105 content->GetController().GetVisibleEntry(); 105 content->GetController().GetVisibleEntry();
106 if (entry) 106 if (entry)
107 logger->ntp_url_ = entry->GetURL(); 107 logger->ntp_url_ = entry->GetURL();
108 108
109 return logger; 109 return logger;
110 } 110 }
111 111
112 void NTPUserDataLogger::EmitNtpStatistics() {
113 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", number_of_mouseovers_);
114 number_of_mouseovers_ = 0;
115
116 // We only send statistics once per page.
117 // And we don't send if there are no tiles recorded.
118 if (has_emitted_ || !number_of_tiles_)
119 return;
120
121 // LoadTime only gets update once per page, so we don't have it on reloads.
122 if (load_time_ > base::TimeDelta::FromMilliseconds(0)) {
123 logLoadTimeHistogram("NewTabPage.LoadTime", load_time_);
124
125 // Split between ML and MV.
126 std::string type = has_server_side_suggestions_ ?
127 "MostLikely" : "MostVisited";
128 logLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time_);
129 // Split between Web and Local.
130 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP";
131 logLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time_);
132
133 // Split between Startup and non-startup.
134 std::string status = during_startup_ ? "Startup" : "NewTab";
135 logLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time_);
136
137 load_time_ = base::TimeDelta::FromMilliseconds(0);
138 }
139 UMA_HISTOGRAM_ENUMERATION(
140 "NewTabPage.SuggestionsType",
141 has_server_side_suggestions_ ? SERVER_SIDE : CLIENT_SIDE,
142 SUGGESTIONS_TYPE_COUNT);
143 has_server_side_suggestions_ = false;
144 has_client_side_suggestions_ = false;
145 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfTiles", number_of_tiles_);
146 number_of_tiles_ = 0;
147 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfThumbnailTiles",
148 number_of_thumbnail_tiles_);
149 number_of_thumbnail_tiles_ = 0;
150 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfGrayTiles",
151 number_of_gray_tiles_);
152 number_of_gray_tiles_ = 0;
153 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfExternalTiles",
154 number_of_external_tiles_);
155 number_of_external_tiles_ = 0;
156 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfThumbnailErrors",
157 number_of_thumbnail_errors_);
158 number_of_thumbnail_errors_ = 0;
159 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfGrayTileFallbacks",
160 number_of_gray_tile_fallbacks_);
161 number_of_gray_tile_fallbacks_ = 0;
162 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfExternalTileFallbacks",
163 number_of_external_tile_fallbacks_);
164 number_of_external_tile_fallbacks_ = 0;
165 has_emitted_ = true;
166 during_startup_ = false;
167 }
168
169 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event, 112 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event,
170 base::TimeDelta time) { 113 base::TimeDelta time) {
171 switch (event) { 114 switch (event) {
172 // It is possible that our page gets update with a different set of 115 // It is possible that our page gets update with a different set of
173 // suggestions if the NTP is left open enough time. 116 // suggestions if the NTP is left open enough time.
174 // In either case, we want to flush our stats before recounting again. 117 // In either case, we want to flush our stats before recounting again.
175 case NTP_SERVER_SIDE_SUGGESTION: 118 case NTP_SERVER_SIDE_SUGGESTION:
176 if (has_client_side_suggestions_) 119 if (has_client_side_suggestions_)
177 EmitNtpStatistics(); 120 EmitNtpStatistics(EmitReason::INTERNAL_FLUSH);
178 has_server_side_suggestions_ = true; 121 has_server_side_suggestions_ = true;
179 break; 122 break;
180 case NTP_CLIENT_SIDE_SUGGESTION: 123 case NTP_CLIENT_SIDE_SUGGESTION:
181 if (has_server_side_suggestions_) 124 if (has_server_side_suggestions_)
182 EmitNtpStatistics(); 125 EmitNtpStatistics(EmitReason::INTERNAL_FLUSH);
183 has_client_side_suggestions_ = true; 126 has_client_side_suggestions_ = true;
184 break; 127 break;
185 case NTP_TILE: 128 case NTP_TILE:
186 number_of_tiles_++; 129 number_of_tiles_++;
187 break; 130 break;
188 case NTP_THUMBNAIL_TILE: 131 case NTP_THUMBNAIL_TILE:
189 number_of_thumbnail_tiles_++; 132 number_of_thumbnail_tiles_++;
190 break; 133 break;
191 case NTP_GRAY_TILE: 134 case NTP_GRAY_TILE:
192 number_of_gray_tiles_++; 135 number_of_gray_tiles_++;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); 198 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked"));
256 } 199 }
257 200
258 // content::WebContentsObserver override 201 // content::WebContentsObserver override
259 void NTPUserDataLogger::NavigationEntryCommitted( 202 void NTPUserDataLogger::NavigationEntryCommitted(
260 const content::LoadCommittedDetails& load_details) { 203 const content::LoadCommittedDetails& load_details) {
261 if (!load_details.previous_url.is_valid()) 204 if (!load_details.previous_url.is_valid())
262 return; 205 return;
263 206
264 if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) { 207 if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) {
265 EmitNtpStatistics(); 208 EmitNtpStatistics(EmitReason::NAVIGATED_AWAY);
266 } 209 }
267 } 210 }
268 211
212 void NTPUserDataLogger::TabDeactivated() {
213 EmitNtpStatistics(EmitReason::CLOSED);
214 }
215
216 void NTPUserDataLogger::MostVisitedItemsChanged() {
217 EmitNtpStatistics(EmitReason::MV_CHANGED);
218 }
219
269 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) 220 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents)
270 : content::WebContentsObserver(contents), 221 : content::WebContentsObserver(contents),
271 has_server_side_suggestions_(false), 222 has_server_side_suggestions_(false),
272 has_client_side_suggestions_(false), 223 has_client_side_suggestions_(false),
273 number_of_tiles_(0), 224 number_of_tiles_(0),
274 number_of_thumbnail_tiles_(0), 225 number_of_thumbnail_tiles_(0),
275 number_of_gray_tiles_(0), 226 number_of_gray_tiles_(0),
276 number_of_external_tiles_(0), 227 number_of_external_tiles_(0),
277 number_of_thumbnail_errors_(0), 228 number_of_thumbnail_errors_(0),
278 number_of_gray_tile_fallbacks_(0), 229 number_of_gray_tile_fallbacks_(0),
(...skipping 14 matching lines...) Expand all
293 browser_sync::SessionsSyncManager* sessions = 244 browser_sync::SessionsSyncManager* sessions =
294 static_cast<browser_sync::SessionsSyncManager*>( 245 static_cast<browser_sync::SessionsSyncManager*>(
295 sync->GetSessionsSyncableService()); 246 sync->GetSessionsSyncableService());
296 if (sessions) { 247 if (sessions) {
297 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( 248 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP(
298 sessions); 249 sessions);
299 } 250 }
300 } 251 }
301 } 252 }
302 } 253 }
254
255 void NTPUserDataLogger::EmitNtpStatistics(EmitReason reason) {
Marc Treib 2016/07/06 12:04:27 We don't do anything with the reason yet - do you
sfiera 2016/07/06 12:08:41 Not at the moment. It would be nice to have a stat
256 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", number_of_mouseovers_);
257 number_of_mouseovers_ = 0;
258
259 // We only send statistics once per page.
260 // And we don't send if there are no tiles recorded.
261 if (has_emitted_ || !number_of_tiles_)
262 return;
263
264 // LoadTime only gets update once per page, so we don't have it on reloads.
265 if (load_time_ > base::TimeDelta::FromMilliseconds(0)) {
266 logLoadTimeHistogram("NewTabPage.LoadTime", load_time_);
267
268 // Split between ML and MV.
269 std::string type = has_server_side_suggestions_ ?
270 "MostLikely" : "MostVisited";
271 logLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time_);
272 // Split between Web and Local.
273 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP";
274 logLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time_);
275
276 // Split between Startup and non-startup.
277 std::string status = during_startup_ ? "Startup" : "NewTab";
278 logLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time_);
279
280 load_time_ = base::TimeDelta::FromMilliseconds(0);
281 }
282 UMA_HISTOGRAM_ENUMERATION(
283 "NewTabPage.SuggestionsType",
284 has_server_side_suggestions_ ? SERVER_SIDE : CLIENT_SIDE,
285 SUGGESTIONS_TYPE_COUNT);
286 has_server_side_suggestions_ = false;
287 has_client_side_suggestions_ = false;
288 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfTiles", number_of_tiles_);
289 number_of_tiles_ = 0;
290 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfThumbnailTiles",
291 number_of_thumbnail_tiles_);
292 number_of_thumbnail_tiles_ = 0;
293 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfGrayTiles",
294 number_of_gray_tiles_);
295 number_of_gray_tiles_ = 0;
296 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfExternalTiles",
297 number_of_external_tiles_);
298 number_of_external_tiles_ = 0;
299 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfThumbnailErrors",
300 number_of_thumbnail_errors_);
301 number_of_thumbnail_errors_ = 0;
302 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfGrayTileFallbacks",
303 number_of_gray_tile_fallbacks_);
304 number_of_gray_tile_fallbacks_ = 0;
305 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfExternalTileFallbacks",
306 number_of_external_tile_fallbacks_);
307 number_of_external_tile_fallbacks_ = 0;
308 has_emitted_ = true;
309 during_startup_ = false;
310 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698