Bug 1408231 - Remove unnecessary forward declarations and add |static| where appropriate. r=glandium. draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 13 Oct 2017 11:54:29 +1100
changeset 679801 dad9a8f01c1d1ac10a05bbfacd0b7451e75d11b9
parent 679022 14662fd5d428bb63fd020249096a4f00fc633ca2
child 735678 a56d115a003d6e8778a2feceb1151c4f831f3561
push id84308
push usernnethercote@mozilla.com
push dateFri, 13 Oct 2017 02:11:26 +0000
reviewersglandium
bugs1408231
milestone58.0a1
Bug 1408231 - Remove unnecessary forward declarations and add |static| where appropriate. r=glandium. This is possible now that all of libpref is in a single .cpp file. For some functions, this required moving the comment from the forward declaration to the definition. MozReview-Commit-ID: 7XjHENZkc61
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -130,73 +130,32 @@ using namespace mozilla;
 #endif // DEBUG
 
 //===========================================================================
 // The old low-level prefs API
 //===========================================================================
 
 struct PrefHashEntry;
 
-extern PLDHashTable* gHashTable;
-
 typedef nsTArray<mozilla::UniqueFreePtr<char>> PrefSaveData;
 
-PrefSaveData
-pref_savePrefs(PLDHashTable* aTable);
-
-nsresult
-pref_SetPref(const mozilla::dom::PrefSetting& aPref);
-
-#ifdef DEBUG
-void
-pref_SetInitPhase(pref_initPhase aPhase);
-
-pref_initPhase
-pref_GetInitPhase();
-
-void
-pref_SetWatchingPref(bool aWatching);
-#endif
-
-PrefHashEntry*
+static PrefHashEntry*
 pref_HashTableLookup(const char* aKey);
 
-bool
-pref_EntryHasAdvisablySizedValues(PrefHashEntry* aHashEntry);
-
-void
-pref_GetPrefFromEntry(PrefHashEntry* aHashEntry,
-                      mozilla::dom::PrefSetting* aPref);
-
-size_t
-pref_SizeOfPrivateData(mozilla::MallocSizeOf aMallocSizeOf);
-
 // 1 MB should be enough for everyone.
 static const uint32_t MAX_PREF_LENGTH = 1 * 1024 * 1024;
 // Actually, 4kb should be enough for everyone.
 static const uint32_t MAX_ADVISABLE_PREF_LENGTH = 4 * 1024;
 
 union PrefValue {
   char* mStringVal;
   int32_t mIntVal;
   bool mBoolVal;
 };
 
