Commit 8b535c56 authored by Nicolas Dossou-gbete's avatar Nicolas Dossou-gbete Committed by Commit Bot

📰 UMA to track how long the placeholder is displayed

Bug: 664578
Change-Id: I47437bd37bd3581d070c72c8fe977cc457d81214
Reviewed-on: https://chromium-review.googlesource.com/686875Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Reviewed-by: default avatarJan Krcal <jkrcal@chromium.org>
Commit-Queue: Nicolas Dossou-Gbété <dgn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505080}
parent a967ccf3
...@@ -418,9 +418,10 @@ public class SuggestionsSection extends InnerNode { ...@@ -418,9 +418,10 @@ public class SuggestionsSection extends InnerNode {
return suggestionIds; return suggestionIds;
} }
private void updatePlaceholderVisibility() { private boolean updatePlaceholderVisibility() {
if (!FeatureUtilities.isChromeHomeEnabled()) return; if (!FeatureUtilities.isChromeHomeEnabled()) return false;
mPlaceholder.setVisible(isLoading() && !hasSuggestions()); mPlaceholder.setVisible(isLoading() && !hasSuggestions());
return mPlaceholder.isVisible();
} }
/** /**
...@@ -575,7 +576,9 @@ public class SuggestionsSection extends InnerNode { ...@@ -575,7 +576,9 @@ public class SuggestionsSection extends InnerNode {
boolean isLoading = SnippetsBridge.isCategoryLoading(status); boolean isLoading = SnippetsBridge.isCategoryLoading(status);
mMoreButton.updateState(isLoading ? ActionItem.State.LOADING : ActionItem.State.BUTTON); mMoreButton.updateState(isLoading ? ActionItem.State.LOADING : ActionItem.State.BUTTON);
updatePlaceholderVisibility(); if (updatePlaceholderVisibility()) {
mPlaceholder.trackVisibilityDuration();
}
} }
/** Clears the suggestions and related data, resetting the state of the section. */ /** Clears the suggestions and related data, resetting the state of the section. */
......
...@@ -13,6 +13,7 @@ import org.chromium.chrome.browser.ntp.cards.ItemViewType; ...@@ -13,6 +13,7 @@ import org.chromium.chrome.browser.ntp.cards.ItemViewType;
import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder; import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder;
import org.chromium.chrome.browser.ntp.cards.NodeVisitor; import org.chromium.chrome.browser.ntp.cards.NodeVisitor;
import org.chromium.chrome.browser.ntp.cards.OptionalLeaf; import org.chromium.chrome.browser.ntp.cards.OptionalLeaf;
import org.chromium.chrome.browser.suggestions.SuggestionsMetrics.DurationTracker;
import org.chromium.chrome.browser.widget.displaystyle.UiConfig; import org.chromium.chrome.browser.widget.displaystyle.UiConfig;
/** /**
...@@ -22,8 +23,20 @@ public class ContentSuggestionPlaceholder extends OptionalLeaf { ...@@ -22,8 +23,20 @@ public class ContentSuggestionPlaceholder extends OptionalLeaf {
/** Color used to fill highlighted empty UI elements of the placeholder. */ /** Color used to fill highlighted empty UI elements of the placeholder. */
private static final @ColorRes int HIGHLIGHT_COLOR = R.color.black_alpha_20; private static final @ColorRes int HIGHLIGHT_COLOR = R.color.black_alpha_20;
private final DurationTracker mVisibilityDurationTracker =
SuggestionsMetrics.getPlaceholderVisibilityReporter();
public void setVisible(boolean visible) { public void setVisible(boolean visible) {
setVisibilityInternal(visible); setVisibilityInternal(visible);
if (!visible) mVisibilityDurationTracker.endTracking();
}
/**
* Start tracking how long we show the placeholder. When it is hidden, it will report that
* duration through UMA.
*/
public void trackVisibilityDuration() {
mVisibilityDurationTracker.startTracking();
} }
@Override @Override
......
...@@ -90,15 +90,12 @@ public abstract class SuggestionsMetrics { ...@@ -90,15 +90,12 @@ public abstract class SuggestionsMetrics {
public static void recordVisit(Tab tab, SnippetArticle suggestion) { public static void recordVisit(Tab tab, SnippetArticle suggestion) {
@CategoryInt @CategoryInt
final int category = suggestion.mCategory; final int category = suggestion.mCategory;
NavigationRecorder.record(tab, new Callback<NavigationRecorder.VisitData>() { NavigationRecorder.record(tab, visit -> {
@Override if (NewTabPage.isNTPUrl(visit.endUrl)) {
public void onResult(NavigationRecorder.VisitData visit) { RecordUserAction.record("MobileNTP.Snippets.VisitEndBackInNTP");
if (NewTabPage.isNTPUrl(visit.endUrl)) {
RecordUserAction.record("MobileNTP.Snippets.VisitEndBackInNTP");
}
RecordUserAction.record("MobileNTP.Snippets.VisitEnd");
SuggestionsEventReporterBridge.onSuggestionTargetVisited(category, visit.duration);
} }
RecordUserAction.record("MobileNTP.Snippets.VisitEnd");
SuggestionsEventReporterBridge.onSuggestionTargetVisited(category, visit.duration);
}); });
} }
...@@ -135,6 +132,18 @@ public abstract class SuggestionsMetrics { ...@@ -135,6 +132,18 @@ public abstract class SuggestionsMetrics {
MostVisitedSitesBridge.MAX_TILE_COUNT); MostVisitedSitesBridge.MAX_TILE_COUNT);
} }
/**
* @return A {@link DurationTracker} to notify to report how long the placeholder is visible
* for.
*/
public static DurationTracker getPlaceholderVisibilityReporter() {
return new DurationTracker((duration) -> {
RecordHistogram.recordTimesHistogram(
"ContentSuggestions.FetchPendingPlaceholder.VisibleDuration", duration,
TimeUnit.MILLISECONDS);
});
}
/** /**
* Measures the amount of time it takes for date formatting in order to track StrictMode * Measures the amount of time it takes for date formatting in order to track StrictMode
* violations. * violations.
...@@ -165,4 +174,33 @@ public abstract class SuggestionsMetrics { ...@@ -165,4 +174,33 @@ public abstract class SuggestionsMetrics {
mFired = false; mFired = false;
} }
} }
/**
* Utility class to track the duration of an event. Call {@link #startTracking()} and
* {@link #endTracking()} to notify about the key moments. These methods are no-ops when called
* while tracking is not in the expected state.
*/
public static class DurationTracker {
private long mTrackingStartTimeMs;
private final Callback<Long> mTrackingCompleteCallback;
private DurationTracker(Callback<Long> trackingCompleteCallback) {
mTrackingCompleteCallback = trackingCompleteCallback;
}
public void startTracking() {
if (isTracking()) return;
mTrackingStartTimeMs = System.currentTimeMillis();
}
public void endTracking() {
if (!isTracking()) return;
mTrackingCompleteCallback.onResult(System.currentTimeMillis() - mTrackingStartTimeMs);
mTrackingStartTimeMs = 0;
}
private boolean isTracking() {
return mTrackingStartTimeMs > 0;
}
}
} }
...@@ -10361,6 +10361,18 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. ...@@ -10361,6 +10361,18 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary> </summary>
</histogram> </histogram>
<histogram name="ContentSuggestions.FetchPendingPlaceholder.VisibleDuration"
units="ms">
<owner>dgn@chromium.org</owner>
<owner>ntp-dev+metrics@chromium.org</owner>
<summary>
Android: How long the content suggestion placeholder is shown. This is
tracked based on when the placeholder is enabled in the UI, not how long it
is actually visible on screen. Depending on the screen size, the used value
could be bigger.
</summary>
</histogram>
<histogram name="ContextMenu.SaveLinkType" enum="ContextMenuSaveLinkType"> <histogram name="ContextMenu.SaveLinkType" enum="ContextMenuSaveLinkType">
<owner>qinmin@chromium.org</owner> <owner>qinmin@chromium.org</owner>
<summary> <summary>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment