Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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: |
|
Marc Treib
2016/07/12 12:40:09
Unrelated to this CL, but: Can we get rid of NTP_T
sfiera
2016/07/12 13:21:21
I think so.
Marc Treib
2016/07/12 13:39:01
Maybe add a TODO for this?
sfiera
2016/07/12 14:10:25
Done.
| |
| 117 number_of_tiles_++; | 110 number_of_tiles_++; |
| 118 break; | 111 break; |
| 119 case NTP_TILE_LOADED: | 112 case NTP_TILE_LOADED: |
| 120 // The time at which the last tile has loaded (title, thumbnail or single) | 113 // 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 | 114 break; |
| 122 // the max as the load time. | 115 case NTP_ALL_TILES_LOADED: |
| 123 load_time_ = std::max(load_time_, time); | 116 load_time_ = time; |
|
Marc Treib
2016/07/12 12:40:09
Might as well get rid of the load_time_ member now
sfiera
2016/07/12 13:21:21
Done.
| |
| 117 EmitNtpStatistics(); | |
| 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 Loading... | |
| 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() { |
| 205 void NTPUserDataLogger::NavigationEntryCommitted( | |
| 206 const content::LoadCommittedDetails& load_details) { | |
| 207 if (!load_details.previous_url.is_valid()) | |
| 208 return; | |
| 209 | |
| 210 if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) | |
| 211 EmitNtpStatistics(EmitReason::NAVIGATED_AWAY); | |
| 212 } | |
| 213 | |
| 214 void NTPUserDataLogger::EmitNtpStatistics(EmitReason reason) { | |
| 215 // We only send statistics once per page. | 190 // We only send statistics once per page. |
| 216 // And we don't send if there are no tiles recorded. | 191 // And we don't send if there are no tiles recorded. |
| 217 if (has_emitted_ || !number_of_tiles_) | 192 if (has_emitted_ || !number_of_tiles_) |
|
Marc Treib
2016/07/12 12:40:09
Can we get rid of the !number_of_tiles_ check now?
sfiera
2016/07/12 13:21:21
I think it was a hack and is now unneeded. Removed
Marc Treib
2016/07/12 13:39:01
Yep, the "going back to NTP" case is what I was th
| |
| 218 return; | 193 return; |
| 219 | 194 |
| 220 // LoadTime only gets update once per page, so we don't have it on reloads. | 195 // LoadTime only gets update once per page, so we don't have it on reloads. |
| 221 if (load_time_ > base::TimeDelta::FromMilliseconds(0)) { | 196 if (load_time_ > base::TimeDelta::FromMilliseconds(0)) { |
| 222 logLoadTimeHistogram("NewTabPage.LoadTime", load_time_); | 197 logLoadTimeHistogram("NewTabPage.LoadTime", load_time_); |
| 223 | 198 |
| 224 // Split between ML and MV. | 199 // Split between ML and MV. |
| 225 std::string type = has_server_side_suggestions_ ? | 200 std::string type = has_server_side_suggestions_ ? |
| 226 "MostLikely" : "MostVisited"; | 201 "MostLikely" : "MostVisited"; |
| 227 logLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time_); | 202 logLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time_); |
| 228 // Split between Web and Local. | 203 // Split between Web and Local. |
| 229 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP"; | 204 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP"; |
| 230 logLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time_); | 205 logLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time_); |
| 231 | 206 |
| 232 // Split between Startup and non-startup. | 207 // Split between Startup and non-startup. |
| 233 std::string status = during_startup_ ? "Startup" : "NewTab"; | 208 std::string status = during_startup_ ? "Startup" : "NewTab"; |
| 234 logLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time_); | 209 logLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time_); |
| 235 | 210 |
| 236 load_time_ = base::TimeDelta::FromMilliseconds(0); | 211 load_time_ = base::TimeDelta::FromMilliseconds(0); |
| 237 } | 212 } |
| 238 has_server_side_suggestions_ = false; | 213 has_server_side_suggestions_ = false; |
| 239 has_client_side_suggestions_ = false; | 214 has_client_side_suggestions_ = false; |
| 240 UMA_HISTOGRAM_CUSTOM_COUNTS( | 215 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 241 "NewTabPage.NumberOfTiles", number_of_tiles_, 0, kNumMostVisited, | 216 "NewTabPage.NumberOfTiles", number_of_tiles_, 0, kNumMostVisited, |
| 242 kNumMostVisited + 1); | 217 kNumMostVisited + 1); |
| 243 number_of_tiles_ = 0; | 218 number_of_tiles_ = 0; |
| 244 has_emitted_ = true; | 219 has_emitted_ = true; |
| 245 during_startup_ = false; | 220 during_startup_ = false; |
| 246 } | 221 } |
| OLD | NEW |