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

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

Issue 2141933002: Split NTP_TILE_LOADED event. (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 #include <string> 8 #include <string>
9 9
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 content->GetController().GetVisibleEntry(); 93 content->GetController().GetVisibleEntry();
94 if (entry) 94 if (entry)
95 logger->ntp_url_ = entry->GetURL(); 95 logger->ntp_url_ = entry->GetURL();
96 96
97 return logger; 97 return logger;
98 } 98 }
99 99
100 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event, 100 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event,
101 base::TimeDelta time) { 101 base::TimeDelta time) {
102 switch (event) { 102 switch (event) {
103 // It is possible that our page gets update with a different set of
104 // suggestions if the NTP is left open enough time.
105 // In either case, we want to flush our stats before recounting again.
106 case NTP_SERVER_SIDE_SUGGESTION: 103 case NTP_SERVER_SIDE_SUGGESTION:
107 if (has_client_side_suggestions_)
108 EmitNtpStatistics(EmitReason::INTERNAL_FLUSH);
109 has_server_side_suggestions_ = true; 104 has_server_side_suggestions_ = true;
110 break; 105 break;
111 case NTP_CLIENT_SIDE_SUGGESTION: 106 case NTP_CLIENT_SIDE_SUGGESTION:
112 if (has_server_side_suggestions_)
113 EmitNtpStatistics(EmitReason::INTERNAL_FLUSH);
114 has_client_side_suggestions_ = true; 107 has_client_side_suggestions_ = true;
115 break; 108 break;
116 case NTP_TILE: 109 case NTP_TILE:
110 // TODO(sfiera): remove NTP_TILE and use NTP_*_SIDE_SUGGESTION.
117 number_of_tiles_++; 111 number_of_tiles_++;
118 break; 112 break;
119 case NTP_TILE_LOADED: 113 case NTP_TILE_LOADED:
120 // The time at which the last tile has loaded (title, thumbnail or single) 114 // We no longer emit statistics for the multi-iframe NTP.
121 // is a good proxy for the total load time of the NTP, therefore we keep 115 break;
122 // the max as the load time. 116 case NTP_ALL_TILES_LOADED:
123 load_time_ = std::max(load_time_, time); 117 EmitNtpStatistics(time);
124 break; 118 break;
125 default: 119 default:
126 NOTREACHED(); 120 NOTREACHED();
127 } 121 }
128 } 122 }
129 123
130 void NTPUserDataLogger::LogMostVisitedImpression( 124 void NTPUserDataLogger::LogMostVisitedImpression(
131 int position, NTPLoggingTileSource tile_source) { 125 int position, NTPLoggingTileSource tile_source) {
132 UMA_HISTOGRAM_ENUMERATION(kMostVisitedImpressionHistogramName, position, 126 UMA_HISTOGRAM_ENUMERATION(kMostVisitedImpressionHistogramName, position,
133 kNumMostVisited); 127 kNumMostVisited);
(...skipping 24 matching lines...) Expand all
158 kNumMostVisited, 152 kNumMostVisited,
159 kNumMostVisited + 1, 153 kNumMostVisited + 1,
160 base::Histogram::kUmaTargetedHistogramFlag); 154 base::Histogram::kUmaTargetedHistogramFlag);
161 counter->Add(position); 155 counter->Add(position);
162 156
163 // Records the action. This will be available as a time-stamped stream 157 // Records the action. This will be available as a time-stamped stream
164 // server-side and can be used to compute time-to-long-dwell. 158 // server-side and can be used to compute time-to-long-dwell.
165 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); 159 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked"));
166 } 160 }
167 161
168 void NTPUserDataLogger::TabDeactivated() {
169 EmitNtpStatistics(EmitReason::CLOSED);
170 }
171
172 void NTPUserDataLogger::MostVisitedItemsChanged() {
173 EmitNtpStatistics(EmitReason::MV_CHANGED);
174 }
175
176 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) 162 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents)
177 : content::WebContentsObserver(contents), 163 : has_server_side_suggestions_(false),
178 has_server_side_suggestions_(false),
179 has_client_side_suggestions_(false), 164 has_client_side_suggestions_(false),
180 number_of_tiles_(0), 165 number_of_tiles_(0),
181 has_emitted_(false), 166 has_emitted_(false),
182 during_startup_(false) { 167 during_startup_(false) {
183 during_startup_ = !AfterStartupTaskUtils::IsBrowserStartupComplete(); 168 during_startup_ = !AfterStartupTaskUtils::IsBrowserStartupComplete();
184 169
185 // We record metrics about session data here because when this class typically 170 // We record metrics about session data here because when this class typically
186 // emits metrics it is too late. This session data would theoretically have 171 // emits metrics it is too late. This session data would theoretically have
187 // been used to populate the page, and we want to learn about its state when 172 // been used to populate the page, and we want to learn about its state when
188 // the NTP is being generated. 173 // the NTP is being generated.
189 if (contents) { 174 if (contents) {
190 ProfileSyncService* sync = ProfileSyncServiceFactory::GetForProfile( 175 ProfileSyncService* sync = ProfileSyncServiceFactory::GetForProfile(
191 Profile::FromBrowserContext(contents->GetBrowserContext())); 176 Profile::FromBrowserContext(contents->GetBrowserContext()));
192 if (sync) { 177 if (sync) {
193 browser_sync::SessionsSyncManager* sessions = 178 browser_sync::SessionsSyncManager* sessions =
194 static_cast<browser_sync::SessionsSyncManager*>( 179 static_cast<browser_sync::SessionsSyncManager*>(
195 sync->GetSessionsSyncableService()); 180 sync->GetSessionsSyncableService());
196 if (sessions) { 181 if (sessions) {
197 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( 182 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP(
198 sessions); 183 sessions);
199 } 184 }
200 } 185 }
201 } 186 }
202 } 187 }
203 188
204 // content::WebContentsObserver override 189 void NTPUserDataLogger::EmitNtpStatistics(base::TimeDelta load_time) {
205 void NTPUserDataLogger::NavigationEntryCommitted( 190 // We only send statistics once per page.
206 const content::LoadCommittedDetails& load_details) { 191 if (has_emitted_)
207 if (!load_details.previous_url.is_valid())
208 return; 192 return;
209 193
210 if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) 194 logLoadTimeHistogram("NewTabPage.LoadTime", load_time);
211 EmitNtpStatistics(EmitReason::NAVIGATED_AWAY);
212 }
213 195
214 void NTPUserDataLogger::EmitNtpStatistics(EmitReason reason) { 196 // Split between ML and MV.
215 // We only send statistics once per page. 197 std::string type = has_server_side_suggestions_ ?
216 // And we don't send if there are no tiles recorded. 198 "MostLikely" : "MostVisited";
217 if (has_emitted_ || !number_of_tiles_) 199 logLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time);
218 return; 200 // Split between Web and Local.
201 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP";
202 logLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time);
219 203
220 // LoadTime only gets update once per page, so we don't have it on reloads. 204 // Split between Startup and non-startup.
221 if (load_time_ > base::TimeDelta::FromMilliseconds(0)) { 205 std::string status = during_startup_ ? "Startup" : "NewTab";
222 logLoadTimeHistogram("NewTabPage.LoadTime", load_time_); 206 logLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time);
223 207
224 // Split between ML and MV.
225 std::string type = has_server_side_suggestions_ ?
226 "MostLikely" : "MostVisited";
227 logLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time_);
228 // Split between Web and Local.
229 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP";
230 logLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time_);
231
232 // Split between Startup and non-startup.
233 std::string status = during_startup_ ? "Startup" : "NewTab";
234 logLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time_);
235
236 load_time_ = base::TimeDelta::FromMilliseconds(0);
237 }
238 has_server_side_suggestions_ = false; 208 has_server_side_suggestions_ = false;
239 has_client_side_suggestions_ = false; 209 has_client_side_suggestions_ = false;
240 UMA_HISTOGRAM_CUSTOM_COUNTS( 210 UMA_HISTOGRAM_CUSTOM_COUNTS(
241 "NewTabPage.NumberOfTiles", number_of_tiles_, 0, kNumMostVisited, 211 "NewTabPage.NumberOfTiles", number_of_tiles_, 0, kNumMostVisited,
242 kNumMostVisited + 1); 212 kNumMostVisited + 1);
243 number_of_tiles_ = 0; 213 number_of_tiles_ = 0;
244 has_emitted_ = true; 214 has_emitted_ = true;
245 during_startup_ = false; 215 during_startup_ = false;
246 } 216 }
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