Bug 1417806 - Avoid "sticky default" terminology. r=glandium draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 16 Nov 2017 16:16:03 +1100
changeset 698941 8164f71065bcae1376c3e2bf241593c62c90b702
parent 698940 20b5b8b8df8b936a22849766552d11f659ffc84b
child 698942 5645a0e5897fc825e6bbc6da2c6d40fb852a9efb
push id89395
push usernnethercote@mozilla.com
push dateThu, 16 Nov 2017 08:14:02 +0000
reviewersglandium
bugs1417806
milestone59.0a1
Bug 1417806 - Avoid "sticky default" terminology. r=glandium It's the user value that's sticky, not the default value. Though we typically talk about the entire pref being sticky, so that's what this patch does. MozReview-Commit-ID: 8THuRCTZ7uw
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -204,21 +204,21 @@ public:
 
   bool HasDefaultValue() const { return mValue & PREF_FLAG_HAS_DEFAULT_VALUE; }
 
   void SetHasDefaultValue(bool aSetOrUnset)
   {
     SetFlag(PREF_FLAG_HAS_DEFAULT_VALUE, aSetOrUnset);
   }
 
-  bool HasStickyDefault() const { return mValue & PREF_FLAG_STICKY_DEFAULT; }
-
-  void SetHasStickyDefault(bool aSetOrUnset)
+  bool IsSticky() const { return mValue & PREF_FLAG_STICKY; }
+
+  void SetIsSticky(bool aSetOrUnset)
   {
-    SetFlag(PREF_FLAG_STICKY_DEFAULT, aSetOrUnset);
+    SetFlag(PREF_FLAG_STICKY, 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_HAS_USER_VALUE; }
 
@@ -237,17 +237,17 @@ private:
 
   // 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_HAS_USER_VALUE = 8,
     PREF_FLAG_HAS_DEFAULT_VALUE = 16,
-    PREF_FLAG_STICKY_DEFAULT = 32,
+    PREF_FLAG_STICKY = 32,
   };
   uint16_t mValue;
 };
 
 struct PrefHashEntry : PLDHashEntryHdr
 {
   PrefTypeFlags mPrefFlags; // this field first to minimize 64-bit struct size
   const char* mKey;
@@ -345,17 +345,17 @@ pref_ValueChanged(PrefValue aOldValue, P
 
 static nsresult
 pref_DoCallback(const char* aChangedPref);
 
 enum
 {
   kPrefSetDefault = 1,
   kPrefForceSet = 2,
-  kPrefStickyDefault = 4,
+  kPrefSticky = 4,
 };
 
 static nsresult
 pref_SetPref(const char* aKey,
              PrefValue aValue,
              PrefType aType,
              uint32_t aFlags);
 
@@ -423,17 +423,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.HasDefaultValue() ||
-         pref->mPrefFlags.HasStickyDefault())) {
+         pref->mPrefFlags.IsSticky())) {
       sourcePref = &pref->mUserPref;
     } else {
       // do not save default prefs that haven't changed
       continue;
     }
 
     nsAutoCString prefName;
     StrEscape(pref->mKey, prefName);