-// The Init function initializes the preference context and creates the
-// preference hashtable.
-void
-PREF_Init();
-
-// Cleanup should be called at program exit to free the list of registered
-// callbacks.
-void
-PREF_Cleanup();
-void
-PREF_CleanupPrefs();
-
 // Preference flags, including the native type of the preference. Changing any
 // of these values will require modifying the code inside of PrefTypeFlags
 // class.
 enum class PrefType
 {
   Invalid = 0,
   String = 1,
   Int = 2,
@@ -296,110 +255,19 @@ private:
 struct PrefHashEntry : PLDHashEntryHdr
 {
   PrefTypeFlags mPrefFlags; // this field first to minimize 64-bit struct size
   const char* mKey;
   PrefValue mDefaultPref;
   PrefValue mUserPref;
 };
 
-// Set the various types of preferences. These functions take a dotted notation
-// of the preference name (e.g. "browser.startup.homepage"). Note that this
-// will cause the preference to be saved to the file if it is different from
-// the default. In other words, these are used to set the _user_ preferences.
-//
-// If aSetDefault is set to true however, it sets the default value. This will
-// only affect the program behavior if the user does not have a value saved
-// over it for the particular preference. In addition, these will never be
-// saved out to disk.
-//
-// Each set returns PREF_VALUECHANGED if the user value changed (triggering a
-// callback), or PREF_NOERROR if the value was unchanged.
-nsresult
-PREF_SetCharPref(const char* aPref, const char* aVal, bool aSetDefault = false);
-nsresult
-PREF_SetIntPref(const char* aPref, int32_t aVal, bool aSetDefault = false);
-nsresult
-PREF_SetBoolPref(const char* aPref, bool aVal, bool aSetDefault = false);
-
-bool
-PREF_HasUserPref(const char* aPrefName);
-
-// Get the various types of preferences. These functions take a dotted
-// notation of the preference name (e.g. "browser.startup.homepage")
-//
-// They also take a pointer to fill in with the return value and return an
-// error value. At the moment, this is simply an int but it may
-// be converted to an enum once the global error strategy is worked out.
-//
-// They will perform conversion if the type doesn't match what was requested.
-// (if it is reasonably possible)
-nsresult
-PREF_GetIntPref(const char* aPref, int32_t* aValueOut, bool aGetDefault);
-nsresult
-PREF_GetBoolPref(const char* aPref, bool* aValueOut, bool aGetDefault);
-
-// These functions are similar to the above "Get" version with the significant
-// difference that the preference module will alloc the memory (e.g. XP_STRDUP)
-// and the caller will need to be responsible for freeing it...
-nsresult
-PREF_CopyCharPref(const char* aPref, char** aValueOut, bool aGetDefault);
-
-// Bool function that returns whether or not the preference is locked and
-// therefore cannot be changed.
-bool
-PREF_PrefIsLocked(const char* aPrefName);
-
-// Function that sets whether or not the preference is locked and therefore
-// cannot be changed.
-nsresult
-PREF_LockPref(const char* aKey, bool aLockIt);
-
-PrefType
-PREF_GetPrefType(const char* aPrefName);
-
-// Delete a branch of the tree.
-nsresult
-PREF_DeleteBranch(const char* aBranchName);
-
-// Clears the given pref (reverts it to its default value).
-nsresult
+static nsresult
 PREF_ClearUserPref(const char* aPrefName);
 
-// Clears all user prefs.
-nsresult
-PREF_ClearAllUserPrefs();
-
-// Register a callback. This takes a node in the preference tree and will call
-// the callback function if anything below that node is modified. Unregister
-// returns PREF_NOERROR if a callback was found that matched all the
-// parameters; otherwise it returns PREF_ERROR.
-void
-PREF_RegisterCallback(const char* aPrefNode,
-                      PrefChangedFunc aCallback,
-                      void* aData,
-                      bool aIsPriority);
-nsresult
-PREF_UnregisterCallback(const char* aPrefNode,
-                        PrefChangedFunc aCallback,
-                        void* aData);
-
-// Used by nsPrefService as the callback function of the prefs parser.
-void
-PREF_ReaderCallback(void* aClosure,
-                    const char* aPref,
-                    PrefValue aValue,
-                    PrefType aType,
-                    bool aIsDefault,
-                    bool aIsStickyDefault);
-
-// Callback for whenever we change a preference.
-typedef void (*PrefsDirtyFunc)();
-void PREF_SetDirtyCallback(PrefsDirtyFunc);
-
 static void
 ClearPrefEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry)
 {
   auto pref = static_cast<PrefHashEntry*>(aEntry);
   if (pref->mPrefFlags.IsTypeString()) {
     if (pref->mDefaultPref.mStringVal) {
       free(pref->mDefaultPref.mStringVal);
     }
@@ -438,17 +306,17 @@ struct CallbackNode
   // If someone attempts to remove the node from the callback list while
   // pref_DoCallback is running, |func| is set to nullptr. Such nodes will
   // be removed at the end of pref_DoCallback.
   PrefChangedFunc mFunc;
   void* mData;
   CallbackNode* mNext;
 };
 
-PLDHashTable* gHashTable;
+static PLDHashTable* gHashTable;
 
 static ArenaAllocator<8192, 4> gPrefNameArena;
 
 // The callback list contains all the priority callbacks followed by the
 // non-priority callbacks. gLastPriorityNode records where the first part ends.
 static CallbackNode* gFirstCallback = nullptr;
 static CallbackNode* gLastPriorityNode = nullptr;
 
@@ -461,32 +329,34 @@ static bool gShouldCleanupDeadNodes = fa
 static PLDHashTableOps pref_HashTableOps = {
   PLDHashTable::HashStringKey,
   MatchPrefEntry,
   PLDHashTable::MoveEntryStub,
   ClearPrefEntry,
   nullptr,
 };
 
+typedef void (*PrefsDirtyFunc)();
 static PrefsDirtyFunc gDirtyCallback = nullptr;
 
-inline void
+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();
   }
 }
 
-void
+// Callback for whenever we change a preference.
+static void
 PREF_SetDirtyCallback(PrefsDirtyFunc aFunc)
 {
   gDirtyCallback = aFunc;
 }
 
 //---------------------------------------------------------------------------
 
 static bool
