Index: chrome/android/java/src/org/chromium/chrome/browser/metrics/UmaSessionStats.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/metrics/UmaSessionStats.java b/chrome/android/java/src/org/chromium/chrome/browser/metrics/UmaSessionStats.java |
index 2ebed96d34158787b336c2510d21812985576498..beac9039c2453dc3dcd5d5c1f738673b3629a4da 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/metrics/UmaSessionStats.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/metrics/UmaSessionStats.java |
@@ -107,7 +107,7 @@ public class UmaSessionStats implements NetworkChangeNotifier.ConnectionTypeObse |
nativeUmaResumeSession(sNativeUmaSessionStats); |
NetworkChangeNotifier.addConnectionTypeObserver(this); |
updatePreferences(); |
- updateMetricsServiceState(); |
+ updateMetricsUploadState(); |
} |
private static void ensureNativeInitialized() { |
@@ -153,15 +153,41 @@ public class UmaSessionStats implements NetworkChangeNotifier.ConnectionTypeObse |
} |
/** |
- * Updates the state of the MetricsService to account for the user's preferences. |
+ * Updates the metrics services based on a change of consent. This can happen during first-run |
+ * flow, and when the user changes their preferences. |
*/ |
- public void updateMetricsServiceState() { |
- boolean mayRecordStats = !PrivacyPreferencesManager.getInstance() |
- .isNeverUploadCrashDump(); |
- boolean mayUploadStats = mReportingPermissionManager.isUmaUploadPermitted(); |
+ public static void changeMetricsReportingConsent(boolean consent) { |
+ PrivacyPreferencesManager privacyManager = PrivacyPreferencesManager.getInstance(); |
+ // Update the new two-choice Android preference. |
+ privacyManager.setUsageAndCrashReporting(consent); |
+ // Update the old three-choice Android preference, and synchronize with Chrome local state |
+ // preferences. Note, this forces the three-choice preferences to be either never upload, |
+ // or only upload on WiFi. |
+ privacyManager.initCrashUploadPreference(consent); |
+ updateMetricsServiceState(true); |
+ } |
+ |
+ /** |
+ * Updates the metrics services state based on existing consent and upload preferences. This can |
+ * be called at any time when consent hasn't changed, such as connection type change, or |
+ * startup. |
+ */ |
+ public static void updateMetricsUploadState() { |
+ updateMetricsServiceState(false); |
+ } |
+ |
+ /** |
+ * Updates the state of the MetricsService to account for the user's preferences. Android prefs |
+ * and Chrome Local State prefs for metrics reporting should be in sync before calling this |
+ * function. |
+ */ |
+ private static void updateMetricsServiceState(boolean consentChange) { |
+ PrivacyPreferencesManager privacyManager = PrivacyPreferencesManager.getInstance(); |
+ boolean mayRecordStats = !privacyManager.isNeverUploadCrashDump(); |
+ boolean mayUploadStats = privacyManager.isUmaUploadPermitted(); |
// Re-start the MetricsService with the given parameters. |
- nativeUpdateMetricsServiceState(mayRecordStats, mayUploadStats); |
+ nativeUpdateMetricsServiceState(consentChange, mayRecordStats, mayUploadStats); |
} |
/** |
@@ -192,13 +218,17 @@ public class UmaSessionStats implements NetworkChangeNotifier.ConnectionTypeObse |
prefManager.setUsageAndCrashReporting(prefBridge.isMetricsReportingEnabled()); |
} |
+ // Update the metrics sampling state so it's available before the native feature list is |
+ // available. |
+ prefManager.setClientInMetricsSample(UmaUtils.isClientInMetricsReportingSample()); |
+ |
// Make sure preferences are in sync. |
prefManager.syncUsageAndCrashReportingPrefs(); |
} |
@Override |
public void onConnectionTypeChanged(int connectionType) { |
- updateMetricsServiceState(); |
+ updateMetricsUploadState(); |
} |
public static void registerExternalExperiment(String studyName, int[] experimentIds) { |
@@ -210,7 +240,8 @@ public class UmaSessionStats implements NetworkChangeNotifier.ConnectionTypeObse |
} |
private static native long nativeInit(); |
- private native void nativeUpdateMetricsServiceState(boolean mayRecord, boolean mayUpload); |
+ private static native void nativeUpdateMetricsServiceState( |
+ boolean consentChange, boolean mayRecord, boolean mayUpload); |
private native void nativeUmaResumeSession(long nativeUmaSessionStats); |
private native void nativeUmaEndSession(long nativeUmaSessionStats); |
private static native void nativeLogRendererCrash(); |