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

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/tabmodel/TabModelSelectorUma.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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 2015 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.tabmodel;
6
7 import android.app.Activity;
8 import android.os.SystemClock;
9
10 import org.chromium.base.ActivityState;
11 import org.chromium.base.ApplicationStatus;
12 import org.chromium.base.metrics.RecordHistogram;
13 import org.chromium.base.metrics.RecordUserAction;
14
15 /**
16 * Centralizes UMA data collection for TabModelSelector. All calls must be made from the UI thread.
17 */
18 public final class TabModelSelectorUma implements ApplicationStatus.ActivityStat eListener {
19 // TabRestoreUserAction defined in tools/metrics/histograms/histograms.xml.
20 private static final int USER_WAITED_FOR_RESTORE_COMPLETION = 0;
21 private static final int USER_LEFT_TAB_DURING_RESTORE = 1;
22 private static final int USER_LEFT_CHROME_DURING_RESTORE = 2;
23 private static final int USER_ACTION_DURING_RESTORE_MAX = 3;
24
25 // Id of the active tab being restored. Equals -1 when the active tab is not being restored.
26 private int mRestoredTabId = -1;
27 // Timestamp of the beginning of the most recent tab restore.
28 private long mRestoreStartedAtMsec = -1;
29
30 TabModelSelectorUma(Activity activity) {
31 ApplicationStatus.registerStateListenerForActivity(this, activity);
32 }
33
34 /**
35 * Cleans up any external dependencies of this class.
36 */
37 public void destroy() {
38 ApplicationStatus.unregisterActivityStateListener(this);
39 }
40
41 @Override
42 public void onActivityStateChange(Activity activity, int newState) {
43 if (newState != ActivityState.STOPPED) return;
44 if (mRestoredTabId != -1) {
45 recordUserActionDuringTabRestore(USER_LEFT_CHROME_DURING_RESTORE);
46 mRestoredTabId = -1;
47 }
48 }
49
50 void userSwitchedToTab() {
51 RecordUserAction.record("MobileTabSwitched");
52 }
53
54 void onShowTab(int tabId, boolean isBeingRestored) {
55 if (mRestoredTabId != -1 && tabId != mRestoredTabId) {
56 recordUserActionDuringTabRestore(USER_LEFT_TAB_DURING_RESTORE);
57 mRestoredTabId = -1;
58 }
59 if (isBeingRestored) {
60 mRestoredTabId = tabId;
61 mRestoreStartedAtMsec = nowMsec();
62 }
63 }
64
65 void onTabClosing(int tabId) {
66 if (mRestoredTabId != -1 && tabId == mRestoredTabId) {
67 recordUserActionDuringTabRestore(USER_LEFT_TAB_DURING_RESTORE);
68 mRestoredTabId = -1;
69 }
70 }
71
72 void onTabCrashed(int tabId) {
73 if (mRestoredTabId != -1 && tabId == mRestoredTabId) {
74 mRestoredTabId = -1;
75 }
76 }
77
78 void onPageLoadFinished(int tabId) {
79 if (mRestoredTabId != -1 && tabId == mRestoredTabId) {
80 recordUserActionDuringTabRestore(USER_WAITED_FOR_RESTORE_COMPLETION) ;
81 mRestoredTabId = -1;
82 }
83 }
84
85 void onPageLoadFailed(int tabId) {
86 if (mRestoredTabId != -1 && tabId == mRestoredTabId) {
87 assert mRestoreStartedAtMsec != -1;
88 // If the pageload fails very quickly we cannot argue that the user "waited for
89 // completion".
90 if (nowMsec() - mRestoreStartedAtMsec >= 5000) {
91 recordUserActionDuringTabRestore(USER_WAITED_FOR_RESTORE_COMPLET ION);
92 }
93 mRestoredTabId = -1;
94 }
95 }
96
97 void onTabsViewShown() {
98 if (mRestoredTabId != -1) {
99 recordUserActionDuringTabRestore(USER_LEFT_TAB_DURING_RESTORE);
100 mRestoredTabId = -1;
101 }
102 }
103
104 private static long nowMsec() {
105 return SystemClock.elapsedRealtime();
106 }
107
108 /**
109 * Logs action to a UMA histogram.
110 */
111 private void recordUserActionDuringTabRestore(int action) {
112 assert action >= 0 && action < USER_ACTION_DURING_RESTORE_MAX;
113 RecordHistogram.recordEnumeratedHistogram(
114 "Tab.RestoreUserPersistence", action, USER_ACTION_DURING_RESTORE _MAX);
115 }
116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698