Bug 1416638 - Add a PrefValueKind arg to Preferences::Set*(). r=glandium draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 13 Nov 2017 09:20:45 +1100
changeset 697564 05ac45f5cfa3d6927b7ef4a51a10e620a91f2236
parent 697563 6a17149cbeed2457cee6b270b7dc0ab51c068994
child 697565 d8c3a5d2af7b150b1d060497db98223efe4d6d23
push id89043
push usernnethercote@mozilla.com
push dateTue, 14 Nov 2017 08:06:49 +0000
reviewersglandium
bugs1416638
milestone58.0a1
Bug 1416638 - Add a PrefValueKind arg to Preferences::Set*(). r=glandium This is unused for now, but will be necessary for nsPrefBranch::Set*() to call into Preferences::Set*(). The patch also renames some arguments from aPref to aPrefName, because that's a better name. MozReview-Commit-ID: 2OPB7CHOgpw
modules/libpref/Preferences.cpp
modules/libpref/Preferences.h
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -4612,76 +4612,92 @@ Preferences::GetLocalizedString(const ch
 /* static */ nsresult
 Preferences::GetComplex(const char* aPref, const nsIID& aType, void** aResult)
 {
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
   return sPreferences->mRootBranch->GetComplexValue(aPref, aType, aResult);
 }
 
 /* static */ nsresult
-Preferences::SetCString(const char* aPref, const char* aValue)
+Preferences::SetCString(const char* aPrefName,
+                        const char* aValue,
+                        PrefValueKind aKind)
 {
-  ENSURE_MAIN_PROCESS("SetCString", aPref);
+  ENSURE_MAIN_PROCESS("SetCString", aPrefName);
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  return PREF_SetCStringPref(aPref, nsDependentCString(aValue), false);
+  return PREF_SetCStringPref(
+    aPrefName, nsDependentCString(aValue), aKind == PrefValueKind::Default);
 }
 
 /* static */ nsresult
-Preferences::SetCString(const char* aPref, const nsACString& aValue)
+Preferences::SetCString(const char* aPrefName,
+                        const nsACString& aValue,
+                        PrefValueKind aKind)
 {
-  ENSURE_MAIN_PROCESS("SetCString", aPref);
+  ENSURE_MAIN_PROCESS("SetCString", aPrefName);
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  return PREF_SetCStringPref(aPref, aValue, false);
+  return PREF_SetCStringPref(
+    aPrefName, aValue, aKind == PrefValueKind::Default);
 }
 
 /* static */ nsresult
-Preferences::SetString(const char* aPref, const char16ptr_t aValue)
+Preferences::SetString(const char* aPrefName,
+                       const char16ptr_t aValue,
+                       PrefValueKind aKind)
 {
-  ENSURE_MAIN_PROCESS("SetString", aPref);
+  ENSURE_MAIN_PROCESS("SetString", aPrefName);
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  return PREF_SetCStringPref(aPref, NS_ConvertUTF16toUTF8(aValue), false);
+  return PREF_SetCStringPref(
+    aPrefName, NS_ConvertUTF16toUTF8(aValue), aKind == PrefValueKind::Default);
 }
 
 /* static */ nsresult
-Preferences::SetString(const char* aPref, const nsAString& aValue)
+Preferences::SetString(const char* aPrefName,
+                       const nsAString& aValue,
+                       PrefValueKind aKind)
 {
-  ENSURE_MAIN_PROCESS("SetString", aPref);
+  ENSURE_MAIN_PROCESS("SetString", aPrefName);
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  return PREF_SetCStringPref(aPref, NS_ConvertUTF16toUTF8(aValue), false);
+  return PREF_SetCStringPref(
+    aPrefName, NS_ConvertUTF16toUTF8(aValue), aKind == PrefValueKind::Default);
 }
 
 /* static */ nsresult
-Preferences::SetBool(const char* aPref, bool aValue)
+Preferences::SetBool(const char* aPrefName, bool aValue, PrefValueKind aKind)
 {
-  ENSURE_MAIN_PROCESS("SetBool", aPref);
+  ENSURE_MAIN_PROCESS("SetBool", aPrefName);
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  return PREF_SetBoolPref(aPref, aValue, false);
+  return PREF_SetBoolPref(aPrefName, aValue, aKind == PrefValueKind::Default);
 }
 
 /* static */ nsresult
-Preferences::SetInt(const char* aPref, int32_t aValue)
+Preferences::SetInt(const char* aPrefName, int32_t aValue, PrefValueKind aKind)
 {
-  ENSURE_MAIN_PROCESS("SetInt", aPref);
+  ENSURE_MAIN_PROCESS("SetInt", aPrefName);
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  return PREF_SetIntPref(aPref, aValue, false);
+  return PREF_SetIntPref(aPrefName, aValue, aKind == PrefValueKind::Default);
 }
 
 /* static */ nsresult
-Preferences::SetFloat(const char* aPref, float aValue)
+Preferences::SetFloat(const char* aPrefName, float aValue, PrefValueKind aKind)
 {
-  return SetCString(aPref, nsPrintfCString("%f", aValue).get());
+  return SetCString(aPrefName, nsPrintfCString("%f", aValue).get(), aKind);
 }
 
 /* static */ nsresult
-Preferences::SetComplex(const char* aPref,
+Preferences::SetComplex(const char* aPrefName,
                         const nsIID& aType,
-                        nsISupports* aValue)
+                        nsISupports* aValue,
+                        PrefValueKind aKind)
 {
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
-  return sPreferences->mRootBranch->SetComplexValue(aPref, aType, aValue);
+  nsCOMPtr<nsIPrefBranch> branch = (aKind == PrefValueKind::Default)
+                                     ? sPreferences->mDefaultRootBranch
+                                     : sPreferences->mRootBranch;
+  return branch->SetComplexValue(aPrefName, aType, aValue);
 }
 
 /* static */ nsresult
 Preferences::ClearUser(const char* aPref)
 {
   ENSURE_MAIN_PROCESS("ClearUser", aPref);
   NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
   return PREF_ClearUserPref(aPref);
--- a/modules/libpref/Preferences.h
+++ b/modules/libpref/Preferences.h
@@ -183,31 +183,48 @@ public:
   }
   static float GetFloat(const char* aPref, float aDefault = 0)
   {
     float result = aDefault;
     GetFloat(aPref, &result);
     return result;
   }
 
-  // Setters of user values.
-  static nsresult SetBool(const char* aPref, bool aValue);
-  static nsresult SetInt(const char* aPref, int32_t aValue);
-  static nsresult SetUint(const char* aPref, uint32_t aValue)
+  // Value setters.
+  static nsresult SetBool(const char* aPrefName,
+                          bool aValue,
+                          PrefValueKind aKind = PrefValueKind::User);
+  static nsresult SetInt(const char* aPrefName,
+                         int32_t aValue,
+                         PrefValueKind aKind = PrefValueKind::User);
+  static nsresult SetUint(const char* aPrefName,
+                          uint32_t aValue,
+                          PrefValueKind aKind = PrefValueKind::User)
   {
-    return SetInt(aPref, static_cast<int32_t>(aValue));
+    return SetInt(aPrefName, static_cast<int32_t>(aValue), aKind);
   }
-  static nsresult SetFloat(const char* aPref, float aValue);
-  static nsresult SetCString(const char* aPref, const char* aValue);
-  static nsresult SetCString(const char* aPref, const nsACString& aValue);
-  static nsresult SetString(const char* aPref, const char16ptr_t aValue);
-  static nsresult SetString(const char* aPref, const nsAString& aValue);
-  static nsresult SetComplex(const char* aPref,
+  static nsresult SetFloat(const char* aPrefName,
+                           float aValue,
+                           PrefValueKind aKind = PrefValueKind::User);
+  static nsresult SetCString(const char* aPrefName,
+                             const char* aValue,
+                             PrefValueKind aKind = PrefValueKind::User);
+  static nsresult SetCString(const char* aPrefName,
+                             const nsACString& aValue,
+                             PrefValueKind aKind = PrefValueKind::User);
+  static nsresult SetString(const char* aPrefName,
+                            const char16ptr_t aValue,
+                            PrefValueKind aKind = PrefValueKind::User);
+  static nsresult SetString(const char* aPrefName,
+                            const nsAString& aValue,
+                            PrefValueKind aKind = PrefValueKind::User);
+  static nsresult SetComplex(const char* aPrefName,
                              const nsIID& aType,
-                             nsISupports* aValue);
+                             nsISupports* aValue,
+                             PrefValueKind aKind = PrefValueKind::User);
 
   // Clears user set pref.
   static nsresult ClearUser(const char* aPref);
 
   // Whether the pref has a user value or not.
   static bool HasUserValue(const char* aPref);
 
   // Adds/Removes the observer for the root pref branch. See nsIPrefBranch.idl