@@ -505,27 +375,40 @@ enum
 static nsresult
 pref_HashPref(const char* aKey,
               PrefValue aValue,
               PrefType aType,
               uint32_t aFlags);
 
 #define PREF_HASHTABLE_INITIAL_LENGTH 1024
 
-void
+// The Init function initializes the preference context and creates the
+// preference hashtable.
+static void
 PREF_Init()
 {
   if (!gHashTable) {
     gHashTable = new PLDHashTable(
       &pref_HashTableOps, sizeof(PrefHashEntry), PREF_HASHTABLE_INITIAL_LENGTH);
   }
 }
 
-// Frees the callback list.
-void
+// Frees up all the objects except the callback list.
+static void
+PREF_CleanupPrefs()
+{
+  if (gHashTable) {
+    delete gHashTable;
+    gHashTable = nullptr;
+    gPrefNameArena.Clear();
+  }
+}
+
+// Frees the callback list. Should be called at program exit.
+static void
 PREF_Cleanup()
 {
   NS_ASSERTION(!gCallbacksInProgress,
                "PREF_Cleanup was called while gCallbacksInProgress is true!");
 
   CallbackNode* node = gFirstCallback;
   CallbackNode* next_node;
 
@@ -535,27 +418,16 @@ PREF_Cleanup()
     free(node);
     node = next_node;
   }
   gLastPriorityNode = gFirstCallback = nullptr;
 
   PREF_CleanupPrefs();
 }
 
-// Frees up all the objects except the callback list.
-void
-PREF_CleanupPrefs()
-{
-  if (gHashTable) {
-    delete gHashTable;
-    gHashTable = nullptr;
-    gPrefNameArena.Clear();
-  }
-}
-
 // Note that this appends to aResult, and does not assign!
 static void
 StrEscape(const char* aOriginal, nsCString& aResult)
 {
   // JavaScript does not allow quotes, slashes, or line terminators inside
   // strings so we must escape them. ECMAScript defines four line terminators,
   // but we're only worrying about \r and \n here.  We currently feed our pref
   // script to the JS interpreter as Latin-1 so  we won't encounter \u2028
@@ -596,41 +468,55 @@ StrEscape(const char* aOriginal, nsCStri
     }
   }
 }
 
 //
 // External calls
 //
 
-nsresult
+// Set a char* pref. This function takes a dotted notation of the preference
+// name (e.g. "browser.startup.homepage"). Note that this will cause the
+// preference to be saved to the file if it is different from the default. In
+// other words, this is used to set the _user_ preferences.
+//
+// If aSetDefault is set to true however, it sets the default value. This will
+// only affect the program behavior if the user does not have a value saved
+// over it for the particular preference. In addition, these will never be
+// saved out to disk.
+//
+// Each set returns PREF_VALUECHANGED if the user value changed (triggering a
+// callback), or PREF_NOERROR if the value was unchanged.
+static nsresult
 PREF_SetCharPref(const char* aPrefName, const char* aValue, bool aSetDefault)
 {
   if (strlen(aValue) > MAX_PREF_LENGTH) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
   PrefValue pref;
   pref.mStringVal = const_cast<char*>(aValue);
 
   return pref_HashPref(
     aPrefName, pref, PrefType::String, aSetDefault ? kPrefSetDefault : 0);
 }
 
-nsresult
+// Like PREF_SetCharPref(), but for integers.
+static nsresult
 PREF_SetIntPref(const char* aPrefName, int32_t aValue, bool aSetDefault)
 {
   PrefValue pref;
   pref.mIntVal = aValue;
 
   return pref_HashPref(
     aPrefName, pref, PrefType::Int, aSetDefault ? kPrefSetDefault : 0);
 }
 
-nsresult
+// Like PREF_SetCharPref(), but for booleans.
+static nsresult
 PREF_SetBoolPref(const char* aPrefName, bool aValue, bool aSetDefault)
 {
   PrefValue pref;
   pref.mBoolVal = aValue;
 
   return pref_HashPref(
     aPrefName, pref, PrefType::Bool, aSetDefault ? kPrefSetDefault : 0);
 }
@@ -659,17 +545,17 @@ SetPrefValue(const char* aPrefName,
     case dom::PrefValue::Tbool:
       return PREF_SetBoolPref(aPrefName, aValue.get_bool(), setDefault);
 
     default:
       MOZ_CRASH();
   }
 }
 
