Bug 1550422 - P13. Add Skip, Once and Live cached preference policy. r=njn,kmag

This works identically to what gfxPrefs UpdatePolicy offers.

Differential Revision: https://phabricator.services.mozilla.com/D31257

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jean-Yves Avenard 2019-05-25 00:03:53 +00:00
Родитель af5790cf9b
Коммит 72db7328f0
5 изменённых файлов: 862 добавлений и 590 удалений

Просмотреть файл

@ -3064,15 +3064,48 @@ class PWRunnable : public Runnable {
};
struct CacheData {
void* mCacheLocation;
CacheData(void* aCacheLocation, bool aValue)
: mCacheLocation(aCacheLocation), mDefaultValueBool(aValue) {}
CacheData(void* aCacheLocation, int32_t aValue)
: mCacheLocation(aCacheLocation), mDefaultValueInt(aValue) {}
CacheData(void* aCacheLocation, uint32_t aValue)
: mCacheLocation(aCacheLocation), mDefaultValueUint(aValue) {}
CacheData(void* aCacheLocation, float aValue)
: mCacheLocation(aCacheLocation), mDefaultValueFloat(aValue) {}
template <typename T>
T GetDefault() const;
void* const mCacheLocation;
private:
union {
bool mDefaultValueBool;
int32_t mDefaultValueInt;
uint32_t mDefaultValueUint;
float mDefaultValueFloat;
const bool mDefaultValueBool;
const int32_t mDefaultValueInt;
const uint32_t mDefaultValueUint;
const float mDefaultValueFloat;
};
};
// We specialise the CacheData::GetDefault() here, as somehow you can't do it
// inline within CacheData definition.
template <>
bool CacheData::GetDefault() const {
return mDefaultValueBool;
}
template <>
int32_t CacheData::GetDefault() const {
return mDefaultValueInt;
}
template <>
uint32_t CacheData::GetDefault() const {
return mDefaultValueUint;
}
template <>
float CacheData::GetDefault() const {
return mDefaultValueFloat;
}
// gCacheDataDesc holds information about prefs startup. It's being used for
// diagnosing prefs startup problems in bug 1276488.
static const char* gCacheDataDesc = "untouched";
@ -3684,11 +3717,23 @@ void Preferences::InitializeUserPrefs() {
sPreferences->NotifyServiceObservers(NS_PREFSERVICE_READ_TOPIC_ID);
RefreshStaticPrefsValues();
// At this point all the prefs files have been read and telemetry has been
// initialized. Send all the file load measurements to telemetry.
SendTelemetryLoadData();
}
/* static */
void Preferences::RefreshStaticPrefsValues() {
MOZ_ASSERT(XRE_IsParentProcess());
// Ensure that StaticPref of type Once are properly set to the underlying
// Preference value as they may have been updated with a user-set or
// enterprise policies value.
StaticPrefs::InitOncePrefs();
}
NS_IMETHODIMP
Preferences::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* someData) {
@ -4319,24 +4364,22 @@ template <typename T>
static T GetPref(const char* aName, T aDefaultValue);
template <>
bool MOZ_MAYBE_UNUSED GetPref<bool>(const char* aName, bool aDefaultValue) {
bool MOZ_MAYBE_UNUSED GetPref(const char* aName, bool aDefaultValue) {
return Preferences::GetBool(aName, aDefaultValue);
}
template <>
int32_t MOZ_MAYBE_UNUSED GetPref<int32_t>(const char* aName,
int32_t aDefaultValue) {
int32_t MOZ_MAYBE_UNUSED GetPref(const char* aName, int32_t aDefaultValue) {
return Preferences::GetInt(aName, aDefaultValue);
}
template <>
uint32_t MOZ_MAYBE_UNUSED GetPref<uint32_t>(const char* aName,
uint32_t aDefaultValue) {
uint32_t MOZ_MAYBE_UNUSED GetPref(const char* aName, uint32_t aDefaultValue) {
return Preferences::GetInt(aName, aDefaultValue);
}
template <>
float MOZ_MAYBE_UNUSED GetPref<float>(const char* aName, float aDefaultValue) {
float MOZ_MAYBE_UNUSED GetPref(const char* aName, float aDefaultValue) {
return Preferences::GetFloat(aName, aDefaultValue);
}
@ -4390,16 +4433,24 @@ static nsresult pref_ReadDefaultPrefs(const RefPtr<nsZipArchive> jarReader,
}
}
if (aIsStartup) {
StaticPrefs::InitOncePrefs();
}
#ifdef DEBUG
// Check that all varcache preferences match their current values. This
// can currently fail if the default value of a static varcache preference
// is changed in a preference file or at runtime, rather than in
// StaticPrefList.h.
// StaticPrefs with a Skip policy aren't updated with an overridden value,
// and shouldn't be checked.
# define PREF(name, cpp_type, value)
# define VARCACHE_PREF(name, id, cpp_type, value) \
MOZ_ASSERT( \
GetPref<StripAtomic<cpp_type>>(name, value) == StaticPrefs::id(), \
# define VARCACHE_PREF(policy, name, id, cpp_type, value) \
MOZ_ASSERT( \
StaticPrefs::UpdatePolicy::policy == \
StaticPrefs::UpdatePolicy::Skip || \
GetPref<StripAtomic<cpp_type>>(name, value) == StaticPrefs::id(), \
"Incorrect cached value for " name);
# include "mozilla/StaticPrefList.h"
# undef PREF
@ -4582,6 +4633,12 @@ static nsresult pref_ReadDefaultPrefs(const RefPtr<nsZipArchive> jarReader,
}
}
if (aIsStartup) {
// Ensure that StaticPref of type Once are properly set to the underlying
// Preference value.
StaticPrefs::InitOncePrefs();
}
if (XRE_IsParentProcess()) {
SetupTelemetryPref();
}
@ -5084,34 +5141,42 @@ static void CacheDataAppendElement(CacheData* aData) {
gCacheData->AppendElement(aData);
}
static void BoolVarChanged(const char* aPref, void* aClosure) {
template <typename T>
static void VarChanged(const char* aPref, void* aClosure) {
CacheData* cache = static_cast<CacheData*>(aClosure);
*static_cast<bool*>(cache->mCacheLocation) =
Preferences::GetBool(aPref, cache->mDefaultValueBool);
*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>
static nsresult AddVarCache(T* aCache, const nsACString& aPref,
StripAtomic<T> aDefault, bool aSkipAssignment) {
if (!aSkipAssignment) {
*aCache = GetPref(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData(aCache, aDefault);
CacheDataAppendElement(data);
RegisterCallbacksInternal::RegisterCallback<T>(data, aPref);
return NS_OK;
}
/* static */
nsresult Preferences::AddBoolVarCache(bool* aCache, const nsACString& aPref,
bool aDefault, bool aSkipAssignment) {
AssertNotAlreadyCached("bool", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetBool(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
data->mDefaultValueBool = aDefault;
CacheDataAppendElement(data);
Preferences::RegisterCallback(BoolVarChanged, aPref, data,
Preferences::ExactMatch,
/* isPriority */ true);
return NS_OK;
}
template <MemoryOrdering Order>
static void AtomicBoolVarChanged(const char* aPref, void* aClosure) {
CacheData* cache = static_cast<CacheData*>(aClosure);
*static_cast<Atomic<bool, Order>*>(cache->mCacheLocation) =
Preferences::GetBool(aPref, cache->mDefaultValueBool);
return AddVarCache(aCache, aPref, aDefault, aSkipAssignment);
}
template <MemoryOrdering Order>
@ -5121,46 +5186,14 @@ nsresult Preferences::AddAtomicBoolVarCache(Atomic<bool, Order>* aCache,
bool aDefault,
bool aSkipAssignment) {
AssertNotAlreadyCached("bool", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetBool(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
data->mDefaultValueBool = aDefault;
CacheDataAppendElement(data);
Preferences::RegisterCallback(AtomicBoolVarChanged<Order>, aPref, data,
Preferences::ExactMatch,
/* isPriority */ true);
return NS_OK;
}
static void IntVarChanged(const char* aPref, void* aClosure) {
CacheData* cache = static_cast<CacheData*>(aClosure);
*static_cast<int32_t*>(cache->mCacheLocation) =
Preferences::GetInt(aPref, cache->mDefaultValueInt);
return AddVarCache(aCache, aPref, aDefault, aSkipAssignment);
}
/* static */
nsresult Preferences::AddIntVarCache(int32_t* aCache, const nsACString& aPref,
int32_t aDefault, bool aSkipAssignment) {
AssertNotAlreadyCached("int", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetInt(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
data->mDefaultValueInt = aDefault;
CacheDataAppendElement(data);
Preferences::RegisterCallback(IntVarChanged, aPref, data,
Preferences::ExactMatch, /* isPriority */ true);
return NS_OK;
}
template <MemoryOrdering Order>
static void AtomicIntVarChanged(const char* aPref, void* aClosure) {
CacheData* cache = static_cast<CacheData*>(aClosure);
*static_cast<Atomic<int32_t, Order>*>(cache->mCacheLocation) =
Preferences::GetInt(aPref, cache->mDefaultValueUint);
return AddVarCache(aCache, aPref, aDefault, aSkipAssignment);
}
template <MemoryOrdering Order>
@ -5170,47 +5203,14 @@ nsresult Preferences::AddAtomicIntVarCache(Atomic<int32_t, Order>* aCache,
int32_t aDefault,
bool aSkipAssignment) {
AssertNotAlreadyCached("int", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetInt(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
data->mDefaultValueUint = aDefault;
CacheDataAppendElement(data);
Preferences::RegisterCallback(AtomicIntVarChanged<Order>, aPref, data,
Preferences::ExactMatch,
/* isPriority */ true);
return NS_OK;
}
static void UintVarChanged(const char* aPref, void* aClosure) {
CacheData* cache = static_cast<CacheData*>(aClosure);
*static_cast<uint32_t*>(cache->mCacheLocation) =
Preferences::GetUint(aPref, cache->mDefaultValueUint);
return AddVarCache(aCache, aPref, aDefault, aSkipAssignment);
}
/* static */
nsresult Preferences::AddUintVarCache(uint32_t* aCache, const nsACString& aPref,
uint32_t aDefault, bool aSkipAssignment) {
AssertNotAlreadyCached("uint", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetUint(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
data->mDefaultValueUint = aDefault;
CacheDataAppendElement(data);
Preferences::RegisterCallback(UintVarChanged, aPref, data,
Preferences::ExactMatch,
/* isPriority */ true);
return NS_OK;
}
template <MemoryOrdering Order>
static void AtomicUintVarChanged(const char* aPref, void* aClosure) {
CacheData* cache = static_cast<CacheData*>(aClosure);
*static_cast<Atomic<uint32_t, Order>*>(cache->mCacheLocation) =
Preferences::GetUint(aPref, cache->mDefaultValueUint);
return AddVarCache(aCache, aPref, aDefault, aSkipAssignment);
}
template <MemoryOrdering Order>
@ -5220,17 +5220,7 @@ nsresult Preferences::AddAtomicUintVarCache(Atomic<uint32_t, Order>* aCache,
uint32_t aDefault,
bool aSkipAssignment) {
AssertNotAlreadyCached("uint", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetUint(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
data->mDefaultValueUint = aDefault;
CacheDataAppendElement(data);
Preferences::RegisterCallback(AtomicUintVarChanged<Order>, aPref, data,
Preferences::ExactMatch,
/* isPriority */ true);
return NS_OK;
return AddVarCache(aCache, aPref, aDefault, aSkipAssignment);
}
// Since the definition of template functions is not in a header file, we
@ -5261,33 +5251,11 @@ template nsresult Preferences::AddAtomicUintVarCache(
Atomic<uint32_t, SequentiallyConsistent>*, const nsACString&, uint32_t,
bool);
static void FloatVarChanged(const char* aPref, void* aClosure) {
CacheData* cache = static_cast<CacheData*>(aClosure);
*static_cast<float*>(cache->mCacheLocation) =
Preferences::GetFloat(aPref, cache->mDefaultValueFloat);
}
/* static */
nsresult Preferences::AddFloatVarCache(float* aCache, const nsACString& aPref,
float aDefault, bool aSkipAssignment) {
AssertNotAlreadyCached("float", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetFloat(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
data->mDefaultValueFloat = aDefault;
CacheDataAppendElement(data);
Preferences::RegisterCallback(FloatVarChanged, aPref, data,
Preferences::ExactMatch,
/* isPriority */ true);
return NS_OK;
}
static void AtomicFloatVarChanged(const char* aPref, void* aClosure) {
CacheData* cache = static_cast<CacheData*>(aClosure);
*static_cast<std::atomic<float>*>(cache->mCacheLocation) =
Preferences::GetFloat(aPref, cache->mDefaultValueFloat);
return AddVarCache(aCache, aPref, aDefault, aSkipAssignment);
}
/* static */
@ -5296,17 +5264,7 @@ nsresult Preferences::AddAtomicFloatVarCache(std::atomic<float>* aCache,
float aDefault,
bool aSkipAssignment) {
AssertNotAlreadyCached("float", aPref, aCache);
if (!aSkipAssignment) {
*aCache = GetFloat(PromiseFlatCString(aPref).get(), aDefault);
}
CacheData* data = new CacheData();
data->mCacheLocation = aCache;
data->mDefaultValueFloat = aDefault;
CacheDataAppendElement(data);
Preferences::RegisterCallback(AtomicFloatVarChanged, aPref, data,
Preferences::ExactMatch,
/* isPriority */ true);
return NS_OK;
return AddVarCache(aCache, aPref, aDefault, aSkipAssignment);
}
// For a VarCache pref like this:
@ -5318,7 +5276,7 @@ nsresult Preferences::AddAtomicFloatVarCache(std::atomic<float>* aCache,
// int32_t StaticPrefs::sVarCache_my_varcache(99);
//
#define PREF(name, cpp_type, value)
#define VARCACHE_PREF(name, id, cpp_type, value) \
#define VARCACHE_PREF(policy, name, id, cpp_type, value) \
cpp_type StaticPrefs::sVarCache_##id(value);
#include "mozilla/StaticPrefList.h"
#undef PREF
@ -5368,108 +5326,36 @@ MOZ_MAYBE_UNUSED static void SetPref_String(const char* aName,
/* fromInit */ true);
}
static void InitVarCachePref(const nsACString& aName, bool* aCache,
bool aDefaultValue, bool aIsStartup,
static void SetPref(const char* aName, bool aDefaultValue) {
SetPref_bool(aName, aDefaultValue);
}
static void SetPref(const char* aName, int32_t aDefaultValue) {
SetPref_int32_t(aName, aDefaultValue);
}
static void SetPref(const char* aName, uint32_t aDefaultValue) {
SetPref_int32_t(aName, int32_t(aDefaultValue));
}
static void SetPref(const char* aName, float aDefaultValue) {
SetPref_float(aName, aDefaultValue);
}
MOZ_MAYBE_UNUSED static void SetPref(const char* aName,
const char* aDefaultValue) {
SetPref_String(aName, aDefaultValue);
}
template <typename T>
static void InitVarCachePref(StaticPrefs::UpdatePolicy aPolicy,
const nsACString& aName, T* aCache,
StripAtomic<T> aDefaultValue, bool aIsStartup,
bool aSetValue) {
if (aSetValue) {
SetPref_bool(PromiseFlatCString(aName).get(), aDefaultValue);
SetPref(PromiseFlatCString(aName).get(), aDefaultValue);
}
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddBoolVarCache(aCache, aName, aDefaultValue, true);
}
}
template <MemoryOrdering Order>
static void InitVarCachePref(const nsACString& aName,
Atomic<bool, Order>* aCache, bool aDefaultValue,
bool aIsStartup, bool aSetValue) {
if (aSetValue) {
SetPref_bool(PromiseFlatCString(aName).get(), aDefaultValue);
}
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddAtomicBoolVarCache(aCache, aName, aDefaultValue, true);
}
}
// XXX: this will eventually become used
MOZ_MAYBE_UNUSED static void InitVarCachePref(const nsACString& aName,
int32_t* aCache,
int32_t aDefaultValue,
bool aIsStartup, bool aSetValue) {
if (aSetValue) {
SetPref_int32_t(PromiseFlatCString(aName).get(), aDefaultValue);
}
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddIntVarCache(aCache, aName, aDefaultValue, true);
}
}
template <MemoryOrdering Order>
static void InitVarCachePref(const nsACString& aName,
Atomic<int32_t, Order>* aCache,
int32_t aDefaultValue, bool aIsStartup,
bool aSetValue) {
if (aSetValue) {
SetPref_int32_t(PromiseFlatCString(aName).get(), aDefaultValue);
}
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddAtomicIntVarCache(aCache, aName, aDefaultValue, true);
}
}
static void InitVarCachePref(const nsACString& aName, uint32_t* aCache,
uint32_t aDefaultValue, bool aIsStartup,
bool aSetValue) {
if (aSetValue) {
SetPref_int32_t(PromiseFlatCString(aName).get(),
static_cast<int32_t>(aDefaultValue));
}
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddUintVarCache(aCache, aName, aDefaultValue, true);
}
}
template <MemoryOrdering Order>
static void InitVarCachePref(const nsACString& aName,
Atomic<uint32_t, Order>* aCache,
uint32_t aDefaultValue, bool aIsStartup,
bool aSetValue) {
if (aSetValue) {
SetPref_int32_t(PromiseFlatCString(aName).get(),
static_cast<int32_t>(aDefaultValue));
}
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddAtomicUintVarCache(aCache, aName, aDefaultValue, true);
}
}
static void InitVarCachePref(const nsACString& aName, float* aCache,
float aDefaultValue, bool aIsStartup,
bool aSetValue) {
if (aSetValue) {
SetPref_float(PromiseFlatCString(aName).get(), aDefaultValue);
}
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddFloatVarCache(aCache, aName, aDefaultValue, true);
}
}
static void InitVarCachePref(const nsACString& aName,
std::atomic<float>* aCache, float aDefaultValue,
bool aIsStartup, bool aSetValue) {
if (aSetValue) {
SetPref_float(PromiseFlatCString(aName).get(), aDefaultValue);
}
*aCache = aDefaultValue;
if (aIsStartup) {
Preferences::AddAtomicFloatVarCache(aCache, aName, aDefaultValue, true);
if (MOZ_LIKELY(aIsStartup) &&
MOZ_LIKELY(aPolicy == StaticPrefs::UpdatePolicy::Live)) {
AddVarCache(aCache, aName, aDefaultValue, true);
}
}
@ -5478,14 +5364,15 @@ void StaticPrefs::InitAll(bool aIsStartup) {
// For prefs like these:
//
// PREF("foo.bar.baz", bool, true)
// VARCACHE_PREF("my.varcache", my_varcache, int32_t, 99)
// VARCACHE_PREF(Live, "my.varcache", my_varcache, int32_t, 99)
//
// we generate registration calls:
//
// if (isParent)
// SetPref_bool("foo.bar.baz", true);
// InitVarCachePref("my.varcache", &StaticPrefs::sVarCache_my_varcache, 99,
// aIsStartup);
// InitVarCachePref(StaticPrefs::UpdatePolicy::Live, "my.varcache",
// &StaticPrefs::sVarCache_my_varcache, 99, aIsStartup,
// isParent);
//
// The SetPref_*() functions have a type suffix to avoid ambiguity between
// prefs having int32_t and float default values. That suffix is not needed
@ -5497,14 +5384,40 @@ void StaticPrefs::InitAll(bool aIsStartup) {
bool isParent = XRE_IsParentProcess();
#define PREF(name, cpp_type, value) \
if (isParent) SetPref_##cpp_type(name, value);
#define VARCACHE_PREF(name, id, cpp_type, value) \
InitVarCachePref(NS_LITERAL_CSTRING(name), &StaticPrefs::sVarCache_##id, \
#define VARCACHE_PREF(policy, name, id, cpp_type, value) \
InitVarCachePref(StaticPrefs::UpdatePolicy::policy, \
NS_LITERAL_CSTRING(name), &StaticPrefs::sVarCache_##id, \
value, aIsStartup, isParent);
#include "mozilla/StaticPrefList.h"
#undef PREF
#undef VARCACHE_PREF
}
/* static */
void StaticPrefs::InitOncePrefs() {
// For prefs like these:
//
// VARCACHE_PREF(Skip, "my.varcache", my_varcache, int32_t, 99)
//
// we generate registration calls:
//
// if (UpdatePolicy::Skip == UpdatePolicy::Once) {
// StaticPrefs::sVarCache_my_varcache =
// GetPref("my.varcache", StripAtomic<int32_t>(99));
// }
//
// This is done to get the potentially updated Preference value as we didn't
// register a callback method for the Once policy.
#define PREF(name, cpp_type, value)
#define VARCACHE_PREF(policy, name, id, cpp_type, value) \
if (UpdatePolicy::policy == UpdatePolicy::Once) { \
StaticPrefs::sVarCache_##id = GetPref(name, StripAtomic<cpp_type>(value)); \
}
#include "mozilla/StaticPrefList.h"
#undef PREF
#undef VARCACHE_PREF
}
} // namespace mozilla
#undef ENSURE_PARENT_PROCESS

Просмотреть файл

@ -34,6 +34,8 @@ class nsPrefBranch;
namespace mozilla {
struct RegisterCallbacksInternal;
void UnloadPrefsModule();
// A typesafe version of PrefChangeFunc, with its data argument type deduced
@ -175,6 +177,8 @@ class Preferences final : public nsIPrefService,
// Initialize user prefs from prefs.js/user.js
static void InitializeUserPrefs();
static void RefreshStaticPrefsValues();
// Returns the singleton instance which is addreffed.
static already_AddRefed<Preferences> GetInstanceForService();
@ -640,6 +644,7 @@ class Preferences final : public nsIPrefService,
static mozilla::Result<mozilla::Ok, const char*> InitInitialObjects(
bool aIsStartup);
friend struct RegisterCallbacksInternal;
static nsresult RegisterCallback(PrefChangedFunc aCallback,
const nsACString& aPref, void* aClosure,
MatchKind aMatchKind,

Просмотреть файл

@ -66,41 +66,51 @@ template <typename T>
struct IsAtomic<std::atomic<T>> : TrueType {};
class StaticPrefs {
// For a VarCache pref like this:
//
// VARCACHE_PREF("my.varcache", my_varcache, int32_t, 99)
//
// we generate a static variable declaration, a getter and a setter definition.
// A StaticPref can be set by using the corresponding Set method. For
// example, if the accessor is Foo() then calling SetFoo(...) will update
// the preference and also change the return value of subsequent Foo() calls.
// Changing StaticPrefs values in one process will not affect the result in
// other processes.
// Important Note: The use of the Setter is strongly discouraged.
//
// 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;
// }
//
// For a VarCache pref like this:
//
// VARCACHE_PREF("my.varcache", my_varcache, int32_t, 99)
//
// we generate a static variable declaration, a getter and a setter
// definition. A StaticPref can be set by using the corresponding Set method.
// For example, if the accessor is Foo() then calling SetFoo(...) will update
// the preference and also change the return value of subsequent Foo() calls.
// Changing StaticPrefs values in one process will not affect the result in
// other processes.
// Important Note: The use of the Setter is strongly discouraged.
//
// 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;
// }
//
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.
};
#define PREF(str, cpp_type, default_value)
#define VARCACHE_PREF(str, id, cpp_type, default_value) \
#define VARCACHE_PREF(policy, str, id, cpp_type, default_value) \
private: \
static cpp_type sVarCache_##id; \
\
public: \
static StripAtomic<cpp_type> id() { \
MOZ_ASSERT(IsAtomic<cpp_type>::value || NS_IsMainThread(), \
MOZ_ASSERT(UpdatePolicy::policy != UpdatePolicy::Live || \
IsAtomic<cpp_type>::value || NS_IsMainThread(), \
"Non-atomic static pref '" str \
"' 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 set pref '" str \
"Non-atomic static pref '" str \
"' being accessed on background thread by setter"); \
sVarCache_##id = aValue; \
}
@ -110,6 +120,7 @@ class StaticPrefs {
public:
static void InitAll(bool aIsStartup);
static void InitOncePrefs();
};
} // namespace mozilla

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -990,6 +990,10 @@ nsXREDirProvider::DoStartup() {
if (policies) {
policies->Observe(nullptr, "policies-startup", nullptr);
}
// We may have modified the existing preferences, it's time to complete
// setting up the Once StaticPreferences.
mozilla::Preferences::RefreshStaticPrefsValues();
}
#if defined(MOZ_SANDBOX) && defined(XP_WIN)