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