Bug 1405908 - Restyle prefapi.cpp (manual + clang-format). r=glandium. draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 05 Oct 2017 13:23:44 +1100
changeset 675256 337fc6dd766b074f4d3eaf71a4d2ae021c3a268c
parent 675255 f35430fde52c24e8e5631688158e0c0ca0666d80
child 734556 430e5c330e44bd07ae0ea26522e768a6960269dc
push id83081
push usernnethercote@mozilla.com
push dateThu, 05 Oct 2017 02:24:23 +0000
reviewersglandium
bugs1405908
milestone58.0a1
Bug 1405908 - Restyle prefapi.cpp (manual + clang-format). r=glandium. MozReview-Commit-ID: 8gcYpRVQeeo
modules/libpref/prefapi.cpp
--- a/modules/libpref/prefapi.cpp
+++ b/modules/libpref/prefapi.cpp
@@ -2,103 +2,121 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <string>
 #include <vector>
 
 #include "base/basictypes.h"
-
+#include "MainThreadUtils.h"
+#include "mozilla/ArenaAllocatorExtensions.h"
+#include "mozilla/ArenaAllocator.h"
+#include "mozilla/dom/ContentPrefs.h"
+#include "mozilla/dom/PContent.h"
+#include "mozilla/Logging.h"
+#include "mozilla/MemoryReporting.h"
+#include "mozilla/ServoStyleSet.h"
+#include "nsCRT.h"
+#include "nsPrintfCString.h"
+#include "nsQuickSort.h"
+#include "nsReadableUtils.h"
+#include "nsString.h"
+#include "plbase64.h"
+#include "PLDHashTable.h"
+#include "plstr.h"
 #include "prefapi.h"
 #include "prefapi_private_data.h"
 #include "prefread.h"
-#include "MainThreadUtils.h"
-#include "nsReadableUtils.h"
-#include "nsCRT.h"
+#include "prlink.h"
 
 #ifdef _WIN32
 #include "windows.h"
-#endif /* _WIN32 */
-
-#include "plstr.h"
-#include "PLDHashTable.h"
-#include "plbase64.h"
-#include "mozilla/ArenaAllocator.h"
-#include "mozilla/ArenaAllocatorExtensions.h"
-#include "mozilla/Logging.h"
-#include "mozilla/MemoryReporting.h"
-#include "mozilla/ServoStyleSet.h"
-#include "mozilla/dom/PContent.h"
-#include "mozilla/dom/ContentPrefs.h"
-#include "nsQuickSort.h"
-#include "nsString.h"
-#include "nsPrintfCString.h"
-#include "prlink.h"
+#endif
 
 using namespace mozilla;
 
 static void
-clearPrefEntry(PLDHashTable* table, PLDHashEntryHdr* entry)
+ClearPrefEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry)
 {
-  PrefHashEntry* pref = static_cast<PrefHashEntry*>(entry);
+  auto pref = static_cast<PrefHashEntry*>(aEntry);
   if (pref->prefFlags.IsTypeString()) {
-    if (pref->defaultPref.stringVal)
+    if (pref->defaultPref.stringVal) {
       PL_strfree(pref->defaultPref.stringVal);
-    if (pref->userPref.stringVal)
+    }
+    if (pref->userPref.stringVal) {
       PL_strfree(pref->userPref.stringVal);
+    }
   }
-  // don't need to free this as it's allocated in memory owned by
-  // gPrefNameArena
+
+  // Don't need to free this because it's allocated in memory owned by
+  // gPrefNameArena.
   pref->key = nullptr;
-  memset(entry, 0, table->EntrySize());
+  memset(aEntry, 0, aTable->EntrySize());
 }
 
 static bool
-matchPrefEntry(const PLDHashEntryHdr* entry, const void* key)
+MatchPrefEntry(const PLDHashEntryHdr* aEntry, const void* aKey)
 {
-  const PrefHashEntry* prefEntry = static_cast<const PrefHashEntry*>(entry);
+  auto prefEntry = static_cast<const PrefHashEntry*>(aEntry);
 
-  if (prefEntry->key == key)
+  if (prefEntry->key == aKey) {
     return true;
+  }
 
-  if (!prefEntry->key || !key)
+  if (!prefEntry->key || !aKey) {
     return false;
+  }
 
-  const char* otherKey = reinterpret_cast<const char*>(key);
+  auto otherKey = static_cast<const char*>(aKey);
   return (strcmp(prefEntry->key, otherKey) == 0);
 }
 
