| 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 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 // Name of the histogram keeping track of suggestion navigations. | 52 // Name of the histogram keeping track of suggestion navigations. |
| 53 const char kMostVisitedNavigationHistogramName[] = | 53 const char kMostVisitedNavigationHistogramName[] = |
| 54 "NewTabPage.MostVisited"; | 54 "NewTabPage.MostVisited"; |
| 55 | 55 |
| 56 // Format string to generate the name for the histogram keeping track of | 56 // Format string to generate the name for the histogram keeping track of |
| 57 // suggestion navigations. | 57 // suggestion navigations. |
| 58 const char kMostVisitedNavigationHistogramWithProvider[] = | 58 const char kMostVisitedNavigationHistogramWithProvider[] = |
| 59 "NewTabPage.MostVisited.%s"; | 59 "NewTabPage.MostVisited.%s"; |
| 60 | 60 |
| 61 std::string GetSourceName(NTPLoggingTileSource tile_source) { |
| 62 switch (tile_source) { |
| 63 case NTPLoggingTileSource::CLIENT: |
| 64 return "client"; |
| 65 case NTPLoggingTileSource::SERVER: |
| 66 return "server"; |
| 67 } |
| 68 NOTREACHED(); |
| 69 return std::string(); |
| 70 } |
| 71 |
| 61 } // namespace | 72 } // namespace |
| 62 | 73 |
| 63 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger); | 74 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger); |
| 64 | 75 |
| 65 | 76 |
| 66 // 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 |
| 67 // 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 |
| 68 // 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. |
| 69 void logLoadTimeHistogram(const std::string& histogram, base::TimeDelta value) { | 80 void logLoadTimeHistogram(const std::string& histogram, base::TimeDelta value) { |
| 70 base::HistogramBase* counter = base::Histogram::FactoryTimeGet( | 81 base::HistogramBase* counter = base::Histogram::FactoryTimeGet( |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // is a good proxy for the total load time of the NTP, therefore we keep | 211 // is a good proxy for the total load time of the NTP, therefore we keep |
| 201 // the max as the load time. | 212 // the max as the load time. |
| 202 load_time_ = std::max(load_time_, time); | 213 load_time_ = std::max(load_time_, time); |
| 203 break; | 214 break; |
| 204 default: | 215 default: |
| 205 NOTREACHED(); | 216 NOTREACHED(); |
| 206 } | 217 } |
| 207 } | 218 } |
| 208 | 219 |
| 209 void NTPUserDataLogger::LogMostVisitedImpression( | 220 void NTPUserDataLogger::LogMostVisitedImpression( |
| 210 int position, const base::string16& provider) { | 221 int position, NTPLoggingTileSource tile_source) { |
| 211 // Log the Most Visited navigation for navigations that have providers and | |
| 212 // those that dont. | |
| 213 UMA_HISTOGRAM_ENUMERATION(kMostVisitedImpressionHistogramName, position, | 222 UMA_HISTOGRAM_ENUMERATION(kMostVisitedImpressionHistogramName, position, |
| 214 kNumMostVisited); | 223 kNumMostVisited); |
| 215 | 224 |
| 216 // If a provider is specified, log the metric specific to it. | 225 // Cannot rely on UMA histograms macro because the name of the histogram is |
| 217 if (!provider.empty()) { | 226 // generated dynamically. |
| 218 // Cannot rely on UMA histograms macro because the name of the histogram is | 227 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
| 219 // generated dynamically. | 228 base::StringPrintf(kMostVisitedImpressionHistogramWithProvider, |
| 220 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | 229 GetSourceName(tile_source).c_str()), |
| 221 base::StringPrintf(kMostVisitedImpressionHistogramWithProvider, | 230 1, |
| 222 base::UTF16ToUTF8(provider).c_str()), | 231 kNumMostVisited, |
| 223 1, | 232 kNumMostVisited + 1, |
| 224 kNumMostVisited, | 233 base::Histogram::kUmaTargetedHistogramFlag); |
| 225 kNumMostVisited + 1, | 234 counter->Add(position); |
| 226 base::Histogram::kUmaTargetedHistogramFlag); | |
| 227 counter->Add(position); | |
| 228 } | |
| 229 } | 235 } |
| 230 | 236 |
| 231 void NTPUserDataLogger::LogMostVisitedNavigation( | 237 void NTPUserDataLogger::LogMostVisitedNavigation( |
| 232 int position, const base::string16& provider) { | 238 int position, NTPLoggingTileSource tile_source) { |
| 233 // Log the Most Visited navigation for navigations that have providers and | |
| 234 // those that dont. | |
| 235 UMA_HISTOGRAM_ENUMERATION(kMostVisitedNavigationHistogramName, position, | 239 UMA_HISTOGRAM_ENUMERATION(kMostVisitedNavigationHistogramName, position, |
| 236 kNumMostVisited); | 240 kNumMostVisited); |
| 237 | 241 |
| 238 // If a provider is specified, log the metric specific to it. | 242 // Cannot rely on UMA histograms macro because the name of the histogram is |
| 239 if (!provider.empty()) { | 243 // generated dynamically. |
| 240 // Cannot rely on UMA histograms macro because the name of the histogram is | 244 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
| 241 // generated dynamically. | 245 base::StringPrintf(kMostVisitedNavigationHistogramWithProvider, |
| 242 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | 246 GetSourceName(tile_source).c_str()), |
| 243 base::StringPrintf(kMostVisitedNavigationHistogramWithProvider, | 247 1, |
| 244 base::UTF16ToUTF8(provider).c_str()), | 248 kNumMostVisited, |
| 245 1, | 249 kNumMostVisited + 1, |
| 246 kNumMostVisited, | 250 base::Histogram::kUmaTargetedHistogramFlag); |
| 247 kNumMostVisited + 1, | 251 counter->Add(position); |
| 248 base::Histogram::kUmaTargetedHistogramFlag); | |
| 249 counter->Add(position); | |
| 250 } | |
| 251 | 252 |
| 252 // Records the action. This will be available as a time-stamped stream | 253 // Records the action. This will be available as a time-stamped stream |
| 253 // server-side and can be used to compute time-to-long-dwell. | 254 // server-side and can be used to compute time-to-long-dwell. |
| 254 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); | 255 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked")); |
| 255 } | 256 } |
| 256 | 257 |
| 257 // content::WebContentsObserver override | 258 // content::WebContentsObserver override |
| 258 void NTPUserDataLogger::NavigationEntryCommitted( | 259 void NTPUserDataLogger::NavigationEntryCommitted( |
| 259 const content::LoadCommittedDetails& load_details) { | 260 const content::LoadCommittedDetails& load_details) { |
| 260 if (!load_details.previous_url.is_valid()) | 261 if (!load_details.previous_url.is_valid()) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 browser_sync::SessionsSyncManager* sessions = | 293 browser_sync::SessionsSyncManager* sessions = |
| 293 static_cast<browser_sync::SessionsSyncManager*>( | 294 static_cast<browser_sync::SessionsSyncManager*>( |
| 294 sync->GetSessionsSyncableService()); | 295 sync->GetSessionsSyncableService()); |
| 295 if (sessions) { | 296 if (sessions) { |
| 296 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( | 297 sync_sessions::SyncSessionsMetrics::RecordYoungestForeignTabAgeOnNTP( |
| 297 sessions); | 298 sessions); |
| 298 } | 299 } |
| 299 } | 300 } |
| 300 } | 301 } |
| 301 } | 302 } |
| OLD | NEW |