Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java |
| index 54f9e9d5ddcd7c45f7fd59457a5509fe7ae2c273..23546820f2b345a4bee7bd228d0445bff907bd34 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java |
| @@ -30,6 +30,7 @@ import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder; |
| import java.net.URI; |
| import java.net.URISyntaxException; |
| +import java.util.concurrent.TimeUnit; |
| /** |
| * A class that represents the view for a single card snippet. |
| @@ -38,6 +39,7 @@ public class SnippetArticleViewHolder extends NewTabPageViewHolder implements Vi |
| private static final String TAG = "NtpSnippets"; |
| private static final String PUBLISHER_FORMAT_STRING = "%s - %s"; |
| private static final int FADE_IN_ANIMATION_TIME_MS = 300; |
| + private static final int[] HISTOGRAM_FOR_POSITIONS = {0, 2, 4, 9}; |
| private final NewTabPageManager mNewTabPageManager; |
| private final TextView mHeadlineTextView; |
| @@ -46,6 +48,8 @@ public class SnippetArticleViewHolder extends NewTabPageViewHolder implements Vi |
| private final ImageView mThumbnailView; |
| private FetchImageCallback mImageCallback; |
| + private long mPublishTimestampMilliseconds; |
| + private float mScore; |
| public String mUrl; |
| public int mPosition; |
| @@ -95,6 +99,21 @@ public class SnippetArticleViewHolder extends NewTabPageViewHolder implements Vi |
| RecordHistogram.recordSparseSlowlyHistogram("NewTabPage.Snippets.CardClicked", mPosition); |
| NewTabPageUma.recordSnippetAction(NewTabPageUma.SNIPPETS_ACTION_CLICKED); |
| NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_SNIPPET); |
| + |
| + // Track how the (approx.) position relates to age / score of the snippet that is clicked. |
| + long age = System.currentTimeMillis() - mPublishTimestampMilliseconds; |
| + recordAge("NewTabPage.Snippets.CardClickedAge", age); |
| + recordScore("NewTabPage.Snippets.CardClickedScore", mScore); |
| + int startPosition = 0; |
| + for (int endPosition : HISTOGRAM_FOR_POSITIONS) { |
| + if (mPosition >= startPosition && mPosition <= endPosition) { |
| + String suffix = "_" + startPosition + "_" + endPosition; |
| + recordAge("NewTabPage.Snippets.CardClickedAge" + suffix, age); |
| + recordScore("NewTabPage.Snippets.CardClickedScore" + suffix, mScore); |
| + break; |
| + } |
| + startPosition = endPosition + 1; |
| + } |
| } |
| @Override |
| @@ -109,6 +128,8 @@ public class SnippetArticleViewHolder extends NewTabPageViewHolder implements Vi |
| mArticleSnippetTextView.setText(item.mPreviewText); |
| mUrl = item.mUrl; |
| mPosition = item.mPosition; |
| + mPublishTimestampMilliseconds = item.mTimestamp; |
| + mScore = item.mScore; |
| // If there's still a pending thumbnail fetch, cancel it. |
| cancelImageFetch(); |
| @@ -146,6 +167,21 @@ public class SnippetArticleViewHolder extends NewTabPageViewHolder implements Vi |
| } |
| } |
| + private static void recordAge(String histogramName, long age) { |
| + // Negative values (when the time of the device is set inappropriately) provide no value. |
| + if (age >= 0) { |
| + long maxAge = TimeUnit.HOURS.toMillis(72); |
|
Alexei Svitkine (slow)
2016/05/20 14:47:58
Nit: Add a comment that if this were changed, the
jkrcal
2016/05/23 10:01:53
Done.
|
| + age = Math.min(age, maxAge); |
|
Alexei Svitkine (slow)
2016/05/20 14:47:58
Nit: This is not necessary - it's done already int
jkrcal
2016/05/23 10:01:53
Done.
|
| + RecordHistogram.recordCustomTimesHistogram( |
| + histogramName, age, 1, maxAge, TimeUnit.MILLISECONDS, 50); |
| + } |
| + } |
| + |
| + private static void recordScore(String histogramName, float score) { |
| + int recordedScore = Math.min((int) Math.ceil(score), 1000); |
| + RecordHistogram.recordCount1000Histogram(histogramName, recordedScore); |
| + } |
| + |
| private void cancelImageFetch() { |
| if (mImageCallback != null) { |
| mImageCallback.cancel(); |