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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPage.java

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, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPage.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPage.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPage.java
index 5325fcefa20308327e82408ba5754bbf75f378d6..2503f96c85e0df2d6c66ababa0e4a86e4a82cf92 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPage.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPage.java
@@ -104,6 +104,13 @@ public class NewTabPage
private static final int CTA_IMAGE_CLICKED = 1;
private static final int ANIMATED_LOGO_CLICKED = 2;
+ // Identifiers for the various tile sources.
+ private static final String HISTOGRAM_CLIENT_NAME = "client";
+ private static final String HISTOGRAM_SERVER_NAME = "server";
+ private static final String HISTOGRAM_SERVER_PREFIX = "server";
+ private static final String HISTOGRAM_POPULAR_NAME = "popular";
+ private static final String HISTOGRAM_WHITELIST_NAME = "whitelist";
+
private static MostVisitedSites sMostVisitedSitesForTests;
private final Tab mTab;
@@ -527,11 +534,7 @@ public class NewTabPage
// If not visible when loading completes, wait until onShown is received.
if (!mTab.isHidden()) recordNTPShown();
- int tileTypes[] = new int[items.length];
- for (int i = 0; i < items.length; i++) {
- tileTypes[i] = items[i].getTileType();
- }
- mMostVisitedSites.recordTileTypeMetrics(tileTypes);
+ recordTileTypeMetrics(items);
if (isNtpOfflinePagesEnabled()) {
final int maxNumTiles = 12;
@@ -547,6 +550,48 @@ public class NewTabPage
};
/**
+ * Records metrics about which types of tiles are displayed.
+ * @param items An array of MostVisitedItem objects to record.
+ */
+ public static void recordTileTypeMetrics(MostVisitedItem[] items) {
Marc Treib 2016/06/29 08:19:31 Hmmmm. I know I said differently on the bug, but I
Bernhard Bauer 2016/06/29 10:17:43 I somewhat prefer doing the tallying up here in Ja
Marc Treib 2016/06/29 10:23:11 Hm, we would have one count per "source+providerIn
dewittj 2016/06/30 17:48:53 I passed the types, sources, and indices back to C
Marc Treib 2016/07/01 10:01:03 SGTM
+ // Filled with zeros by default.
+ int[] countsPerType = new int[MostVisitedTileType.NUM_TILE_TYPES];
+
+ for (int i = 0; i < items.length; ++i) {
+ MostVisitedItem item = items[i];
+ int tileType = item.getTileType();
+ ++countsPerType[tileType];
Bernhard Bauer 2016/06/29 10:17:43 Small nit: I'm not sure to what extent the microop
dewittj 2016/06/30 17:48:53 Done.
+ String histogram = "NewTabPage.TileType."
+ + getSourceHistogramName(item.getSource(), item.getProviderIndex());
+ RecordHistogram.recordLinearCountHistogram(histogram, tileType, 0,
+ MostVisitedTileType.NUM_TILE_TYPES, MostVisitedTileType.NUM_TILE_TYPES + 1);
+ }
+
+ RecordHistogram.recordSparseSlowlyHistogram(
+ "NewTabPage.IconsReal", countsPerType[MostVisitedTileType.ICON_REAL]);
+ RecordHistogram.recordSparseSlowlyHistogram(
+ "NewTabPage.IconsColor", countsPerType[MostVisitedTileType.ICON_COLOR]);
+ RecordHistogram.recordSparseSlowlyHistogram(
+ "NewTabPage.IconsGray", countsPerType[MostVisitedTileType.ICON_DEFAULT]);
+ }
+
+ private static String getSourceHistogramName(int source, int providerIndex) {
+ switch (source) {
+ case MostVisitedSource.TOP_SITES:
+ return HISTOGRAM_CLIENT_NAME;
+ case MostVisitedSource.POPULAR:
+ return HISTOGRAM_POPULAR_NAME;
+ case MostVisitedSource.WHITELIST:
+ return HISTOGRAM_WHITELIST_NAME;
+ case MostVisitedSource.SUGGESTIONS_SERVICE:
+ return providerIndex >= 0 ? HISTOGRAM_SERVER_PREFIX + providerIndex
+ : HISTOGRAM_SERVER_NAME;
+ }
+ assert false; // An unknown source was used.
Bernhard Bauer 2016/06/29 10:17:43 Nit: additional space before comments. Also, you c
dewittj 2016/06/30 17:48:53 Done.
+ return "";
+ }
+
+ /**
* Constructs a NewTabPage.
* @param activity The activity used for context to create the new tab page's View.
* @param tab The Tab that is showing this new tab page.

Powered by Google App Engine
This is Rietveld 408576698