Bug 1444275 - Don't set the telemetry pref in content processes. r=glandium draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 13 Mar 2018 14:33:48 +1100
changeset 766591 d5e84aa1034c3643ad5d37476c16ce8401f3d438
parent 765160 3b7250cea630bebf35992bb69e651509c863c1c6
child 766592 e584f9292360f197b37891505870eafa184de720
push id102363
push usernnethercote@mozilla.com
push dateTue, 13 Mar 2018 03:36:09 +0000
reviewersglandium
bugs1444275
milestone60.0a1
Bug 1444275 - Don't set the telemetry pref in content processes. r=glandium It'll be set via the normal parent-to-child pref setting process. MozReview-Commit-ID: By4mG7brc55
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -2946,16 +2946,18 @@ TelemetryPrefValue()
     kChannelPref, channelPrefValue, PrefValueKind::Default);
   return Some(prefValue.EqualsLiteral("beta"));
 #endif
 }
 
 /* static */ void
 Preferences::SetupTelemetryPref()
 {
+  MOZ_ASSERT(XRE_IsParentProcess());
+
   Maybe<bool> telemetryPrefValue = TelemetryPrefValue();
   if (telemetryPrefValue.isSome()) {
     Preferences::SetBoolInAnyProcess(
       kTelemetryPref, *telemetryPrefValue, PrefValueKind::Default);
   }
 }
 
 #else // !MOZ_WIDGET_ANDROID
@@ -2994,21 +2996,37 @@ TelemetryPrefValue()
   }
 
   return false;
 }
 
 /* static */ void
 Preferences::SetupTelemetryPref()
 {
+  MOZ_ASSERT(XRE_IsParentProcess());
+
   Preferences::SetBoolInAnyProcess(
     kTelemetryPref, TelemetryPrefValue(), PrefValueKind::Default);
   Preferences::LockInAnyProcess(kTelemetryPref);
 }
 
+static void
+CheckTelemetryPref()
+{
+  MOZ_ASSERT(!XRE_IsParentProcess());
+
+  // Make sure the children got passed the right telemetry pref details.
+  DebugOnly<bool> value;
+  MOZ_ASSERT(NS_SUCCEEDED(Preferences::GetBool(kTelemetryPref, &value)) &&
+             value == TelemetryPrefValue());
+  // njn: uncomment after bug 1436911 lands; it ensures that the locked status
+  //      is passed correctly
+  // MOZ_ASSERT(Preferences::IsLocked(kTelemetryPref));
+}
+
 #endif // MOZ_WIDGET_ANDROID
 
 /* static */ already_AddRefed<Preferences>
 Preferences::GetInstanceForService()
 {
   if (sPreferences) {
     return do_AddRef(sPreferences);
   }
@@ -3037,16 +3055,20 @@ Preferences::GetInstanceForService()
   if (!XRE_IsParentProcess()) {
     MOZ_ASSERT(gEarlyDomPrefs);
     for (unsigned int i = 0; i < gEarlyDomPrefs->Length(); i++) {
       Preferences::SetPreference(gEarlyDomPrefs->ElementAt(i));
     }
     delete gEarlyDomPrefs;
     gEarlyDomPrefs = nullptr;
 
+#ifndef MOZ_WIDGET_ANDROID
+    CheckTelemetryPref();
+#endif
+
   } else {
     // Check if there is a deployment configuration file. If so, set up the
     // pref config machinery, which will actually read the file.
     nsAutoCString lockFileName;
     nsresult rv = Preferences::GetCString(
       "general.config.filename", lockFileName, PrefValueKind::User);
     if (NS_SUCCEEDED(rv)) {
       NS_CreateServicesFromCategory(
@@ -4022,17 +4044,19 @@ Preferences::InitInitialObjects()
         continue;
       }
 
       // Do we care if a file provided by this process fails to load?
       pref_LoadPrefsInDir(path, nullptr, 0);
     }
   }
 
-  SetupTelemetryPref();
+  if (XRE_IsParentProcess()) {
+    SetupTelemetryPref();
+  }
 
   NS_CreateServicesFromCategory(NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID,
                                 nullptr,
                                 NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID);
 
   nsCOMPtr<nsIObserverService> observerService =
     mozilla::services::GetObserverService();
   NS_ENSURE_SUCCESS(rv, Err("GetObserverService() failed (2)"));