Skip to content

Commit

Permalink
[Home] Add some histograms for Chrome Home
Browse files Browse the repository at this point in the history
Adds histograms for:
 * The reason Chrome Home was opened
 * The duration Chrome Home is opened
 * The time between app creation and the first CH open
 * The time between the last CH close and the next open

BUG=700592, 700593

Review-Url: https://codereview.chromium.org/2784383002
Cr-Commit-Position: refs/heads/master@{#460925}
  • Loading branch information
twellington authored and Commit bot committed Mar 30, 2017
1 parent 6a44d44 commit 831d8b9
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.widget.TintedImageButton;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetMetrics;

/**
* The new tab page to display when Chrome Home is enabled.
Expand Down Expand Up @@ -116,7 +117,6 @@ public void onHidden(Tab tab) {

mLogoDelegate = initializeLogoView();
initializeCloseButton();
onNewTabPageShown();

// TODO(twellington): disallow moving the NTP to the other window in Android N+
// multi-window mode.
Expand Down Expand Up @@ -191,6 +191,8 @@ private void onNewTabPageShown() {
if (getLayoutManager() != null && getLayoutManager().overviewVisible()) return;

mBottomSheet.setSheetState(BottomSheet.SHEET_STATE_HALF, true);
mBottomSheet.getBottomSheetMetrics().recordSheetOpenReason(
BottomSheetMetrics.OPENED_BY_NEW_TAB_CREATION);
}

private boolean isTabChromeHomeNewTabPage(Tab tab) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.chromium.chrome.R;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetMetrics;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetObserver;
import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;

Expand Down Expand Up @@ -129,7 +130,13 @@ protected void triggerUrlFocusAnimation(final boolean hasFocus) {

if (mBottomSheet == null || !hasFocus) return;

boolean wasSheetOpen = mBottomSheet.isSheetOpen();
mBottomSheet.setSheetState(BottomSheet.SHEET_STATE_FULL, true);

if (!wasSheetOpen) {
mBottomSheet.getBottomSheetMetrics().recordSheetOpenReason(
BottomSheetMetrics.OPENED_BY_OMNIBOX_FOCUS);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public class BottomSheet
/** The minimum distance between half and full states to allow the half state. */
private final float mMinHalfFullDistance;

/** The {@link BottomSheetMetrics} used to record user actions and histograms. */
private final BottomSheetMetrics mMetrics;

/** For detecting scroll and fling events on the bottom sheet. */
private GestureDetector mGestureDetector;

Expand Down Expand Up @@ -264,16 +267,22 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
}

float newOffset = getSheetOffsetFromBottom() + distanceY;
boolean wasOpenBeforeSwipe = mIsSheetOpen;
setSheetOffsetFromBottom(MathUtils.clamp(newOffset, getMinOffset(), getMaxOffset()));

setInternalCurrentState(SHEET_STATE_SCROLLING);

if (!wasOpenBeforeSwipe && mIsSheetOpen) {
mMetrics.recordSheetOpenReason(BottomSheetMetrics.OPENED_BY_SWIPE);
}

mIsScrolling = true;
return true;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
cancelAnimation();
boolean wasOpenBeforeSwipe = mIsSheetOpen;

// Figure out the projected state of the sheet and animate there. Note that a swipe up
// will have a negative velocity, swipe down will have a positive velocity. Negate this
Expand All @@ -284,6 +293,10 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
setSheetState(targetState, true);
mIsScrolling = false;

if (!wasOpenBeforeSwipe && mIsSheetOpen) {
mMetrics.recordSheetOpenReason(BottomSheetMetrics.OPENED_BY_SWIPE);
}

return true;
}
}
Expand All @@ -310,7 +323,8 @@ public BottomSheet(Context context, AttributeSet atts) {
mGestureDetector = new GestureDetector(context, new BottomSheetSwipeDetector());
mGestureDetector.setIsLongpressEnabled(false);

addObserver(new BottomSheetMetrics());
mMetrics = new BottomSheetMetrics();
addObserver(mMetrics);
}

@Override
Expand Down Expand Up @@ -846,6 +860,11 @@ public int getSheetState() {
return mCurrentState;
}

/** @return Whether the sheet is currently open. */
public boolean isSheetOpen() {
return mIsSheetOpen;
}

/**
* Set the current state of the bottom sheet. This is for internal use to notify observers of
* state change events.
Expand Down Expand Up @@ -873,6 +892,13 @@ public BottomSheetContent getCurrentSheetContent() {
return mSheetContent;
}

/**
* @return The {@link BottomSheetMetrics} used to record user actions and histograms.
*/
public BottomSheetMetrics getBottomSheetMetrics() {
return mMetrics;
}

