Bug 1417806 - Rename some things in PrefTypeFlags. r=glandium draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 16 Nov 2017 16:02:07 +1100
changeset 698939 3f27992630e6e834ce470693a15d8f6b99706cfe
parent 698938 5780456f1f0cf18f98ab3b42efcaec514324a171
child 698940 20b5b8b8df8b936a22849766552d11f659ffc84b
push id89395
push usernnethercote@mozilla.com
push dateThu, 16 Nov 2017 08:14:02 +0000
reviewersglandium
bugs1417806
milestone59.0a1
Bug 1417806 - Rename some things in PrefTypeFlags. r=glandium So that "default value" and "user value" are used consistently. MozReview-Commit-ID: Hmfct8STu33
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -197,56 +197,56 @@ public:
   }
 
   PrefType GetPrefType() const
   {
     return (PrefType)(mValue & (AsInt(PrefType::String) | AsInt(PrefType::Int) |
                                 AsInt(PrefType::Bool)));
   }
 
-  bool HasDefault() const { return mValue & PREF_FLAG_HAS_DEFAULT; }
-
-  void SetHasDefault(bool aSetOrUnset)
+  bool HasDefaultValue() const { return mValue & PREF_FLAG_HAS_DEFAULT_VALUE; }
+
+  void SetHasDefaultValue(bool aSetOrUnset)
   {
-    SetFlag(PREF_FLAG_HAS_DEFAULT, aSetOrUnset);
+    SetFlag(PREF_FLAG_HAS_DEFAULT_VALUE, aSetOrUnset);
   }
 
   bool HasStickyDefault() const { return mValue & PREF_FLAG_STICKY_DEFAULT; }
 
   void SetHasStickyDefault(bool aSetOrUnset)
   {
     SetFlag(PREF_FLAG_STICKY_DEFAULT, aSetOrUnset);
   }
 
   bool IsLocked() const { return mValue & PREF_FLAG_LOCKED; }
 
   void SetLocked(bool aSetOrUnset) { SetFlag(PREF_FLAG_LOCKED, aSetOrUnset); }
 
