Bug 1394578 - Remove the kPref* enum. r=glandium

It's something of an obfuscation, and it forces together various bool values
that don't necessarily have to be together (and won't be together after future
refactorings).

The patch also reorders some function arguments for consistency: PrefType, then
PrefValueKind, then PrefValue.

MozReview-Commit-ID: KNY0Pxo0Nxf

--HG--
extra : rebase_source : d46d228c3b13549b2159757dcdaf9583cca828f7
This commit is contained in:
Nicholas Nethercote 2017-11-23 13:07:04 +11:00
Родитель 53ec464e06
Коммит 5208f7436b
1 изменённых файлов: 32 добавлений и 29 удалений

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

@ -226,13 +226,6 @@ StrEscape(const char* aOriginal, nsCString& aResult)
aResult.Append('"');
}
enum
{
kPrefSetDefault = 1,
kPrefForceSet = 2,
kPrefSticky = 4,
};
static ArenaAllocator<8192, 1> gPrefNameArena;
class Pref : public PLDHashEntryHdr
@ -489,12 +482,14 @@ public:
}
nsresult SetValue(PrefType aType,
PrefValueKind aKind,
PrefValue aValue,
uint32_t aFlags,
bool aIsSticky,
bool aForceSet,
bool* aValueChanged,
bool* aDirty)
{
if (aFlags & kPrefSetDefault) {
if (aKind == PrefValueKind::Default) {
// Types must always match when setting the default value.
if (!IsType(aType)) {
return NS_ERROR_UNEXPECTED;
@ -504,7 +499,7 @@ public:
// doing so would change the default value.
if (!IsLocked() && !ValueMatches(PrefValueKind::Default, aType, aValue)) {
ReplaceValue(PrefValueKind::Default, aType, aValue);
if (aFlags & kPrefSticky) {
if (aIsSticky) {
mIsSticky = true;
}
if (!mHasUserValue) {
@ -524,7 +519,7 @@ public:
// matches the default value, and the pref isn't sticky, and we aren't
// force-setting it.
if (ValueMatches(PrefValueKind::Default, aType, aValue) && !mIsSticky &&
!(aFlags & kPrefForceSet)) {
!aForceSet) {
if (mHasUserValue) {
ClearUserValue();
if (!IsLocked()) {
@ -759,9 +754,11 @@ pref_HashTableLookup(const char* aKey)
static nsresult
pref_SetPref(const char* aPrefName,
PrefValue aValue,
PrefType aType,
uint32_t aFlags)
PrefValueKind aKind,
PrefValue aValue,
bool aIsSticky,
bool aForceSet)
{
MOZ_ASSERT(NS_IsMainThread());
@ -780,14 +777,14 @@ pref_SetPref(const char* aPrefName,
}
bool valueChanged = false, handleDirty = false;
nsresult rv =
pref->SetValue(aType, aValue, aFlags, &valueChanged, &handleDirty);
nsresult rv = pref->SetValue(
aType, aKind, aValue, aIsSticky, aForceSet, &valueChanged, &handleDirty);
if (NS_FAILED(rv)) {
NS_WARNING(
nsPrintfCString(
"Rejected attempt to change type of pref %s's %s value from %s to %s",
aPrefName,
(aFlags & kPrefSetDefault) ? "default" : "user",
(aKind == PrefValueKind::Default) ? "default" : "user",
PrefTypeToString(pref->Type()),
PrefTypeToString(aType))
.get());
@ -1008,16 +1005,16 @@ Parser::HandleValue(const char* aPrefName,
bool aIsDefault,
bool aIsSticky)
{
uint32_t flags = 0;
PrefValueKind kind;
bool forceSet;
if (aIsDefault) {
flags |= kPrefSetDefault;
if (aIsSticky) {
flags |= kPrefSticky;
}
kind = PrefValueKind::Default;
forceSet = false;
} else {
flags |= kPrefForceSet;
kind = PrefValueKind::User;
forceSet = true;
}
pref_SetPref(aPrefName, aValue, aType, flags);
pref_SetPref(aPrefName, aType, kind, aValue, aIsSticky, forceSet);
}
// Report an error or a warning. If not specified, just dump to stderr.
@ -4417,9 +4414,11 @@ Preferences::SetCStringInAnyProcess(const char* aPrefName,
const nsCString& flat = PromiseFlatCString(aValue);
prefValue.mStringVal = flat.get();
return pref_SetPref(aPrefName,
prefValue,
PrefType::String,
aKind == PrefValueKind::Default ? kPrefSetDefault : 0);
aKind,
prefValue,
/* isSticky */ false,
/* forceSet */ false);
}
/* static */ nsresult
@ -4441,9 +4440,11 @@ Preferences::SetBoolInAnyProcess(const char* aPrefName,
PrefValue prefValue;
prefValue.mBoolVal = aValue;
return pref_SetPref(aPrefName,
prefValue,
PrefType::Bool,
aKind == PrefValueKind::Default ? kPrefSetDefault : 0);
aKind,
prefValue,
/* isSticky */ false,
/* forceSet */ false);
}
/* static */ nsresult
@ -4463,9 +4464,11 @@ Preferences::SetIntInAnyProcess(const char* aPrefName,
PrefValue prefValue;
prefValue.mIntVal = aValue;
return pref_SetPref(aPrefName,
prefValue,
PrefType::Int,
aKind == PrefValueKind::Default ? kPrefSetDefault : 0);
aKind,
prefValue,
/* isSticky */ false,
/* forceSet */ false);
}
/* static */ nsresult