/**
* Gets the height of the bottom sheet based on a provided state.
* @param state The state to get the height from.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,77 @@

package org.chromium.chrome.browser.widget.bottomsheet;

import android.support.annotation.IntDef;

import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet.BottomSheetContent;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.concurrent.TimeUnit;

/**
* Records user action and histograms related to the {@link BottomSheet}.
*/
public class BottomSheetMetrics extends EmptyBottomSheetObserver {
/**
* The different ways that the bottom sheet can be opened. This is used to back a UMA
* histogram and should therefore be treated as append-only.
*/
@IntDef({OPENED_BY_SWIPE, OPENED_BY_OMNIBOX_FOCUS, OPENED_BY_NEW_TAB_CREATION})
@Retention(RetentionPolicy.SOURCE)
public @interface SheetOpenReason {}
public static final int OPENED_BY_SWIPE = 0;
public static final int OPENED_BY_OMNIBOX_FOCUS = 1;
public static final int OPENED_BY_NEW_TAB_CREATION = 2;
private static final int OPENED_BY_BOUNDARY = 3;

/** Whether the sheet is currently open. */
private boolean mIsSheetOpen;

/** The last {@link BottomSheetContent} that was displayed. */
private BottomSheetContent mLastContent;

/** When this class was created. Used as a proxy for when the app was started. */
private long mCreationTime;

/** The last time the sheet was opened. */
private long mLastOpenTime;

/** The last time the sheet was closed. */
private long mLastCloseTime;

public BottomSheetMetrics() {
mCreationTime = System.currentTimeMillis();
}

@Override
public void onSheetOpened() {
mIsSheetOpen = true;
RecordUserAction.record("Android.ChromeHome.Opened");

boolean isFirstOpen = mLastOpenTime == 0;
mLastOpenTime = System.currentTimeMillis();

if (isFirstOpen) {
RecordHistogram.recordMediumTimesHistogram("Android.ChromeHome.TimeToFirstOpen",
mLastOpenTime - mCreationTime, TimeUnit.MILLISECONDS);
} else {
RecordHistogram.recordMediumTimesHistogram(
"Android.ChromeHome.TimeBetweenCloseAndNextOpen",
mLastOpenTime - mLastCloseTime, TimeUnit.MILLISECONDS);
}
}

@Override
public void onSheetClosed() {
mIsSheetOpen = false;
RecordUserAction.record("Android.ChromeHome.Closed");

mLastCloseTime = System.currentTimeMillis();
RecordHistogram.recordMediumTimesHistogram("Android.ChromeHome.DurationOpen",
mLastCloseTime - mLastOpenTime, TimeUnit.MILLISECONDS);
}

@Override
Expand Down Expand Up @@ -59,4 +110,12 @@ public void onSheetContentChanged(BottomSheetContent newContent) {
mLastContent = newContent;
}

/**
* Records the reason the sheet was opened.
* @param reason The {@link SheetOpenReason} that caused the bottom sheet to open.
*/
public void recordSheetOpenReason(@SheetOpenReason int reason) {
RecordHistogram.recordEnumeratedHistogram(
"Android.ChromeHome.OpenReason", reason, OPENED_BY_BOUNDARY);
}
}
36 changes: 36 additions & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,36 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>

<histogram name="Android.ChromeHome.DurationOpen" units="ms">
<owner>mdjones@chromium.org</owner>
<owner>twellington@chromium.org</owner>
<summary>The duration the Chrome Home bottom sheet was open.</summary>
</histogram>

<histogram name="Android.ChromeHome.OpenReason" enum="ChromeHomeOpenReason">
<owner>mdjones@chromium.org</owner>
<owner>twellington@chromium.org</owner>
<summary>The reason the bottom sheet was opened.</summary>
</histogram>

<histogram name="Android.ChromeHome.TimeBetweenCloseAndNextOpen" units="ms">
<owner>mdjones@chromium.org</owner>
<owner>twellington@chromium.org</owner>
<summary>
The time between the last time the Chrome Home bottom sheet was closed and
the next time it was opened.
</summary>
</histogram>

<histogram name="Android.ChromeHome.TimeToFirstOpen" units="ms">
<owner>mdjones@chromium.org</owner>
<owner>twellington@chromium.org</owner>
<summary>
The time between app creation and the first open of the Chrome Home bottom
sheet for this run of Chrome.
</summary>
</histogram>

<histogram name="Android.CustomFeedback.Category"
enum="AndroidFeedbackCategory">
<owner>jwanda@chromium.org</owner>
Expand Down Expand Up @@ -84466,6 +84496,12 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<int value="4" label="Initiated by Plugin Installer"/>
</enum>

<enum name="ChromeHomeOpenReason" type="int">
<int value="0" label="Swipe"/>
<int value="1" label="Omnibox Focus"/>
<int value="2" label="New Tab Creation"/>
</enum>

<enum name="ChromeNotifierServiceActionType" type="int">
<int value="0" label="Unknown"/>
<int value="1" label="First service enabled"/>
Expand Down

0 comments on commit 831d8b9

Please sign in to comment.