Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Side by Side Diff: chrome/browser/ui/webui/ntp/ntp_user_data_logger.cc

Issue 178253008: Redoing Issue 36073011: Allowing file:/// in Instant Extended's Most Visited links. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment fixes; more symmetry to logImpression() and logNavigation(). Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "chrome/browser/search/search.h" 11 #include "chrome/browser/search/search.h"
12 #include "chrome/common/search_urls.h" 12 #include "chrome/common/search_urls.h"
13 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
14 #include "content/public/browser/navigation_details.h" 14 #include "content/public/browser/navigation_details.h"
15 #include "content/public/browser/navigation_entry.h" 15 #include "content/public/browser/navigation_entry.h"
16 #include "content/public/browser/user_metrics.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 18
18 // Macro to log UMA statistics related to the 8 tiles shown on the NTP. 19 // Macro to log UMA statistics related to the 8 tiles shown on the NTP.
19 #define UMA_HISTOGRAM_NTP_TILES(name, sample) \ 20 #define UMA_HISTOGRAM_NTP_TILES(name, sample) \
20 UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, 0, 8, 9) 21 UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, 0, 8, 9)
21 22
22 namespace { 23 namespace {
23 24
24 // Used to track if suggestions were issued by the client or the server. 25 // Used to track if suggestions were issued by the client or the server.
25 enum SuggestionsType { 26 enum SuggestionsType {
26 CLIENT_SIDE = 0, 27 CLIENT_SIDE = 0,
27 SERVER_SIDE = 1, 28 SERVER_SIDE = 1,
28 SUGGESTIONS_TYPE_COUNT = 2 29 SUGGESTIONS_TYPE_COUNT = 2
29 }; 30 };
30 31
32 // Number of Most Visited elements on the NTP for logging purposes.
33 const int kNumMostVisited = 8;
34
35 // Name of the histogram keeping track of Most Visited impressions.
36 const char kImpressionHistogramName[] = "NewTabPage.SuggestionsImpression";
37
31 // Format string to generate the name for the histogram keeping track of 38 // Format string to generate the name for the histogram keeping track of
32 // suggestion impressions. 39 // suggestion impressions.
33 const char kImpressionHistogramWithProvider[] = 40 const char kImpressionHistogramWithProvider[] =
34 "NewTabPage.SuggestionsImpression.%s"; 41 "NewTabPage.SuggestionsImpression.%s";
35 42
43 // Name of the histogram keeping track of Most Visited navigations.
44 const char kMostVisitedHistogramName[] = "NewTabPage.MostVisited";
45
46 // Format string to generate the name for the histogram keeping track of
47 // suggestion navigations.
48 const char kMostVisitedHistogramWithProvider[] = "NewTabPage.MostVisited.%s";
49
36 } // namespace 50 } // namespace
37 51
38 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger); 52 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger);
39 53
40 NTPUserDataLogger::~NTPUserDataLogger() {} 54 NTPUserDataLogger::~NTPUserDataLogger() {}
41 55
42 // static 56 // static
43 NTPUserDataLogger* NTPUserDataLogger::GetOrCreateFromWebContents( 57 NTPUserDataLogger* NTPUserDataLogger::GetOrCreateFromWebContents(
44 content::WebContents* content) { 58 content::WebContents* content) {
45 // Calling CreateForWebContents when an instance is already attached has no 59 // Calling CreateForWebContents when an instance is already attached has no
46 // effect, so we can do this. 60 // effect, so we can do this.
47 NTPUserDataLogger::CreateForWebContents(content); 61 NTPUserDataLogger::CreateForWebContents(content);
48 NTPUserDataLogger* logger = NTPUserDataLogger::FromWebContents(content); 62 NTPUserDataLogger* logger = NTPUserDataLogger::FromWebContents(content);
49 63
50 // We record the URL of this NTP in order to identify navigations that 64 // We record the URL of this NTP in order to identify navigations that
51 // originate from it. We use the NavigationController's URL since it might 65 // originate from it. We use the NavigationController's URL since it might
52 // differ from the WebContents URL which is usually chrome://newtab/. 66 // differ from the WebContents URL which is usually chrome://newtab/.
53 const content::NavigationEntry* entry = 67 const content::NavigationEntry* entry =
54 content->GetController().GetVisibleEntry(); 68 content->GetController().GetVisibleEntry();
55 if (entry) 69 if (entry)
56 logger->ntp_url_ = entry->GetURL(); 70 logger->ntp_url_ = entry->GetURL();
57 71
58 return logger; 72 return logger;
59 } 73 }
60 74
75 // static
76 std::string NTPUserDataLogger::GetImpressionHistogramNameForProvider(
77 const std::string& provider) {
78 return base::StringPrintf(kImpressionHistogramWithProvider,
79 provider.c_str());
80 }
81
82 // static
83 std::string NTPUserDataLogger::GetNavigationHistogramNameForProvider(
84 const std::string& provider) {
85 return base::StringPrintf(kMostVisitedHistogramWithProvider,
86 provider.c_str());
87 }
88
61 void NTPUserDataLogger::EmitNtpStatistics() { 89 void NTPUserDataLogger::EmitNtpStatistics() {
62 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", number_of_mouseovers_); 90 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", number_of_mouseovers_);
63 number_of_mouseovers_ = 0; 91 number_of_mouseovers_ = 0;
64 92
65 // Only log the following statistics if at least one tile is recorded. This 93 // Only log the following statistics if at least one tile is recorded. This
66 // check is required because the statistics are emitted whenever the user 94 // check is required because the statistics are emitted whenever the user
67 // changes tab away from the NTP. However, if the user comes back to that NTP 95 // changes tab away from the NTP. However, if the user comes back to that NTP
68 // later the statistics are not regenerated (i.e. they are all 0). If we log 96 // later the statistics are not regenerated (i.e. they are all 0). If we log
69 // them again we get a strong bias. 97 // them again we get a strong bias.
70 if (number_of_tiles_ > 0) { 98 if (number_of_tiles_ > 0) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 case NTP_MOUSEOVER: 159 case NTP_MOUSEOVER:
132 number_of_mouseovers_++; 160 number_of_mouseovers_++;
133 break; 161 break;
134 default: 162 default:
135 NOTREACHED(); 163 NOTREACHED();
136 } 164 }
137 } 165 }
138 166
139 void NTPUserDataLogger::LogImpression(int position, 167 void NTPUserDataLogger::LogImpression(int position,
140 const base::string16& provider) { 168 const base::string16& provider) {
141 // Cannot rely on UMA histograms macro because the name of the histogram is 169 // Log the Most Visited navigation for navigations that have providers and
142 // generated dynamically. 170 // those that dont.
143 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( 171 UMA_HISTOGRAM_ENUMERATION(kImpressionHistogramName, position,
144 base::StringPrintf(kImpressionHistogramWithProvider, 172 kNumMostVisited);
145 base::UTF16ToUTF8(provider).c_str()), 173
146 1, MostVisitedIframeSource::kNumMostVisited, 174 // If a provider is specified, log the metric specific to it.
147 MostVisitedIframeSource::kNumMostVisited + 1, 175 if (!provider.empty()) {
148 base::Histogram::kUmaTargetedHistogramFlag); 176 // Cannot rely on UMA histograms macro because the name of the histogram is
149 counter->Add(position); 177 // generated dynamically.
178 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
179 GetImpressionHistogramNameForProvider(base::UTF16ToUTF8(provider)),
180 1,
181 kNumMostVisited,
182 kNumMostVisited + 1,
183 base::Histogram::kUmaTargetedHistogramFlag);
184 counter->Add(position);
185 }
186 }
187
188 void NTPUserDataLogger::LogNavigation(int position,
189 const base::string16& provider) {
190 // Log the Most Visited navigation for navigations that have providers and
191 // those that dont.
192 UMA_HISTOGRAM_ENUMERATION(kMostVisitedHistogramName, position,
193 kNumMostVisited);
194
195 // If a provider is specified, log the metric specific to it.
196 if (!provider.empty()) {
197 // Cannot rely on UMA histograms macro because the name of the histogram is
198 // generated dynamically.
199 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
200 GetNavigationHistogramNameForProvider(base::UTF16ToUTF8(provider)),
201 1,
202 kNumMostVisited,
203 kNumMostVisited + 1,
204 base::Histogram::kUmaTargetedHistogramFlag);
205 counter->Add(position);
206 }
207
208 // Records the action. This will be available as a time-stamped stream
209 // server-side and can be used to compute time-to-long-dwell.
210 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked"));
150 } 211 }
151 212
152 // content::WebContentsObserver override 213 // content::WebContentsObserver override
153 void NTPUserDataLogger::NavigationEntryCommitted( 214 void NTPUserDataLogger::NavigationEntryCommitted(
154 const content::LoadCommittedDetails& load_details) { 215 const content::LoadCommittedDetails& load_details) {
155 if (!load_details.previous_url.is_valid()) 216 if (!load_details.previous_url.is_valid())
156 return; 217 return;
157 218
158 if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) { 219 if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) {
159 EmitNtpStatistics(); 220 EmitNtpStatistics();
160 } 221 }
161 } 222 }
162 223
163 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) 224 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents)
164 : content::WebContentsObserver(contents), 225 : content::WebContentsObserver(contents),
165 has_server_side_suggestions_(false), 226 has_server_side_suggestions_(false),
166 number_of_tiles_(0), 227 number_of_tiles_(0),
167 number_of_thumbnail_tiles_(0), 228 number_of_thumbnail_tiles_(0),
168 number_of_gray_tiles_(0), 229 number_of_gray_tiles_(0),
169 number_of_external_tiles_(0), 230 number_of_external_tiles_(0),
170 number_of_thumbnail_errors_(0), 231 number_of_thumbnail_errors_(0),
171 number_of_gray_tile_fallbacks_(0), 232 number_of_gray_tile_fallbacks_(0),
172 number_of_external_tile_fallbacks_(0), 233 number_of_external_tile_fallbacks_(0),
173 number_of_mouseovers_(0) { 234 number_of_mouseovers_(0) {
174 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698