+struct CallbackNode
+{
+  char* mDomain;
+
+  // 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 ArenaAllocator<8192, 4> gPrefNameArena;
 
-static struct CallbackNode* gFirstCallback = nullptr;
-static struct CallbackNode* gLastPriorityNode = nullptr;
+static CallbackNode* gFirstCallback = nullptr;
+static CallbackNode* gLastPriorityNode = nullptr;
+
 static bool gIsAnyPrefLocked = false;
-// These are only used during the call to pref_DoCallback
+
+// These are only used during the call to pref_DoCallback.
 static bool gCallbacksInProgress = false;
 static bool gShouldCleanupDeadNodes = false;
 
 static PLDHashTableOps pref_HashTableOps = {
   PLDHashTable::HashStringKey,
-  matchPrefEntry,
+  MatchPrefEntry,
   PLDHashTable::MoveEntryStub,
-  clearPrefEntry,
+  ClearPrefEntry,
   nullptr,
 };
 
-// PR_ALIGN_OF_WORD is only defined on some platforms.  ALIGN_OF_WORD has
-// already been defined to PR_ALIGN_OF_WORD everywhere
+// PR_ALIGN_OF_WORD is only defined on some platforms. ALIGN_OF_WORD has
+// already been defined to PR_ALIGN_OF_WORD everywhere.
 #ifndef PR_ALIGN_OF_WORD
 #define PR_ALIGN_OF_WORD PR_ALIGN_OF_POINTER
 #endif
 
 #define WORD_ALIGN_MASK (PR_ALIGN_OF_WORD - 1)
 
-// sanity checking
+// Sanity checking.
 #if (PR_ALIGN_OF_WORD & WORD_ALIGN_MASK) != 0
 #error "PR_ALIGN_OF_WORD must be a power of 2!"
 #endif
 
 static PrefsDirtyFunc gDirtyCallback = nullptr;
 
 inline void
 MakeDirtyCallback()
@@ -114,109 +132,102 @@ MakeDirtyCallback()
 }
 
 void
 PREF_SetDirtyCallback(PrefsDirtyFunc aFunc)
 {
   gDirtyCallback = aFunc;
 }
 
-/*---------------------------------------------------------------------------*/
+//---------------------------------------------------------------------------
 
 static bool
-pref_ValueChanged(PrefValue oldValue, PrefValue newValue, PrefType type);
-/* -- Privates */
-struct CallbackNode
-{
-  char* domain;
-  // 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 func;
-  void* data;
-  struct CallbackNode* next;
-};
+pref_ValueChanged(PrefValue aOldValue, PrefValue aNewValue, PrefType aType);
 
-/* -- Prototypes */
 static nsresult
-pref_DoCallback(const char* changed_pref);
+pref_DoCallback(const char* aChangedPref);
 
 enum
 {
   kPrefSetDefault = 1,
   kPrefForceSet = 2,
   kPrefStickyDefault = 4,
 };
+
 static nsresult
-pref_HashPref(const char* key, PrefValue value, PrefType type, uint32_t flags);
+pref_HashPref(const char* aKey,
+              PrefValue aValue,
+              PrefType aType,
+              uint32_t aFlags);
 
 #define PREF_HASHTABLE_INITIAL_LENGTH 1024
 
 void
 PREF_Init()
 {
   if (!gHashTable) {
     gHashTable = new PLDHashTable(
       &pref_HashTableOps, sizeof(PrefHashEntry), PREF_HASHTABLE_INITIAL_LENGTH);
   }
 }
 
-/* Frees the callback list. */
+// Frees the callback list.
 void
 PREF_Cleanup()
 {
   NS_ASSERTION(!gCallbacksInProgress,
                "PREF_Cleanup was called while gCallbacksInProgress is true!");
-  struct CallbackNode* node = gFirstCallback;
-  struct CallbackNode* next_node;
+
+  CallbackNode* node = gFirstCallback;
+  CallbackNode* next_node;
 
   while (node) {
-    next_node = node->next;
-    PL_strfree(node->domain);
+    next_node = node->mNext;
+    PL_strfree(node->mDomain);
     free(node);
     node = next_node;
   }
   gLastPriorityNode = gFirstCallback = nullptr;
 
   PREF_CleanupPrefs();
 }
 
-/* Frees up all the objects except the callback list. */
+// 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!
+// Note that this appends to aResult, and does not assign!
 static void
-str_escape(const char* original, nsCString& aResult)
+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 (line separator) or \u2029 (paragraph separator).
-     *
-     * WARNING: There are hints that we may be moving to storing prefs
-     * as utf8. If we ever feed them to the JS compiler as UTF8 then
-     * we'll have to worry about the multibyte sequences that would be
-     * interpreted as \u2028 and \u2029
-     */
+  // 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
+  // (line separator) or \u2029 (paragraph separator).
+  //
+  // WARNING: There are hints that we may be moving to storing prefs as utf8.
+  // If we ever feed them to the JS compiler as UTF8 then we'll have to worry
+  // about the multibyte sequences that would be interpreted as \u2028 and
+  // \u2029.
   const char* p;
 
-  if (original == nullptr)
+  if (aOriginal == nullptr) {
     return;
+  }
 
-  /* Paranoid worst case all slashes will free quickly */
-  for (p = original; *p; ++p) {
+  // Paranoid worst case all slashes will free quickly.
+  for (p = aOriginal; *p; ++p) {
     switch (*p) {
       case '\n':
         aResult.AppendLiteral("\\n");
         break;
 
       case '\r':
         aResult.AppendLiteral("\\r");
         break;
@@ -231,72 +242,78 @@ str_escape(const char* original, nsCStri
 
       default:
         aResult.Append(*p);
         break;
     }
   }
 }
 
-/*
-** External calls
-*/
+//
+// External calls
+//
+
 nsresult
-PREF_SetCharPref(const char* pref_name, const char* value, bool set_default)
+PREF_SetCharPref(const char* aPrefName, const char* aValue, bool aSetDefault)
 {
-  if ((uint32_t)strlen(value) > MAX_PREF_LENGTH) {
+  if (strlen(aValue) > MAX_PREF_LENGTH) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
   PrefValue pref;
-  pref.stringVal = (char*)value;
+  pref.stringVal = const_cast<char*>(aValue);
 
   return pref_HashPref(
-    pref_name, pref, PrefType::String, set_default ? kPrefSetDefault : 0);
+    aPrefName, pref, PrefType::String, aSetDefault ? kPrefSetDefault : 0);
 }
 
 nsresult
-PREF_SetIntPref(const char* pref_name, int32_t value, bool set_default)
+PREF_SetIntPref(const char* aPrefName, int32_t aValue, bool aSetDefault)
 {
   PrefValue pref;
-  pref.intVal = value;
+  pref.intVal = aValue;
 
   return pref_HashPref(
-    pref_name, pref, PrefType::Int, set_default ? kPrefSetDefault : 0);
+    aPrefName, pref, PrefType::Int, aSetDefault ? kPrefSetDefault : 0);
 }
 
 nsresult
