Bug 1550422 - P14. Add GetXXName and GetXXDefault methods to StaticPrefs. r?njn! draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 15 May 2019 21:17:18 +1000
changeset 2008591 24a3cfcfbbf8f8c24bb97cf5e60d6879673fd00a
parent 2008590 ec0a38113cabe8476e9c3acc37f62c96cbbfb0a8
child 2008592 3e8772162de640369f151f83282f6fa8c2d7401a
push id363925
push userjyavenard@mozilla.com
push dateSat, 18 May 2019 07:53:18 +0000
treeherdertry@5082cd581229 [default view] [failures only]
reviewersnjn
bugs1550422
milestone68.0a1
Bug 1550422 - P14. Add GetXXName and GetXXDefault methods to StaticPrefs. r?njn! This is required to emulate some gfxPrefs functionalities. Differential Revision: https://phabricator.services.mozilla.com/D31258
modules/libpref/StaticPrefs.h
--- a/modules/libpref/StaticPrefs.h
+++ b/modules/libpref/StaticPrefs.h
@@ -80,16 +80,18 @@ class StaticPrefs {
   //
   //   private:
   //     static int32_t sVarCache_my_varcache;
   //   public:
   //     static int32_t my_varcache() { return sVarCache_my_varcache; }
   //     static void Setmy_varcache(int32_t aValue) {
   //	     sVarCache_my_varcache = aValue;
   //     }
+  //     static const char* Getmy_varcachePrefName() { return "my.varcache"; }
+  //     static int32_t Getmy_varcachePrefDefault() { return 99; }
   //
 
  public:
   // Enums for the update policy.
   enum class UpdatePolicy {
     Skip,  // Set the value to default, skip any Preferences calls.
     Once,  // Evaluate the preference once, unchanged during the session.
     Live   // Evaluate the preference and set callback so it stays current/live.
@@ -108,17 +110,20 @@ class StaticPrefs {
                "' being accessed on background thread by getter"); \
     return sVarCache_##id;                                         \
   }                                                                \
   static void Set##id(StripAtomic<cpp_type> aValue) {              \
     MOZ_ASSERT(IsAtomic<cpp_type>::value || NS_IsMainThread(),     \
                "Non-atomic static pref '" str                      \
                "' being accessed on background thread by setter"); \
     sVarCache_##id = aValue;                                       \
-  }
+  }                                                                \
+  static const char* Get##id##PrefName() { return str; }           \
+  static StripAtomic<cpp_type> Get##id##PrefDefault() { return default_value; }
+
 #include "mozilla/StaticPrefList.h"
 #undef PREF
 #undef VARCACHE_PREF
 
  public:
   static void InitAll(bool aIsStartup);
   static void InitOncePrefs();
 };