Bug 1421541 - Make Preferences::HandleDirty() only work in the parent process. r=glandium draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 29 Nov 2017 18:48:10 +1100
changeset 704980 fefb67f6e48ec83368b6170aba050883d512eb22
parent 704979 707a68baebc71af572974943702b57246b080533
child 704981 01c8327784e356e71511eedea17d1d8e0d008776
push id91299
push usernnethercote@mozilla.com
push dateWed, 29 Nov 2017 08:10:36 +0000
reviewersglandium
bugs1421541
milestone59.0a1
Bug 1421541 - Make Preferences::HandleDirty() only work in the parent process. r=glandium pref_SetPref() is now the only function that runs in the content process and calls HandleDirty(). So this patch moves the parent process check out of HandleDirty() into pref_SetPref(). The patch also adds assertions to a couple of other parent-process-only functions. MozReview-Commit-ID: KurXKMl4IIb
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -839,17 +839,17 @@ pref_SetPref(const char* aPrefName,
         (aKind == PrefValueKind::Default) ? "default" : "user",
         PrefTypeToString(pref->Type()),
         PrefTypeToString(aType))
         .get());
 
     return rv;
   }
 
-  if (handleDirty) {
+  if (handleDirty && XRE_IsParentProcess()) {
     Preferences::HandleDirty();
   }
   if (valueChanged) {
     NotifyCallbacks(aPrefName);
   }
 
   return NS_OK;
 }
@@ -2775,22 +2775,17 @@ namespace mozilla {
 
 #define INITIAL_PREF_FILES 10
 
 static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
 
 void
 Preferences::HandleDirty()
 {
-  if (!XRE_IsParentProcess()) {
-    // This path is hit a lot when setting up prefs for content processes. Just
-    // ignore it in that case, because content processes aren't responsible for
-    // saving prefs.
-    return;
-  }
+  MOZ_ASSERT(XRE_IsParentProcess());
 
   if (!gHashTable || !sPreferences) {
     return;
   }
 
   if (sPreferences->mProfileShutdown) {
     NS_WARNING("Setting user pref after profile shutdown.");
     return;
@@ -3441,16 +3436,17 @@ NS_INTERFACE_MAP_END
 Preferences::SetInitPreferences(nsTArray<dom::Pref>* aDomPrefs)
 {
   gInitDomPrefs = new InfallibleTArray<dom::Pref>(mozilla::Move(*aDomPrefs));
 }
 
 /* static */ void
 Preferences::InitializeUserPrefs()
 {
+  MOZ_ASSERT(XRE_IsParentProcess());
   MOZ_ASSERT(!sPreferences->mCurrentFile, "Should only initialize prefs once");
 
   // Prefs which are set before we initialize the profile are silently
   // discarded. This is stupid, but there are various tests which depend on
   // this behavior.
   sPreferences->ResetUserPrefs();
 
   nsCOMPtr<nsIFile> prefsFile = sPreferences->ReadSavedPrefs();
@@ -3880,16 +3876,18 @@ Preferences::SavePrefFileInternal(nsIFil
     // We only allow off main thread writes on mCurrentFile.
     return WritePrefFile(aFile, SaveMethod::Blocking);
   }
 }
 
 nsresult
 Preferences::WritePrefFile(nsIFile* aFile, SaveMethod aSaveMethod)
 {
+  MOZ_ASSERT(XRE_IsParentProcess());
+
   if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   AUTO_PROFILER_LABEL("Preferences::WritePrefFile", OTHER);
 
   if (AllowOffMainThreadSave()) {