Merge mozilla-inbound to mozilla-central. r=merge a=merge
authorSebastian Hengst <archaeopteryx@coole-files.de>
Fri, 27 Oct 2017 00:10:27 +0200
changeset 441732 aa958b29c149a67fce772f8473e9586e71fbdb46
parent 441725 0213562857403b8b52f75075c4d59a7326dc2cfa (current diff)
parent 441731 2b219c2cb0d6ca49ef1cc419756ccdee430f0258 (diff)
child 441764 6ececf81e454060461347de9cf0058268584b9aa
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge, merge
milestone58.0a1
first release with
nightly linux32
aa958b29c149 / 58.0a1 / 20171026221945 / files
nightly linux64
aa958b29c149 / 58.0a1 / 20171026221945 / files
nightly mac
aa958b29c149 / 58.0a1 / 20171026221945 / files
nightly win32
aa958b29c149 / 58.0a1 / 20171026221945 / files
nightly win64
aa958b29c149 / 58.0a1 / 20171026221945 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge mozilla-inbound to mozilla-central. r=merge a=merge MozReview-Commit-ID: 26KLqf6YOiM
--- a/modules/libjar/nsJARProtocolHandler.cpp
+++ b/modules/libjar/nsJARProtocolHandler.cpp
@@ -68,16 +68,18 @@ nsJARProtocolHandler::GetSingleton()
 {
     if (!gJarHandler) {
         auto jar = MakeRefPtr<nsJARProtocolHandler>();
         gJarHandler = jar.get();
         if (NS_FAILED(jar->Init())) {
             gJarHandler = nullptr;
             return nullptr;
         }
+        // We release this reference on module shutdown.
+        NS_ADDREF(gJarHandler);
         return jar.forget();
     }
     return do_AddRef(gJarHandler);
 }
 
 NS_IMETHODIMP
 nsJARProtocolHandler::GetJARCache(nsIZipReaderCache* *result)
 {
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -328,39 +328,16 @@ static bool gShouldCleanupDeadNodes = fa
 static PLDHashTableOps pref_HashTableOps = {
   PLDHashTable::HashStringKey,
   MatchPrefEntry,
   PLDHashTable::MoveEntryStub,
   ClearPrefEntry,
   nullptr,
 };
 
-typedef void (*PrefsDirtyFunc)();
-static PrefsDirtyFunc gDirtyCallback = nullptr;
-
-static inline void
-MakeDirtyCallback()
-{
-  // Right now the callback function is always set, so we don't need
-  // to complicate the code to cover the scenario where we set the callback
-  // after we've already tried to make it dirty.  If this assert triggers
-  // we will add that code.
-  MOZ_ASSERT(gDirtyCallback);
-  if (gDirtyCallback) {
-    gDirtyCallback();
-  }
-}
-
-// Callback for whenever we change a preference.
-static void
-PREF_SetDirtyCallback(PrefsDirtyFunc aFunc)
-{
-  gDirtyCallback = aFunc;
-}
-
 //---------------------------------------------------------------------------
 
 static bool
 pref_ValueChanged(PrefValue aOldValue, PrefValue aNewValue, PrefType aType);
 
 static nsresult
 pref_DoCallback(const char* aChangedPref);
 
@@ -847,17 +824,17 @@ PREF_DeleteBranch(const char* aBranchNam
     // "ldap" (if such a leaf node exists) but not "ldap_1.xxx".
     if (PL_strncmp(entry->mKey, to_delete, len) == 0 ||
         (len - 1 == strlen(entry->mKey) &&
          PL_strncmp(entry->mKey, to_delete, len - 1) == 0)) {
       iter.Remove();
     }
   }
 
-  MakeDirtyCallback();
+  Preferences::HandleDirty();
   return NS_OK;
 }
 
 // Clears the given pref (reverts it to its default value).
 static nsresult
 PREF_ClearUserPref(const char* aPrefName)
 {
   if (!gHashTable) {
@@ -868,17 +845,17 @@ PREF_ClearUserPref(const char* aPrefName
   if (pref && pref->mPrefFlags.HasUserValue()) {
     pref->mPrefFlags.SetHasUserValue(false);
 
     if (!pref->mPrefFlags.HasDefault()) {
       gHashTable->RemoveEntry(pref);
     }
 
     pref_DoCallback(aPrefName);
-    MakeDirtyCallback();
+    Preferences::HandleDirty();
   }
   return NS_OK;
 }
 
 // Clears all user prefs.
 static nsresult
 PREF_ClearAllUserPrefs()
 {
@@ -901,17 +878,17 @@ PREF_ClearAllUserPrefs()
       }
     }
   }
 
   for (std::string& prefString : prefStrings) {
     pref_DoCallback(prefString.c_str());
   }
 