-  bool HasUserValue() const { return mValue & PREF_FLAG_USERSET; }
+  bool HasUserValue() const { return mValue & PREF_FLAG_HAS_USER_VALUE; }
 
   void SetHasUserValue(bool aSetOrUnset)
   {
-    SetFlag(PREF_FLAG_USERSET, aSetOrUnset);
+    SetFlag(PREF_FLAG_HAS_USER_VALUE, aSetOrUnset);
   }
 
 private:
   static uint16_t AsInt(PrefType aType) { return (uint16_t)aType; }
 
   void SetFlag(uint16_t aFlag, bool aSetOrUnset)
   {
     mValue = aSetOrUnset ? mValue | aFlag : mValue & ~aFlag;
   }
 
   // We pack both the value of type (PrefType) and flags into the same int. The
   // flag enum starts at 4 so that the PrefType can occupy the bottom two bits.
   enum
   {
     PREF_FLAG_LOCKED = 4,
-    PREF_FLAG_USERSET = 8,
-    PREF_FLAG_HAS_DEFAULT = 16,
+    PREF_FLAG_HAS_USER_VALUE = 8,
+    PREF_FLAG_HAS_DEFAULT_VALUE = 16,
     PREF_FLAG_STICKY_DEFAULT = 32,
   };
   uint16_t mValue;
 };
 
 struct PrefHashEntry : PLDHashEntryHdr
 {
   PrefTypeFlags mPrefFlags; // this field first to minimize 64-bit struct size
@@ -254,17 +254,17 @@ struct PrefHashEntry : PLDHashEntryHdr
   PrefValue mDefaultPref;
   PrefValue mUserPref;
 
   size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf)
   {
     // Note: mKey is allocated in gPrefNameArena, measured elsewhere.
     size_t n = 0;
     if (mPrefFlags.IsTypeString()) {
-      if (mPrefFlags.HasDefault()) {
+      if (mPrefFlags.HasDefaultValue()) {
         n += aMallocSizeOf(mDefaultPref.mStringVal);
       }
       if (mPrefFlags.HasUserValue()) {
         n += aMallocSizeOf(mUserPref.mStringVal);
       }
     }
     return n;
   }
@@ -422,17 +422,17 @@ pref_savePrefs()
 
     // where we're getting our pref from
     PrefValue* sourcePref;
 
     if (pref->mPrefFlags.HasUserValue() &&
         (pref_ValueChanged(pref->mDefaultPref,
                            pref->mUserPref,
                            pref->mPrefFlags.GetPrefType()) ||
-         !pref->mPrefFlags.HasDefault() ||
+         !pref->mPrefFlags.HasDefaultValue() ||
          pref->mPrefFlags.HasStickyDefault())) {
       sourcePref = &pref->mUserPref;
     } else {
       // do not save default prefs that haven't changed
       continue;
     }
 
     nsAutoCString prefName;
@@ -459,17 +459,17 @@ pref_savePrefs()
 static bool
 pref_EntryHasAdvisablySizedValues(PrefHashEntry* aHashEntry)
 {
   if (aHashEntry->mPrefFlags.GetPrefType() != PrefType::String) {
     return true;
   }
 
   const char* stringVal;
-  if (aHashEntry->mPrefFlags.HasDefault()) {
+  if (aHashEntry->mPrefFlags.HasDefaultValue()) {
     stringVal = aHashEntry->mDefaultPref.mStringVal;
     if (strlen(stringVal) > MAX_ADVISABLE_PREF_LENGTH) {
       return false;
     }
   }
 
   if (aHashEntry->mPrefFlags.HasUserValue()) {
     stringVal = aHashEntry->mUserPref.mStringVal;
@@ -513,17 +513,17 @@ GetPrefValueFromEntry(PrefHashEntry* aHa
   }
 }
 
 static void
 pref_GetPrefFromEntry(PrefHashEntry* aHashEntry, dom::PrefSetting* aPref)
 {
   aPref->name() = aHashEntry->mKey;
 
-  if (aHashEntry->mPrefFlags.HasDefault()) {
+  if (aHashEntry->mPrefFlags.HasDefaultValue()) {
     GetPrefValueFromEntry(aHashEntry, aPref, PrefValueKind::Default);
   } else {
     aPref->defaultValue() = null_t();
   }
 
   if (aHashEntry->mPrefFlags.HasUserValue()) {
     GetPrefValueFromEntry(aHashEntry, aPref, PrefValueKind::User);
   } else {
@@ -554,17 +554,17 @@ PREF_ClearUserPref(const char* aPrefName
   if (!gHashTable) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
   if (pref && pref->mPrefFlags.HasUserValue()) {
     pref->mPrefFlags.SetHasUserValue(false);
 
-    if (!pref->mPrefFlags.HasDefault()) {
+    if (!pref->mPrefFlags.HasDefaultValue()) {
       gHashTable->RemoveEntry(pref);
     }
 
     pref_DoCallback(aPrefName);
     Preferences::HandleDirty();
   }
   return NS_OK;
 }
@@ -584,17 +584,17 @@ PREF_ClearAllUserPrefs()
     auto pref = static_cast<PrefHashEntry*>(iter.Get());
 
     if (pref->mPrefFlags.HasUserValue()) {
       if (!prefNames.append(pref->mKey)) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
 
       pref->mPrefFlags.SetHasUserValue(false);
-      if (!pref->mPrefFlags.HasDefault()) {
+      if (!pref->mPrefFlags.HasDefaultValue()) {
         iter.Remove();
       }
     }
   }
 
   for (const char* prefName : prefNames) {
     pref_DoCallback(prefName);
   }
@@ -771,17 +771,17 @@ pref_SetPref(const char* aKey,
   // New entry, need to initialize.
   if (!pref->mKey) {
     // Initialize the pref entry.
     pref->mPrefFlags.Reset().SetPrefType(aType);
     pref->mKey = ArenaStrdup(aKey, gPrefNameArena);
     memset(&pref->mDefaultPref, 0, sizeof(pref->mDefaultPref));
     memset(&pref->mUserPref, 0, sizeof(pref->mUserPref));
 
-  } else if (pref->mPrefFlags.HasDefault() &&
+  } else if (pref->mPrefFlags.HasDefaultValue() &&
              !pref->mPrefFlags.IsPrefType(aType)) {
     NS_WARNING(
       nsPrintfCString(
         "Ignoring attempt to overwrite value of default pref %s (type %s) with "
         "the wrong type (%s)!",
         aKey,
         PrefTypeToString(pref->mPrefFlags.GetPrefType()),
         PrefTypeToString(aType))
@@ -790,36 +790,36 @@ pref_SetPref(const char* aKey,
     return NS_ERROR_UNEXPECTED;
   }
 
   bool valueChanged = false;
   if (aFlags & kPrefSetDefault) {
     if (!pref->mPrefFlags.IsLocked()) {
       // ?? change of semantics?
       if (pref_ValueChanged(pref->mDefaultPref, aValue, aType) ||
-          !pref->mPrefFlags.HasDefault()) {
+          !pref->mPrefFlags.HasDefaultValue()) {
         pref_SetValue(
           &pref->mDefaultPref, pref->mPrefFlags.GetPrefType(), aValue, aType);
         pref->mPrefFlags.SetPrefType(aType);
-        pref->mPrefFlags.SetHasDefault(true);
+        pref->mPrefFlags.SetHasDefaultValue(true);
         if (aFlags & kPrefStickyDefault) {
           pref->mPrefFlags.SetHasStickyDefault(true);
         }
         if (!pref->mPrefFlags.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 ((pref->mPrefFlags.HasDefault()) &&
+    if ((pref->mPrefFlags.HasDefaultValue()) &&
         !(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()) {
           Preferences::HandleDirty();
@@ -4507,17 +4507,17 @@ Preferences::GetBool(const char* aPrefNa
   if (!pref || !pref->mPrefFlags.IsTypeBool()) {
     return NS_ERROR_UNEXPECTED;
   }
 
   if (aKind == PrefValueKind::Default || pref->mPrefFlags.IsLocked() ||
       !pref->mPrefFlags.HasUserValue()) {
 
     // Do we have a default?
-    if (!pref->mPrefFlags.HasDefault()) {
+    if (!pref->mPrefFlags.HasDefaultValue()) {
       return NS_ERROR_UNEXPECTED;
     }
     *aResult = pref->mDefaultPref.mBoolVal;
   } else {
     *aResult = pref->mUserPref.mBoolVal;
   }
 
   return NS_OK;
@@ -4535,17 +4535,17 @@ Preferences::GetInt(const char* aPrefNam
   if (!pref || !pref->mPrefFlags.IsTypeInt()) {
     return NS_ERROR_UNEXPECTED;
   }
 
   if (aKind == PrefValueKind::Default || pref->mPrefFlags.IsLocked() ||
       !pref->mPrefFlags.HasUserValue()) {
 
     // Do we have a default?
-    if (!pref->mPrefFlags.HasDefault()) {
+    if (!pref->mPrefFlags.HasDefaultValue()) {
       return NS_ERROR_UNEXPECTED;
     }
     *aResult = pref->mDefaultPref.mIntVal;
   } else {
     *aResult = pref->mUserPref.mIntVal;
   }
 
   return NS_OK;
@@ -4580,17 +4580,17 @@ Preferences::GetCString(const char* aPre
     return NS_ERROR_UNEXPECTED;
   }
 
   const char* stringVal = nullptr;
   if (aKind == PrefValueKind::Default || pref->mPrefFlags.IsLocked() ||
       !pref->mPrefFlags.HasUserValue()) {
 
     // Do we have a default?
-    if (!pref->mPrefFlags.HasDefault()) {
+    if (!pref->mPrefFlags.HasDefaultValue()) {
       return NS_ERROR_UNEXPECTED;
     }
     stringVal = pref->mDefaultPref.mStringVal;
   } else {
     stringVal = pref->mUserPref.mStringVal;
   }
 
   if (!stringVal) {