-nsresult
+static nsresult
 pref_SetPref(const dom::PrefSetting& aPref)
 {
   const char* prefName = aPref.name().get();
   const dom::MaybePrefValue& defaultValue = aPref.defaultValue();
   const dom::MaybePrefValue& userValue = aPref.userValue();
 
   nsresult rv;
   if (defaultValue.type() == dom::MaybePrefValue::TPrefValue) {
@@ -686,17 +572,17 @@ pref_SetPref(const dom::PrefSetting& aPr
   }
 
   // NB: we should never try to clear a default value, that doesn't
   // make sense
 
   return rv;
 }
 
-PrefSaveData
+static PrefSaveData
 pref_savePrefs(PLDHashTable* aTable)
 {
   PrefSaveData savedPrefs(aTable->EntryCount());
 
   for (auto iter = aTable->Iter(); !iter.Done(); iter.Next()) {
     auto pref = static_cast<PrefHashEntry*>(iter.Get());
 
     nsAutoCString prefValue;
@@ -737,17 +623,17 @@ pref_savePrefs(PLDHashTable* aTable)
     savedPrefs.AppendElement()->reset(
       ToNewCString(prefPrefix + prefName + NS_LITERAL_CSTRING("\", ") +
                    prefValue + NS_LITERAL_CSTRING(");")));
   }
 
   return savedPrefs;
 }
 
-bool
+static bool
 pref_EntryHasAdvisablySizedValues(PrefHashEntry* aHashEntry)
 {
   if (aHashEntry->mPrefFlags.GetPrefType() != PrefType::String) {
     return true;
   }
 
   char* stringVal;
   if (aHashEntry->mPrefFlags.HasDefault()) {
@@ -794,17 +680,17 @@ GetPrefValueFromEntry(PrefHashEntry* aHa
     case PrefType::Bool:
       *settingValue = !!value->mBoolVal;
       return;
     default:
       MOZ_CRASH();
   }
 }
 
-void
+static void
 pref_GetPrefFromEntry(PrefHashEntry* aHashEntry, dom::PrefSetting* aPref)
 {
   aPref->name() = aHashEntry->mKey;
 
   if (aHashEntry->mPrefFlags.HasDefault()) {
     GetPrefValueFromEntry(aHashEntry, aPref, DEFAULT_VALUE);
   } else {
     aPref->defaultValue() = null_t();
@@ -817,28 +703,29 @@ pref_GetPrefFromEntry(PrefHashEntry* aHa
   }
 
   MOZ_ASSERT(aPref->defaultValue().type() == dom::MaybePrefValue::Tnull_t ||
              aPref->userValue().type() == dom::MaybePrefValue::Tnull_t ||
              (aPref->defaultValue().get_PrefValue().type() ==
               aPref->userValue().get_PrefValue().type()));
 }
 
-bool
+static bool
 PREF_HasUserPref(const char* aPrefName)
 {
   if (!gHashTable) {
     return false;
   }
 
   PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
   return pref && pref->mPrefFlags.HasUserValue();
 }
 
-nsresult
+// This function allocates memory and the caller is responsible for freeing it.
+static nsresult
 PREF_CopyCharPref(const char* aPrefName, char** aValueOut, bool aGetDefault)
 {
   if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = NS_ERROR_UNEXPECTED;
   char* stringVal;
@@ -856,17 +743,26 @@ PREF_CopyCharPref(const char* aPrefName,
       *aValueOut = moz_xstrdup(stringVal);
       rv = NS_OK;
     }
   }
 
   return rv;
 }
 
-nsresult
+// Get an int preference. This function takes a dotted notation of the
+// preference name (e.g. "browser.startup.homepage")
+//
+// It also takes a pointer to fill in with the return value and return an error
+// value. At the moment, this is simply an int but it may be converted to an
+// enum once the global error strategy is worked out.
+//
+// This function will perform conversion if the type doesn't match what was
+// requested. (If it is reasonably possible.)
+static nsresult
 PREF_GetIntPref(const char* aPrefName, int32_t* aValueOut, bool aGetDefault)
 {
   if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = NS_ERROR_UNEXPECTED;
   PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
@@ -884,17 +780,18 @@ PREF_GetIntPref(const char* aPrefName, i
       *aValueOut = pref->mUserPref.mIntVal;
     }
     rv = NS_OK;
   }
 
   return rv;
 }
 
-nsresult
+// Like PREF_GetIntPref(), but for booleans.
+static nsresult
 PREF_GetBoolPref(const char* aPrefName, bool* aValueOut, bool aGetDefault)
 {
   if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = NS_ERROR_UNEXPECTED;
   PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
@@ -913,17 +810,18 @@ PREF_GetBoolPref(const char* aPrefName, 
       *aValueOut = pref->mUserPref.mBoolVal;
       rv = NS_OK;
     }
   }
 
   return rv;
 }
 
