зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1557630 - P1. Simplify Preferences' getters code. r=njn
We use templates where appropriate instead. Differential Revision: https://phabricator.services.mozilla.com/D34272 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
e02ac4e321
Коммит
5adb6b1a6d
|
@ -986,7 +986,7 @@ class MOZ_STACK_CLASS PrefWrapper : public PrefWrapperBase {
|
||||||
return PrefValueKind::User;
|
return PrefValueKind::User;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult GetBoolValue(PrefValueKind aKind, bool* aResult) const {
|
nsresult GetValue(PrefValueKind aKind, bool* aResult) const {
|
||||||
PrefValueKind kind;
|
PrefValueKind kind;
|
||||||
MOZ_TRY_VAR(kind, WantValueKind(PrefType::Bool, aKind));
|
MOZ_TRY_VAR(kind, WantValueKind(PrefType::Bool, aKind));
|
||||||
|
|
||||||
|
@ -994,7 +994,7 @@ class MOZ_STACK_CLASS PrefWrapper : public PrefWrapperBase {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult GetIntValue(PrefValueKind aKind, int32_t* aResult) const {
|
nsresult GetValue(PrefValueKind aKind, int32_t* aResult) const {
|
||||||
PrefValueKind kind;
|
PrefValueKind kind;
|
||||||
MOZ_TRY_VAR(kind, WantValueKind(PrefType::Int, aKind));
|
MOZ_TRY_VAR(kind, WantValueKind(PrefType::Int, aKind));
|
||||||
|
|
||||||
|
@ -1002,7 +1002,21 @@ class MOZ_STACK_CLASS PrefWrapper : public PrefWrapperBase {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult GetCStringValue(PrefValueKind aKind, nsACString& aResult) const {
|
nsresult GetValue(PrefValueKind aKind, uint32_t* aResult) const {
|
||||||
|
return GetValue(aKind, reinterpret_cast<int32_t*>(aResult));
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult GetValue(PrefValueKind aKind, float* aResult) const {
|
||||||
|
nsAutoCString result;
|
||||||
|
nsresult rv = GetValue(aKind, result);
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
// ToFloat() does a locale-independent conversion.
|
||||||
|
*aResult = result.ToFloat(&rv);
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult GetValue(PrefValueKind aKind, nsACString& aResult) const {
|
||||||
PrefValueKind kind;
|
PrefValueKind kind;
|
||||||
MOZ_TRY_VAR(kind, WantValueKind(PrefType::String, aKind));
|
MOZ_TRY_VAR(kind, WantValueKind(PrefType::String, aKind));
|
||||||
|
|
||||||
|
@ -4380,73 +4394,6 @@ static nsresult pref_ReadPrefFromJar(nsZipArchive* aJarReader,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// These preference getter wrappers allow us to look up the value for static
|
|
||||||
// preferences based on their native types, rather than manually mapping them to
|
|
||||||
// the appropriate Preferences::Get* functions.
|
|
||||||
template <typename T>
|
|
||||||
static T GetPref(const char* aName, T aDefaultValue);
|
|
||||||
|
|
||||||
template <>
|
|
||||||
bool MOZ_MAYBE_UNUSED GetPref(const char* aName, bool aDefaultValue) {
|
|
||||||
return Preferences::GetBool(aName, aDefaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
|
||||||
int32_t MOZ_MAYBE_UNUSED GetPref(const char* aName, int32_t aDefaultValue) {
|
|
||||||
return Preferences::GetInt(aName, aDefaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
|
||||||
uint32_t MOZ_MAYBE_UNUSED GetPref(const char* aName, uint32_t aDefaultValue) {
|
|
||||||
return Preferences::GetUint(aName, aDefaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
|
||||||
float MOZ_MAYBE_UNUSED GetPref(const char* aName, float aDefaultValue) {
|
|
||||||
return Preferences::GetFloat(aName, aDefaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static nsresult GetSharedPref(const char* aName, T* aResult);
|
|
||||||
|
|
||||||
template <>
|
|
||||||
nsresult MOZ_MAYBE_UNUSED GetSharedPref(const char* aName, bool* aResult) {
|
|
||||||
MOZ_ASSERT(aResult);
|
|
||||||
|
|
||||||
Maybe<PrefWrapper> pref = pref_SharedLookup(aName);
|
|
||||||
return pref ? pref->GetBoolValue(PrefValueKind::User, aResult)
|
|
||||||
: NS_ERROR_UNEXPECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
|
||||||
nsresult MOZ_MAYBE_UNUSED GetSharedPref(const char* aName, int32_t* aResult) {
|
|
||||||
MOZ_ASSERT(aResult);
|
|
||||||
|
|
||||||
Maybe<PrefWrapper> pref = pref_SharedLookup(aName);
|
|
||||||
return pref ? pref->GetIntValue(PrefValueKind::User, aResult)
|
|
||||||
: NS_ERROR_UNEXPECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
|
||||||
nsresult MOZ_MAYBE_UNUSED GetSharedPref(const char* aName, uint32_t* aResult) {
|
|
||||||
return GetSharedPref(aName, reinterpret_cast<int32_t*>(aResult));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
|
||||||
nsresult MOZ_MAYBE_UNUSED GetSharedPref(const char* aName, float* aResult) {
|
|
||||||
MOZ_ASSERT(aResult);
|
|
||||||
|
|
||||||
Maybe<PrefWrapper> pref = pref_SharedLookup(aName);
|
|
||||||
if (!pref) {
|
|
||||||
return NS_ERROR_UNEXPECTED;
|
|
||||||
}
|
|
||||||
nsAutoCString result;
|
|
||||||
nsresult rv = pref->GetCStringValue(PrefValueKind::User, result);
|
|
||||||
// ToFloat() does a locale-independent conversion.
|
|
||||||
*aResult = result.ToFloat(&rv);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsresult pref_ReadDefaultPrefs(const RefPtr<nsZipArchive> jarReader,
|
static nsresult pref_ReadDefaultPrefs(const RefPtr<nsZipArchive> jarReader,
|
||||||
const char* path) {
|
const char* path) {
|
||||||
nsZipFind* findPtr;
|
nsZipFind* findPtr;
|
||||||
|
@ -4474,6 +4421,55 @@ static nsresult pref_ReadDefaultPrefs(const RefPtr<nsZipArchive> jarReader,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These preference getter wrappers allow us to look up the value for static
|
||||||
|
// preferences based on their native types, rather than manually mapping them to
|
||||||
|
// the appropriate Preferences::Get* functions.
|
||||||
|
// We define these methods in a struct which is made friend of Preferences in
|
||||||
|
// order to access private members.
|
||||||
|
struct PreferencesInternalMethods {
|
||||||
|
template <typename T>
|
||||||
|
static nsresult GetPrefValue(const char* aPrefName, T&& aResult,
|
||||||
|
PrefValueKind aKind) {
|
||||||
|
NS_ENSURE_TRUE(Preferences::InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
|
||||||
|
|
||||||
|
if (Maybe<PrefWrapper> pref = pref_Lookup(aPrefName)) {
|
||||||
|
return pref->GetValue(aKind, std::forward<T>(aResult));
|
||||||
|
}
|
||||||
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static nsresult GetSharedPrefValue(const char* aName, T* aResult) {
|
||||||
|
if (Maybe<PrefWrapper> pref = pref_SharedLookup(aName)) {
|
||||||
|
return pref->GetValue(PrefValueKind::User, aResult);
|
||||||
|
}
|
||||||
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static T GetPref(const char* aPrefName, T aFallback,
|
||||||
|
PrefValueKind aKind = PrefValueKind::User) {
|
||||||
|
T result = aFallback;
|
||||||
|
GetPrefValue(aPrefName, &result, aKind);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static void VarChanged(const char* aPref, void* aClosure) {
|
||||||
|
CacheData* cache = static_cast<CacheData*>(aClosure);
|
||||||
|
*static_cast<T*>(cache->mCacheLocation) =
|
||||||
|
GetPref(aPref, cache->GetDefault<StripAtomic<T>>());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static nsresult RegisterCallback(CacheData* aCacheData,
|
||||||
|
const nsACString& aPref) {
|
||||||
|
return Preferences::RegisterCallback(VarChanged<T>, aPref, aCacheData,
|
||||||
|
Preferences::ExactMatch,
|
||||||
|
/* isPriority */ true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Initialize default preference JavaScript buffers from appropriate TEXT
|
// Initialize default preference JavaScript buffers from appropriate TEXT
|
||||||
// resources.
|
// resources.
|
||||||
/* static */ Result<Ok, const char*> Preferences::InitInitialObjects(
|
/* static */ Result<Ok, const char*> Preferences::InitInitialObjects(
|
||||||
|
@ -4510,12 +4506,12 @@ static nsresult pref_ReadDefaultPrefs(const RefPtr<nsZipArchive> jarReader,
|
||||||
// and shouldn't be checked.
|
// and shouldn't be checked.
|
||||||
|
|
||||||
# define PREF(name, cpp_type, value)
|
# define PREF(name, cpp_type, value)
|
||||||
# define VARCACHE_PREF(policy, name, id, cpp_type, value) \
|
# define VARCACHE_PREF(policy, name, id, cpp_type, value) \
|
||||||
MOZ_ASSERT( \
|
MOZ_ASSERT(StaticPrefs::UpdatePolicy::policy == \
|
||||||
StaticPrefs::UpdatePolicy::policy == \
|
StaticPrefs::UpdatePolicy::Skip || \
|
||||||
StaticPrefs::UpdatePolicy::Skip || \
|
PreferencesInternalMethods::GetPref<StripAtomic<cpp_type>>( \
|
||||||
GetPref<StripAtomic<cpp_type>>(name, value) == StaticPrefs::id(), \
|
name, value) == StaticPrefs::id(), \
|
||||||
"Incorrect cached value for " name);
|
"Incorrect cached value for " name);
|
||||||
# include "mozilla/StaticPrefList.h"
|
# include "mozilla/StaticPrefList.h"
|
||||||
# undef PREF
|
# undef PREF
|
||||||
# undef VARCACHE_PREF
|
# undef VARCACHE_PREF
|
||||||
|
@ -4718,48 +4714,28 @@ static nsresult pref_ReadDefaultPrefs(const RefPtr<nsZipArchive> jarReader,
|
||||||
nsresult Preferences::GetBool(const char* aPrefName, bool* aResult,
|
nsresult Preferences::GetBool(const char* aPrefName, bool* aResult,
|
||||||
PrefValueKind aKind) {
|
PrefValueKind aKind) {
|
||||||
MOZ_ASSERT(aResult);
|
MOZ_ASSERT(aResult);
|
||||||
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
|
return PreferencesInternalMethods::GetPrefValue(aPrefName, aResult, aKind);
|
||||||
|
|
||||||
Maybe<PrefWrapper> pref = pref_Lookup(aPrefName);
|
|
||||||
return pref.isSome() ? pref->GetBoolValue(aKind, aResult)
|
|
||||||
: NS_ERROR_UNEXPECTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
nsresult Preferences::GetInt(const char* aPrefName, int32_t* aResult,
|
nsresult Preferences::GetInt(const char* aPrefName, int32_t* aResult,
|
||||||
PrefValueKind aKind) {
|
PrefValueKind aKind) {
|
||||||
MOZ_ASSERT(aResult);
|
MOZ_ASSERT(aResult);
|
||||||
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
|
return PreferencesInternalMethods::GetPrefValue(aPrefName, aResult, aKind);
|
||||||
|
|
||||||
Maybe<PrefWrapper> pref = pref_Lookup(aPrefName);
|
|
||||||
return pref.isSome() ? pref->GetIntValue(aKind, aResult)
|
|
||||||
: NS_ERROR_UNEXPECTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
nsresult Preferences::GetFloat(const char* aPrefName, float* aResult,
|
nsresult Preferences::GetFloat(const char* aPrefName, float* aResult,
|
||||||
PrefValueKind aKind) {
|
PrefValueKind aKind) {
|
||||||
MOZ_ASSERT(aResult);
|
MOZ_ASSERT(aResult);
|
||||||
|
return PreferencesInternalMethods::GetPrefValue(aPrefName, aResult, aKind);
|
||||||
nsAutoCString result;
|
|
||||||
nsresult rv = Preferences::GetCString(aPrefName, result, aKind);
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
// ToFloat() does a locale-independent conversion.
|
|
||||||
*aResult = result.ToFloat(&rv);
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
nsresult Preferences::GetCString(const char* aPrefName, nsACString& aResult,
|
nsresult Preferences::GetCString(const char* aPrefName, nsACString& aResult,
|
||||||
PrefValueKind aKind) {
|
PrefValueKind aKind) {
|
||||||
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
|
|
||||||
|
|
||||||
aResult.SetIsVoid(true);
|
aResult.SetIsVoid(true);
|
||||||
|
return PreferencesInternalMethods::GetPrefValue(aPrefName, aResult, aKind);
|
||||||
Maybe<PrefWrapper> pref = pref_Lookup(aPrefName);
|
|
||||||
return pref.isSome() ? pref->GetCStringValue(aKind, aResult)
|
|
||||||
: NS_ERROR_UNEXPECTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
|
@ -4808,6 +4784,30 @@ nsresult Preferences::GetComplex(const char* aPrefName, const nsIID& aType,
|
||||||
return GetRootBranch(aKind)->GetComplexValue(aPrefName, aType, aResult);
|
return GetRootBranch(aKind)->GetComplexValue(aPrefName, aType, aResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
bool Preferences::GetBool(const char* aPrefName, bool aFallback,
|
||||||
|
PrefValueKind aKind) {
|
||||||
|
return PreferencesInternalMethods::GetPref(aPrefName, aFallback, aKind);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
int32_t Preferences::GetInt(const char* aPrefName, int32_t aFallback,
|
||||||
|
PrefValueKind aKind) {
|
||||||
|
return PreferencesInternalMethods::GetPref(aPrefName, aFallback, aKind);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
uint32_t Preferences::GetUint(const char* aPrefName, uint32_t aFallback,
|
||||||
|
PrefValueKind aKind) {
|
||||||
|
return PreferencesInternalMethods::GetPref(aPrefName, aFallback, aKind);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
float Preferences::GetFloat(const char* aPrefName, float aFallback,
|
||||||
|
PrefValueKind aKind) {
|
||||||
|
return PreferencesInternalMethods::GetPref(aPrefName, aFallback, aKind);
|
||||||
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
nsresult Preferences::SetCString(const char* aPrefName,
|
nsresult Preferences::SetCString(const char* aPrefName,
|
||||||
const nsACString& aValue,
|
const nsACString& aValue,
|
||||||
|
@ -5199,34 +5199,16 @@ static void CacheDataAppendElement(CacheData* aData) {
|
||||||
gCacheData->AppendElement(aData);
|
gCacheData->AppendElement(aData);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static void VarChanged(const char* aPref, void* aClosure) {
|
|
||||||
CacheData* cache = static_cast<CacheData*>(aClosure);
|
|
||||||
*static_cast<T*>(cache->mCacheLocation) =
|
|
||||||
GetPref(aPref, cache->GetDefault<StripAtomic<T>>());
|
|
||||||
}
|
|
||||||
|
|
||||||
// We define this method in a struct which is made friend of Preferences in
|
|
||||||
// order to access private members.
|
|
||||||
struct RegisterCallbacksInternal {
|
|
||||||
template <typename T>
|
|
||||||
static nsresult RegisterCallback(CacheData* aCacheData,
|
|
||||||
const nsACString& aPref) {
|
|
||||||
return Preferences::RegisterCallback(VarChanged<T>, aPref, aCacheData,
|
|
||||||
Preferences::ExactMatch,
|
|
||||||
/* isPriority */ true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static nsresult AddVarCache(T* aCache, const nsACString& aPref,
|
static nsresult AddVarCache(T* aCache, const nsACString& aPref,
|
||||||
StripAtomic<T> aDefault, bool aSkipAssignment) {
|
StripAtomic<T> aDefault, bool aSkipAssignment) {
|
||||||
if (!aSkipAssignment) {
|
if (!aSkipAssignment) {
|
||||||
*aCache = GetPref(PromiseFlatCString(aPref).get(), aDefault);
|
*aCache = PreferencesInternalMethods::GetPref(
|
||||||
|
PromiseFlatCString(aPref).get(), aDefault);
|
||||||
}
|
}
|
||||||
CacheData* data = new CacheData(aCache, aDefault);
|
CacheData* data = new CacheData(aCache, aDefault);
|
||||||
CacheDataAppendElement(data);
|
CacheDataAppendElement(data);
|
||||||
RegisterCallbacksInternal::RegisterCallback<T>(data, aPref);
|
PreferencesInternalMethods::RegisterCallback<T>(data, aPref);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5440,8 +5422,8 @@ static StaticMutex sOncePrefMutex;
|
||||||
// void StaticPrefs::Setmy_varcache(int32_t aValue) {
|
// void StaticPrefs::Setmy_varcache(int32_t aValue) {
|
||||||
// SetPref(Getmy_varcachePrefName(), aValue);
|
// SetPref(Getmy_varcachePrefName(), aValue);
|
||||||
// if (UpdatePolicy::policy == UpdatePolicy::Once) {
|
// if (UpdatePolicy::policy == UpdatePolicy::Once) {
|
||||||
// sVarCache_my_varcache =
|
// sVarCache_my_varcache = PreferencesInternalMethods::GetPref(
|
||||||
// GetPref(Getmy_varcachePrefName(), sVarCache_my_varcache);
|
// Getmy_varcachePrefName(), sVarCache_my_varcache);
|
||||||
// }
|
// }
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
@ -5468,8 +5450,8 @@ static StaticMutex sOncePrefMutex;
|
||||||
!sOncePrefRead); \
|
!sOncePrefRead); \
|
||||||
SetPref(Get##id##PrefName(), aValue); \
|
SetPref(Get##id##PrefName(), aValue); \
|
||||||
if (UpdatePolicy::policy == UpdatePolicy::Once) { \
|
if (UpdatePolicy::policy == UpdatePolicy::Once) { \
|
||||||
sVarCache_##id = \
|
sVarCache_##id = PreferencesInternalMethods::GetPref( \
|
||||||
GetPref(Get##id##PrefName(), StripAtomic<cpp_type>(sVarCache_##id)); \
|
Get##id##PrefName(), StripAtomic<cpp_type>(sVarCache_##id)); \
|
||||||
} \
|
} \
|
||||||
/* The StaticPrefs storage will be updated by the registered callback */ \
|
/* The StaticPrefs storage will be updated by the registered callback */ \
|
||||||
return; \
|
return; \
|
||||||
|
@ -5522,7 +5504,8 @@ void StaticPrefs::InitOncePrefs() {
|
||||||
//
|
//
|
||||||
// if (UpdatePolicy::Skip == UpdatePolicy::Once) {
|
// if (UpdatePolicy::Skip == UpdatePolicy::Once) {
|
||||||
// StaticPrefs::sVarCache_my_varcache =
|
// StaticPrefs::sVarCache_my_varcache =
|
||||||
// GetPref("my.varcache", StripAtomic<int32_t>(99));
|
// PreferencesInternalMethods::GetPref("my.varcache",
|
||||||
|
// StripAtomic<int32_t>(99));
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// This is done to get the potentially updated Preference value as we didn't
|
// This is done to get the potentially updated Preference value as we didn't
|
||||||
|
@ -5534,31 +5517,32 @@ void StaticPrefs::InitOncePrefs() {
|
||||||
// and that maybe instead they should have been made `Live`.
|
// and that maybe instead they should have been made `Live`.
|
||||||
#define PREF(name, cpp_type, value)
|
#define PREF(name, cpp_type, value)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# define VARCACHE_PREF(policy, name, id, cpp_type, value) \
|
# define VARCACHE_PREF(policy, name, id, cpp_type, value) \
|
||||||
if (UpdatePolicy::policy == UpdatePolicy::Once) { \
|
if (UpdatePolicy::policy == UpdatePolicy::Once) { \
|
||||||
StaticPrefs::sVarCache_##id = \
|
StaticPrefs::sVarCache_##id = PreferencesInternalMethods::GetPref( \
|
||||||
GetPref(name, StripAtomic<cpp_type>(value)); \
|
name, StripAtomic<cpp_type>(value)); \
|
||||||
auto checkPref = [&]() { \
|
auto checkPref = [&]() { \
|
||||||
if (!sOncePrefRead) { \
|
if (!sOncePrefRead) { \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
StripAtomic<cpp_type> staticPrefValue = StaticPrefs::id(); \
|
StripAtomic<cpp_type> staticPrefValue = StaticPrefs::id(); \
|
||||||
StripAtomic<cpp_type> preferenceValue = \
|
StripAtomic<cpp_type> preferenceValue = \
|
||||||
GetPref(Get##id##PrefName(), StripAtomic<cpp_type>(value)); \
|
PreferencesInternalMethods::GetPref(Get##id##PrefName(), \
|
||||||
MOZ_ASSERT( \
|
StripAtomic<cpp_type>(value)); \
|
||||||
staticPrefValue == preferenceValue, \
|
MOZ_ASSERT( \
|
||||||
"Preference '" name "' got modified since StaticPrefs::" #id \
|
staticPrefValue == preferenceValue, \
|
||||||
" got initialized. Consider using a `Live` StaticPrefs instead"); \
|
"Preference '" name "' got modified since StaticPrefs::" #id \
|
||||||
}; \
|
" got initialized. Consider using a `Live` StaticPrefs instead"); \
|
||||||
gOnceStaticPrefsAntiFootgun->insert( \
|
}; \
|
||||||
std::pair<const char*, AntiFootgunCallback>(Get##id##PrefName(), \
|
gOnceStaticPrefsAntiFootgun->insert( \
|
||||||
std::move(checkPref))); \
|
std::pair<const char*, AntiFootgunCallback>(Get##id##PrefName(), \
|
||||||
|
std::move(checkPref))); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define VARCACHE_PREF(policy, name, id, cpp_type, value) \
|
# define VARCACHE_PREF(policy, name, id, cpp_type, value) \
|
||||||
if (UpdatePolicy::policy == UpdatePolicy::Once) { \
|
if (UpdatePolicy::policy == UpdatePolicy::Once) { \
|
||||||
StaticPrefs::sVarCache_##id = \
|
StaticPrefs::sVarCache_##id = PreferencesInternalMethods::GetPref( \
|
||||||
GetPref(name, StripAtomic<cpp_type>(value)); \
|
name, StripAtomic<cpp_type>(value)); \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -5668,17 +5652,19 @@ void StaticPrefs::InitOncePrefsFromShared() {
|
||||||
// if (UpdatePolicy::Once == UpdatePolicy::Once) {
|
// if (UpdatePolicy::Once == UpdatePolicy::Once) {
|
||||||
// int32_t val;
|
// int32_t val;
|
||||||
// MOZ_DIAGNOSTIC_ALWAYS_TRUE(
|
// MOZ_DIAGNOSTIC_ALWAYS_TRUE(
|
||||||
// NS_SUCCEEDED(GetSharedPref(ONCE_PREF_NAME(name), &val)));
|
// NS_SUCCEEDED(PreferencesInternalMethods::GetSharedPrefValue(
|
||||||
|
// ONCE_PREF_NAME(name), &val)));
|
||||||
// StaticPrefs::sVarCache_my_varcache = val;
|
// StaticPrefs::sVarCache_my_varcache = val;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
#define PREF(name, cpp_type, value)
|
#define PREF(name, cpp_type, value)
|
||||||
#define VARCACHE_PREF(policy, name, id, cpp_type, value) \
|
#define VARCACHE_PREF(policy, name, id, cpp_type, value) \
|
||||||
if (UpdatePolicy::policy == UpdatePolicy::Once) { \
|
if (UpdatePolicy::policy == UpdatePolicy::Once) { \
|
||||||
StripAtomic<cpp_type> val; \
|
StripAtomic<cpp_type> val; \
|
||||||
MOZ_DIAGNOSTIC_ALWAYS_TRUE( \
|
MOZ_DIAGNOSTIC_ALWAYS_TRUE( \
|
||||||
NS_SUCCEEDED(GetSharedPref(ONCE_PREF_NAME(name), &val))); \
|
NS_SUCCEEDED(PreferencesInternalMethods::GetSharedPrefValue( \
|
||||||
StaticPrefs::sVarCache_##id = val; \
|
ONCE_PREF_NAME(name), &val))); \
|
||||||
|
StaticPrefs::sVarCache_##id = val; \
|
||||||
}
|
}
|
||||||
#include "mozilla/StaticPrefList.h"
|
#include "mozilla/StaticPrefList.h"
|
||||||
#undef PREF
|
#undef PREF
|
||||||
|
|
|
@ -229,29 +229,13 @@ class Preferences final : public nsIPrefService,
|
||||||
// failure. When `aKind` is `User` they will get the user value if possible,
|
// failure. When `aKind` is `User` they will get the user value if possible,
|
||||||
// and fall back to the default value otherwise.
|
// and fall back to the default value otherwise.
|
||||||
static bool GetBool(const char* aPrefName, bool aFallback = false,
|
static bool GetBool(const char* aPrefName, bool aFallback = false,
|
||||||
PrefValueKind aKind = PrefValueKind::User) {
|
PrefValueKind aKind = PrefValueKind::User);
|
||||||
bool result = aFallback;
|
|
||||||
GetBool(aPrefName, &result, aKind);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
static int32_t GetInt(const char* aPrefName, int32_t aFallback = 0,
|
static int32_t GetInt(const char* aPrefName, int32_t aFallback = 0,
|
||||||
PrefValueKind aKind = PrefValueKind::User) {
|
PrefValueKind aKind = PrefValueKind::User);
|
||||||
int32_t result = aFallback;
|
|
||||||
GetInt(aPrefName, &result, aKind);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
static uint32_t GetUint(const char* aPrefName, uint32_t aFallback = 0,
|
static uint32_t GetUint(const char* aPrefName, uint32_t aFallback = 0,
|
||||||
PrefValueKind aKind = PrefValueKind::User) {
|
PrefValueKind aKind = PrefValueKind::User);
|
||||||
uint32_t result = aFallback;
|
|
||||||
GetUint(aPrefName, &result, aKind);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
static float GetFloat(const char* aPrefName, float aFallback = 0.0f,
|
static float GetFloat(const char* aPrefName, float aFallback = 0.0f,
|
||||||
PrefValueKind aKind = PrefValueKind::User) {
|
PrefValueKind aKind = PrefValueKind::User);
|
||||||
float result = aFallback;
|
|
||||||
GetFloat(aPrefName, &result, aKind);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value setters. These fail if run outside the parent process.
|
// Value setters. These fail if run outside the parent process.
|
||||||
|
|
||||||
|
@ -642,7 +626,8 @@ class Preferences final : public nsIPrefService,
|
||||||
static mozilla::Result<mozilla::Ok, const char*> InitInitialObjects(
|
static mozilla::Result<mozilla::Ok, const char*> InitInitialObjects(
|
||||||
bool aIsStartup);
|
bool aIsStartup);
|
||||||
|
|
||||||
friend struct RegisterCallbacksInternal;
|
friend struct PreferencesInternalMethods;
|
||||||
|
|
||||||
static nsresult RegisterCallback(PrefChangedFunc aCallback,
|
static nsresult RegisterCallback(PrefChangedFunc aCallback,
|
||||||
const nsACString& aPref, void* aClosure,
|
const nsACString& aPref, void* aClosure,
|
||||||
MatchKind aMatchKind,
|
MatchKind aMatchKind,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче