| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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.content.ComponentCallbacks; | 8 import android.content.ComponentCallbacks; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.res.Configuration; | 10 import android.content.res.Configuration; |
| 11 import android.text.TextUtils; | |
| 12 | 11 |
| 13 import org.chromium.base.ActivityState; | 12 import org.chromium.base.ActivityState; |
| 14 import org.chromium.base.ApplicationStatus; | 13 import org.chromium.base.ApplicationStatus; |
| 15 import org.chromium.chrome.browser.Tab; | 14 import org.chromium.chrome.browser.Tab; |
| 16 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | |
| 17 import org.chromium.chrome.browser.preferences.privacy.CrashReportingPermissionM
anager; | 15 import org.chromium.chrome.browser.preferences.privacy.CrashReportingPermissionM
anager; |
| 18 import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager
; | 16 import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager
; |
| 19 import org.chromium.chrome.browser.tabmodel.TabModel; | 17 import org.chromium.chrome.browser.tabmodel.TabModel; |
| 20 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | 18 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| 21 import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver; | 19 import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver; |
| 22 import org.chromium.components.variations.VariationsAssociatedData; | |
| 23 import org.chromium.content_public.browser.WebContents; | 20 import org.chromium.content_public.browser.WebContents; |
| 24 import org.chromium.net.NetworkChangeNotifier; | 21 import org.chromium.net.NetworkChangeNotifier; |
| 25 | 22 |
| 26 /** | 23 /** |
| 27 * Mainly sets up session stats for chrome. A session is defined as the duration
when the | 24 * Mainly sets up session stats for chrome. A session is defined as the duration
when the |
| 28 * application is in the foreground. Also used to communicate information betwe
en Chrome | 25 * application is in the foreground. Also used to communicate information betwe
en Chrome |
| 29 * and the framework's MetricService. | 26 * and the framework's MetricService. |
| 30 */ | 27 */ |
| 31 public class UmaSessionStats implements NetworkChangeNotifier.ConnectionTypeObse
rver { | 28 public class UmaSessionStats implements NetworkChangeNotifier.ConnectionTypeObse
rver { |
| 32 private static final String SAMSUNG_MULTWINDOW_PACKAGE = "com.sec.feature.mu
ltiwindow"; | 29 private static final String SAMSUNG_MULTWINDOW_PACKAGE = "com.sec.feature.mu
ltiwindow"; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(mTabM
odelSelector) { | 95 mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(mTabM
odelSelector) { |
| 99 @Override | 96 @Override |
| 100 public void onPageLoadFinished(Tab tab) { | 97 public void onPageLoadFinished(Tab tab) { |
| 101 recordPageLoadStats(tab.getId()); | 98 recordPageLoadStats(tab.getId()); |
| 102 } | 99 } |
| 103 }; | 100 }; |
| 104 } | 101 } |
| 105 | 102 |
| 106 nativeUmaResumeSession(sNativeUmaSessionStats); | 103 nativeUmaResumeSession(sNativeUmaSessionStats); |
| 107 NetworkChangeNotifier.addConnectionTypeObserver(this); | 104 NetworkChangeNotifier.addConnectionTypeObserver(this); |
| 108 updatePreferences(); | |
| 109 updateMetricsServiceState(); | 105 updateMetricsServiceState(); |
| 110 } | 106 } |
| 111 | 107 |
| 112 private static void ensureNativeInitialized() { | 108 private static void ensureNativeInitialized() { |
| 113 // Lazily create the native object and the notification handler. These o
bjects are never | 109 // Lazily create the native object and the notification handler. These o
bjects are never |
| 114 // destroyed. | 110 // destroyed. |
| 115 if (sNativeUmaSessionStats == 0) { | 111 if (sNativeUmaSessionStats == 0) { |
| 116 sNativeUmaSessionStats = nativeInit(); | 112 sNativeUmaSessionStats = nativeInit(); |
| 117 } | 113 } |
| 118 } | 114 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 */ | 152 */ |
| 157 public void updateMetricsServiceState() { | 153 public void updateMetricsServiceState() { |
| 158 boolean mayRecordStats = !PrivacyPreferencesManager.getInstance(mContext
) | 154 boolean mayRecordStats = !PrivacyPreferencesManager.getInstance(mContext
) |
| 159 .isNeverUploadCrashDump(); | 155 .isNeverUploadCrashDump(); |
| 160 boolean mayUploadStats = mReportingPermissionManager.isUploadPermitted()
; | 156 boolean mayUploadStats = mReportingPermissionManager.isUploadPermitted()
; |
| 161 | 157 |
| 162 // Re-start the MetricsService with the given parameters. | 158 // Re-start the MetricsService with the given parameters. |
| 163 nativeUpdateMetricsServiceState(mayRecordStats, mayUploadStats); | 159 nativeUpdateMetricsServiceState(mayRecordStats, mayUploadStats); |
| 164 } | 160 } |
| 165 | 161 |
| 166 /** | |
| 167 * Updating Android preferences according to equivalent native preferences s
o that the values | |
| 168 * can be retrieved while native preferences are not accessible. | |
| 169 */ | |
| 170 private void updatePreferences() { | |
| 171 // Update cellular experiment preference. | |
| 172 PrivacyPreferencesManager prefManager = PrivacyPreferencesManager.getIns
tance(mContext); | |
| 173 boolean cellularExperiment = TextUtils.equals("true", | |
| 174 VariationsAssociatedData.getVariationParamValue( | |
| 175 "UMA_EnableCellularLogUpload", "Enabled")); | |
| 176 prefManager.setCellularExperiment(cellularExperiment); | |
| 177 | |
| 178 // Update metrics reporting preference. | |
| 179 if (cellularExperiment) { | |
| 180 PrefServiceBridge prefBridge = PrefServiceBridge.getInstance(); | |
| 181 // If the native preference metrics reporting has not been set, then
initialize it | |
| 182 // based on the older android preference. | |
| 183 if (!prefBridge.hasSetMetricsReporting()) { | |
| 184 prefBridge.setMetricsReportingEnabled(prefManager.isUploadCrashD
umpEnabled()); | |
| 185 } | |
| 186 | |
| 187 // Set new Android preference for usage and crash reporting. | |
| 188 prefManager.setUsageAndCrashReporting(prefBridge.isMetricsReportingE
nabled()); | |
| 189 } | |
| 190 } | |
| 191 | |
| 192 @Override | 162 @Override |
| 193 public void onConnectionTypeChanged(int connectionType) { | 163 public void onConnectionTypeChanged(int connectionType) { |
| 194 updateMetricsServiceState(); | 164 updateMetricsServiceState(); |
| 195 } | 165 } |
| 196 | 166 |
| 197 public static void registerExternalExperiment(int studyId, int experimentId)
{ | 167 public static void registerExternalExperiment(int studyId, int experimentId)
{ |
| 198 nativeRegisterExternalExperiment(studyId, experimentId); | 168 nativeRegisterExternalExperiment(studyId, experimentId); |
| 199 } | 169 } |
| 200 | 170 |
| 201 public static void registerSyntheticFieldTrial(String trialName, String grou
pName) { | 171 public static void registerSyntheticFieldTrial(String trialName, String grou
pName) { |
| 202 nativeRegisterSyntheticFieldTrial(trialName, groupName); | 172 nativeRegisterSyntheticFieldTrial(trialName, groupName); |
| 203 } | 173 } |
| 204 | 174 |
| 205 private static native long nativeInit(); | 175 private static native long nativeInit(); |
| 206 private native void nativeUpdateMetricsServiceState(boolean mayRecord, boole
an mayUpload); | 176 private native void nativeUpdateMetricsServiceState(boolean mayRecord, boole
an mayUpload); |
| 207 private native void nativeUmaResumeSession(long nativeUmaSessionStats); | 177 private native void nativeUmaResumeSession(long nativeUmaSessionStats); |
| 208 private native void nativeUmaEndSession(long nativeUmaSessionStats); | 178 private native void nativeUmaEndSession(long nativeUmaSessionStats); |
| 209 private static native void nativeLogRendererCrash(boolean isPaused); | 179 private static native void nativeLogRendererCrash(boolean isPaused); |
| 210 private static native void nativeRegisterExternalExperiment(int studyId, | 180 private static native void nativeRegisterExternalExperiment(int studyId, |
| 211 int experimentId
); | 181 int experimentId
); |
| 212 private static native void nativeRegisterSyntheticFieldTrial( | 182 private static native void nativeRegisterSyntheticFieldTrial( |
| 213 String trialName, String groupName); | 183 String trialName, String groupName); |
| 214 private static native void nativeRecordMultiWindowSession(int areaPercent, i
nt instanceCount); | 184 private static native void nativeRecordMultiWindowSession(int areaPercent, i
nt instanceCount); |
| 215 private static native void nativeRecordTabCountPerLoad(int numTabsOpen); | 185 private static native void nativeRecordTabCountPerLoad(int numTabsOpen); |
| 216 private static native void nativeRecordPageLoaded(boolean isDesktopUserAgent
); | 186 private static native void nativeRecordPageLoaded(boolean isDesktopUserAgent
); |
| 217 private static native void nativeRecordPageLoadedWithKeyboard(); | 187 private static native void nativeRecordPageLoadedWithKeyboard(); |
| 218 | 188 |
| 219 } | 189 } |
| OLD | NEW |