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

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 // We only send statistics once per page.
114 // And we don't send if there are no tiles recorded.
115 if (has_emitted_ || !number_of_tiles_)
116 return;
117
118 // LoadTime only gets update once per page, so we don't have it on reloads.
119 if (load_time_ > base::TimeDelta::FromMilliseconds(0)) {
120 logLoadTimeHistogram("NewTabPage.LoadTime", load_time_);
121
122 // Split between ML and MV.
123 std::string type = has_server_side_suggestions_ ?
124 "MostLikely" : "MostVisited";
125 logLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time_);
126 // Split between Web and Local.
127 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP";
128 logLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time_);
129
130 // Split between Startup and non-startup.
131 std::string status = during_startup_ ? "Startup" : "NewTab";
132 logLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time_);
133
134 load_time_ = base::TimeDelta::FromMilliseconds(0);
135 }
136 UMA_HISTOGRAM_ENUMERATION(
137 "NewTabPage.SuggestionsType",
138 has_server_side_suggestions_ ? SERVER_SIDE : CLIENT_SIDE,
139 SUGGESTIONS_TYPE_COUNT);
140 has_server_side_suggestions_ = false;
141 has_client_side_suggestions_ = false;
142 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfTiles", number_of_tiles_);
143 number_of_tiles_ = 0;
144 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfThumbnailTiles",
145 number_of_thumbnail_tiles_);
146 number_of_thumbnail_tiles_ = 0;
147 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfGrayTiles",
148 number_of_gray_tiles_);
149 number_of_gray_tiles_ = 0;
150 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfExternalTiles",
151 number_of_external_tiles_);
152 number_of_external_tiles_ = 0;
153 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfThumbnailErrors",
154 number_of_thumbnail_errors_);
155 number_of_thumbnail_errors_ = 0;
156 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfGrayTileFallbacks",
157 number_of_gray_tile_fallbacks_);
158 number_of_gray_tile_fallbacks_ = 0;
159 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfExternalTileFallbacks",
160 number_of_external_tile_fallbacks_);
161 number_of_external_tile_fallbacks_ = 0;
162 has_emitted_ = true;
163 during_startup_ = false;
164 }
165
166 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event, 112 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event,
167 base::TimeDelta time) { 113 base::TimeDelta time) {
168 switch (event) { 114 switch (event) {
169 // 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
170 // suggestions if the NTP is left open enough time. 116 // suggestions if the NTP is left open enough time.
171 // 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.
172 case NTP_SERVER_SIDE_SUGGESTION: 118 case NTP_SERVER_SIDE_SUGGESTION:
173 if (has_client_side_suggestions_) 119 if (has_client_side_suggestions_)
174 EmitNtpStatistics(); 120 EmitNtpStatistics(EmitReason::INTERNAL_FLUSH);
175 has_server_side_suggestions_ = true; 121 has_server_side_suggestions_ = true;
176 break; 122 break;
177 case NTP_CLIENT_SIDE_SUGGESTION: 123 case NTP_CLIENT_SIDE_SUGGESTION:
178 if (has_server_side_suggestions_) 124 if (has_server_side_suggestions_)
179 EmitNtpStatistics(); 125 EmitNtpStatistics(EmitReason::INTERNAL_FLUSH);
180 has_client_side_suggestions_ = true; 126 has_client_side_suggestions_ = true;
181 break; 127 break;
182 case NTP_TILE: 128 case NTP_TILE:
183 number_of_tiles_++; 129 number_of_tiles_++;
184 break; 130 break;
185 case NTP_THUMBNAIL_TILE: 131 case NTP_THUMBNAIL_TILE:
186 number_of_thumbnail_tiles_++; 132 number_of_thumbnail_tiles_++;
187 break; 133 break;
188 case NTP_GRAY_TILE: 134 case NTP_GRAY_TILE:
189 number_of_gray_tiles_++; 135 number_of_gray_tiles_++;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); 195 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked"));
250 } 196 }
251 197
252 // content::WebContentsObserver override 198 // content::WebContentsObserver override
253 void NTPUserDataLogger::NavigationEntryCommitted( 199 void NTPUserDataLogger::NavigationEntryCommitted(
254 const content::LoadCommittedDetails& load_details) { 200 const content::LoadCommittedDetails& load_details) {
255 if (!load_details.previous_url.is_valid()) 201 if (!load_details.previous_url.is_valid())
256 return; 202 return;
257 203
258 if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) { 204 if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) {
259 EmitNtpStatistics(); 205 EmitNtpStatistics(EmitReason::NAVIGATED_AWAY);
260 } 206 }
261 } 207 }
262 208
209 void NTPUserDataLogger::TabDeactivated() {
210 EmitNtpStatistics(EmitReason::CLOSED);
211 }
212
213 void NTPUserDataLogger::MostVisitedItemsChanged() {
214 EmitNtpStatistics(EmitReason::MV_CHANGED);
215 }
216
263 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) 217 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents)
264 : content::WebContentsObserver(contents), 218 : content::WebContentsObserver(contents),
265 has_server_side_suggestions_(false), 219 has_server_side_suggestions_(false),
266 has_client_side_suggestions_(false), 220 has_client_side_suggestions_(false),
267 number_of_tiles_(0), 221 number_of_tiles_(0),
268 number_of_thumbnail_tiles_(0), 222 number_of_thumbnail_tiles_(0),
269 number_of_gray_tiles_(0), 223 number_of_gray_tiles_(0),
270 number_of_external_tiles_(0), 224 number_of_external_tiles_(0),
271 number_of_thumbnail_errors_(0), 225 number_of_thumbnail_errors_(0),
272 number_of_gray_tile_fallbacks_(0), 226 number_of_gray_tile_fallbacks_(0),
(...skipping 13 matching lines...) Expand all
286 browser_sync::SessionsSyncManager* sessions = 240 browser_sync::SessionsSyncManager* sessions =
287 static_cast<browser_sync::SessionsSyncManager*>( 241 static_cast<browser_sync::SessionsSyncManager*>(
288 sync->GetSessionsSyncableService()); 242 sync->GetSessionsSyncableService());
289 if (sessions) { 243 if (sessions) {
290 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( 244 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP(
291 sessions); 245 sessions);
292 } 246 }
293 } 247 }
294 } 248 }
295 } 249 }
250
251 void NTPUserDataLogger::EmitNtpStatistics(EmitReason reason) {
252 // We only send statistics once per page.
253 // And we don't send if there are no tiles recorded.
254 if (has_emitted_ || !number_of_tiles_)
255 return;
256
257 // LoadTime only gets update once per page, so we don't have it on reloads.
258 if (load_time_ > base::TimeDelta::FromMilliseconds(0)) {
259 logLoadTimeHistogram("NewTabPage.LoadTime", load_time_);
260
261 // Split between ML and MV.
262 std::string type = has_server_side_suggestions_ ?
263 "MostLikely" : "MostVisited";
264 logLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time_);
265 // Split between Web and Local.
266 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP";
267 logLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time_);
268
269 // Split between Startup and non-startup.
270 std::string status = during_startup_ ? "Startup" : "NewTab";
271 logLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time_);
272
273 load_time_ = base::TimeDelta::FromMilliseconds(0);
274 }
275 UMA_HISTOGRAM_ENUMERATION(
276 "NewTabPage.SuggestionsType",
277 has_server_side_suggestions_ ? SERVER_SIDE : CLIENT_SIDE,
278 SUGGESTIONS_TYPE_COUNT);
279 has_server_side_suggestions_ = false;
280 has_client_side_suggestions_ = false;
281 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfTiles", number_of_tiles_);
282 number_of_tiles_ = 0;
283 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfThumbnailTiles",
284 number_of_thumbnail_tiles_);
285 number_of_thumbnail_tiles_ = 0;
286 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfGrayTiles",
287 number_of_gray_tiles_);
288 number_of_gray_tiles_ = 0;
289 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfExternalTiles",
290 number_of_external_tiles_);
291 number_of_external_tiles_ = 0;
292 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfThumbnailErrors",
293 number_of_thumbnail_errors_);
294 number_of_thumbnail_errors_ = 0;
295 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfGrayTileFallbacks",
296 number_of_gray_tile_fallbacks_);
297 number_of_gray_tile_fallbacks_ = 0;
298 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfExternalTileFallbacks",
299 number_of_external_tile_fallbacks_);
300 number_of_external_tile_fallbacks_ = 0;
301 has_emitted_ = true;
302 during_startup_ = false;
303 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_user_data_logger.h ('k') | chrome/browser/ui/webui/ntp/ntp_user_data_logger_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698