-PREF_SetBoolPref(const char* pref_name, bool value, bool set_default)
+PREF_SetBoolPref(const char* aPrefName, bool aValue, bool aSetDefault)
 {
   PrefValue pref;
-  pref.boolVal = value;
+  pref.boolVal = aValue;
 
   return pref_HashPref(
-    pref_name, pref, PrefType::Bool, set_default ? kPrefSetDefault : 0);
+    aPrefName, pref, PrefType::Bool, aSetDefault ? kPrefSetDefault : 0);
 }
 
 enum WhichValue
 {
   DEFAULT_VALUE,
   USER_VALUE
 };
+
 static nsresult
 SetPrefValue(const char* aPrefName,
              const dom::PrefValue& aValue,
              WhichValue aWhich)
 {
   bool setDefault = (aWhich == DEFAULT_VALUE);
+
   switch (aValue.type()) {
     case dom::PrefValue::TnsCString:
       return PREF_SetCharPref(
         aPrefName, aValue.get_nsCString().get(), setDefault);
+
     case dom::PrefValue::Tint32_t:
       return PREF_SetIntPref(aPrefName, aValue.get_int32_t(), setDefault);
+
     case dom::PrefValue::Tbool:
       return PREF_SetBoolPref(aPrefName, aValue.get_bool(), setDefault);
+
     default:
       MOZ_CRASH();
   }
 }
 
 nsresult
 pref_SetPref(const dom::PrefSetting& aPref)
 {
@@ -337,44 +354,44 @@ pref_savePrefs(PLDHashTable* aTable)
     prefPrefix.AssignLiteral("user_pref(\"");
 
     // where we're getting our pref from
     PrefValue* sourcePref;
 
     if (pref->prefFlags.HasUserValue() &&
         (pref_ValueChanged(
            pref->defaultPref, pref->userPref, pref->prefFlags.GetPrefType()) ||
-         !(pref->prefFlags.HasDefault()) ||
-         pref->prefFlags.HasStickyDefault())) {
+         !pref->prefFlags.HasDefault() || pref->prefFlags.HasStickyDefault())) {
       sourcePref = &pref->userPref;
     } else {
       // do not save default prefs that haven't changed
       continue;
     }
 
     // strings are in quotes!
     if (pref->prefFlags.IsTypeString()) {
       prefValue = '\"';
-      str_escape(sourcePref->stringVal, prefValue);
+      StrEscape(sourcePref->stringVal, prefValue);
       prefValue += '\"';
 
     } else if (pref->prefFlags.IsTypeInt()) {
       prefValue.AppendInt(sourcePref->intVal);
 
     } else if (pref->prefFlags.IsTypeBool()) {
       prefValue = (sourcePref->boolVal) ? "true" : "false";
     }
 
     nsAutoCString prefName;
-    str_escape(pref->key, prefName);
+    StrEscape(pref->key, prefName);
 
     savedPrefs.AppendElement()->reset(
       ToNewCString(prefPrefix + prefName + NS_LITERAL_CSTRING("\", ") +
                    prefValue + NS_LITERAL_CSTRING(");")));
   }
