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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.metrics;
6
7 import android.app.Activity;
8 import android.support.annotation.IntDef;
9
10 import org.chromium.base.ApplicationStatus;
11 import org.chromium.base.metrics.RecordHistogram;
12
13 import java.lang.annotation.Retention;
14 import java.lang.annotation.RetentionPolicy;
15
16 /**
17 * Tracks metrics caused by a particular Activity stopping.
18 */
19 public class ActivityStopMetrics {
20 @Retention(RetentionPolicy.SOURCE)
21 @IntDef({
22 STOP_REASON_UNKNOWN,
23 STOP_REASON_BACK_BUTTON,
24 STOP_REASON_RETURN_BUTTON,
25 STOP_REASON_CUSTOM_TAB_STARTED,
26 STOP_REASON_CUSTOM_TAB_STOPPED,
27 STOP_REASON_OTHER_CHROME_ACTIVITY_IN_FOREGROUND,
28 STOP_REASON_COUNT
29 })
30 public @interface StopReason{}
31
32 /** Activity stopped for unknown reasons. */
33 public static final int STOP_REASON_UNKNOWN = 0;
34
35 /** Activity stopped after the user hit the back button. */
36 public static final int STOP_REASON_BACK_BUTTON = 1;
37
38 /** Activity stopped after the user hit the close/return UI button. */
39 public static final int STOP_REASON_RETURN_BUTTON = 2;
40
41 /** Activity stopped because it launched a {@link CustomTabActivity} on top of itself. */
42 public static final int STOP_REASON_CUSTOM_TAB_STARTED = 3;
43
44 /** Activity stopped because its child {@link CustomTabActivity} stopped its elf. */
45 public static final int STOP_REASON_CUSTOM_TAB_STOPPED = 4;
46
47 /** Activity stopped because another of Chrome Activities came into focus. * /
48 public static final int STOP_REASON_OTHER_CHROME_ACTIVITY_IN_FOREGROUND = 5;
49
50 /** Boundary. Shouldn't ever be passed to the metrics service. */
51 public static final int STOP_REASON_COUNT = 6;
52
53 /** Name of the histogram that will be recorded. */
54 private final String mHistogramName;
55
56 /** Why the Activity is being stopped. */
57 @StopReason private int mStopReason;
58
59 /**
60 * Constructs an {@link ActivityStopMetrics} instance.
61 *
62 * @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
63 */
64 public ActivityStopMetrics(String histogramName) {
65 mHistogramName = histogramName;
66 mStopReason = STOP_REASON_COUNT;
67 }
68
69 /**
70 * Records the reason that the parent Activity was stopped.
71 * @param parent Activity that owns this {@link ActivityStopMetrics} instanc e.
72 */
73 public void onStopWithNative(Activity parent) {
74 if (mStopReason == STOP_REASON_COUNT) {
75 if (parent != ApplicationStatus.getLastTrackedFocusedActivity()) {
76 mStopReason = STOP_REASON_OTHER_CHROME_ACTIVITY_IN_FOREGROUND;
77 } else {
78 mStopReason = STOP_REASON_UNKNOWN;
79 }
80 }
81 RecordHistogram.recordEnumeratedHistogram(mHistogramName, mStopReason, S TOP_REASON_COUNT);
82 mStopReason = STOP_REASON_COUNT;
83 }
84
85 /**
86 * Tracks the reason that the parent Activity was stopped.
87 * @param reason Reason the Activity was stopped (see {@link StopReason}).
88 */
89 public void setStopReason(@StopReason int reason) {
90 if (mStopReason != STOP_REASON_COUNT) return;
91 mStopReason = reason;
92 }
93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698