OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.metrics; | 5 package org.chromium.chrome.browser.metrics; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.os.Handler; | 8 import android.os.Handler; |
9 import android.support.annotation.IntDef; | 9 import android.support.annotation.IntDef; |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 import java.lang.annotation.Retention; | 22 import java.lang.annotation.Retention; |
23 import java.lang.annotation.RetentionPolicy; | 23 import java.lang.annotation.RetentionPolicy; |
24 import java.util.Locale; | 24 import java.util.Locale; |
25 import java.util.concurrent.TimeUnit; | 25 import java.util.concurrent.TimeUnit; |
26 | 26 |
27 /** | 27 /** |
28 * Records the behavior metrics after an ACTION_MAIN intent is received. | 28 * Records the behavior metrics after an ACTION_MAIN intent is received. |
29 */ | 29 */ |
30 public class MainIntentBehaviorMetrics implements ApplicationStatus.ActivityStat
eListener { | 30 public class MainIntentBehaviorMetrics implements ApplicationStatus.ActivityStat
eListener { |
31 | 31 |
| 32 private static final long BACKGROUND_TIME_24_HOUR_MS = 86400000; |
| 33 private static final long BACKGROUND_TIME_12_HOUR_MS = 43200000; |
| 34 private static final long BACKGROUND_TIME_6_HOUR_MS = 21600000; |
| 35 private static final long BACKGROUND_TIME_1_HOUR_MS = 3600000; |
| 36 |
32 private static final long TIMEOUT_DURATION_MS = 10000; | 37 private static final long TIMEOUT_DURATION_MS = 10000; |
33 | 38 |
34 @Retention(RetentionPolicy.SOURCE) | 39 @Retention(RetentionPolicy.SOURCE) |
35 @IntDef({ | 40 @IntDef({ |
36 CONTINUATION, | 41 CONTINUATION, |
37 FOCUS_OMNIBOX, | 42 FOCUS_OMNIBOX, |
38 SWITCH_TABS, | 43 SWITCH_TABS, |
39 NTP_CREATED, | 44 NTP_CREATED, |
40 BACKGROUNDED | 45 BACKGROUNDED |
41 }) | 46 }) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 80 } |
76 | 81 |
77 /** | 82 /** |
78 * Signal that an intent with ACTION_MAIN was received. | 83 * Signal that an intent with ACTION_MAIN was received. |
79 * | 84 * |
80 * This must only be called after the native libraries have been initialized
. | 85 * This must only be called after the native libraries have been initialized
. |
81 */ | 86 */ |
82 public void onMainIntentWithNative(long backgroundDurationMs) { | 87 public void onMainIntentWithNative(long backgroundDurationMs) { |
83 RecordUserAction.record("MobileStartup.MainIntentReceived"); | 88 RecordUserAction.record("MobileStartup.MainIntentReceived"); |
84 | 89 |
| 90 if (backgroundDurationMs >= BACKGROUND_TIME_24_HOUR_MS) { |
| 91 RecordUserAction.record("MobileStartup.MainIntentReceived.After24Hou
rs"); |
| 92 } else if (backgroundDurationMs >= BACKGROUND_TIME_12_HOUR_MS) { |
| 93 RecordUserAction.record("MobileStartup.MainIntentReceived.After12Hou
rs"); |
| 94 } else if (backgroundDurationMs >= BACKGROUND_TIME_6_HOUR_MS) { |
| 95 RecordUserAction.record("MobileStartup.MainIntentReceived.After6Hour
s"); |
| 96 } else if (backgroundDurationMs >= BACKGROUND_TIME_1_HOUR_MS) { |
| 97 RecordUserAction.record("MobileStartup.MainIntentReceived.After1Hour
"); |
| 98 } |
| 99 |
85 if (mPendingActionRecordForMainIntent) return; | 100 if (mPendingActionRecordForMainIntent) return; |
86 mBackgroundDurationMs = backgroundDurationMs; | 101 mBackgroundDurationMs = backgroundDurationMs; |
87 | 102 |
88 ApplicationStatus.registerStateListenerForActivity(this, mActivity); | 103 ApplicationStatus.registerStateListenerForActivity(this, mActivity); |
89 mPendingActionRecordForMainIntent = true; | 104 mPendingActionRecordForMainIntent = true; |
90 | 105 |
91 mHandler.postDelayed(mTimeoutRunnable , TIMEOUT_DURATION_MS); | 106 mHandler.postDelayed(mTimeoutRunnable , TIMEOUT_DURATION_MS); |
92 | 107 |
93 mTabModelObserver = new TabModelSelectorTabModelObserver( | 108 mTabModelObserver = new TabModelSelectorTabModelObserver( |
94 mActivity.getTabModelSelector()) { | 109 mActivity.getTabModelSelector()) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 180 } |
166 | 181 |
167 ApplicationStatus.unregisterActivityStateListener(this); | 182 ApplicationStatus.unregisterActivityStateListener(this); |
168 | 183 |
169 mHandler.removeCallbacksAndMessages(null); | 184 mHandler.removeCallbacksAndMessages(null); |
170 | 185 |
171 mTabModelObserver.destroy(); | 186 mTabModelObserver.destroy(); |
172 mTabModelObserver = null; | 187 mTabModelObserver = null; |
173 } | 188 } |
174 } | 189 } |
OLD | NEW |