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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/metrics/ActivityStopMetrics.java

Issue 1727823002: [Herb] Add metrics to track button usage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments Created 4 years, 10 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/metrics/ActivityStopMetrics.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/metrics/ActivityStopMetrics.java b/chrome/android/java/src/org/chromium/chrome/browser/metrics/ActivityStopMetrics.java
new file mode 100644
index 0000000000000000000000000000000000000000..89623f86e99b0bef048f1c01a299caaba2a8d7db
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/metrics/ActivityStopMetrics.java
@@ -0,0 +1,93 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.metrics;
+
+import android.app.Activity;
+import android.support.annotation.IntDef;
+
+import org.chromium.base.ApplicationStatus;
+import org.chromium.base.metrics.RecordHistogram;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Tracks metrics caused by a particular Activity stopping.
+ */
+public class ActivityStopMetrics {
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ STOP_REASON_UNKNOWN,
+ STOP_REASON_BACK_BUTTON,
+ STOP_REASON_RETURN_BUTTON,
+ STOP_REASON_CUSTOM_TAB_STARTED,
+ STOP_REASON_CUSTOM_TAB_STOPPED,
+ STOP_REASON_OTHER_CHROME_ACTIVITY_IN_FOREGROUND,
+ STOP_REASON_COUNT
+ })
+ public @interface StopReason{}
+
+ /** Activity stopped for unknown reasons. */
+ public static final int STOP_REASON_UNKNOWN = 0;
+
+ /** Activity stopped after the user hit the back button. */
+ public static final int STOP_REASON_BACK_BUTTON = 1;
+
+ /** Activity stopped after the user hit the close/return UI button. */
+ public static final int STOP_REASON_RETURN_BUTTON = 2;
+
+ /** Activity stopped because it launched a {@link CustomTabActivity} on top of itself. */
+ public static final int STOP_REASON_CUSTOM_TAB_STARTED = 3;
+
+ /** Activity stopped because its child {@link CustomTabActivity} stopped itself. */
+ public static final int STOP_REASON_CUSTOM_TAB_STOPPED = 4;
+
+ /** Activity stopped because another of Chrome Activities came into focus. */
+ public static final int STOP_REASON_OTHER_CHROME_ACTIVITY_IN_FOREGROUND = 5;
+
+ /** Boundary. Shouldn't ever be passed to the metrics service. */
+ public static final int STOP_REASON_COUNT = 6;
+
+ /** Name of the histogram that will be recorded. */
+ private final String mHistogramName;
+
+ /** Why the Activity is being stopped. */
+ @StopReason private int mStopReason;
+
+ /**
+ * Constructs an {@link ActivityStopMetrics} instance.
+ *
+ * @param histogramName Name to use for the histogram.
Ilya Sherman 2016/02/25 21:41:25 Mmm, why did you choose to parametrize this?
gone 2016/02/25 22:18:14 Just in case we want to track this kind of stat fo
Ilya Sherman 2016/02/25 23:13:57 Seems like the sort of capability that would be be
gone 2016/02/25 23:29:45 Fair enough. I've hard-coded the histogram name f
+ */
+ public ActivityStopMetrics(String histogramName) {
+ mHistogramName = histogramName;
+ mStopReason = STOP_REASON_COUNT;
+ }
+
+ /**
+ * Records the reason that the parent Activity was stopped.
+ * @param parent Activity that owns this {@link ActivityStopMetrics} instance.
+ */
+ public void onStopWithNative(Activity parent) {
+ if (mStopReason == STOP_REASON_COUNT) {
+ if (parent != ApplicationStatus.getLastTrackedFocusedActivity()) {
+ mStopReason = STOP_REASON_OTHER_CHROME_ACTIVITY_IN_FOREGROUND;
+ } else {
+ mStopReason = STOP_REASON_UNKNOWN;
+ }
+ }
+ RecordHistogram.recordEnumeratedHistogram(mHistogramName, mStopReason, STOP_REASON_COUNT);
+ mStopReason = STOP_REASON_COUNT;
+ }
+
+ /**
+ * Tracks the reason that the parent Activity was stopped.
+ * @param reason Reason the Activity was stopped (see {@link StopReason}).
+ */
+ public void setStopReason(@StopReason int reason) {
+ if (mStopReason != STOP_REASON_COUNT) return;
+ mStopReason = reason;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698