| 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_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 DVLOG(1) << "NTP URL changed from \"" << logger->ntp_url_ << "\" to \"" | 115 DVLOG(1) << "NTP URL changed from \"" << logger->ntp_url_ << "\" to \"" |
| 116 << entry->GetURL() << "\""; | 116 << entry->GetURL() << "\""; |
| 117 logger->ntp_url_ = entry->GetURL(); | 117 logger->ntp_url_ = entry->GetURL(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 return logger; | 120 return logger; |
| 121 } | 121 } |
| 122 | 122 |
| 123 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event, | 123 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event, |
| 124 base::TimeDelta time) { | 124 base::TimeDelta time) { |
| 125 switch (event) { | 125 DCHECK_EQ(NTP_ALL_TILES_LOADED, event); |
| 126 case NTP_SERVER_SIDE_SUGGESTION: | 126 EmitNtpStatistics(time); |
| 127 has_server_side_suggestions_ = true; | |
| 128 number_of_tiles_++; | |
| 129 return; | |
| 130 case NTP_CLIENT_SIDE_SUGGESTION: | |
| 131 has_client_side_suggestions_ = true; | |
| 132 number_of_tiles_++; | |
| 133 return; | |
| 134 case NTP_ALL_TILES_LOADED: | |
| 135 EmitNtpStatistics(time); | |
| 136 return; | |
| 137 } | |
| 138 NOTREACHED(); | |
| 139 } | 127 } |
| 140 | 128 |
| 141 void NTPUserDataLogger::LogMostVisitedImpression( | 129 void NTPUserDataLogger::LogMostVisitedImpression( |
| 142 int position, NTPLoggingTileSource tile_source) { | 130 int position, NTPLoggingTileSource tile_source) { |
| 143 if ((position >= kNumMostVisited) || impression_was_logged_[position]) { | 131 if ((position >= kNumMostVisited) || impression_was_logged_[position]) { |
| 144 return; | 132 return; |
| 145 } | 133 } |
| 146 impression_was_logged_[position] = true; | 134 impression_was_logged_[position] = true; |
| 147 | 135 |
| 136 switch (tile_source) { |
| 137 case NTPLoggingTileSource::CLIENT: |
| 138 has_client_side_suggestions_ = true; |
| 139 break; |
| 140 case NTPLoggingTileSource::SERVER: |
| 141 has_server_side_suggestions_ = true; |
| 142 break; |
| 143 } |
| 144 |
| 148 UMA_HISTOGRAM_ENUMERATION(kMostVisitedImpressionHistogramName, position, | 145 UMA_HISTOGRAM_ENUMERATION(kMostVisitedImpressionHistogramName, position, |
| 149 kNumMostVisited); | 146 kNumMostVisited); |
| 150 | 147 |
| 151 // Cannot rely on UMA histograms macro because the name of the histogram is | 148 // Cannot rely on UMA histograms macro because the name of the histogram is |
| 152 // generated dynamically. | 149 // generated dynamically. |
| 153 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | 150 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
| 154 base::StringPrintf(kMostVisitedImpressionHistogramWithProvider, | 151 base::StringPrintf(kMostVisitedImpressionHistogramWithProvider, |
| 155 GetSourceName(tile_source).c_str()), | 152 GetSourceName(tile_source).c_str()), |
| 156 1, | 153 1, |
| 157 kNumMostVisited, | 154 kNumMostVisited, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 178 | 175 |
| 179 // Records the action. This will be available as a time-stamped stream | 176 // Records the action. This will be available as a time-stamped stream |
| 180 // server-side and can be used to compute time-to-long-dwell. | 177 // server-side and can be used to compute time-to-long-dwell. |
| 181 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); | 178 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); |
| 182 } | 179 } |
| 183 | 180 |
| 184 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) | 181 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) |
| 185 : content::WebContentsObserver(contents), | 182 : content::WebContentsObserver(contents), |
| 186 has_server_side_suggestions_(false), | 183 has_server_side_suggestions_(false), |
| 187 has_client_side_suggestions_(false), | 184 has_client_side_suggestions_(false), |
| 188 number_of_tiles_(0), | |
| 189 has_emitted_(false), | 185 has_emitted_(false), |
| 190 during_startup_(!AfterStartupTaskUtils::IsBrowserStartupComplete()) { | 186 during_startup_(!AfterStartupTaskUtils::IsBrowserStartupComplete()) { |
| 191 // We record metrics about session data here because when this class typically | 187 // We record metrics about session data here because when this class typically |
| 192 // emits metrics it is too late. This session data would theoretically have | 188 // emits metrics it is too late. This session data would theoretically have |
| 193 // been used to populate the page, and we want to learn about its state when | 189 // been used to populate the page, and we want to learn about its state when |
| 194 // the NTP is being generated. | 190 // the NTP is being generated. |
| 195 RecordSyncSessionMetrics(contents); | 191 RecordSyncSessionMetrics(contents); |
| 196 } | 192 } |
| 197 | 193 |
| 198 // content::WebContentsObserver override | 194 // content::WebContentsObserver override |
| 199 void NTPUserDataLogger::NavigationEntryCommitted( | 195 void NTPUserDataLogger::NavigationEntryCommitted( |
| 200 const content::LoadCommittedDetails& load_details) { | 196 const content::LoadCommittedDetails& load_details) { |
| 201 NavigatedFromURLToURL(load_details.previous_url, | 197 NavigatedFromURLToURL(load_details.previous_url, |
| 202 load_details.entry->GetURL()); | 198 load_details.entry->GetURL()); |
| 203 } | 199 } |
| 204 | 200 |
| 205 void NTPUserDataLogger::NavigatedFromURLToURL(const GURL& from, | 201 void NTPUserDataLogger::NavigatedFromURLToURL(const GURL& from, |
| 206 const GURL& to) { | 202 const GURL& to) { |
| 207 // User is returning to NTP, probably via the back button; reset stats. | 203 // User is returning to NTP, probably via the back button; reset stats. |
| 208 if (from.is_valid() && to.is_valid() && (to == ntp_url_)) { | 204 if (from.is_valid() && to.is_valid() && (to == ntp_url_)) { |
| 209 DVLOG(1) << "Returning to New Tab Page"; | 205 DVLOG(1) << "Returning to New Tab Page"; |
| 210 impression_was_logged_.reset(); | 206 impression_was_logged_.reset(); |
| 211 has_emitted_ = false; | 207 has_emitted_ = false; |
| 212 number_of_tiles_ = 0; | |
| 213 has_server_side_suggestions_ = false; | 208 has_server_side_suggestions_ = false; |
| 214 has_client_side_suggestions_ = false; | 209 has_client_side_suggestions_ = false; |
| 215 } | 210 } |
| 216 } | 211 } |
| 217 | 212 |
| 218 void NTPUserDataLogger::EmitNtpStatistics(base::TimeDelta load_time) { | 213 void NTPUserDataLogger::EmitNtpStatistics(base::TimeDelta load_time) { |
| 219 // We only send statistics once per page. | 214 // We only send statistics once per page. |
| 220 if (has_emitted_) | 215 if (has_emitted_) |
| 221 return; | 216 return; |
| 217 |
| 218 size_t number_of_tiles = impression_was_logged_.count(); |
| 222 DVLOG(1) << "Emitting NTP load time: " << load_time << ", " | 219 DVLOG(1) << "Emitting NTP load time: " << load_time << ", " |
| 223 << "number of tiles: " << number_of_tiles_; | 220 << "number of tiles: " << number_of_tiles; |
| 224 | 221 |
| 225 LogLoadTimeHistogram("NewTabPage.LoadTime", load_time); | 222 LogLoadTimeHistogram("NewTabPage.LoadTime", load_time); |
| 226 | 223 |
| 227 // Split between ML and MV. | 224 // Split between ML and MV. |
| 228 std::string type = has_server_side_suggestions_ ? | 225 std::string type = has_server_side_suggestions_ ? |
| 229 "MostLikely" : "MostVisited"; | 226 "MostLikely" : "MostVisited"; |
| 230 LogLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time); | 227 LogLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time); |
| 231 // Split between Web and Local. | 228 // Split between Web and Local. |
| 232 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP"; | 229 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP"; |
| 233 LogLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time); | 230 LogLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time); |
| 234 | 231 |
| 235 // Split between Startup and non-startup. | 232 // Split between Startup and non-startup. |
| 236 std::string status = during_startup_ ? "Startup" : "NewTab"; | 233 std::string status = during_startup_ ? "Startup" : "NewTab"; |
| 237 LogLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time); | 234 LogLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time); |
| 238 | 235 |
| 239 has_server_side_suggestions_ = false; | |
| 240 has_client_side_suggestions_ = false; | |
| 241 UMA_HISTOGRAM_CUSTOM_COUNTS( | 236 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 242 "NewTabPage.NumberOfTiles", number_of_tiles_, 1, kNumMostVisited, | 237 "NewTabPage.NumberOfTiles", number_of_tiles, 1, kNumMostVisited, |
| 243 kNumMostVisited + 1); | 238 kNumMostVisited + 1); |
| 244 number_of_tiles_ = 0; | |
| 245 has_emitted_ = true; | 239 has_emitted_ = true; |
| 246 during_startup_ = false; | 240 during_startup_ = false; |
| 247 } | 241 } |
| OLD | NEW |