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 "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/search/most_visited_iframe_source.h" | 10 #include "chrome/browser/search/most_visited_iframe_source.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 // originate from it. We use the NavigationController's URL since it might | 47 // originate from it. We use the NavigationController's URL since it might |
48 // differ from the WebContents URL which is usually chrome://newtab/. | 48 // differ from the WebContents URL which is usually chrome://newtab/. |
49 const content::NavigationEntry* entry = | 49 const content::NavigationEntry* entry = |
50 content->GetController().GetVisibleEntry(); | 50 content->GetController().GetVisibleEntry(); |
51 if (entry) | 51 if (entry) |
52 logger->ntp_url_ = entry->GetURL(); | 52 logger->ntp_url_ = entry->GetURL(); |
53 | 53 |
54 return logger; | 54 return logger; |
55 } | 55 } |
56 | 56 |
57 void NTPUserDataLogger::EmitThumbnailErrorRate() { | |
58 DCHECK_LE(number_of_thumbnail_errors_, number_of_thumbnail_attempts_); | |
59 if (number_of_thumbnail_attempts_ != 0) { | |
60 UMA_HISTOGRAM_PERCENTAGE( | |
61 "NewTabPage.ThumbnailErrorRate", | |
62 GetPercentError(number_of_thumbnail_errors_, | |
63 number_of_thumbnail_attempts_)); | |
64 } | |
65 DCHECK_LE(number_of_fallback_thumbnails_used_, | |
66 number_of_fallback_thumbnails_requested_); | |
67 if (number_of_fallback_thumbnails_requested_ != 0) { | |
68 UMA_HISTOGRAM_PERCENTAGE( | |
69 "NewTabPage.ThumbnailFallbackRate", | |
70 GetPercentError(number_of_fallback_thumbnails_used_, | |
71 number_of_fallback_thumbnails_requested_)); | |
72 } | |
73 number_of_thumbnail_attempts_ = 0; | |
74 number_of_thumbnail_errors_ = 0; | |
75 number_of_fallback_thumbnails_requested_ = 0; | |
76 number_of_fallback_thumbnails_used_ = 0; | |
77 } | |
78 | |
79 void NTPUserDataLogger::EmitNtpStatistics() { | 57 void NTPUserDataLogger::EmitNtpStatistics() { |
80 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", number_of_mouseovers_); | 58 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", number_of_mouseovers_); |
81 number_of_mouseovers_ = 0; | 59 number_of_mouseovers_ = 0; |
82 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfExternalTiles", | 60 |
83 number_of_external_tiles_); | 61 // Only log the following statistics if there is we recorded at least one |
Mathieu
2014/01/09 18:37:18
*if at least one tile was recorded
beaudoin
2014/01/15 23:39:56
Done.
| |
84 number_of_external_tiles_ = 0; | 62 // tile. This check is required because the statistics are emitted whenever |
85 UMA_HISTOGRAM_ENUMERATION( | 63 // the user changes tab away from the NTP. However, if he comes back to that |
Mathieu
2014/01/09 18:37:18
he -> the user
beaudoin
2014/01/15 23:39:56
Done.
| |
86 "NewTabPage.SuggestionsType", | 64 // NTP tab later the statistics are not regenerated (ie. they are all 0). If |
Jered
2014/01/10 15:12:36
nit: NTP tab -> NTP, ie. -> i.e.
beaudoin
2014/01/15 23:39:56
Done.
| |
87 server_side_suggestions_ ? SERVER_SIDE : CLIENT_SIDE, | 65 // we log them again we get a strong bias. |
88 SUGGESTIONS_TYPE_COUNT); | 66 if (number_of_tiles_ > 0) { |
89 server_side_suggestions_ = false; | 67 UMA_HISTOGRAM_CUSTOM_COUNTS("NewTabPage.NumberOfTiles", |
68 number_of_tiles_, 0, 8, 9 ); | |
Alexei Svitkine (slow)
2014/01/09 18:54:41
Perhaps its worth defining your own macro for this
beaudoin
2014/01/15 23:39:56
Done.
| |
69 number_of_tiles_ = 0; | |
70 UMA_HISTOGRAM_CUSTOM_COUNTS("NewTabPage.NumberOfThumbnailAttempts", | |
71 number_of_thumbnail_attempts_, 0, 8, 9 ); | |
72 number_of_thumbnail_attempts_ = 0; | |
73 UMA_HISTOGRAM_CUSTOM_COUNTS("NewTabPage.NumberOfThumbnailErrors", | |
74 number_of_thumbnail_errors_, 0, 8, 9 ); | |
75 number_of_thumbnail_errors_ = 0; | |
76 UMA_HISTOGRAM_CUSTOM_COUNTS("NewTabPage.NumberOfGrayTileFallbacks", | |
77 number_of_gray_tile_fallbacks_, 0, 8, 9 ); | |
78 number_of_gray_tile_fallbacks_ = 0; | |
79 UMA_HISTOGRAM_CUSTOM_COUNTS("NewTabPage.NumberOfExternalFallbacks", | |
80 number_of_external_fallbacks_, 0, 8, 9 ); | |
81 number_of_external_fallbacks_ = 0; | |
82 UMA_HISTOGRAM_CUSTOM_COUNTS("NewTabPage.NumberOfExternalTiles", | |
83 number_of_external_tiles_, 0, 8, 9 ); | |
84 number_of_external_tiles_ = 0; | |
85 UMA_HISTOGRAM_CUSTOM_COUNTS("NewTabPage.NumberOfGrayTiles", | |
86 number_of_gray_tiles_, 0, 8, 9 ); | |
Mathieu
2014/01/09 18:37:18
you tested this does the right thing at boundary c
beaudoin
2014/01/15 23:39:56
Yes. (It didn't, that's why I has to use CUSTOM_CO
| |
87 number_of_gray_tiles_ = 0; | |
88 UMA_HISTOGRAM_ENUMERATION( | |
89 "NewTabPage.SuggestionsType", | |
90 server_side_suggestions_ ? SERVER_SIDE : CLIENT_SIDE, | |
91 SUGGESTIONS_TYPE_COUNT); | |
92 server_side_suggestions_ = false; | |
93 } | |
90 } | 94 } |
91 | 95 |
92 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event) { | 96 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event) { |
93 switch (event) { | 97 switch (event) { |
94 case NTP_MOUSEOVER: | 98 case NTP_MOUSEOVER: |
95 number_of_mouseovers_++; | 99 number_of_mouseovers_++; |
96 break; | 100 break; |
97 case NTP_THUMBNAIL_ATTEMPT: | 101 case NTP_THUMBNAIL_ATTEMPT: |
98 number_of_thumbnail_attempts_++; | 102 number_of_thumbnail_attempts_++; |
99 break; | 103 break; |
100 case NTP_THUMBNAIL_ERROR: | 104 case NTP_THUMBNAIL_ERROR: |
101 number_of_thumbnail_errors_++; | 105 number_of_thumbnail_errors_++; |
102 break; | 106 break; |
103 case NTP_FALLBACK_THUMBNAIL_REQUESTED: | |
104 number_of_fallback_thumbnails_requested_++; | |
105 break; | |
106 case NTP_FALLBACK_THUMBNAIL_USED: | |
107 number_of_fallback_thumbnails_used_++; | |
108 break; | |
109 case NTP_SERVER_SIDE_SUGGESTION: | 107 case NTP_SERVER_SIDE_SUGGESTION: |
110 server_side_suggestions_ = true; | 108 server_side_suggestions_ = true; |
111 break; | 109 break; |
112 case NTP_CLIENT_SIDE_SUGGESTION: | 110 case NTP_CLIENT_SIDE_SUGGESTION: |
113 // We should never get a mix of server and client side suggestions, | 111 // We should never get a mix of server and client side suggestions, |
114 // otherwise there could be a race condition depending on the order in | 112 // otherwise there could be a race condition depending on the order in |
115 // which the iframes call this method. | 113 // which the iframes call this method. |
116 DCHECK(!server_side_suggestions_); | 114 DCHECK(!server_side_suggestions_); |
117 break; | 115 break; |
118 case NTP_EXTERNAL_TILE: | 116 case NTP_EXTERNAL_TILE: |
119 number_of_external_tiles_++; | 117 number_of_external_tiles_++; |
120 break; | 118 break; |
119 case NTP_TILE: | |
120 number_of_tiles_++; | |
121 break; | |
122 case NTP_GRAY_TILE: | |
123 number_of_gray_tiles_++; | |
124 break; | |
125 case NTP_GRAY_TILE_FALLBACK: | |
126 number_of_gray_tile_fallbacks_++; | |
127 break; | |
128 case NTP_EXTERNAL_FALLBACK: | |
129 number_of_external_fallbacks_++; | |
130 break; | |
121 default: | 131 default: |
122 NOTREACHED(); | 132 NOTREACHED(); |
123 } | 133 } |
124 } | 134 } |
125 | 135 |
126 void NTPUserDataLogger::LogImpression(int position, | 136 void NTPUserDataLogger::LogImpression(int position, |
127 const base::string16& provider) { | 137 const base::string16& provider) { |
128 // Cannot rely on UMA histograms macro because the name of the histogram is | 138 // Cannot rely on UMA histograms macro because the name of the histogram is |
129 // generated dynamically. | 139 // generated dynamically. |
130 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | 140 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
131 base::StringPrintf(kImpressionHistogramWithProvider, | 141 base::StringPrintf(kImpressionHistogramWithProvider, |
132 base::UTF16ToUTF8(provider).c_str()), | 142 base::UTF16ToUTF8(provider).c_str()), |
133 1, MostVisitedIframeSource::kNumMostVisited, | 143 1, MostVisitedIframeSource::kNumMostVisited, |
134 MostVisitedIframeSource::kNumMostVisited + 1, | 144 MostVisitedIframeSource::kNumMostVisited + 1, |
135 base::Histogram::kUmaTargetedHistogramFlag); | 145 base::Histogram::kUmaTargetedHistogramFlag); |
136 counter->Add(position); | 146 counter->Add(position); |
137 } | 147 } |
138 | 148 |
139 // content::WebContentsObserver override | 149 // content::WebContentsObserver override |
140 void NTPUserDataLogger::NavigationEntryCommitted( | 150 void NTPUserDataLogger::NavigationEntryCommitted( |
141 const content::LoadCommittedDetails& load_details) { | 151 const content::LoadCommittedDetails& load_details) { |
142 if (!load_details.previous_url.is_valid()) | 152 if (!load_details.previous_url.is_valid()) |
143 return; | 153 return; |
144 | 154 |
145 if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) { | 155 if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) { |
146 EmitNtpStatistics(); | 156 EmitNtpStatistics(); |
147 // Only log thumbnail error rates for Instant NTP pages, as we do not have | |
148 // this data for non-Instant NTPs. | |
149 if (ntp_url_ != GURL(chrome::kChromeUINewTabURL)) | |
150 EmitThumbnailErrorRate(); | |
151 } | 157 } |
152 } | 158 } |
153 | 159 |
154 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) | 160 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) |
155 : content::WebContentsObserver(contents), | 161 : content::WebContentsObserver(contents), |
156 number_of_mouseovers_(0), | 162 number_of_mouseovers_(0), |
163 number_of_tiles_(0), | |
157 number_of_thumbnail_attempts_(0), | 164 number_of_thumbnail_attempts_(0), |
158 number_of_thumbnail_errors_(0), | 165 number_of_thumbnail_errors_(0), |
159 number_of_fallback_thumbnails_requested_(0), | 166 number_of_gray_tile_fallbacks_(0), |
160 number_of_fallback_thumbnails_used_(0), | 167 number_of_external_fallbacks_(0), |
161 number_of_external_tiles_(0), | 168 number_of_external_tiles_(0), |
169 number_of_gray_tiles_(0), | |
162 server_side_suggestions_(false) { | 170 server_side_suggestions_(false) { |
163 } | 171 } |
164 | |
165 size_t NTPUserDataLogger::GetPercentError(size_t errors, size_t events) const { | |
166 return (100 * errors) / events; | |
167 } | |
OLD | NEW |