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
--- 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()) {