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

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: Adding and using logNavigation(); updating tests; removing ping and the log.html page. 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
31 // Format string to generate the name for the histogram keeping track of 32 // Format string to generate the name for the histogram keeping track of
32 // suggestion impressions. 33 // suggestion impressions.
33 const char kImpressionHistogramWithProvider[] = 34 const char kImpressionHistogramWithProvider[] =
34 "NewTabPage.SuggestionsImpression.%s"; 35 "NewTabPage.SuggestionsImpression.%s";
35 36
37 // Number of Most Visited elements on the NTP for logging purposes.
38 const int kNumMostVisited = 8;
39
40 // Name of the histogram keeping track of Most Visited clicks.
41 const char kMostVisitedHistogramName[] = "NewTabPage.MostVisited";
42
43 // Format string to generate the name for the histogram keeping track of
44 // suggestion clicks.
45 const char kMostVisitedHistogramWithProvider[] = "NewTabPage.MostVisited.%s";
46
36 } // namespace 47 } // namespace
37 48
38 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger); 49 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NTPUserDataLogger);
39 50
40 NTPUserDataLogger::~NTPUserDataLogger() {} 51 NTPUserDataLogger::~NTPUserDataLogger() {}
41 52
42 // static 53 // static
43 NTPUserDataLogger* NTPUserDataLogger::GetOrCreateFromWebContents( 54 NTPUserDataLogger* NTPUserDataLogger::GetOrCreateFromWebContents(
44 content::WebContents* content) { 55 content::WebContents* content) {
45 // Calling CreateForWebContents when an instance is already attached has no 56 // Calling CreateForWebContents when an instance is already attached has no
46 // effect, so we can do this. 57 // effect, so we can do this.
47 NTPUserDataLogger::CreateForWebContents(content); 58 NTPUserDataLogger::CreateForWebContents(content);
48 NTPUserDataLogger* logger = NTPUserDataLogger::FromWebContents(content); 59 NTPUserDataLogger* logger = NTPUserDataLogger::FromWebContents(content);
49 60
50 // We record the URL of this NTP in order to identify navigations that 61 // 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 62 // originate from it. We use the NavigationController's URL since it might
52 // differ from the WebContents URL which is usually chrome://newtab/. 63 // differ from the WebContents URL which is usually chrome://newtab/.
53 const content::NavigationEntry* entry = 64 const content::NavigationEntry* entry =
54 content->GetController().GetVisibleEntry(); 65 content->GetController().GetVisibleEntry();
55 if (entry) 66 if (entry)
56 logger->ntp_url_ = entry->GetURL(); 67 logger->ntp_url_ = entry->GetURL();
57 68
58 return logger; 69 return logger;
59 } 70 }
60 71
72 // static
73 std::string NTPUserDataLogger::GetHistogramNameForProvider(
beaudoin 2014/03/04 21:33:15 GetNavigationHistogramNameForProvider( Maybe add
huangs 2014/03/04 22:10:43 Done; added GetImpressionHistogramNameForProvider(
74 const std::string& provider) {
75 return base::StringPrintf(kMostVisitedHistogramWithProvider,
76 provider.c_str());
77 }
78
61 void NTPUserDataLogger::EmitNtpStatistics() { 79 void NTPUserDataLogger::EmitNtpStatistics() {
62 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", number_of_mouseovers_); 80 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", number_of_mouseovers_);
63 number_of_mouseovers_ = 0; 81 number_of_mouseovers_ = 0;
64 82
65 // Only log the following statistics if at least one tile is recorded. This 83 // 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 84 // 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 85 // 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 86 // later the statistics are not regenerated (i.e. they are all 0). If we log
69 // them again we get a strong bias. 87 // them again we get a strong bias.
70 if (number_of_tiles_ > 0) { 88 if (number_of_tiles_ > 0) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 154 }
137 } 155 }
138 156
139 void NTPUserDataLogger::LogImpression(int position, 157 void NTPUserDataLogger::LogImpression(int position,
140 const base::string16& provider) { 158 const base::string16& provider) {
141 // Cannot rely on UMA histograms macro because the name of the histogram is 159 // Cannot rely on UMA histograms macro because the name of the histogram is
142 // generated dynamically. 160 // generated dynamically.
143 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( 161 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
144 base::StringPrintf(kImpressionHistogramWithProvider, 162 base::StringPrintf(kImpressionHistogramWithProvider,
145 base::UTF16ToUTF8(provider).c_str()), 163 base::UTF16ToUTF8(provider).c_str()),
146 1, MostVisitedIframeSource::kNumMostVisited, 164 1,
147 MostVisitedIframeSource::kNumMostVisited + 1, 165 kNumMostVisited,
166 kNumMostVisited + 1,
148 base::Histogram::kUmaTargetedHistogramFlag); 167 base::Histogram::kUmaTargetedHistogramFlag);
149 counter->Add(position); 168 counter->Add(position);
beaudoin 2014/03/04 21:33:15 I'd be tempted to use the exact same pattern as be
huangs 2014/03/04 22:10:43 Done; added kImpressionHistogramName. Note that t
150 } 169 }
151 170
171 void NTPUserDataLogger::LogNavigation(int position,
172 const base::string16& provider) {
173 // Log the Most Visited navigation.
beaudoin 2014/03/04 21:33:15 for both navigations that have providers and those
huangs 2014/03/04 22:10:43 Done.
174 UMA_HISTOGRAM_ENUMERATION(kMostVisitedHistogramName, position,
175 kNumMostVisited);
176
177 // If a provider is specified, log the metric specific to it.
178 if (!provider.empty()) {
179 // Cannot rely on UMA histograms macro because the name of the histogram is
180 // generated dynamically.
181 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
182 GetHistogramNameForProvider(base::UTF16ToUTF8(provider)),
183 1,
184 kNumMostVisited,
185 kNumMostVisited + 1,
186 base::Histogram::kUmaTargetedHistogramFlag);
187 counter->Add(position);
188 }
189
190 // Records the action. This will be available as a time-stamped stream
191 // server-side and can be used to compute time-to-long-dwell.
192 content::RecordAction(base::UserMetricsAction("MostVisited_Clicked"));
193 }
194
152 // content::WebContentsObserver override 195 // content::WebContentsObserver override
153 void NTPUserDataLogger::NavigationEntryCommitted( 196 void NTPUserDataLogger::NavigationEntryCommitted(
154 const content::LoadCommittedDetails& load_details) { 197 const content::LoadCommittedDetails& load_details) {
155 if (!load_details.previous_url.is_valid()) 198 if (!load_details.previous_url.is_valid())
156 return; 199 return;
157 200
158 if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) { 201 if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) {
159 EmitNtpStatistics(); 202 EmitNtpStatistics();
160 } 203 }
161 } 204 }
162 205
163 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) 206 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents)
164 : content::WebContentsObserver(contents), 207 : content::WebContentsObserver(contents),
165 has_server_side_suggestions_(false), 208 has_server_side_suggestions_(false),
166 number_of_tiles_(0), 209 number_of_tiles_(0),
167 number_of_thumbnail_tiles_(0), 210 number_of_thumbnail_tiles_(0),
168 number_of_gray_tiles_(0), 211 number_of_gray_tiles_(0),
169 number_of_external_tiles_(0), 212 number_of_external_tiles_(0),
170 number_of_thumbnail_errors_(0), 213 number_of_thumbnail_errors_(0),
171 number_of_gray_tile_fallbacks_(0), 214 number_of_gray_tile_fallbacks_(0),
172 number_of_external_tile_fallbacks_(0), 215 number_of_external_tile_fallbacks_(0),
173 number_of_mouseovers_(0) { 216 number_of_mouseovers_(0) {
174 } 217 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698