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 "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 Loading... | |
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 Loading... | |
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 // Only blacklist in the server-side suggestions service if it's active. | 239 // Only blacklist in the server-side suggestions service if it's active. |
256 if (mv_source_ == SUGGESTIONS_SERVICE) { | 240 if (mv_source_ == SUGGESTIONS_SERVICE) { |
257 if (add_url) | 241 if (add_url) |
258 suggestions_service_->BlacklistURL(url); | 242 suggestions_service_->BlacklistURL(url); |
259 else | 243 else |
260 suggestions_service_->UndoBlacklistURL(url); | 244 suggestions_service_->UndoBlacklistURL(url); |
261 } | 245 } |
262 } | 246 } |
263 | 247 |
264 void MostVisitedSites::RecordTileTypeMetrics( | 248 void MostVisitedSites::RecordTileTypeMetrics( |
265 const std::vector<int>& tile_types) { | 249 const std::vector<int>& tile_types, |
266 DCHECK_EQ(current_suggestions_.size(), tile_types.size()); | 250 const std::vector<int>& sources, |
251 const std::vector<int>& provider_indices) { | |
267 int counts_per_type[NUM_TILE_TYPES] = {0}; | 252 int counts_per_type[NUM_TILE_TYPES] = {0}; |
268 for (size_t i = 0; i < tile_types.size(); ++i) { | 253 for (size_t i = 0; i < tile_types.size(); ++i) { |
269 int tile_type = tile_types[i]; | 254 int tile_type = tile_types[i]; |
270 ++counts_per_type[tile_type]; | 255 ++counts_per_type[tile_type]; |
271 std::string histogram = base::StringPrintf( | 256 std::string histogram = base::StringPrintf( |
272 "NewTabPage.TileType.%s", | 257 "NewTabPage.TileType.%s", |
273 GetSourceHistogramName(current_suggestions_[i]).c_str()); | 258 GetSourceHistogramName(sources[i], provider_indices[i]).c_str()); |
274 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES); | 259 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES); |
275 } | 260 } |
276 | 261 |
277 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal", | 262 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal", |
278 counts_per_type[ICON_REAL]); | 263 counts_per_type[ICON_REAL]); |
279 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor", | 264 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor", |
280 counts_per_type[ICON_COLOR]); | 265 counts_per_type[ICON_COLOR]); |
281 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray", | 266 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray", |
282 counts_per_type[ICON_DEFAULT]); | 267 counts_per_type[ICON_DEFAULT]); |
283 } | 268 } |
284 | 269 |
285 void MostVisitedSites::RecordOpenedMostVisitedItem(int index, int tile_type) { | 270 void MostVisitedSites::RecordOpenedMostVisitedItem(int index, int tile_type) { |
286 DCHECK_GE(index, 0); | 271 DCHECK_GE(index, 0); |
287 DCHECK_LT(index, static_cast<int>(current_suggestions_.size())); | 272 DCHECK_LT(index, static_cast<int>(current_suggestions_.size())); |
Marc Treib
2016/07/01 10:01:04
Huh, now that I look at this, it seems that this m
dewittj
2016/07/01 21:35:21
Done.
| |
288 std::string histogram = base::StringPrintf( | 273 std::string histogram = base::StringPrintf( |
289 "NewTabPage.MostVisited.%s", | 274 "NewTabPage.MostVisited.%s", |
290 GetSourceHistogramName(current_suggestions_[index]).c_str()); | 275 GetSourceHistogramNameFromSuggestion(current_suggestions_[index]) |
276 .c_str()); | |
291 LogHistogramEvent(histogram, index, num_sites_); | 277 LogHistogramEvent(histogram, index, num_sites_); |
292 | 278 |
293 histogram = base::StringPrintf( | 279 histogram = base::StringPrintf( |
294 "NewTabPage.TileTypeClicked.%s", | 280 "NewTabPage.TileTypeClicked.%s", |
295 GetSourceHistogramName(current_suggestions_[index]).c_str()); | 281 GetSourceHistogramNameFromSuggestion(current_suggestions_[index]) |
282 .c_str()); | |
296 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES); | 283 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES); |
297 } | 284 } |
298 | 285 |
299 void MostVisitedSites::OnBlockedSitesChanged() { | 286 void MostVisitedSites::OnBlockedSitesChanged() { |
300 BuildCurrentSuggestions(); | 287 BuildCurrentSuggestions(); |
301 } | 288 } |
302 | 289 |
303 // static | 290 // static |
304 void MostVisitedSites::RegisterProfilePrefs( | 291 void MostVisitedSites::RegisterProfilePrefs( |
305 user_prefs::PrefRegistrySyncable* registry) { | 292 user_prefs::PrefRegistrySyncable* registry) { |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 observer_->OnPopularURLsAvailable(popular_sites_->sites()); | 545 observer_->OnPopularURLsAvailable(popular_sites_->sites()); |
559 | 546 |
560 // Re-build the suggestions list. Once done, this will notify the observer. | 547 // Re-build the suggestions list. Once done, this will notify the observer. |
561 BuildCurrentSuggestions(); | 548 BuildCurrentSuggestions(); |
562 } | 549 } |
563 | 550 |
564 void MostVisitedSites::RecordImpressionUMAMetrics() { | 551 void MostVisitedSites::RecordImpressionUMAMetrics() { |
565 for (size_t i = 0; i < current_suggestions_.size(); i++) { | 552 for (size_t i = 0; i < current_suggestions_.size(); i++) { |
566 std::string histogram = base::StringPrintf( | 553 std::string histogram = base::StringPrintf( |
567 "NewTabPage.SuggestionsImpression.%s", | 554 "NewTabPage.SuggestionsImpression.%s", |
568 GetSourceHistogramName(current_suggestions_[i]).c_str()); | 555 GetSourceHistogramNameFromSuggestion(current_suggestions_[i]).c_str()); |
569 LogHistogramEvent(histogram, static_cast<int>(i), num_sites_); | 556 LogHistogramEvent(histogram, static_cast<int>(i), num_sites_); |
570 } | 557 } |
571 } | 558 } |
572 | 559 |
573 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {} | 560 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {} |
574 | 561 |
575 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, | 562 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, |
576 ChangeReason change_reason) { | 563 ChangeReason change_reason) { |
577 if (mv_source_ == TOP_SITES) { | 564 if (mv_source_ == TOP_SITES) { |
578 // The displayed suggestions are invalidated. | 565 // The displayed suggestions are invalidated. |
579 InitiateTopSitesQuery(); | 566 InitiateTopSitesQuery(); |
580 } | 567 } |
581 } | 568 } |
582 | 569 |
583 } // namespace ntp_tiles | 570 } // namespace ntp_tiles |
OLD | NEW |