-nsresult
+// Delete a branch of the tree.
+static nsresult
 PREF_DeleteBranch(const char* aBranchName)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   size_t len = strlen(aBranchName);
 
   if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
@@ -954,17 +852,18 @@ PREF_DeleteBranch(const char* aBranchNam
       iter.Remove();
     }
   }
 
   MakeDirtyCallback();
   return NS_OK;
 }
 
-nsresult
+// Clears the given pref (reverts it to its default value).
+static nsresult
 PREF_ClearUserPref(const char* aPrefName)
 {
   if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
   if (pref && pref->mPrefFlags.HasUserValue()) {
@@ -975,17 +874,18 @@ PREF_ClearUserPref(const char* aPrefName
     }
 
     pref_DoCallback(aPrefName);
     MakeDirtyCallback();
   }
   return NS_OK;
 }
 
-nsresult
+// Clears all user prefs.
+static nsresult
 PREF_ClearAllUserPrefs()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
@@ -1006,17 +906,19 @@ PREF_ClearAllUserPrefs()
   for (std::string& prefString : prefStrings) {
     pref_DoCallback(prefString.c_str());
   }
 
   MakeDirtyCallback();
   return NS_OK;
 }
 
-nsresult
+// Function that sets whether or not the preference is locked and therefore
+// cannot be changed.
+static nsresult
 PREF_LockPref(const char* aKey, bool aLockIt)
 {
   if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   PrefHashEntry* pref = pref_HashTableLookup(aKey);
   if (!pref) {
@@ -1095,45 +997,45 @@ pref_SetValue(PrefValue* aExistingValue,
 }
 
 #ifdef DEBUG
 
 static pref_initPhase gPhase = START;
 
 static bool gWatchingPref = false;
 
-void
+static void
 pref_SetInitPhase(pref_initPhase aPhase)
 {
   gPhase = aPhase;
 }
 
-pref_initPhase
+static pref_initPhase
 pref_GetInitPhase()
 {
   return gPhase;
 }
 
-void
+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); }
 };
 
-bool
+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);
 }
 
@@ -1147,17 +1049,17 @@ public:
 #define WATCHING_PREF_RAII() WatchingPrefRAII watchingPrefRAII
 
 #else // DEBUG
 
 #define WATCHING_PREF_RAII()
 
 #endif // DEBUG
 
-PrefHashEntry*
+static PrefHashEntry*
 pref_HashTableLookup(const char* aKey)
 {
   MOZ_ASSERT(NS_IsMainThread() || mozilla::ServoStyleSet::IsInServoTraversal());
   MOZ_ASSERT((!XRE_IsContentProcess() || gPhase != START),
              "pref access before commandline prefs set");
 
   // If you're hitting this assertion, you've added a pref access to start up.
   // Consider moving it later or add it to the whitelist in ContentPrefs.cpp
@@ -1168,17 +1070,17 @@ pref_HashTableLookup(const char* aKey)
     MOZ_CRASH_UNSAFE_PRINTF(
       "accessing non-init pref %s before the rest of the prefs are sent", aKey);
   }
 #endif
 
   return static_cast<PrefHashEntry*>(gHashTable->Search(aKey));
 }
 
-nsresult
+static nsresult
 pref_HashPref(const char* aKey,
               PrefValue aValue,
               PrefType aType,
               uint32_t aFlags)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!gHashTable) {
@@ -1259,55 +1161,58 @@ pref_HashPref(const char* aKey,
 
   if (valueChanged) {
     return pref_DoCallback(aKey);
   }
 
   return NS_OK;
 }
 
-size_t
+static size_t
 pref_SizeOfPrivateData(MallocSizeOf aMallocSizeOf)
 {
   size_t n = gPrefNameArena.SizeOfExcludingThis(aMallocSizeOf);
   for (CallbackNode* node = gFirstCallback; node; node = node->mNext) {
     n += aMallocSizeOf(node);
     n += aMallocSizeOf(node->mDomain);
   }
   return n;
 }
 
-PrefType
+static PrefType
 PREF_GetPrefType(const char* aPrefName)
 {
   if (gHashTable) {
     PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
     if (pref) {
       return pref->mPrefFlags.GetPrefType();
     }
   }
   return PrefType::Invalid;
 }
 
-bool
+// 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);
     if (pref && pref->mPrefFlags.IsLocked()) {
       result = true;
     }
   }
 
   return result;
 }
 
