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..c1bf81c3554e4e963c59025ba5269ca8937d5b37 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 |
@@ -153,12 +153,33 @@ 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); |
+ |
+ // Perform native changes needed to reflect the new consent value. |
+ nativeChangeMetricsReportingConsent(consent); |
+ |
+ updateMetricsServiceState(); |
+ } |
+ |
+ /** |
+ * Updates the state of 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. |
+ */ |
+ public static void updateMetricsServiceState() { |
+ PrivacyPreferencesManager privacyManager = PrivacyPreferencesManager.getInstance(); |
+ boolean mayRecordStats = !privacyManager.isNeverUploadCrashDump(); |
+ boolean mayUploadStats = privacyManager.isUmaUploadPermitted(); |
// Re-start the MetricsService with the given parameters. |
nativeUpdateMetricsServiceState(mayRecordStats, mayUploadStats); |
@@ -192,6 +213,10 @@ 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(); |
} |
@@ -208,9 +233,10 @@ public class UmaSessionStats implements NetworkChangeNotifier.ConnectionTypeObse |
public static void registerSyntheticFieldTrial(String trialName, String groupName) { |
nativeRegisterSyntheticFieldTrial(trialName, groupName); |
} |
- |
private static native long nativeInit(); |
- private native void nativeUpdateMetricsServiceState(boolean mayRecord, boolean mayUpload); |
+ private static native void nativeChangeMetricsReportingConsent(boolean consent); |
+ private static native void nativeUpdateMetricsServiceState( |
+ boolean mayRecord, boolean mayUpload); |
private native void nativeUmaResumeSession(long nativeUmaSessionStats); |
private native void nativeUmaEndSession(long nativeUmaSessionStats); |
private static native void nativeLogRendererCrash(); |