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

Side by Side Diff: components/ntp_tiles/most_visited_sites.cc

Issue 2105933002: NTP: Fix metrics recording crash by plumbing the necessary data to Java. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address treib@ comments. Created 4 years, 5 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
« no previous file with comments | « components/ntp_tiles/most_visited_sites.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/ntp_tiles/most_visited_sites.h" 5 #include "components/ntp_tiles/most_visited_sites.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 const char kHistogramServerName[] = "server"; 42 const char kHistogramServerName[] = "server";
43 const char kHistogramServerFormat[] = "server%d"; 43 const char kHistogramServerFormat[] = "server%d";
44 const char kHistogramPopularName[] = "popular"; 44 const char kHistogramPopularName[] = "popular";
45 const char kHistogramWhitelistName[] = "whitelist"; 45 const char kHistogramWhitelistName[] = "whitelist";
46 46
47 const char kPopularSitesFieldTrialName[] = "NTPPopularSites"; 47 const char kPopularSitesFieldTrialName[] = "NTPPopularSites";
48 48
49 const base::Feature kDisplaySuggestionsServiceTiles{ 49 const base::Feature kDisplaySuggestionsServiceTiles{
50 "DisplaySuggestionsServiceTiles", base::FEATURE_ENABLED_BY_DEFAULT}; 50 "DisplaySuggestionsServiceTiles", base::FEATURE_ENABLED_BY_DEFAULT};
51 51
52 // The visual type of a most visited tile.
53 //
54 // These values must stay in sync with the MostVisitedTileType enum
55 // in histograms.xml.
56 //
57 // A Java counterpart will be generated for this enum.
58 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.ntp
59 enum MostVisitedTileType {
60 // The icon or thumbnail hasn't loaded yet.
61 NONE,
62 // The item displays a site's actual favicon or touch icon.
63 ICON_REAL,
64 // The item displays a color derived from the site's favicon or touch icon.
65 ICON_COLOR,
66 // The item displays a default gray box in place of an icon.
67 ICON_DEFAULT,
68 NUM_TILE_TYPES,
69 };
70
71 // Log an event for a given |histogram| at a given element |position|. This 52 // Log an event for a given |histogram| at a given element |position|. This
72 // routine exists because regular histogram macros are cached thus can't be used 53 // routine exists because regular histogram macros are cached thus can't be used
73 // if the name of the histogram will change at a given call site. 54 // if the name of the histogram will change at a given call site.
74 void LogHistogramEvent(const std::string& histogram, 55 void LogHistogramEvent(const std::string& histogram,
75 int position, 56 int position,
76 int num_sites) { 57 int num_sites) {
77 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( 58 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
78 histogram, 59 histogram,
79 1, 60 1,
80 num_sites, 61 num_sites,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 107 }
127 // The whole grid is already filled with personal suggestions, no point in 108 // The whole grid is already filled with personal suggestions, no point in
128 // bothering with popular ones. 109 // bothering with popular ones.
129 return false; 110 return false;
130 } 111 }
131 112
132 bool AreURLsEquivalent(const GURL& url1, const GURL& url2) { 113 bool AreURLsEquivalent(const GURL& url1, const GURL& url2) {
133 return url1.host() == url2.host() && url1.path() == url2.path(); 114 return url1.host() == url2.host() && url1.path() == url2.path();
134 } 115 }
135 116
136 std::string GetSourceHistogramName( 117 std::string GetSourceHistogramName(int source, int provider_index) {
137 const MostVisitedSites::Suggestion& suggestion) { 118 switch (source) {
138 switch (suggestion.source) {
139 case MostVisitedSites::TOP_SITES: 119 case MostVisitedSites::TOP_SITES:
140 return kHistogramClientName; 120 return kHistogramClientName;
141 case MostVisitedSites::POPULAR: 121 case MostVisitedSites::POPULAR:
142 return kHistogramPopularName; 122 return kHistogramPopularName;
143 case MostVisitedSites::WHITELIST: 123 case MostVisitedSites::WHITELIST:
144 return kHistogramWhitelistName; 124 return kHistogramWhitelistName;
145 case MostVisitedSites::SUGGESTIONS_SERVICE: 125 case MostVisitedSites::SUGGESTIONS_SERVICE:
146 return suggestion.provider_index >= 0 126 return provider_index >= 0
147 ? base::StringPrintf(kHistogramServerFormat, 127 ? base::StringPrintf(kHistogramServerFormat, provider_index)
148 suggestion.provider_index)
149 : kHistogramServerName; 128 : kHistogramServerName;
150 } 129 }
151 NOTREACHED(); 130 NOTREACHED();
152 return std::string(); 131 return std::string();
153 } 132 }
154 133
134 std::string GetSourceHistogramNameFromSuggestion(
135 const MostVisitedSites::Suggestion& suggestion) {
136 return GetSourceHistogramName(suggestion.source, suggestion.provider_index);
137 }
138
155 void AppendSuggestions(MostVisitedSites::SuggestionsVector src, 139 void AppendSuggestions(MostVisitedSites::SuggestionsVector src,
156 MostVisitedSites::SuggestionsVector* dst) { 140 MostVisitedSites::SuggestionsVector* dst) {
157 dst->insert(dst->end(), 141 dst->insert(dst->end(),
158 std::make_move_iterator(src.begin()), 142 std::make_move_iterator(src.begin()),
159 std::make_move_iterator(src.end())); 143 std::make_move_iterator(src.end()));
160 } 144 }
161 145
162 } // namespace 146 } // namespace
163 147
164 MostVisitedSites::Suggestion::Suggestion() : provider_index(-1) {} 148 MostVisitedSites::Suggestion::Suggestion() : provider_index(-1) {}
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 // Only blacklist in the server-side suggestions service if it's active. 242 // Only blacklist in the server-side suggestions service if it's active.
259 if (mv_source_ == SUGGESTIONS_SERVICE) { 243 if (mv_source_ == SUGGESTIONS_SERVICE) {
260 if (add_url) 244 if (add_url)
261 suggestions_service_->BlacklistURL(url); 245 suggestions_service_->BlacklistURL(url);
262 else 246 else
263 suggestions_service_->UndoBlacklistURL(url); 247 suggestions_service_->UndoBlacklistURL(url);
264 } 248 }
265 } 249 }
266 250
267 void MostVisitedSites::RecordTileTypeMetrics( 251 void MostVisitedSites::RecordTileTypeMetrics(
268 const std::vector<int>& tile_types) { 252 const std::vector<int>& tile_types,
269 DCHECK_EQ(current_suggestions_.size(), tile_types.size()); 253 const std::vector<int>& sources,
254 const std::vector<int>& provider_indices) {
270 int counts_per_type[NUM_TILE_TYPES] = {0}; 255 int counts_per_type[NUM_TILE_TYPES] = {0};
271 for (size_t i = 0; i < tile_types.size(); ++i) { 256 for (size_t i = 0; i < tile_types.size(); ++i) {
272 int tile_type = tile_types[i]; 257 int tile_type = tile_types[i];
273 ++counts_per_type[tile_type]; 258 ++counts_per_type[tile_type];
274 std::string histogram = base::StringPrintf( 259 std::string histogram = base::StringPrintf(
275 "NewTabPage.TileType.%s", 260 "NewTabPage.TileType.%s",
276 GetSourceHistogramName(current_suggestions_[i]).c_str()); 261 GetSourceHistogramName(sources[i], provider_indices[i]).c_str());
277 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES); 262 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES);
278 } 263 }
279 264
280 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal", 265 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal",
281 counts_per_type[ICON_REAL]); 266 counts_per_type[ICON_REAL]);
282 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor", 267 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor",
283 counts_per_type[ICON_COLOR]); 268 counts_per_type[ICON_COLOR]);
284 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray", 269 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray",
285 counts_per_type[ICON_DEFAULT]); 270 counts_per_type[ICON_DEFAULT]);
286 } 271 }
287 272
288 void MostVisitedSites::RecordOpenedMostVisitedItem(int index, int tile_type) { 273 void MostVisitedSites::RecordOpenedMostVisitedItem(int index, int tile_type) {
274 // TODO(treib): |current_suggestions_| could be updated before this function
275 // is called, leading to DCHECKs and/or memory corruption. Adjust this
276 // function to work with asynchronous UI.
289 DCHECK_GE(index, 0); 277 DCHECK_GE(index, 0);
290 DCHECK_LT(index, static_cast<int>(current_suggestions_.size())); 278 DCHECK_LT(index, static_cast<int>(current_suggestions_.size()));
291 std::string histogram = base::StringPrintf( 279 std::string histogram = base::StringPrintf(
292 "NewTabPage.MostVisited.%s", 280 "NewTabPage.MostVisited.%s",
293 GetSourceHistogramName(current_suggestions_[index]).c_str()); 281 GetSourceHistogramNameFromSuggestion(current_suggestions_[index])
282 .c_str());
294 LogHistogramEvent(histogram, index, num_sites_); 283 LogHistogramEvent(histogram, index, num_sites_);
295 284
296 histogram = base::StringPrintf( 285 histogram = base::StringPrintf(
297 "NewTabPage.TileTypeClicked.%s", 286 "NewTabPage.TileTypeClicked.%s",
298 GetSourceHistogramName(current_suggestions_[index]).c_str()); 287 GetSourceHistogramNameFromSuggestion(current_suggestions_[index])
288 .c_str());
299 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES); 289 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES);
300 } 290 }
301 291
302 void MostVisitedSites::OnBlockedSitesChanged() { 292 void MostVisitedSites::OnBlockedSitesChanged() {
303 BuildCurrentSuggestions(); 293 BuildCurrentSuggestions();
304 } 294 }
305 295
306 // static 296 // static
307 void MostVisitedSites::RegisterProfilePrefs( 297 void MostVisitedSites::RegisterProfilePrefs(
308 user_prefs::PrefRegistrySyncable* registry) { 298 user_prefs::PrefRegistrySyncable* registry) {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 observer_->OnPopularURLsAvailable(popular_sites_->sites()); 553 observer_->OnPopularURLsAvailable(popular_sites_->sites());
564 554
565 // Re-build the suggestions list. Once done, this will notify the observer. 555 // Re-build the suggestions list. Once done, this will notify the observer.
566 BuildCurrentSuggestions(); 556 BuildCurrentSuggestions();
567 } 557 }
568 558
569 void MostVisitedSites::RecordImpressionUMAMetrics() { 559 void MostVisitedSites::RecordImpressionUMAMetrics() {
570 for (size_t i = 0; i < current_suggestions_.size(); i++) { 560 for (size_t i = 0; i < current_suggestions_.size(); i++) {
571 std::string histogram = base::StringPrintf( 561 std::string histogram = base::StringPrintf(
572 "NewTabPage.SuggestionsImpression.%s", 562 "NewTabPage.SuggestionsImpression.%s",
573 GetSourceHistogramName(current_suggestions_[i]).c_str()); 563 GetSourceHistogramNameFromSuggestion(current_suggestions_[i]).c_str());
574 LogHistogramEvent(histogram, static_cast<int>(i), num_sites_); 564 LogHistogramEvent(histogram, static_cast<int>(i), num_sites_);
575 } 565 }
576 } 566 }
577 567
578 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {} 568 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {}
579 569
580 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, 570 void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
581 ChangeReason change_reason) { 571 ChangeReason change_reason) {
582 if (mv_source_ == TOP_SITES) { 572 if (mv_source_ == TOP_SITES) {
583 // The displayed suggestions are invalidated. 573 // The displayed suggestions are invalidated.
584 InitiateTopSitesQuery(); 574 InitiateTopSitesQuery();
585 } 575 }
586 } 576 }
587 577
588 } // namespace ntp_tiles 578 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/most_visited_sites.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698