| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 switch (tile_source) { | 47 switch (tile_source) { |
| 48 case NTPLoggingTileSource::CLIENT: | 48 case NTPLoggingTileSource::CLIENT: |
| 49 return "client"; | 49 return "client"; |
| 50 case NTPLoggingTileSource::SERVER: | 50 case NTPLoggingTileSource::SERVER: |
| 51 return "server"; | 51 return "server"; |
| 52 } | 52 } |
| 53 NOTREACHED(); | 53 NOTREACHED(); |
| 54 return std::string(); | 54 return std::string(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void RecordSyncSessionMetrics(content::WebContents* contents) { |
| 58 if (!contents) |
| 59 return; |
| 60 browser_sync::ProfileSyncService* sync = |
| 61 ProfileSyncServiceFactory::GetForProfile( |
| 62 Profile::FromBrowserContext(contents->GetBrowserContext())); |
| 63 if (!sync) |
| 64 return; |
| 65 sync_sessions::SessionsSyncManager* sessions = |
| 66 static_cast<sync_sessions::SessionsSyncManager*>( |
| 67 sync->GetSessionsSyncableService()); |
| 68 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( |
| 69 sessions); |
| 70 } |
| 71 |
| 57 } // namespace | 72 } // namespace |
| 58 | 73 |
| 59 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger); | 74 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger); |
| 60 | 75 |
| 61 | 76 |
| 62 // Log a time event for a given |histogram| at a given |value|. This | 77 // Log a time event for a given |histogram| at a given |value|. This |
| 63 // routine exists because regular histogram macros are cached thus can't be used | 78 // routine exists because regular histogram macros are cached thus can't be used |
| 64 // if the name of the histogram will change at a given call site. | 79 // if the name of the histogram will change at a given call site. |
| 65 void logLoadTimeHistogram(const std::string& histogram, base::TimeDelta value) { | 80 void LogLoadTimeHistogram(const std::string& histogram, base::TimeDelta value) { |
| 66 base::HistogramBase* counter = base::Histogram::FactoryTimeGet( | 81 base::HistogramBase* counter = base::Histogram::FactoryTimeGet( |
| 67 histogram, | 82 histogram, |
| 68 base::TimeDelta::FromMilliseconds(1), | 83 base::TimeDelta::FromMilliseconds(1), |
| 69 base::TimeDelta::FromSeconds(60), 100, | 84 base::TimeDelta::FromSeconds(60), 100, |
| 70 base::Histogram::kUmaTargetedHistogramFlag); | 85 base::Histogram::kUmaTargetedHistogramFlag); |
| 71 if (counter) | 86 if (counter) |
| 72 counter->AddTime(value); | 87 counter->AddTime(value); |
| 73 } | 88 } |
| 74 | 89 |
| 75 | 90 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 103 } | 118 } |
| 104 | 119 |
| 105 return logger; | 120 return logger; |
| 106 } | 121 } |
| 107 | 122 |
| 108 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event, | 123 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event, |
| 109 base::TimeDelta time) { | 124 base::TimeDelta time) { |
| 110 switch (event) { | 125 switch (event) { |
| 111 case NTP_SERVER_SIDE_SUGGESTION: | 126 case NTP_SERVER_SIDE_SUGGESTION: |
| 112 has_server_side_suggestions_ = true; | 127 has_server_side_suggestions_ = true; |
| 113 break; | 128 number_of_tiles_++; |
| 129 return; |
| 114 case NTP_CLIENT_SIDE_SUGGESTION: | 130 case NTP_CLIENT_SIDE_SUGGESTION: |
| 115 has_client_side_suggestions_ = true; | 131 has_client_side_suggestions_ = true; |
| 116 break; | |
| 117 case NTP_TILE: | |
| 118 // TODO(sfiera): remove NTP_TILE and use NTP_*_SIDE_SUGGESTION. | |
| 119 number_of_tiles_++; | 132 number_of_tiles_++; |
| 120 break; | 133 return; |
| 121 case NTP_TILE_LOADED: | |
| 122 // We no longer emit statistics for the multi-iframe NTP. | |
| 123 break; | |
| 124 case NTP_ALL_TILES_LOADED: | 134 case NTP_ALL_TILES_LOADED: |
| 125 EmitNtpStatistics(time); | 135 EmitNtpStatistics(time); |
| 126 break; | 136 return; |
| 127 default: | |
| 128 NOTREACHED(); | |
| 129 } | 137 } |
| 138 NOTREACHED(); |
| 130 } | 139 } |
| 131 | 140 |
| 132 void NTPUserDataLogger::LogMostVisitedImpression( | 141 void NTPUserDataLogger::LogMostVisitedImpression( |
| 133 int position, NTPLoggingTileSource tile_source) { | 142 int position, NTPLoggingTileSource tile_source) { |
| 134 if ((position >= kNumMostVisited) || impression_was_logged_[position]) { | 143 if ((position >= kNumMostVisited) || impression_was_logged_[position]) { |
| 135 return; | 144 return; |
| 136 } | 145 } |
| 137 impression_was_logged_[position] = true; | 146 impression_was_logged_[position] = true; |
| 138 | 147 |
| 139 UMA_HISTOGRAM_ENUMERATION(kMostVisitedImpressionHistogramName, position, | 148 UMA_HISTOGRAM_ENUMERATION(kMostVisitedImpressionHistogramName, position, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // server-side and can be used to compute time-to-long-dwell. | 180 // server-side and can be used to compute time-to-long-dwell. |
| 172 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); | 181 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); |
| 173 } | 182 } |
| 174 | 183 |
| 175 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) | 184 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) |
| 176 : content::WebContentsObserver(contents), | 185 : content::WebContentsObserver(contents), |
| 177 has_server_side_suggestions_(false), | 186 has_server_side_suggestions_(false), |
| 178 has_client_side_suggestions_(false), | 187 has_client_side_suggestions_(false), |
| 179 number_of_tiles_(0), | 188 number_of_tiles_(0), |
| 180 has_emitted_(false), | 189 has_emitted_(false), |
| 181 during_startup_(false) { | 190 during_startup_(!AfterStartupTaskUtils::IsBrowserStartupComplete()) { |
| 182 during_startup_ = !AfterStartupTaskUtils::IsBrowserStartupComplete(); | |
| 183 | |
| 184 // We record metrics about session data here because when this class typically | 191 // We record metrics about session data here because when this class typically |
| 185 // emits metrics it is too late. This session data would theoretically have | 192 // emits metrics it is too late. This session data would theoretically have |
| 186 // been used to populate the page, and we want to learn about its state when | 193 // been used to populate the page, and we want to learn about its state when |
| 187 // the NTP is being generated. | 194 // the NTP is being generated. |
| 188 if (contents) { | 195 RecordSyncSessionMetrics(contents); |
| 189 browser_sync::ProfileSyncService* sync = | |
| 190 ProfileSyncServiceFactory::GetForProfile( | |
| 191 Profile::FromBrowserContext(contents->GetBrowserContext())); | |
| 192 if (sync) { | |
| 193 sync_sessions::SessionsSyncManager* sessions = | |
| 194 static_cast<sync_sessions::SessionsSyncManager*>( | |
| 195 sync->GetSessionsSyncableService()); | |
| 196 if (sessions) { | |
| 197 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( | |
| 198 sessions); | |
| 199 } | |
| 200 } | |
| 201 } | |
| 202 } | 196 } |
| 203 | 197 |
| 204 // content::WebContentsObserver override | 198 // content::WebContentsObserver override |
| 205 void NTPUserDataLogger::NavigationEntryCommitted( | 199 void NTPUserDataLogger::NavigationEntryCommitted( |
| 206 const content::LoadCommittedDetails& load_details) { | 200 const content::LoadCommittedDetails& load_details) { |
| 207 NavigatedFromURLToURL(load_details.previous_url, | 201 NavigatedFromURLToURL(load_details.previous_url, |
| 208 load_details.entry->GetURL()); | 202 load_details.entry->GetURL()); |
| 209 } | 203 } |
| 210 | 204 |
| 211 void NTPUserDataLogger::NavigatedFromURLToURL(const GURL& from, | 205 void NTPUserDataLogger::NavigatedFromURLToURL(const GURL& from, |
| 212 const GURL& to) { | 206 const GURL& to) { |
| 213 // User is returning to NTP, probably via the back button; reset stats. | 207 // User is returning to NTP, probably via the back button; reset stats. |
| 214 if (from.is_valid() && to.is_valid() && (to == ntp_url_)) { | 208 if (from.is_valid() && to.is_valid() && (to == ntp_url_)) { |
| 215 DVLOG(1) << "Returning to New Tab Page"; | 209 DVLOG(1) << "Returning to New Tab Page"; |
| 216 impression_was_logged_.reset(); | 210 impression_was_logged_.reset(); |
| 217 has_emitted_ = false; | 211 has_emitted_ = false; |
| 218 number_of_tiles_ = 0; | 212 number_of_tiles_ = 0; |
| 219 has_server_side_suggestions_ = false; | 213 has_server_side_suggestions_ = false; |
| 220 has_client_side_suggestions_ = false; | 214 has_client_side_suggestions_ = false; |
| 221 } | 215 } |
| 222 } | 216 } |
| 223 | 217 |
| 224 void NTPUserDataLogger::EmitNtpStatistics(base::TimeDelta load_time) { | 218 void NTPUserDataLogger::EmitNtpStatistics(base::TimeDelta load_time) { |
| 225 // We only send statistics once per page. | 219 // We only send statistics once per page. |
| 226 if (has_emitted_) | 220 if (has_emitted_) |
| 227 return; | 221 return; |
| 228 DVLOG(1) << "Emitting NTP load time: " << load_time << ", " | 222 DVLOG(1) << "Emitting NTP load time: " << load_time << ", " |
| 229 << "number of tiles: " << number_of_tiles_; | 223 << "number of tiles: " << number_of_tiles_; |
| 230 | 224 |
| 231 logLoadTimeHistogram("NewTabPage.LoadTime", load_time); | 225 LogLoadTimeHistogram("NewTabPage.LoadTime", load_time); |
| 232 | 226 |
| 233 // Split between ML and MV. | 227 // Split between ML and MV. |
| 234 std::string type = has_server_side_suggestions_ ? | 228 std::string type = has_server_side_suggestions_ ? |
| 235 "MostLikely" : "MostVisited"; | 229 "MostLikely" : "MostVisited"; |
| 236 logLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time); | 230 LogLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time); |
| 237 // Split between Web and Local. | 231 // Split between Web and Local. |
| 238 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP"; | 232 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP"; |
| 239 logLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time); | 233 LogLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time); |
| 240 | 234 |
| 241 // Split between Startup and non-startup. | 235 // Split between Startup and non-startup. |
| 242 std::string status = during_startup_ ? "Startup" : "NewTab"; | 236 std::string status = during_startup_ ? "Startup" : "NewTab"; |
| 243 logLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time); | 237 LogLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time); |
| 244 | 238 |
| 245 has_server_side_suggestions_ = false; | 239 has_server_side_suggestions_ = false; |
| 246 has_client_side_suggestions_ = false; | 240 has_client_side_suggestions_ = false; |
| 247 UMA_HISTOGRAM_CUSTOM_COUNTS( | 241 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 248 "NewTabPage.NumberOfTiles", number_of_tiles_, 1, kNumMostVisited, | 242 "NewTabPage.NumberOfTiles", number_of_tiles_, 1, kNumMostVisited, |
| 249 kNumMostVisited + 1); | 243 kNumMostVisited + 1); |
| 250 number_of_tiles_ = 0; | 244 number_of_tiles_ = 0; |
| 251 has_emitted_ = true; | 245 has_emitted_ = true; |
| 252 during_startup_ = false; | 246 during_startup_ = false; |
| 253 } | 247 } |
| OLD | NEW |