+
   return savedPrefs;
 }
 
 bool
 pref_EntryHasAdvisablySizedValues(PrefHashEntry* aHashEntry)
 {
   if (aHashEntry->prefFlags.GetPrefType() != PrefType::String) {
     return true;
@@ -429,187 +446,201 @@ GetPrefValueFromEntry(PrefHashEntry* aHa
       MOZ_CRASH();
   }
 }
 
 void
 pref_GetPrefFromEntry(PrefHashEntry* aHashEntry, dom::PrefSetting* aPref)
 {
   aPref->name() = aHashEntry->key;
+
   if (aHashEntry->prefFlags.HasDefault()) {
     GetPrefValueFromEntry(aHashEntry, aPref, DEFAULT_VALUE);
   } else {
     aPref->defaultValue() = null_t();
   }
+
   if (aHashEntry->prefFlags.HasUserValue()) {
     GetPrefValueFromEntry(aHashEntry, aPref, USER_VALUE);
   } else {
     aPref->userValue() = null_t();
   }
 
   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
-PREF_HasUserPref(const char* pref_name)
+PREF_HasUserPref(const char* aPrefName)
 {
-  if (!gHashTable)
+  if (!gHashTable) {
     return false;
+  }
 
-  PrefHashEntry* pref = pref_HashTableLookup(pref_name);
+  PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
   return pref && pref->prefFlags.HasUserValue();
 }
 
 nsresult
-PREF_CopyCharPref(const char* pref_name, char** return_buffer, bool get_default)
+PREF_CopyCharPref(const char* aPrefName, char** aStringOut, bool aGetDefault)
 {
-  if (!gHashTable)
+  if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
+  }
 
   nsresult rv = NS_ERROR_UNEXPECTED;
   char* stringVal;
-  PrefHashEntry* pref = pref_HashTableLookup(pref_name);
+  PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
 
-  if (pref && (pref->prefFlags.IsTypeString())) {
-    if (get_default || pref->prefFlags.IsLocked() ||
+  if (pref && pref->prefFlags.IsTypeString()) {
+    if (aGetDefault || pref->prefFlags.IsLocked() ||
         !pref->prefFlags.HasUserValue()) {
       stringVal = pref->defaultPref.stringVal;
     } else {
       stringVal = pref->userPref.stringVal;
     }
 
     if (stringVal) {
-      *return_buffer = NS_strdup(stringVal);
+      *aStringOut = NS_strdup(stringVal);
       rv = NS_OK;
     }
   }
+
   return rv;
 }
 
 nsresult
-PREF_GetIntPref(const char* pref_name, int32_t* return_int, bool get_default)
+PREF_GetIntPref(const char* aPrefName, int32_t* aIntOut, bool aGetDefault)
 {
-  if (!gHashTable)
+  if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
+  }
 
   nsresult rv = NS_ERROR_UNEXPECTED;
-  PrefHashEntry* pref = pref_HashTableLookup(pref_name);
-  if (pref && (pref->prefFlags.IsTypeInt())) {
-    if (get_default || pref->prefFlags.IsLocked() ||
+  PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
+  if (pref && pref->prefFlags.IsTypeInt()) {
+    if (aGetDefault || pref->prefFlags.IsLocked() ||
         !pref->prefFlags.HasUserValue()) {
       int32_t tempInt = pref->defaultPref.intVal;
-      /* check to see if we even had a default */
+
+      // Check to see if we even had a default.
       if (!pref->prefFlags.HasDefault()) {
         return NS_ERROR_UNEXPECTED;
       }
-      *return_int = tempInt;
+      *aIntOut = tempInt;
     } else {
-      *return_int = pref->userPref.intVal;
+      *aIntOut = pref->userPref.intVal;
     }
     rv = NS_OK;
   }
+
   return rv;
 }
 
 nsresult
-PREF_GetBoolPref(const char* pref_name, bool* return_value, bool get_default)
+PREF_GetBoolPref(const char* aPrefName, bool* aBoolOut, bool aGetDefault)
 {
-  if (!gHashTable)
+  if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
+  }
 
   nsresult rv = NS_ERROR_UNEXPECTED;
-  PrefHashEntry* pref = pref_HashTableLookup(pref_name);
-  //NS_ASSERTION(pref, pref_name);
-  if (pref && (pref->prefFlags.IsTypeBool())) {
-    if (get_default || pref->prefFlags.IsLocked() ||
+  PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
+  //NS_ASSERTION(pref, aPrefName);
+  if (pref && pref->prefFlags.IsTypeBool()) {
+    if (aGetDefault || pref->prefFlags.IsLocked() ||
         !pref->prefFlags.HasUserValue()) {
       bool tempBool = pref->defaultPref.boolVal;
-      /* check to see if we even had a default */
+
+      // Check to see if we even had a default.
       if (pref->prefFlags.HasDefault()) {
-        *return_value = tempBool;
+        *aBoolOut = tempBool;
         rv = NS_OK;
       }
     } else {
-      *return_value = pref->userPref.boolVal;
+      *aBoolOut = pref->userPref.boolVal;
       rv = NS_OK;
     }
   }
+
   return rv;
 }
 
 nsresult
-PREF_DeleteBranch(const char* branch_name)
+PREF_DeleteBranch(const char* aBranchName)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  int len = (int)strlen(branch_name);
+  size_t len = strlen(aBranchName);
 
-  if (!gHashTable)
+  if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
+  }
 
-  /* The following check insures that if the branch name already has a "."
-     * at the end, we don't end up with a "..". This fixes an incompatibility
-     * between nsIPref, which needs the period added, and nsIPrefBranch which
-     * does not. When nsIPref goes away this function should be fixed to
-     * never add the period at all.
-     */
-  nsAutoCString branch_dot(branch_name);
-  if ((len > 1) && branch_name[len - 1] != '.')
+  // The following check insures that if the branch name already has a "." at
+  // the end, we don't end up with a "..". This fixes an incompatibility
+  // between nsIPref, which needs the period added, and nsIPrefBranch which
+  // does not. When nsIPref goes away this function should be fixed to never
+  // add the period at all.
+  nsAutoCString branch_dot(aBranchName);
+  if (len > 1 && aBranchName[len - 1] != '.') {
     branch_dot += '.';
+  }
 
-  /* Delete a branch. Used for deleting mime types */
+  // Delete a branch. Used for deleting mime types.
   const char* to_delete = branch_dot.get();
   MOZ_ASSERT(to_delete);
   len = strlen(to_delete);
   for (auto iter = gHashTable->Iter(); !iter.Done(); iter.Next()) {
     auto entry = static_cast<PrefHashEntry*>(iter.Get());
 
-    /* note if we're deleting "ldap" then we want to delete "ldap.xxx"
-            and "ldap" (if such a leaf node exists) but not "ldap_1.xxx" */
-    if (PL_strncmp(entry->key, to_delete, (uint32_t)len) == 0 ||
-        (len - 1 == (int)strlen(entry->key) &&
-         PL_strncmp(entry->key, to_delete, (uint32_t)(len - 1)) == 0)) {
+    // Note: if we're deleting "ldap" then we want to delete "ldap.xxx" and
+    // "ldap" (if such a leaf node exists) but not "ldap_1.xxx".
+    if (PL_strncmp(entry->key, to_delete, len) == 0 ||
+        (len - 1 == strlen(entry->key) &&
+         PL_strncmp(entry->key, to_delete, len - 1) == 0)) {
       iter.Remove();
     }
   }
 
   MakeDirtyCallback();
   return NS_OK;
 }
 
 nsresult
-PREF_ClearUserPref(const char* pref_name)
+PREF_ClearUserPref(const char* aPrefName)
 {
-  if (!gHashTable)
+  if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
+  }
 
-  PrefHashEntry* pref = pref_HashTableLookup(pref_name);
+  PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
   if (pref && pref->prefFlags.HasUserValue()) {
     pref->prefFlags.SetHasUserValue(false);
 
     if (!pref->prefFlags.HasDefault()) {
       gHashTable->RemoveEntry(pref);
     }
 
-    pref_DoCallback(pref_name);
+    pref_DoCallback(aPrefName);
     MakeDirtyCallback();
   }
   return NS_OK;
 }
 
 nsresult
 PREF_ClearAllUserPrefs()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  if (!gHashTable)
+  if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
+  }
 
   std::vector<std::string> prefStrings;
   for (auto iter = gHashTable->Iter(); !iter.Done(); iter.Next()) {
     auto pref = static_cast<PrefHashEntry*>(iter.Get());
 
     if (pref->prefFlags.HasUserValue()) {
       prefStrings.push_back(std::string(pref->key));
 
@@ -624,100 +655,107 @@ PREF_ClearAllUserPrefs()
     pref_DoCallback(prefString.c_str());
   }
 
   MakeDirtyCallback();
   return NS_OK;
 }
 
 nsresult
-PREF_LockPref(const char* key, bool lockit)
+PREF_LockPref(const char* aKey, bool aLockIt)
 {
-  if (!gHashTable)
+  if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
+  }
 
-  PrefHashEntry* pref = pref_HashTableLookup(key);
-  if (!pref)
+  PrefHashEntry* pref = pref_HashTableLookup(aKey);
+  if (!pref) {
     return NS_ERROR_UNEXPECTED;
+  }
 
-  if (lockit) {
+  if (aLockIt) {
     if (!pref->prefFlags.IsLocked()) {
       pref->prefFlags.SetLocked(true);
       gIsAnyPrefLocked = true;
-      pref_DoCallback(key);
+      pref_DoCallback(aKey);
     }
-  } else {
-    if (pref->prefFlags.IsLocked()) {
-      pref->prefFlags.SetLocked(false);
-      pref_DoCallback(key);
-    }
+  } else if (pref->prefFlags.IsLocked()) {
+    pref->prefFlags.SetLocked(false);
+    pref_DoCallback(aKey);
   }
+
   return NS_OK;
 }
 
-/*
- * Hash table functions
- */
+//
+// Hash table functions
+//
+
 static bool
-pref_ValueChanged(PrefValue oldValue, PrefValue newValue, PrefType type)
+pref_ValueChanged(PrefValue aOldValue, PrefValue aNewValue, PrefType aType)
 {
   bool changed = true;
-  switch (type) {
+  switch (aType) {
     case PrefType::String:
-      if (oldValue.stringVal && newValue.stringVal) {
-        changed = (strcmp(oldValue.stringVal, newValue.stringVal) != 0);
+      if (aOldValue.stringVal && aNewValue.stringVal) {
+        changed = (strcmp(aOldValue.stringVal, aNewValue.stringVal) != 0);
       }
       break;
+
     case PrefType::Int:
-      changed = oldValue.intVal != newValue.intVal;
+      changed = aOldValue.intVal != aNewValue.intVal;
       break;
+
     case PrefType::Bool:
-      changed = oldValue.boolVal != newValue.boolVal;
+      changed = aOldValue.boolVal != aNewValue.boolVal;
       break;
+
     case PrefType::Invalid:
     default:
       changed = false;
       break;
   }
+
   return changed;
 }
 
-/*
- * Overwrite the type and value of an existing preference. Caller must
- * ensure that they are not changing the type of a preference that has
- * a default value.
- */
+// Overwrite the type and value of an existing preference. Caller must ensure
+// that they are not changing the type of a preference that has a default
+// value.
 static PrefTypeFlags
-pref_SetValue(PrefValue* existingValue,
-              PrefTypeFlags flags,
-              PrefValue newValue,
-              PrefType newType)
+pref_SetValue(PrefValue* aExistingValue,
+              PrefTypeFlags aFlags,
+              PrefValue aNewValue,
+              PrefType aNewType)
 {
-  if (flags.IsTypeString() && existingValue->stringVal) {
-    PL_strfree(existingValue->stringVal);
+  if (aFlags.IsTypeString() && aExistingValue->stringVal) {
+    PL_strfree(aExistingValue->stringVal);
   }
-  flags.SetPrefType(newType);
-  if (flags.IsTypeString()) {
-    MOZ_ASSERT(newValue.stringVal);
-    existingValue->stringVal =
-      newValue.stringVal ? PL_strdup(newValue.stringVal) : nullptr;
+
+  aFlags.SetPrefType(aNewType);
+  if (aFlags.IsTypeString()) {
+    MOZ_ASSERT(aNewValue.stringVal);
+    aExistingValue->stringVal =
+      aNewValue.stringVal ? PL_strdup(aNewValue.stringVal) : nullptr;
   } else {
-    *existingValue = newValue;
+    *aExistingValue = aNewValue;
   }
-  return flags;
+
+  return aFlags;
 }
+
 #ifdef DEBUG
 static pref_initPhase gPhase = START;
 
 static bool gWatchingPref = false;
 
 void
-pref_SetInitPhase(pref_initPhase phase)
+pref_SetInitPhase(pref_initPhase aPhase)
 {
-  gPhase = phase;
+  gPhase = aPhase;
 }
 
 pref_initPhase
 pref_GetInitPhase()
 {
   return gPhase;
 }
 
@@ -729,331 +767,333 @@ pref_SetWatchingPref(bool watching)
 
 struct StringComparator
 {
   const char* mKey;
   explicit StringComparator(const char* aKey)
     : mKey(aKey)
   {
   }
-  int operator()(const char* string) const { return strcmp(mKey, string); }
+  int operator()(const char* aString) const { return strcmp(mKey, aString); }
 };
 
 bool
-inInitArray(const char* key)
+InInitArray(const char* aKey)
 {
   size_t prefsLen;
   size_t found;
   const char** list = mozilla::dom::ContentPrefs::GetContentPrefs(&prefsLen);
-  return BinarySearchIf(list, 0, prefsLen, StringComparator(key), &found);
+  return BinarySearchIf(list, 0, prefsLen, StringComparator(aKey), &found);
 }
 #endif
 
 PrefHashEntry*
-pref_HashTableLookup(const char* key)
+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
-     * and get review from a DOM peer
-     */
+
+  // 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
+  // and get review from a DOM peer
 #ifdef DEBUG
   if (XRE_IsContentProcess() && gPhase <= END_INIT_PREFS && !gWatchingPref &&
-      !inInitArray(key)) {
+      !InInitArray(aKey)) {
     MOZ_CRASH_UNSAFE_PRINTF(
-      "accessing non-init pref %s before the rest of the prefs are sent", key);
+      "accessing non-init pref %s before the rest of the prefs are sent", aKey);
   }
 #endif
-  return static_cast<PrefHashEntry*>(gHashTable->Search(key));
+
+  return static_cast<PrefHashEntry*>(gHashTable->Search(aKey));
 }
 
 nsresult
-pref_HashPref(const char* key, PrefValue value, PrefType type, uint32_t flags)
+pref_HashPref(const char* aKey,
+              PrefValue aValue,
+              PrefType aType,
+              uint32_t aFlags)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  if (!gHashTable)
+  if (!gHashTable) {
     return NS_ERROR_OUT_OF_MEMORY;
-
-  auto pref = static_cast<PrefHashEntry*>(gHashTable->Add(key, fallible));
-  if (!pref)
-    return NS_ERROR_OUT_OF_MEMORY;
+  }
 
-  // new entry, better initialize
-  if (!pref->key) {
+  auto pref = static_cast<PrefHashEntry*>(gHashTable->Add(aKey, fallible));
+  if (!pref) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
 
-    // initialize the pref entry
-    pref->prefFlags.Reset().SetPrefType(type);
-    pref->key = ArenaStrdup(key, gPrefNameArena);
+  // New entry, need to initialize.
+  if (!pref->key) {
+    // Initialize the pref entry.
+    pref->prefFlags.Reset().SetPrefType(aType);
+    pref->key = ArenaStrdup(aKey, gPrefNameArena);
     memset(&pref->defaultPref, 0, sizeof(pref->defaultPref));
     memset(&pref->userPref, 0, sizeof(pref->userPref));
+
   } else if (pref->prefFlags.HasDefault() &&
-             !pref->prefFlags.IsPrefType(type)) {
+             !pref->prefFlags.IsPrefType(aType)) {
     NS_WARNING(
       nsPrintfCString(
         "Trying to overwrite value of default pref %s with the wrong type!",
-        key)
+        aKey)
         .get());
+
     return NS_ERROR_UNEXPECTED;
   }
 
   bool valueChanged = false;
-  if (flags & kPrefSetDefault) {
+  if (aFlags & kPrefSetDefault) {
     if (!pref->prefFlags.IsLocked()) {
-      /* ?? change of semantics? */
-      if (pref_ValueChanged(pref->defaultPref, value, type) ||
+      // ?? change of semantics?
+      if (pref_ValueChanged(pref->defaultPref, aValue, aType) ||
           !pref->prefFlags.HasDefault()) {
         pref->prefFlags =
-          pref_SetValue(&pref->defaultPref, pref->prefFlags, value, type)
+          pref_SetValue(&pref->defaultPref, pref->prefFlags, aValue, aType)
             .SetHasDefault(true);
-        if (flags & kPrefStickyDefault) {
+        if (aFlags & kPrefStickyDefault) {
           pref->prefFlags.SetHasStickyDefault(true);
         }
         if (!pref->prefFlags.HasUserValue()) {
           valueChanged = true;
         }
       }
       // What if we change the default to be the same as the user value?
       // Should we clear the user value?
     }
   } else {
-    /* If new value is same as the default value and it's not a "sticky"
-           pref, then un-set the user value.
-           Otherwise, set the user value only if it has changed */
+    // If new value is same as the default value and it's not a "sticky" pref,
+    // then un-set the user value. Otherwise, set the user value only if it has
+    // changed.
     if ((pref->prefFlags.HasDefault()) &&
         !(pref->prefFlags.HasStickyDefault()) &&
-        !pref_ValueChanged(pref->defaultPref, value, type) &&
-        !(flags & kPrefForceSet)) {
+        !pref_ValueChanged(pref->defaultPref, aValue, aType) &&
+        !(aFlags & kPrefForceSet)) {
       if (pref->prefFlags.HasUserValue()) {
-        /* XXX should we free a user-set string value if there is one? */
+        // XXX should we free a user-set string value if there is one?
         pref->prefFlags.SetHasUserValue(false);
         if (!pref->prefFlags.IsLocked()) {
           MakeDirtyCallback();
           valueChanged = true;
         }
       }
     } else if (!pref->prefFlags.HasUserValue() ||
-               !pref->prefFlags.IsPrefType(type) ||
-               pref_ValueChanged(pref->userPref, value, type)) {
+               !pref->prefFlags.IsPrefType(aType) ||
+               pref_ValueChanged(pref->userPref, aValue, aType)) {
       pref->prefFlags =
-        pref_SetValue(&pref->userPref, pref->prefFlags, value, type)
+        pref_SetValue(&pref->userPref, pref->prefFlags, aValue, aType)
           .SetHasUserValue(true);
       if (!pref->prefFlags.IsLocked()) {
         MakeDirtyCallback();
         valueChanged = true;
       }
     }
   }
 
   if (valueChanged) {
-    return pref_DoCallback(key);
+    return pref_DoCallback(aKey);
   }
+
   return NS_OK;
 }
 
 size_t
 pref_SizeOfPrivateData(MallocSizeOf aMallocSizeOf)
 {
   size_t n = gPrefNameArena.SizeOfExcludingThis(aMallocSizeOf);
-  for (struct CallbackNode* node = gFirstCallback; node; node = node->next) {
+  for (CallbackNode* node = gFirstCallback; node; node = node->mNext) {
     n += aMallocSizeOf(node);
-    n += aMallocSizeOf(node->domain);
+    n += aMallocSizeOf(node->mDomain);
   }
   return n;
 }
 
 PrefType
-PREF_GetPrefType(const char* pref_name)
+PREF_GetPrefType(const char* aPrefName)
 {
   if (gHashTable) {
-    PrefHashEntry* pref = pref_HashTableLookup(pref_name);
+    PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
     if (pref) {
       return pref->prefFlags.GetPrefType();
     }
   }
   return PrefType::Invalid;
 }
 
-/* -- */
-
 bool
-PREF_PrefIsLocked(const char* pref_name)
+PREF_PrefIsLocked(const char* aPrefName)
 {
   bool result = false;
   if (gIsAnyPrefLocked && gHashTable) {
-    PrefHashEntry* pref = pref_HashTableLookup(pref_name);
+    PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
     if (pref && pref->prefFlags.IsLocked()) {
       result = true;
     }
   }
 
   return result;
 }
 
-/* Adds a node to the beginning of the callback list. */
+// Adds a node to the beginning of the callback list.
 void
-PREF_RegisterPriorityCallback(const char* pref_node,
-                              PrefChangedFunc callback,
-                              void* instance_data)
+PREF_RegisterPriorityCallback(const char* aPrefNode,
+                              PrefChangedFunc aCallback,
+                              void* aData)
 {
-  NS_PRECONDITION(pref_node, "pref_node must not be nullptr");
-  NS_PRECONDITION(callback, "callback must not be nullptr");
+  NS_PRECONDITION(aPrefNode, "aPrefNode must not be nullptr");
+  NS_PRECONDITION(aCallback, "aCallback must not be nullptr");
 
-  struct CallbackNode* node =
-    (struct CallbackNode*)malloc(sizeof(struct CallbackNode));
+  auto node = (CallbackNode*)malloc(sizeof(struct CallbackNode));
   if (node) {
-    node->domain = PL_strdup(pref_node);
-    node->func = callback;
-    node->data = instance_data;
-    node->next = gFirstCallback;
+    node->mDomain = PL_strdup(aPrefNode);
+    node->mFunc = aCallback;
+    node->mData = aData;
+    node->mNext = gFirstCallback;
     gFirstCallback = node;
     if (!gLastPriorityNode) {
       gLastPriorityNode = node;
     }
   }
 }
 
-/* Adds a node to the end of the callback list. */
+// Adds a node to the end of the callback list.
 void
-PREF_RegisterCallback(const char* pref_node,
-                      PrefChangedFunc callback,
-                      void* instance_data)
+PREF_RegisterCallback(const char* aPrefNode,
+                      PrefChangedFunc aCallback,
+                      void* aData)
 {
-  NS_PRECONDITION(pref_node, "pref_node must not be nullptr");
-  NS_PRECONDITION(callback, "callback must not be nullptr");
+  NS_PRECONDITION(aPrefNode, "aPrefNode must not be nullptr");
+  NS_PRECONDITION(aCallback, "aCallback must not be nullptr");
 
-  struct CallbackNode* node =
-    (struct CallbackNode*)malloc(sizeof(struct CallbackNode));
+  auto node = (CallbackNode*)malloc(sizeof(struct CallbackNode));
   if (node) {
-    node->domain = PL_strdup(pref_node);
-    node->func = callback;
-    node->data = instance_data;
+    node->mDomain = PL_strdup(aPrefNode);
+    node->mFunc = aCallback;
+    node->mData = aData;
     if (gLastPriorityNode) {
-      node->next = gLastPriorityNode->next;
-      gLastPriorityNode->next = node;
+      node->mNext = gLastPriorityNode->mNext;
+      gLastPriorityNode->mNext = node;
     } else {
-      node->next = gFirstCallback;
+      node->mNext = gFirstCallback;
       gFirstCallback = node;
     }
   }
 }
 
-/* Removes |node| from callback list.
-   Returns the node after the deleted one. */
-struct CallbackNode*
-pref_RemoveCallbackNode(struct CallbackNode* node,
-                        struct CallbackNode* prev_node)
+// Removes |node| from callback list. Returns the node after the deleted one.
+CallbackNode*
+pref_RemoveCallbackNode(CallbackNode* aNode, CallbackNode* aPrevNode)
 {
-  NS_PRECONDITION(!prev_node || prev_node->next == node, "invalid params");
-  NS_PRECONDITION(prev_node || gFirstCallback == node, "invalid params");
+  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");
 
-  struct CallbackNode* next_node = node->next;
-  if (prev_node) {
-    prev_node->next = next_node;
+  CallbackNode* next_node = aNode->mNext;
+  if (aPrevNode) {
+    aPrevNode->mNext = next_node;
   } else {
     gFirstCallback = next_node;
   }
-  if (gLastPriorityNode == node) {
-    gLastPriorityNode = prev_node;
+  if (gLastPriorityNode == aNode) {
+    gLastPriorityNode = aPrevNode;
   }
-  PL_strfree(node->domain);
-  free(node);
+  PL_strfree(aNode->mDomain);
+  free(aNode);
   return next_node;
 }
 
-/* Deletes a node from the callback list or marks it for deletion. */
+// Deletes a node from the callback list or marks it for deletion.
 nsresult
-PREF_UnregisterCallback(const char* pref_node,
-                        PrefChangedFunc callback,
-                        void* instance_data)
+PREF_UnregisterCallback(const char* aPrefNode,
+                        PrefChangedFunc aCallback,
+                        void* aData)
 {
   nsresult rv = NS_ERROR_FAILURE;
-  struct CallbackNode* node = gFirstCallback;
-  struct CallbackNode* prev_node = nullptr;
+  CallbackNode* node = gFirstCallback;
+  CallbackNode* prev_node = nullptr;
 
   while (node != nullptr) {
-    if (node->func == callback && node->data == instance_data &&
-        strcmp(node->domain, pref_node) == 0) {
+    if (node->mFunc == aCallback && node->mData == aData &&
+        strcmp(node->mDomain, aPrefNode) == 0) {
       if (gCallbacksInProgress) {
         // postpone the node removal until after
         // callbacks enumeration is finished.
-        node->func = nullptr;
+        node->mFunc = nullptr;
         gShouldCleanupDeadNodes = true;
         prev_node = node;
-        node = node->next;
+        node = node->mNext;
       } else {
         node = pref_RemoveCallbackNode(node, prev_node);
       }
       rv = NS_OK;
     } else {
       prev_node = node;
-      node = node->next;
+      node = node->mNext;
     }
   }
   return rv;
 }
 
 static nsresult
-pref_DoCallback(const char* changed_pref)
+pref_DoCallback(const char* aChangedPref)
 {
   nsresult rv = NS_OK;
-  struct CallbackNode* node;
+  CallbackNode* node;
 
   bool reentered = gCallbacksInProgress;
-  gCallbacksInProgress = true;
+
   // Nodes must not be deleted while gCallbacksInProgress is true.
   // Nodes that need to be deleted are marked for deletion by nulling
   // out the |func| pointer. We release them at the end of this function
   // if we haven't reentered.
+  gCallbacksInProgress = true;
 
-  for (node = gFirstCallback; node != nullptr; node = node->next) {
-    if (node->func &&
-        PL_strncmp(changed_pref, node->domain, strlen(node->domain)) == 0) {
-      (*node->func)(changed_pref, node->data);
+  for (node = gFirstCallback; node != nullptr; node = node->mNext) {
+    if (node->mFunc &&
+        PL_strncmp(aChangedPref, node->mDomain, strlen(node->mDomain)) == 0) {
+      (*node->mFunc)(aChangedPref, node->mData);
     }
   }
 
   gCallbacksInProgress = reentered;
 
   if (gShouldCleanupDeadNodes && !gCallbacksInProgress) {
-    struct CallbackNode* prev_node = nullptr;
+    CallbackNode* prev_node = nullptr;
     node = gFirstCallback;
 
     while (node != nullptr) {
-      if (!node->func) {
+      if (!node->mFunc) {
         node = pref_RemoveCallbackNode(node, prev_node);
       } else {
         prev_node = node;
-        node = node->next;
+        node = node->mNext;
       }
     }
     gShouldCleanupDeadNodes = false;
   }
 
   return rv;
 }
 
 void
-PREF_ReaderCallback(void* closure,
-                    const char* pref,
-                    PrefValue value,
-                    PrefType type,
-                    bool isDefault,
-                    bool isStickyDefault)
-
+PREF_ReaderCallback(void* aClosure,
+                    const char* aPref,
+                    PrefValue aValue,
+                    PrefType aType,
+                    bool aIsDefault,
+                    bool aIsStickyDefault)
 {
   uint32_t flags = 0;
-  if (isDefault) {
+  if (aIsDefault) {
     flags |= kPrefSetDefault;
-    if (isStickyDefault) {
+    if (aIsStickyDefault) {
       flags |= kPrefStickyDefault;
     }
   } else {
     flags |= kPrefForceSet;
   }
-  pref_HashPref(pref, value, type, flags);
+  pref_HashPref(aPref, aValue, aType, flags);
 }