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

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

Issue 2150313002: NTP: Fix metrics recording crash by plumbing the necessary data to Java. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: 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 29 matching lines...) Expand all
40 // Identifiers for the various tile sources. 40 // Identifiers for the various tile sources.
41 const char kHistogramClientName[] = "client"; 41 const char kHistogramClientName[] = "client";
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 base::Feature kDisplaySuggestionsServiceTiles{ 47 const base::Feature kDisplaySuggestionsServiceTiles{
48 "DisplaySuggestionsServiceTiles", base::FEATURE_ENABLED_BY_DEFAULT}; 48 "DisplaySuggestionsServiceTiles", base::FEATURE_ENABLED_BY_DEFAULT};
49 49
50 // The visual type of a most visited tile.
51 //
52 // These values must stay in sync with the MostVisitedTileType enum
53 // in histograms.xml.
54 //
55 // A Java counterpart will be generated for this enum.
56 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.ntp
57 enum MostVisitedTileType {
58 // The icon or thumbnail hasn't loaded yet.
59 NONE,
60 // The item displays a site's actual favicon or touch icon.
61 ICON_REAL,
62 // The item displays a color derived from the site's favicon or touch icon.
63 ICON_COLOR,
64 // The item displays a default gray box in place of an icon.
65 ICON_DEFAULT,
66 NUM_TILE_TYPES,
67 };
68
69 // Log an event for a given |histogram| at a given element |position|. This 50 // Log an event for a given |histogram| at a given element |position|. This
70 // routine exists because regular histogram macros are cached thus can't be used 51 // routine exists because regular histogram macros are cached thus can't be used
71 // if the name of the histogram will change at a given call site. 52 // if the name of the histogram will change at a given call site.
72 void LogHistogramEvent(const std::string& histogram, 53 void LogHistogramEvent(const std::string& histogram,
73 int position, 54 int position,
74 int num_sites) { 55 int num_sites) {
75 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( 56 base::HistogramBase* counter = base::LinearHistogram::FactoryGet(
76 histogram, 57 histogram,
77 1, 58 1,
78 num_sites, 59 num_sites,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 95 }
115 // The whole grid is already filled with personal suggestions, no point in 96 // The whole grid is already filled with personal suggestions, no point in
116 // bothering with popular ones. 97 // bothering with popular ones.
117 return false; 98 return false;
118 } 99 }
119 100
120 bool AreURLsEquivalent(const GURL& url1, const GURL& url2) { 101 bool AreURLsEquivalent(const GURL& url1, const GURL& url2) {
121 return url1.host() == url2.host() && url1.path() == url2.path(); 102 return url1.host() == url2.host() && url1.path() == url2.path();
122 } 103 }
123 104
124 std::string GetSourceHistogramName( 105 std::string GetSourceHistogramName(int source, int provider_index) {
125 const MostVisitedSites::Suggestion& suggestion) { 106 switch (source) {
126 switch (suggestion.source) {
127 case MostVisitedSites::TOP_SITES: 107 case MostVisitedSites::TOP_SITES:
128 return kHistogramClientName; 108 return kHistogramClientName;
129 case MostVisitedSites::POPULAR: 109 case MostVisitedSites::POPULAR:
130 return kHistogramPopularName; 110 return kHistogramPopularName;
131 case MostVisitedSites::WHITELIST: 111 case MostVisitedSites::WHITELIST:
132 return kHistogramWhitelistName; 112 return kHistogramWhitelistName;
133 case MostVisitedSites::SUGGESTIONS_SERVICE: 113 case MostVisitedSites::SUGGESTIONS_SERVICE:
134 return suggestion.provider_index >= 0 114 return provider_index >= 0
135 ? base::StringPrintf(kHistogramServerFormat, 115 ? base::StringPrintf(kHistogramServerFormat, provider_index)
136 suggestion.provider_index)
137 : kHistogramServerName; 116 : kHistogramServerName;
138 } 117 }
139 NOTREACHED(); 118 NOTREACHED();
140 return std::string(); 119 return std::string();
141 } 120 }
142 121
122 std::string GetSourceHistogramNameFromSuggestion(
123 const MostVisitedSites::Suggestion& suggestion) {
124 return GetSourceHistogramName(suggestion.source, suggestion.provider_index);
125 }
126
143 void AppendSuggestions(MostVisitedSites::SuggestionsVector src, 127 void AppendSuggestions(MostVisitedSites::SuggestionsVector src,
144 MostVisitedSites::SuggestionsVector* dst) { 128 MostVisitedSites::SuggestionsVector* dst) {
145 dst->insert(dst->end(), 129 dst->insert(dst->end(),
146 std::make_move_iterator(src.begin()), 130 std::make_move_iterator(src.begin()),
147 std::make_move_iterator(src.end())); 131 std::make_move_iterator(src.end()));
148 } 132 }
149 133
150 } // namespace 134 } // namespace
151 135
152 MostVisitedSites::Suggestion::Suggestion() : provider_index(-1) {} 136 MostVisitedSites::Suggestion::Suggestion() : provider_index(-1) {}
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 // Only blacklist in the server-side suggestions service if it's active. 229 // Only blacklist in the server-side suggestions service if it's active.
246 if (mv_source_ == SUGGESTIONS_SERVICE) { 230 if (mv_source_ == SUGGESTIONS_SERVICE) {
247 if (add_url) 231 if (add_url)
248 suggestions_service_->BlacklistURL(url); 232 suggestions_service_->BlacklistURL(url);
249 else 233 else
250 suggestions_service_->UndoBlacklistURL(url); 234 suggestions_service_->UndoBlacklistURL(url);
251 } 235 }
252 } 236 }
253 237
254 void MostVisitedSites::RecordTileTypeMetrics( 238 void MostVisitedSites::RecordTileTypeMetrics(
255 const std::vector<int>& tile_types) { 239 const std::vector<int>& tile_types,
256 DCHECK_EQ(current_suggestions_.size(), tile_types.size()); 240 const std::vector<int>& sources,
241 const std::vector<int>& provider_indices) {
257 int counts_per_type[NUM_TILE_TYPES] = {0}; 242 int counts_per_type[NUM_TILE_TYPES] = {0};
258 for (size_t i = 0; i < tile_types.size(); ++i) { 243 for (size_t i = 0; i < tile_types.size(); ++i) {
259 int tile_type = tile_types[i]; 244 int tile_type = tile_types[i];
260 ++counts_per_type[tile_type]; 245 ++counts_per_type[tile_type];
261 std::string histogram = base::StringPrintf( 246 std::string histogram = base::StringPrintf(
262 "NewTabPage.TileType.%s", 247 "NewTabPage.TileType.%s",
263 GetSourceHistogramName(current_suggestions_[i]).c_str()); 248 GetSourceHistogramName(sources[i], provider_indices[i]).c_str());
264 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES); 249 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES);
265 } 250 }
266 251
267 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal", 252 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal",
268 counts_per_type[ICON_REAL]); 253 counts_per_type[ICON_REAL]);
269 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor", 254 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor",
270 counts_per_type[ICON_COLOR]); 255 counts_per_type[ICON_COLOR]);
271 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray", 256 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray",
272 counts_per_type[ICON_DEFAULT]); 257 counts_per_type[ICON_DEFAULT]);
273 } 258 }
274 259
275 void MostVisitedSites::RecordOpenedMostVisitedItem(int index, int tile_type) { 260 void MostVisitedSites::RecordOpenedMostVisitedItem(int index, int tile_type) {
261 // TODO(treib): |current_suggestions_| could be updated before this function
262 // is called, leading to DCHECKs and/or memory corruption. Adjust this
263 // function to work with asynchronous UI.
276 DCHECK_GE(index, 0); 264 DCHECK_GE(index, 0);
277 DCHECK_LT(index, static_cast<int>(current_suggestions_.size())); 265 DCHECK_LT(index, static_cast<int>(current_suggestions_.size()));
278 std::string histogram = base::StringPrintf( 266 std::string histogram = base::StringPrintf(
279 "NewTabPage.MostVisited.%s", 267 "NewTabPage.MostVisited.%s",
280 GetSourceHistogramName(current_suggestions_[index]).c_str()); 268 GetSourceHistogramNameFromSuggestion(current_suggestions_[index])
269 .c_str());
281 LogHistogramEvent(histogram, index, num_sites_); 270 LogHistogramEvent(histogram, index, num_sites_);
282 271
283 histogram = base::StringPrintf( 272 histogram = base::StringPrintf(
284 "NewTabPage.TileTypeClicked.%s", 273 "NewTabPage.TileTypeClicked.%s",
285 GetSourceHistogramName(current_suggestions_[index]).c_str()); 274 GetSourceHistogramNameFromSuggestion(current_suggestions_[index])
275 .c_str());
286 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES); 276 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES);
287 } 277 }
288 278
289 void MostVisitedSites::OnBlockedSitesChanged() { 279 void MostVisitedSites::OnBlockedSitesChanged() {
290 BuildCurrentSuggestions(); 280 BuildCurrentSuggestions();
291 } 281 }
292 282
293 // static 283 // static
294 void MostVisitedSites::RegisterProfilePrefs( 284 void MostVisitedSites::RegisterProfilePrefs(
295 user_prefs::PrefRegistrySyncable* registry) { 285 user_prefs::PrefRegistrySyncable* registry) {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 observer_->OnPopularURLsAvailable(popular_sites_->sites()); 540 observer_->OnPopularURLsAvailable(popular_sites_->sites());
551 541
552 // Re-build the suggestions list. Once done, this will notify the observer. 542 // Re-build the suggestions list. Once done, this will notify the observer.
553 BuildCurrentSuggestions(); 543 BuildCurrentSuggestions();
554 } 544 }
555 545
556 void MostVisitedSites::RecordImpressionUMAMetrics() { 546 void MostVisitedSites::RecordImpressionUMAMetrics() {
557 for (size_t i = 0; i < current_suggestions_.size(); i++) { 547 for (size_t i = 0; i < current_suggestions_.size(); i++) {
558 std::string histogram = base::StringPrintf( 548 std::string histogram = base::StringPrintf(
559 "NewTabPage.SuggestionsImpression.%s", 549 "NewTabPage.SuggestionsImpression.%s",
560 GetSourceHistogramName(current_suggestions_[i]).c_str()); 550 GetSourceHistogramNameFromSuggestion(current_suggestions_[i]).c_str());
561 LogHistogramEvent(histogram, static_cast<int>(i), num_sites_); 551 LogHistogramEvent(histogram, static_cast<int>(i), num_sites_);
562 } 552 }
563 } 553 }
564 554
565 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {} 555 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {}
566 556
567 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, 557 void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
568 ChangeReason change_reason) { 558 ChangeReason change_reason) {
569 if (mv_source_ == TOP_SITES) { 559 if (mv_source_ == TOP_SITES) {
570 // The displayed suggestions are invalidated. 560 // The displayed suggestions are invalidated.
571 InitiateTopSitesQuery(); 561 InitiateTopSitesQuery();
572 } 562 }
573 } 563 }
574 564
575 } // namespace ntp_tiles 565 } // 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