-// Adds a node to the callback list; the position depends on aIsPriority.
-void
+// Adds a node to the callback list; the position depends on aIsPriority. The
+// callback function will be called if anything below that node is modified.
+static void
 PREF_RegisterCallback(const char* aPrefNode,
                       PrefChangedFunc aCallback,
                       void* aData,
                       bool aIsPriority)
 {
   NS_PRECONDITION(aPrefNode, "aPrefNode must not be nullptr");
   NS_PRECONDITION(aCallback, "aCallback must not be nullptr");
 
@@ -1331,17 +1236,17 @@ PREF_RegisterCallback(const char* aPrefN
     } else {
       node->mNext = gFirstCallback;
       gFirstCallback = node;
     }
   }
 }
 
 // Removes |node| from callback list. Returns the node after the deleted one.
-CallbackNode*
+static CallbackNode*
 pref_RemoveCallbackNode(CallbackNode* aNode, CallbackNode* aPrevNode)
 {
   NS_PRECONDITION(!aPrevNode || aPrevNode->mNext == aNode, "invalid params");
   NS_PRECONDITION(aPrevNode || gFirstCallback == aNode, "invalid params");
 
   NS_ASSERTION(
     !gCallbacksInProgress,
     "modifying the callback list while gCallbacksInProgress is true");
@@ -1355,18 +1260,19 @@ pref_RemoveCallbackNode(CallbackNode* aN
   if (gLastPriorityNode == aNode) {
     gLastPriorityNode = aPrevNode;
   }
   free(aNode->mDomain);
   free(aNode);
   return next_node;
 }
 
-// Deletes a node from the callback list or marks it for deletion.
-nsresult
+// Deletes a node from the callback list or marks it for deletion. Succeeds if
+// a callback was found that matched all the parameters.
+static nsresult
 PREF_UnregisterCallback(const char* aPrefNode,
                         PrefChangedFunc aCallback,
                         void* aData)
 {
   nsresult rv = NS_ERROR_FAILURE;
   CallbackNode* node = gFirstCallback;
   CallbackNode* prev_node = nullptr;
 
@@ -1428,17 +1334,18 @@ pref_DoCallback(const char* aChangedPref
       }
     }
     gShouldCleanupDeadNodes = false;
   }
 
   return rv;
 }
 
-void
+// The callback function of the prefs parser.
+static void
 PREF_ReaderCallback(void* aClosure,
                     const char* aPref,
                     PrefValue aValue,
                     PrefType aType,
                     bool aIsDefault,
                     bool aIsStickyDefault)
 {
   uint32_t flags = 0;
@@ -1497,43 +1404,16 @@ struct PrefParseState
   char* mLbCur;          // line buffer cursor
   char* mLbEnd;          // line buffer end
   char* mVb;             // value buffer (ptr into mLb)
   PrefType mVtype;       // PREF_{STRING,INT,BOOL}
   bool mIsDefault;       // true if (default) pref
   bool mIsStickyDefault; // true if (sticky) pref
 };
 
-// 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.
-// |aClosure| is extra data passed to |aReader|.
-void
-PREF_InitParseState(PrefParseState* aPS,
-                    PrefReader aReader,
-                    PrefParseErrorReporter aReporter,
-                    void* aClosure);
-
-// Release any memory in use by the PrefParseState instance.
-void
-PREF_FinalizeParseState(PrefParseState* aPS);
-
-// Parse a buffer containing some portion of a preference file.  This function
-// may be called repeatedly as new data is made available. The PrefReader
-// callback function passed PREF_InitParseState will be called as preference
-// name value pairs are extracted from the data. Returns false if buffer
-// contains malformed content.
-bool
-PREF_ParseBuf(PrefParseState* aPS, const char* aBuf, int aBufLen);
-
 // Pref parser states.
 enum
 {
   PREF_PARSE_INIT,
   PREF_PARSE_MATCH_STRING,
   PREF_PARSE_UNTIL_NAME,
   PREF_PARSE_QUOTED_STRING,
   PREF_PARSE_UNTIL_COMMA,
@@ -1658,36 +1538,52 @@ pref_DoCallback(PrefParseState* aPS)
                   aPS->mLb,
                   value,
                   aPS->mVtype,
                   aPS->mIsDefault,
                   aPS->mIsStickyDefault);
   return true;
 }
 