@@ -795,32 +795,32 @@ pref_SetPref(const char* aKey,
     if (!pref->mPrefFlags.IsLocked()) {
       // ?? change of semantics?
       if (pref_ValueChanged(pref->mDefaultPref, aValue, aType) ||
           !pref->mPrefFlags.HasDefaultValue()) {
         pref_SetValue(
           &pref->mDefaultPref, pref->mPrefFlags.GetPrefType(), aValue, aType);
         pref->mPrefFlags.SetPrefType(aType);
         pref->mPrefFlags.SetHasDefaultValue(true);
-        if (aFlags & kPrefStickyDefault) {
-          pref->mPrefFlags.SetHasStickyDefault(true);
+        if (aFlags & kPrefSticky) {
+          pref->mPrefFlags.SetIsSticky(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.HasDefaultValue()) &&
-        !(pref->mPrefFlags.HasStickyDefault()) &&
+        !(pref->mPrefFlags.IsSticky()) &&
         !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();
           valueChanged = true;
@@ -1008,23 +1008,23 @@ pref_DoCallback(const char* aChangedPref
 
 // The callback function of the prefs parser.
 static void
 PREF_ReaderCallback(void* aClosure,
                     const char* aPref,
                     PrefValue aValue,
                     PrefType aType,
                     bool aIsDefault,
-                    bool aIsStickyDefault)
+                    bool aIsSticky)
 {
   uint32_t flags = 0;
   if (aIsDefault) {
     flags |= kPrefSetDefault;
-    if (aIsStickyDefault) {
-      flags |= kPrefStickyDefault;
+    if (aIsSticky) {
+      flags |= kPrefSticky;
     }
   } else {
     flags |= kPrefForceSet;
   }
   pref_SetPref(aPref, aValue, aType, flags);
 }
 
 //===========================================================================
@@ -1035,23 +1035,23 @@ PREF_ReaderCallback(void* aClosure,
 // The pref name and value must be copied by the implementor of the callback
 // if they are needed beyond the scope of the callback function.
 //
 // |aClosure| is user data passed to PREF_InitParseState.
 // |aPref| is the preference name.
 // |aValue| is the preference value.
 // |aType| is the preference type (PREF_STRING, PREF_INT, or PREF_BOOL).
 // |aIsDefault| indicates if it's a default preference.
-// |aIsStickyDefault| indicates if it's a sticky default preference.
+// |aIsSticky| indicates if it's a sticky preference.
 typedef void (*PrefReader)(void* aClosure,
                            const char* aPref,
                            PrefValue aValue,
                            PrefType aType,
                            bool aIsDefault,
-                           bool aIsStickyDefault);
+                           bool aIsSticky);
 
 // Report any errors or warnings we encounter during parsing.
 typedef void (*PrefParseErrorReporter)(const char* aMessage,
                                        int aLine,
                                        bool aError);
 
 struct PrefParseState
 {
@@ -1068,17 +1068,17 @@ struct PrefParseState
   char mEscTmp[6];       // raw escape to put back if err
   char mQuoteChar;       // char delimiter for quotations
   char* mLb;             // line buffer (only allocation)
   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
+  bool mIsSticky;        // true if (sticky) pref
 };
 
 // Pref parser states.
 enum
 {
   PREF_PARSE_INIT,
   PREF_PARSE_MATCH_STRING,
   PREF_PARSE_UNTIL_NAME,
@@ -1244,17 +1244,17 @@ PREF_ParseBuf(PrefParseState* aPS, const
     switch (state) {
       // initial state
       case PREF_PARSE_INIT:
         if (aPS->mLbCur != aPS->mLb) { // reset state
           aPS->mLbCur = aPS->mLb;
           aPS->mVb = nullptr;
           aPS->mVtype = PrefType::Invalid;
           aPS->mIsDefault = false;
-          aPS->mIsStickyDefault = false;
+          aPS->mIsSticky = false;
         }
         switch (c) {
           case '/': // begin comment block or line?
             state = PREF_PARSE_COMMENT_MAYBE_START;
             break;
           case '#': // accept shell style comments
             state = PREF_PARSE_UNTIL_EOL;
             break;
@@ -1309,17 +1309,17 @@ PREF_ParseBuf(PrefParseState* aPS, const
         }
         break;
 
       // name parsing
       case PREF_PARSE_UNTIL_NAME:
         if (c == '\"' || c == '\'') {
           aPS->mIsDefault =
             (aPS->mStrMatch == kPref || aPS->mStrMatch == kStickyPref);
-          aPS->mIsStickyDefault = (aPS->mStrMatch == kStickyPref);
+          aPS->mIsSticky = (aPS->mStrMatch == kStickyPref);
           aPS->mQuoteChar = c;
           aPS->mNextState = PREF_PARSE_UNTIL_COMMA; // return here when done
           state = PREF_PARSE_QUOTED_STRING;
         } else if (c == '/') {     // allow embedded comment
           aPS->mNextState = state; // return here when done with comment
           state = PREF_PARSE_COMMENT_MAYBE_START;
         } else if (!isspace(c)) {
           pref_ReportParseProblem(
@@ -1638,17 +1638,17 @@ PREF_ParseBuf(PrefParseState* aPS, const
           }
 
           // We've extracted a complete name/value pair.
           aPS->mReader(aPS->mClosure,
                        aPS->mLb,
                        value,
                        aPS->mVtype,
                        aPS->mIsDefault,
-                       aPS->mIsStickyDefault);
+                       aPS->mIsSticky);
 
           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);