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

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: Hard-coded histogram name 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..5a3c2dffbdef0d5b7babda4cddda732f43e4e77a
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/metrics/ActivityStopMetrics.java
@@ -0,0 +1,90 @@
+// 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 static final String HISTOGRAM_NAME = "Android.Activity.ChromeTabbedActivity.StopReason";
+
+ /** Why the Activity is being stopped. */
+ @StopReason private int mStopReason;
+
+ /**
+ * Constructs an {@link ActivityStopMetrics} instance.
+ */
+ public ActivityStopMetrics() {
+ 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(HISTOGRAM_NAME, 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