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: |
| 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 EmitNtpStatistics(time); |
| 124 break; | 117 break; |
| 125 default: | 118 default: |
| 126 NOTREACHED(); | 119 NOTREACHED(); |
| 127 } | 120 } |
| 128 } | 121 } |
| 129 | 122 |
| 130 void NTPUserDataLogger::LogMostVisitedImpression( | 123 void NTPUserDataLogger::LogMostVisitedImpression( |
| 131 int position, NTPLoggingTileSource tile_source) { | 124 int position, NTPLoggingTileSource tile_source) { |
| 132 UMA_HISTOGRAM_ENUMERATION(kMostVisitedImpressionHistogramName, position, | 125 UMA_HISTOGRAM_ENUMERATION(kMostVisitedImpressionHistogramName, position, |
| 133 kNumMostVisited); | 126 kNumMostVisited); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 158 kNumMostVisited, | 151 kNumMostVisited, |
| 159 kNumMostVisited + 1, | 152 kNumMostVisited + 1, |
| 160 base::Histogram::kUmaTargetedHistogramFlag); | 153 base::Histogram::kUmaTargetedHistogramFlag); |
| 161 counter->Add(position); | 154 counter->Add(position); |
| 162 | 155 |
| 163 // Records the action. This will be available as a time-stamped stream | 156 // 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. | 157 // server-side and can be used to compute time-to-long-dwell. |
| 165 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); | 158 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); |
| 166 } | 159 } |
| 167 | 160 |
| 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) | 161 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) |
| 177 : content::WebContentsObserver(contents), | 162 : has_server_side_suggestions_(false), |
| 178 has_server_side_suggestions_(false), | |
| 179 has_client_side_suggestions_(false), | 163 has_client_side_suggestions_(false), |
| 180 number_of_tiles_(0), | 164 number_of_tiles_(0), |
| 181 has_emitted_(false), | 165 has_emitted_(false), |
| 182 during_startup_(false) { | 166 during_startup_(false) { |
| 183 during_startup_ = !AfterStartupTaskUtils::IsBrowserStartupComplete(); | 167 during_startup_ = !AfterStartupTaskUtils::IsBrowserStartupComplete(); |
| 184 | 168 |
| 185 // We record metrics about session data here because when this class typically | 169 // 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 | 170 // 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 | 171 // been used to populate the page, and we want to learn about its state when |
| 188 // the NTP is being generated. | 172 // the NTP is being generated. |
| 189 if (contents) { | 173 if (contents) { |
| 190 ProfileSyncService* sync = ProfileSyncServiceFactory::GetForProfile( | 174 ProfileSyncService* sync = ProfileSyncServiceFactory::GetForProfile( |
| 191 Profile::FromBrowserContext(contents->GetBrowserContext())); | 175 Profile::FromBrowserContext(contents->GetBrowserContext())); |
| 192 if (sync) { | 176 if (sync) { |
| 193 browser_sync::SessionsSyncManager* sessions = | 177 browser_sync::SessionsSyncManager* sessions = |
| 194 static_cast<browser_sync::SessionsSyncManager*>( | 178 static_cast<browser_sync::SessionsSyncManager*>( |
| 195 sync->GetSessionsSyncableService()); | 179 sync->GetSessionsSyncableService()); |
| 196 if (sessions) { | 180 if (sessions) { |
| 197 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( | 181 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( |
| 198 sessions); | 182 sessions); |
| 199 } | 183 } |
| 200 } | 184 } |
| 201 } | 185 } |
| 202 } | 186 } |
| 203 | 187 |
| 204 // content::WebContentsObserver override | 188 void NTPUserDataLogger::EmitNtpStatistics(base::TimeDelta load_time) { |
| 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. | 189 // We only send statistics once per page. |
| 216 // And we don't send if there are no tiles recorded. | 190 // And we don't send if there are no tiles recorded. |
| 217 if (has_emitted_ || !number_of_tiles_) | 191 if (has_emitted_) |
| 218 return; | 192 return; |
| 219 | 193 |
| 220 // LoadTime only gets update once per page, so we don't have it on reloads. | 194 // LoadTime only gets update once per page, so we don't have it on reloads. |
|
Marc Treib
2016/07/12 13:39:01
nit: Comment is out of date now
sfiera
2016/07/12 14:10:25
Removed comment and the conditional too--we should
| |
| 221 if (load_time_ > base::TimeDelta::FromMilliseconds(0)) { | 195 if (load_time > base::TimeDelta::FromMilliseconds(0)) { |
| 222 logLoadTimeHistogram("NewTabPage.LoadTime", load_time_); | 196 logLoadTimeHistogram("NewTabPage.LoadTime", load_time); |
| 223 | 197 |
| 224 // Split between ML and MV. | 198 // Split between ML and MV. |
| 225 std::string type = has_server_side_suggestions_ ? | 199 std::string type = has_server_side_suggestions_ ? |
| 226 "MostLikely" : "MostVisited"; | 200 "MostLikely" : "MostVisited"; |
| 227 logLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time_); | 201 logLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time); |
| 228 // Split between Web and Local. | 202 // Split between Web and Local. |
| 229 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP"; | 203 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP"; |
| 230 logLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time_); | 204 logLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time); |
| 231 | 205 |
| 232 // Split between Startup and non-startup. | 206 // Split between Startup and non-startup. |
| 233 std::string status = during_startup_ ? "Startup" : "NewTab"; | 207 std::string status = during_startup_ ? "Startup" : "NewTab"; |
| 234 logLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time_); | 208 logLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time); |
| 235 | |
| 236 load_time_ = base::TimeDelta::FromMilliseconds(0); | |
| 237 } | 209 } |
| 238 has_server_side_suggestions_ = false; | 210 has_server_side_suggestions_ = false; |
| 239 has_client_side_suggestions_ = false; | 211 has_client_side_suggestions_ = false; |
| 240 UMA_HISTOGRAM_CUSTOM_COUNTS( | 212 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 241 "NewTabPage.NumberOfTiles", number_of_tiles_, 0, kNumMostVisited, | 213 "NewTabPage.NumberOfTiles", number_of_tiles_, 0, kNumMostVisited, |
| 242 kNumMostVisited + 1); | 214 kNumMostVisited + 1); |
| 243 number_of_tiles_ = 0; | 215 number_of_tiles_ = 0; |
| 244 has_emitted_ = true; | 216 has_emitted_ = true; |
| 245 during_startup_ = false; | 217 during_startup_ = false; |
| 246 } | 218 } |
| OLD | NEW |