-  MakeDirtyCallback();
+  Preferences::HandleDirty();
   return NS_OK;
 }
 
 // Function that sets whether or not the preference is locked and therefore
 // cannot be changed.
 static nsresult
 PREF_LockPref(const char* aKey, bool aLockIt)
 {
@@ -994,36 +971,16 @@ pref_SetValue(PrefValue* aExistingValue,
 
   return aFlags;
 }
 
 #ifdef DEBUG
 
 static pref_initPhase gPhase = START;
 
-static bool gWatchingPref = false;
-
-static void
-pref_SetInitPhase(pref_initPhase aPhase)
-{
-  gPhase = aPhase;
-}
-
-static pref_initPhase
-pref_GetInitPhase()
-{
-  return gPhase;
-}
-
-static void
-pref_SetWatchingPref(bool aWatching)
-{
-  gWatchingPref = aWatching;
-}
-
 struct StringComparator
 {
   const char* mKey;
   explicit StringComparator(const char* aKey)
     : mKey(aKey)
   {
   }
   int operator()(const char* aString) const { return strcmp(mKey, aString); }
@@ -1033,21 +990,23 @@ static bool
 InInitArray(const char* aKey)
 {
   size_t prefsLen;
   size_t found;
   const char** list = mozilla::dom::ContentPrefs::GetContentPrefs(&prefsLen);
   return BinarySearchIf(list, 0, prefsLen, StringComparator(aKey), &found);
 }
 
+static bool gWatchingPref = false;
+
 class WatchingPrefRAII
 {
 public:
-  WatchingPrefRAII() { pref_SetWatchingPref(true); }
-  ~WatchingPrefRAII() { pref_SetWatchingPref(false); }
+  WatchingPrefRAII() { gWatchingPref = true; }
+  ~WatchingPrefRAII() { gWatchingPref = false; }
 };
 
 #define WATCHING_PREF_RAII() WatchingPrefRAII watchingPrefRAII
 
 #else // DEBUG
 
 #define WATCHING_PREF_RAII()
 
@@ -1136,28 +1095,28 @@ pref_HashPref(const char* aKey,
     if ((pref->mPrefFlags.HasDefault()) &&
         !(pref->mPrefFlags.HasStickyDefault()) &&
         !pref_ValueChanged(pref->mDefaultPref, aValue, aType) &&
         !(aFlags & kPrefForceSet)) {
       if (pref->mPrefFlags.HasUserValue()) {
         // XXX should we free a user-set string value if there is one?
         pref->mPrefFlags.SetHasUserValue(false);
         if (!pref->mPrefFlags.IsLocked()) {
-          MakeDirtyCallback();
+          Preferences::HandleDirty();
           valueChanged = true;
         }
       }
     } else if (!pref->mPrefFlags.HasUserValue() ||
                !pref->mPrefFlags.IsPrefType(aType) ||
                pref_ValueChanged(pref->mUserPref, aValue, aType)) {
       pref->mPrefFlags =
         pref_SetValue(&pref->mUserPref, pref->mPrefFlags, aValue, aType)
           .SetHasUserValue(true);
       if (!pref->mPrefFlags.IsLocked()) {
-        MakeDirtyCallback();
+        Preferences::HandleDirty();
         valueChanged = true;
       }
     }
   }
 
   if (valueChanged) {
     return pref_DoCallback(aKey);
   }
@@ -1171,28 +1130,16 @@ pref_SizeOfPrivateData(MallocSizeOf aMal
   size_t n = gPrefNameArena.SizeOfExcludingThis(aMallocSizeOf);
   for (CallbackNode* node = gFirstCallback; node; node = node->mNext) {
     n += aMallocSizeOf(node);
     n += aMallocSizeOf(node->mDomain);
   }
   return n;
 }
 
-static PrefType
-PREF_GetPrefType(const char* aPrefName)
-{
-  if (gHashTable) {
-    PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
-    if (pref) {
-      return pref->mPrefFlags.GetPrefType();
-    }
-  }
-  return PrefType::Invalid;
-}
-
 // Bool function that returns whether or not the preference is locked and
 // therefore cannot be changed.
 static bool
 PREF_PrefIsLocked(const char* aPrefName)
 {
   bool result = false;
   if (gIsAnyPrefLocked && gHashTable) {
     PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
@@ -1494,59 +1441,16 @@ pref_ReportParseProblem(PrefParseState& 
   } else {
     printf_stderr("**** Preference parsing %s (line %d) = %s **\n",
                   (aError ? "error" : "warning"),
                   aLine,
                   aMessage);
   }
 }
 
-// This function is called when a complete pref name-value pair has been
-// extracted from the input data.
-//
-// @param aPS
-//        parse state instance
-//
-// @return false to indicate a fatal error.
-static bool
-pref_DoCallback(PrefParseState* aPS)
-{
-  PrefValue value;
-
-  switch (aPS->mVtype) {
-    case PrefType::String:
-      value.mStringVal = aPS->mVb;
-      break;
-
-    case PrefType::Int:
-      if ((aPS->mVb[0] == '-' || aPS->mVb[0] == '+') && aPS->mVb[1] == '\0') {
-        pref_ReportParseProblem(*aPS, "invalid integer value", 0, true);
-        NS_WARNING("malformed integer value");
-        return false;
-      }
-      value.mIntVal = atoi(aPS->mVb);
-      break;
-
-    case PrefType::Bool:
-      value.mBoolVal = (aPS->mVb == kTrue);
-      break;
-
-    default:
-      break;
-  }
-
-  (*aPS->mReader)(aPS->mClosure,
-                  aPS->mLb,
-                  value,
-                  aPS->mVtype,
-                  aPS->mIsDefault,
-                  aPS->mIsStickyDefault);
-  return true;
-}
-
 // Initialize a PrefParseState instance.
 //
 // |aPS| is the PrefParseState instance.
 // |aReader| is the PrefReader callback function, which will be called once for
 // each preference name value pair extracted.
 // |aReporter| is the PrefParseErrorReporter callback function, which will be
 // called if we encounter any errors (stop) or warnings (continue) during
 // parsing.
@@ -1981,19 +1885,50 @@ PREF_ParseBuf(PrefParseState* aPS, const
           return false;
         }
         break;
 
       // function terminator ';' parsing
       case PREF_PARSE_UNTIL_SEMICOLON:
         // tolerate only whitespace and embedded comments
         if (c == ';') {
-          if (!pref_DoCallback(aPS)) {
-            return false;
+
+          PrefValue value;
+
+          switch (aPS->mVtype) {
+            case PrefType::String:
+              value.mStringVal = aPS->mVb;
+              break;
+
+            case PrefType::Int:
+              if ((aPS->mVb[0] == '-' || aPS->mVb[0] == '+') &&
+                  aPS->mVb[1] == '\0') {
+                pref_ReportParseProblem(*aPS, "invalid integer value", 0, true);
+                NS_WARNING("malformed integer value");
+                return false;
+              }
+              value.mIntVal = atoi(aPS->mVb);
+              break;
+
+            case PrefType::Bool:
+              value.mBoolVal = (aPS->mVb == kTrue);
+              break;
+
+            default:
+              break;
           }
+
+          // We've extracted a complete name/value pair.
+          aPS->mReader(aPS->mClosure,
+                       aPS->mLb,
+                       value,
+                       aPS->mVtype,
+                       aPS->mIsDefault,
+                       aPS->mIsStickyDefault);
+
           state = PREF_PARSE_INIT;
         } else if (c == '/') {
           aPS->mNextState = state; // return here when done with comment
           state = PREF_PARSE_COMMENT_MAYBE_START;
         } else if (!isspace(c)) {
           pref_ReportParseProblem(
             *aPS, "need space, comment or semicolon", lineNum, true);
           NS_WARNING("malformed pref file");
@@ -2340,18 +2275,27 @@ nsPrefBranch::GetRoot(char** aRoot)
   *aRoot = ToNewCString(mPrefRoot);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPrefBranch::GetPrefType(const char* aPrefName, int32_t* aRetVal)
 {
   NS_ENSURE_ARG(aPrefName);
+
   const PrefName& pref = GetPrefName(aPrefName);
-  switch (PREF_GetPrefType(pref.get())) {
+  PrefType type = PrefType::Invalid;
+  if (gHashTable) {
+    PrefHashEntry* entry = pref_HashTableLookup(pref.get());
+    if (entry) {
+      type = entry->mPrefFlags.GetPrefType();
+    }
+  }
+
+  switch (type) {
     case PrefType::String:
       *aRetVal = PREF_STRING;
       break;
 
     case PrefType::Int:
       *aRetVal = PREF_INT;
       break;
 
@@ -3261,17 +3205,17 @@ nsRelativeFilePref::SetRelativeToKey(con
 
 namespace mozilla {
 
 #define INITIAL_PREF_FILES 10
 
 static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
 
 void
-Preferences::DirtyCallback()
+Preferences::HandleDirty()
 {
   if (!XRE_IsParentProcess()) {
     // TODO: this should really assert because you can't set prefs in a
     // content process. But so much code currently does this that we just
     // ignore it for now.
     return;
   }
 
@@ -3569,17 +3513,17 @@ public:
       nsresult rvCopy = rv;
       nsCOMPtr<nsIFile> fileCopy(mFile);
       SystemGroup::Dispatch(
         TaskCategory::Other,
         NS_NewRunnableFunction("Preferences::WriterRunnable",
                                [fileCopy, rvCopy] {
                                  MOZ_RELEASE_ASSERT(NS_IsMainThread());
                                  if (NS_FAILED(rvCopy)) {
-                                   Preferences::DirtyCallback();
+                                   Preferences::HandleDirty();
                                  }
                                }));
     }
     return rv;
   }
 
 protected:
   nsCOMPtr<nsIFile> mFile;
@@ -3956,17 +3900,16 @@ static InfallibleTArray<Preferences::Pre
 Preferences::SetInitPreferences(nsTArray<PrefSetting>* aPrefs)
 {
   gInitPrefs = new InfallibleTArray<PrefSetting>(mozilla::Move(*aPrefs));
 }
 
 Result<Ok, const char*>
 Preferences::Init()
 {
-  PREF_SetDirtyCallback(&DirtyCallback);
   PREF_Init();
 
   MOZ_TRY(pref_InitInitialObjects());
 
   if (XRE_IsContentProcess()) {
     MOZ_ASSERT(gInitPrefs);
     for (unsigned int i = 0; i < gInitPrefs->Length(); i++) {
       Preferences::SetPreference(gInitPrefs->ElementAt(i));
@@ -4254,25 +4197,25 @@ Preferences::GetPreferences(InfallibleTA
 
     dom::PrefSetting* pref = aPrefs->AppendElement();
     pref_GetPrefFromEntry(entry, pref);
   }
 }
 
 #ifdef DEBUG
 void
-Preferences::SetInitPhase(pref_initPhase phase)
-{
-  pref_SetInitPhase(phase);
+Preferences::SetInitPhase(pref_initPhase aPhase)
+{
+  gPhase = aPhase;
 }
 
 pref_initPhase
 Preferences::InitPhase()
 {
-  return pref_GetInitPhase();
+  return gPhase;
 }
 #endif
 
 NS_IMETHODIMP
 Preferences::GetBranch(const char* aPrefRoot, nsIPrefBranch** aRetVal)
 {
   if ((nullptr != aPrefRoot) && (*aPrefRoot != '\0')) {
     // TODO: Cache this stuff and allow consumers to share branches (hold weak
@@ -4430,17 +4373,17 @@ Preferences::SavePrefFileInternal(nsIFil
 
     // The mDirty flag tells us if we should write to mCurrentFile. We only
     // check this flag when the caller wants to write to the default.
     if (!mDirty) {
       return NS_OK;
     }
 
     // Check for profile shutdown after mDirty because the runnables from
-    // DirtyCallback can still be pending.
+    // HandleDirty() can still be pending.
     if (mProfileShutdown) {
       NS_WARNING("Cannot save pref file after profile shutdown.");
       return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
     }
 
     // It's possible that we never got a prefs file.
     nsresult rv = NS_OK;
     if (mCurrentFile) {
--- a/modules/libpref/Preferences.h
+++ b/modules/libpref/Preferences.h
@@ -329,17 +329,17 @@ public:
 #ifdef DEBUG
   static void SetInitPhase(pref_initPhase phase);
   static pref_initPhase InitPhase();
 #endif
 
   static int64_t SizeOfIncludingThisAndOtherStuff(
     mozilla::MallocSizeOf aMallocSizeOf);
 
-  static void DirtyCallback();
+  static void HandleDirty();
 
   // Explicitly choosing synchronous or asynchronous (if allowed) preferences
   // file write. Only for the default file.  The guarantee for the "blocking"
   // is that when it returns, the file on disk reflect the current state of
   // preferences.
   nsresult SavePrefFileBlocking();
   nsresult SavePrefFileAsynchronous();