-void
+// 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.
+// |aClosure| is extra data passed to |aReader|.
+static void
 PREF_InitParseState(PrefParseState* aPS,
                     PrefReader aReader,
                     PrefParseErrorReporter aReporter,
                     void* aClosure)
 {
   memset(aPS, 0, sizeof(*aPS));
   aPS->mReader = aReader;
   aPS->mClosure = aClosure;
   aPS->mReporter = aReporter;
 }
 
-void
+// Release any memory in use by the PrefParseState instance.
+static void
 PREF_FinalizeParseState(PrefParseState* aPS)
 {
   if (aPS->mLb) {
     free(aPS->mLb);
   }
 }
 
+// Parse a buffer containing some portion of a preference file. This function
+// may be called repeatedly as new data is made available. The PrefReader
+// callback function passed PREF_InitParseState will be called as preference
+// name value pairs are extracted from the data. Returns false if buffer
+// contains malformed content.
+//
 // Pseudo-BNF
 // ----------
 // function      = LJUNK function-name JUNK function-args
 // function-name = "user_pref" | "pref" | "sticky_pref"
 // function-args = "(" JUNK pref-name JUNK "," JUNK pref-value JUNK ")" JUNK ";"
 // pref-name     = quoted-string
 // pref-value    = quoted-string | "true" | "false" | integer-value
 // JUNK          = *(WS | comment-block | comment-line)
@@ -1698,17 +1594,17 @@ PREF_FinalizeParseState(PrefParseState* 
 // LF            = <US-ASCII LF, linefeed (10)>
 // VT            = <US-ASCII HT, vertical-tab (11)>
 // FF            = <US-ASCII FF, form-feed (12)>
 // CR            = <US-ASCII CR, carriage return (13)>
 // comment-block = <C/C++ style comment block>
 // comment-line  = <C++ style comment line>
 // bcomment-line = <bourne-shell style comment line>
 //
-bool
+static bool
 PREF_ParseBuf(PrefParseState* aPS, const char* aBuf, int aBufLen)
 {
   const char* end;
   char c;
   char udigit;
   int state;
 
   // The line number is currently only used for the error/warning reporting.
@@ -3423,18 +3319,16 @@ nsRelativeFilePref::SetRelativeToKey(con
   mRelativeToKey.Assign(aRelativeToKey);
   return NS_OK;
 }
 
 //===========================================================================
 // Core prefs code
 //===========================================================================
 
-class PrefCallback;
-
 namespace mozilla {
 
 #define INITIAL_PREF_FILES 10
 
 static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
 
 void
 Preferences::DirtyCallback()
@@ -3475,19 +3369,16 @@ static nsresult
 openPrefFile(nsIFile* aFile);
 
 static Result<Ok, const char*>
 pref_InitInitialObjects();
 
 static nsresult
 pref_LoadPrefsInDirList(const char* aListId);
 
-static nsresult
-ReadExtensionPrefs(nsIFile* aFile);
-
 static const char kTelemetryPref[] = "toolkit.telemetry.enabled";
 static const char kOldTelemetryPref[] = "toolkit.telemetry.enabledPreRelease";
 static const char kChannelPref[] = "app.update.channel";
 
 // clang-format off
 static const char kPrefFileHeader[] =
   "# Mozilla User Preferences"
   NS_LINEBREAK
@@ -4121,17 +4012,17 @@ NS_INTERFACE_MAP_BEGIN(Preferences)
   NS_INTERFACE_MAP_ENTRY(nsIPrefBranch)
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
 NS_INTERFACE_MAP_END
 
 //
 // nsIPrefService Implementation
 //
 
-InfallibleTArray<Preferences::PrefSetting>* gInitPrefs;
+static InfallibleTArray<Preferences::PrefSetting>* gInitPrefs;
 
 /* static */ void
 Preferences::SetInitPreferences(nsTArray<PrefSetting>* aPrefs)
 {
   gInitPrefs = new InfallibleTArray<PrefSetting>(mozilla::Move(*aPrefs));
 }
 
 Result<Ok, const char*>