| 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" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "chrome/browser/after_startup_task_utils.h" | 12 #include "chrome/browser/after_startup_task_utils.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/search/search.h" | 14 #include "chrome/browser/search/search.h" |
| 15 #include "chrome/browser/sync/profile_sync_service_factory.h" | 15 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 16 #include "chrome/common/search/search_urls.h" | 16 #include "chrome/common/search/search_urls.h" |
| 17 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 18 #include "components/browser_sync/profile_sync_service.h" | 18 #include "components/browser_sync/profile_sync_service.h" |
| 19 #include "components/ntp_tiles/metrics.h" |
| 19 #include "components/sync_sessions/sessions_sync_manager.h" | 20 #include "components/sync_sessions/sessions_sync_manager.h" |
| 20 #include "components/sync_sessions/sync_sessions_metrics.h" | 21 #include "components/sync_sessions/sync_sessions_metrics.h" |
| 21 #include "content/public/browser/navigation_details.h" | 22 #include "content/public/browser/navigation_details.h" |
| 22 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
| 23 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // Name of the histogram keeping track of suggestion impressions. | |
| 29 const char kMostVisitedImpressionHistogramName[] = | |
| 30 "NewTabPage.SuggestionsImpression"; | |
| 31 | |
| 32 // Format string to generate the name for the histogram keeping track of | |
| 33 // suggestion impressions. | |
| 34 const char kMostVisitedImpressionHistogramWithProvider[] = | |
| 35 "NewTabPage.SuggestionsImpression.%s"; | |
| 36 | |
| 37 // Name of the histogram keeping track of suggestion navigations. | |
| 38 const char kMostVisitedNavigationHistogramName[] = | |
| 39 "NewTabPage.MostVisited"; | |
| 40 | |
| 41 // Format string to generate the name for the histogram keeping track of | |
| 42 // suggestion navigations. | |
| 43 const char kMostVisitedNavigationHistogramWithProvider[] = | |
| 44 "NewTabPage.MostVisited.%s"; | |
| 45 | |
| 46 std::string GetSourceName(NTPLoggingTileSource tile_source) { | |
| 47 switch (tile_source) { | |
| 48 case NTPLoggingTileSource::CLIENT: | |
| 49 return "client"; | |
| 50 case NTPLoggingTileSource::SERVER: | |
| 51 return "server"; | |
| 52 } | |
| 53 NOTREACHED(); | |
| 54 return std::string(); | |
| 55 } | |
| 56 | |
| 57 void RecordSyncSessionMetrics(content::WebContents* contents) { | 29 void RecordSyncSessionMetrics(content::WebContents* contents) { |
| 58 if (!contents) | 30 if (!contents) |
| 59 return; | 31 return; |
| 60 browser_sync::ProfileSyncService* sync = | 32 browser_sync::ProfileSyncService* sync = |
| 61 ProfileSyncServiceFactory::GetForProfile( | 33 ProfileSyncServiceFactory::GetForProfile( |
| 62 Profile::FromBrowserContext(contents->GetBrowserContext())); | 34 Profile::FromBrowserContext(contents->GetBrowserContext())); |
| 63 if (!sync) | 35 if (!sync) |
| 64 return; | 36 return; |
| 65 sync_sessions::SessionsSyncManager* sessions = | 37 sync_sessions::SessionsSyncManager* sessions = |
| 66 static_cast<sync_sessions::SessionsSyncManager*>( | 38 static_cast<sync_sessions::SessionsSyncManager*>( |
| 67 sync->GetSessionsSyncableService()); | 39 sync->GetSessionsSyncableService()); |
| 68 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( | 40 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( |
| 69 sessions); | 41 sessions); |
| 70 } | 42 } |
| 71 | 43 |
| 44 ntp_tiles::NTPTileSource ConvertTileSource(NTPLoggingTileSource tile_source) { |
| 45 switch (tile_source) { |
| 46 case NTPLoggingTileSource::CLIENT: |
| 47 return ntp_tiles::NTPTileSource::TOP_SITES; |
| 48 case NTPLoggingTileSource::SERVER: |
| 49 return ntp_tiles::NTPTileSource::SUGGESTIONS_SERVICE; |
| 50 } |
| 51 NOTREACHED(); |
| 52 return ntp_tiles::NTPTileSource::TOP_SITES; |
| 53 } |
| 54 |
| 72 } // namespace | 55 } // namespace |
| 73 | 56 |
| 74 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger); | 57 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger); |
| 75 | 58 |
| 76 | 59 |
| 77 // Log a time event for a given |histogram| at a given |value|. This | 60 // Log a time event for a given |histogram| at a given |value|. This |
| 78 // routine exists because regular histogram macros are cached thus can't be used | 61 // routine exists because regular histogram macros are cached thus can't be used |
| 79 // if the name of the histogram will change at a given call site. | 62 // if the name of the histogram will change at a given call site. |
| 80 void LogLoadTimeHistogram(const std::string& histogram, base::TimeDelta value) { | 63 void LogLoadTimeHistogram(const std::string& histogram, base::TimeDelta value) { |
| 81 base::HistogramBase* counter = base::Histogram::FactoryTimeGet( | 64 base::HistogramBase* counter = base::Histogram::FactoryTimeGet( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 118 |
| 136 switch (tile_source) { | 119 switch (tile_source) { |
| 137 case NTPLoggingTileSource::CLIENT: | 120 case NTPLoggingTileSource::CLIENT: |
| 138 has_client_side_suggestions_ = true; | 121 has_client_side_suggestions_ = true; |
| 139 break; | 122 break; |
| 140 case NTPLoggingTileSource::SERVER: | 123 case NTPLoggingTileSource::SERVER: |
| 141 has_server_side_suggestions_ = true; | 124 has_server_side_suggestions_ = true; |
| 142 break; | 125 break; |
| 143 } | 126 } |
| 144 | 127 |
| 145 UMA_HISTOGRAM_ENUMERATION(kMostVisitedImpressionHistogramName, position, | 128 ntp_tiles::metrics::RecordTileImpression(position, |
| 146 kNumMostVisited); | 129 ConvertTileSource(tile_source)); |
| 147 | |
| 148 // Cannot rely on UMA histograms macro because the name of the histogram is | |
| 149 // generated dynamically. | |
| 150 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | |
| 151 base::StringPrintf(kMostVisitedImpressionHistogramWithProvider, | |
| 152 GetSourceName(tile_source).c_str()), | |
| 153 1, | |
| 154 kNumMostVisited, | |
| 155 kNumMostVisited + 1, | |
| 156 base::Histogram::kUmaTargetedHistogramFlag); | |
| 157 counter->Add(position); | |
| 158 } | 130 } |
| 159 | 131 |
| 160 void NTPUserDataLogger::LogMostVisitedNavigation( | 132 void NTPUserDataLogger::LogMostVisitedNavigation( |
| 161 int position, NTPLoggingTileSource tile_source) { | 133 int position, NTPLoggingTileSource tile_source) { |
| 162 UMA_HISTOGRAM_ENUMERATION(kMostVisitedNavigationHistogramName, position, | 134 ntp_tiles::metrics::RecordTileClick(position, ConvertTileSource(tile_source), |
| 163 kNumMostVisited); | 135 ntp_tiles::metrics::THUMBNAIL); |
| 164 | |
| 165 // Cannot rely on UMA histograms macro because the name of the histogram is | |
| 166 // generated dynamically. | |
| 167 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | |
| 168 base::StringPrintf(kMostVisitedNavigationHistogramWithProvider, | |
| 169 GetSourceName(tile_source).c_str()), | |
| 170 1, | |
| 171 kNumMostVisited, | |
| 172 kNumMostVisited + 1, | |
| 173 base::Histogram::kUmaTargetedHistogramFlag); | |
| 174 counter->Add(position); | |
| 175 | 136 |
| 176 // Records the action. This will be available as a time-stamped stream | 137 // Records the action. This will be available as a time-stamped stream |
| 177 // server-side and can be used to compute time-to-long-dwell. | 138 // server-side and can be used to compute time-to-long-dwell. |
| 178 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); | 139 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); |
| 179 } | 140 } |
| 180 | 141 |
| 181 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) | 142 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) |
| 182 : content::WebContentsObserver(contents), | 143 : content::WebContentsObserver(contents), |
| 183 has_server_side_suggestions_(false), | 144 has_server_side_suggestions_(false), |
| 184 has_client_side_suggestions_(false), | 145 has_client_side_suggestions_(false), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 212 | 173 |
| 213 void NTPUserDataLogger::EmitNtpStatistics(base::TimeDelta load_time) { | 174 void NTPUserDataLogger::EmitNtpStatistics(base::TimeDelta load_time) { |
| 214 // We only send statistics once per page. | 175 // We only send statistics once per page. |
| 215 if (has_emitted_) | 176 if (has_emitted_) |
| 216 return; | 177 return; |
| 217 | 178 |
| 218 size_t number_of_tiles = impression_was_logged_.count(); | 179 size_t number_of_tiles = impression_was_logged_.count(); |
| 219 DVLOG(1) << "Emitting NTP load time: " << load_time << ", " | 180 DVLOG(1) << "Emitting NTP load time: " << load_time << ", " |
| 220 << "number of tiles: " << number_of_tiles; | 181 << "number of tiles: " << number_of_tiles; |
| 221 | 182 |
| 183 ntp_tiles::metrics::RecordPageImpression(number_of_tiles); |
| 184 |
| 222 LogLoadTimeHistogram("NewTabPage.LoadTime", load_time); | 185 LogLoadTimeHistogram("NewTabPage.LoadTime", load_time); |
| 223 | 186 |
| 224 // Split between ML and MV. | 187 // Split between ML and MV. |
| 225 std::string type = has_server_side_suggestions_ ? | 188 std::string type = has_server_side_suggestions_ ? |
| 226 "MostLikely" : "MostVisited"; | 189 "MostLikely" : "MostVisited"; |
| 227 LogLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time); | 190 LogLoadTimeHistogram("NewTabPage.LoadTime." + type, load_time); |
| 191 |
| 228 // Split between Web and Local. | 192 // Split between Web and Local. |
| 229 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP"; | 193 std::string source = ntp_url_.SchemeIsHTTPOrHTTPS() ? "Web" : "LocalNTP"; |
| 230 LogLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time); | 194 LogLoadTimeHistogram("NewTabPage.LoadTime." + source, load_time); |
| 231 | 195 |
| 232 // Split between Startup and non-startup. | 196 // Split between Startup and non-startup. |
| 233 std::string status = during_startup_ ? "Startup" : "NewTab"; | 197 std::string status = during_startup_ ? "Startup" : "NewTab"; |
| 234 LogLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time); | 198 LogLoadTimeHistogram("NewTabPage.LoadTime." + status, load_time); |
| 235 | 199 |
| 236 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
| 237 "NewTabPage.NumberOfTiles", number_of_tiles, 1, kNumMostVisited, | |
| 238 kNumMostVisited + 1); | |
| 239 has_emitted_ = true; | 200 has_emitted_ = true; |
| 240 during_startup_ = false; | 201 during_startup_ = false; |
| 241 } | 202 } |
| OLD | NEW |