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

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: Fix test. 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
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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 235
255 // Only blacklist in the server-side suggestions service if it's active. 236 // Only blacklist in the server-side suggestions service if it's active.
256 if (mv_source_ == SUGGESTIONS_SERVICE) { 237 if (mv_source_ == SUGGESTIONS_SERVICE) {
257 if (add_url) 238 if (add_url)
258 suggestions_service_->BlacklistURL(url); 239 suggestions_service_->BlacklistURL(url);
259 else 240 else
260 suggestions_service_->UndoBlacklistURL(url); 241 suggestions_service_->UndoBlacklistURL(url);
261 } 242 }
262 } 243 }
263 244
264 void MostVisitedSites::RecordTileTypeMetrics(
265 const std::vector<int>& tile_types) {
266 DCHECK_EQ(current_suggestions_.size(), tile_types.size());
267 int counts_per_type[NUM_TILE_TYPES] = {0};
268 for (size_t i = 0; i < tile_types.size(); ++i) {
269 int tile_type = tile_types[i];
270 ++counts_per_type[tile_type];
271 std::string histogram = base::StringPrintf(
272 "NewTabPage.TileType.%s",
273 GetSourceHistogramName(current_suggestions_[i]).c_str());
274 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES);
275 }
276
277 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal",
278 counts_per_type[ICON_REAL]);
279 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor",
280 counts_per_type[ICON_COLOR]);
281 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray",
282 counts_per_type[ICON_DEFAULT]);
283 }
284
285 void MostVisitedSites::RecordOpenedMostVisitedItem(int index, int tile_type) { 245 void MostVisitedSites::RecordOpenedMostVisitedItem(int index, int tile_type) {
286 DCHECK_GE(index, 0); 246 DCHECK_GE(index, 0);
287 DCHECK_LT(index, static_cast<int>(current_suggestions_.size())); 247 DCHECK_LT(index, static_cast<int>(current_suggestions_.size()));
288 std::string histogram = base::StringPrintf( 248 std::string histogram = base::StringPrintf(
289 "NewTabPage.MostVisited.%s", 249 "NewTabPage.MostVisited.%s",
290 GetSourceHistogramName(current_suggestions_[index]).c_str()); 250 GetSourceHistogramName(current_suggestions_[index]).c_str());
291 LogHistogramEvent(histogram, index, num_sites_); 251 LogHistogramEvent(histogram, index, num_sites_);
292 252
293 histogram = base::StringPrintf( 253 histogram = base::StringPrintf(
294 "NewTabPage.TileTypeClicked.%s", 254 "NewTabPage.TileTypeClicked.%s",
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 534
575 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, 535 void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
576 ChangeReason change_reason) { 536 ChangeReason change_reason) {
577 if (mv_source_ == TOP_SITES) { 537 if (mv_source_ == TOP_SITES) {
578 // The displayed suggestions are invalidated. 538 // The displayed suggestions are invalidated.
579 InitiateTopSitesQuery(); 539 InitiateTopSitesQuery();
580 } 540 }
581 } 541 }
582 542
583 } // namespace ntp_tiles 543 } // namespace ntp_tiles
OLDNEW
« components/ntp_tiles/most_visited_sites.h ('K') | « 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