mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 1536163 - Part 2 - use native Maybe syntax in place of MaybePrefValue in IPDL; r=mccr8
--HG-- extra : rebase_source : 9c93e3b61ceef67e33242af4415e144ff16ba49d
This commit is contained in:
parent
5b83ddbaf3
commit
1ad3f60e94
@ -3009,7 +3009,7 @@ ContentParent::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
// We know prefs are ASCII here.
|
||||
NS_LossyConvertUTF16toASCII strData(aData);
|
||||
|
||||
Pref pref(strData, /* isLocked */ false, null_t(), null_t());
|
||||
Pref pref(strData, /* isLocked */ false, Nothing(), Nothing());
|
||||
Preferences::GetPreference(&pref);
|
||||
if (IsAlive()) {
|
||||
MOZ_ASSERT(mQueuedPrefs.IsEmpty());
|
||||
|
@ -14,11 +14,6 @@ union PrefValue {
|
||||
bool;
|
||||
};
|
||||
|
||||
union MaybePrefValue {
|
||||
PrefValue;
|
||||
null_t;
|
||||
};
|
||||
|
||||
// This serialization form mirrors that used in mozilla::Pref in
|
||||
// Preferences.cpp. The two should be kept in sync, e.g. if something is added
|
||||
// to one it should also be added to the other.
|
||||
@ -28,8 +23,8 @@ union MaybePrefValue {
|
||||
struct Pref {
|
||||
nsCString name;
|
||||
bool isLocked;
|
||||
MaybePrefValue defaultValue;
|
||||
MaybePrefValue userValue;
|
||||
PrefValue? defaultValue;
|
||||
PrefValue? userValue;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
@ -276,31 +276,31 @@ union PrefValue {
|
||||
}
|
||||
|
||||
static char* Deserialize(PrefType aType, char* aStr,
|
||||
dom::MaybePrefValue* aDomValue) {
|
||||
Maybe<dom::PrefValue>* aDomValue) {
|
||||
char* p = aStr;
|
||||
|
||||
switch (aType) {
|
||||
case PrefType::Bool:
|
||||
if (*p == 'T') {
|
||||
*aDomValue = true;
|
||||
*aDomValue = Some(true);
|
||||
} else if (*p == 'F') {
|
||||
*aDomValue = false;
|
||||
*aDomValue = Some(false);
|
||||
} else {
|
||||
*aDomValue = false;
|
||||
*aDomValue = Some(false);
|
||||
NS_ERROR("bad bool pref value");
|
||||
}
|
||||
p++;
|
||||
return p;
|
||||
|
||||
case PrefType::Int: {
|
||||
*aDomValue = int32_t(strtol(p, &p, 10));
|
||||
*aDomValue = Some(int32_t(strtol(p, &p, 10)));
|
||||
return p;
|
||||
}
|
||||
|
||||
case PrefType::String: {
|
||||
nsCString str;
|
||||
p = DeserializeString(p, str);
|
||||
*aDomValue = str;
|
||||
*aDomValue = Some(str);
|
||||
return p;
|
||||
}
|
||||
|
||||
@ -533,25 +533,23 @@ class Pref {
|
||||
aDomPref->isLocked() = mIsLocked;
|
||||
|
||||
if (mHasDefaultValue) {
|
||||
aDomPref->defaultValue() = dom::PrefValue();
|
||||
mDefaultValue.ToDomPrefValue(Type(),
|
||||
&aDomPref->defaultValue().get_PrefValue());
|
||||
aDomPref->defaultValue() = Some(dom::PrefValue());
|
||||
mDefaultValue.ToDomPrefValue(Type(), &aDomPref->defaultValue().ref());
|
||||
} else {
|
||||
aDomPref->defaultValue() = null_t();
|
||||
aDomPref->defaultValue() = Nothing();
|
||||
}
|
||||
|
||||
if (mHasUserValue) {
|
||||
aDomPref->userValue() = dom::PrefValue();
|
||||
mUserValue.ToDomPrefValue(Type(), &aDomPref->userValue().get_PrefValue());
|
||||
aDomPref->userValue() = Some(dom::PrefValue());
|
||||
mUserValue.ToDomPrefValue(Type(), &aDomPref->userValue().ref());
|
||||
} else {
|
||||
aDomPref->userValue() = null_t();
|
||||
aDomPref->userValue() = Nothing();
|
||||
}
|
||||
|
||||
MOZ_ASSERT(aDomPref->defaultValue().type() ==
|
||||
dom::MaybePrefValue::Tnull_t ||
|
||||
aDomPref->userValue().type() == dom::MaybePrefValue::Tnull_t ||
|
||||
(aDomPref->defaultValue().get_PrefValue().type() ==
|
||||
aDomPref->userValue().get_PrefValue().type()));
|
||||
MOZ_ASSERT(aDomPref->defaultValue().isNothing() ||
|
||||
aDomPref->userValue().isNothing() ||
|
||||
(aDomPref->defaultValue().ref().type() ==
|
||||
aDomPref->userValue().ref().type()));
|
||||
}
|
||||
|
||||
void FromDomPref(const dom::Pref& aDomPref, bool* aValueChanged) {
|
||||
@ -560,11 +558,11 @@ class Pref {
|
||||
|
||||
mIsLocked = aDomPref.isLocked();
|
||||
|
||||
const dom::MaybePrefValue& defaultValue = aDomPref.defaultValue();
|
||||
const Maybe<dom::PrefValue>& defaultValue = aDomPref.defaultValue();
|
||||
bool defaultValueChanged = false;
|
||||
if (defaultValue.type() == dom::MaybePrefValue::TPrefValue) {
|
||||
if (defaultValue.isSome()) {
|
||||
PrefValue value;
|
||||
PrefType type = value.FromDomPrefValue(defaultValue.get_PrefValue());
|
||||
PrefType type = value.FromDomPrefValue(defaultValue.ref());
|
||||
if (!ValueMatches(PrefValueKind::Default, type, value)) {
|
||||
// Type() is PrefType::None if it's a newly added pref. This is ok.
|
||||
mDefaultValue.Replace(mHasDefaultValue, Type(), type, value);
|
||||
@ -575,11 +573,11 @@ class Pref {
|
||||
}
|
||||
// Note: we never clear a default value.
|
||||
|
||||
const dom::MaybePrefValue& userValue = aDomPref.userValue();
|
||||
const Maybe<dom::PrefValue>& userValue = aDomPref.userValue();
|
||||
bool userValueChanged = false;
|
||||
if (userValue.type() == dom::MaybePrefValue::TPrefValue) {
|
||||
if (userValue.isSome()) {
|
||||
PrefValue value;
|
||||
PrefType type = value.FromDomPrefValue(userValue.get_PrefValue());
|
||||
PrefType type = value.FromDomPrefValue(userValue.ref());
|
||||
if (!ValueMatches(PrefValueKind::User, type, value)) {
|
||||
// Type() is PrefType::None if it's a newly added pref. This is ok.
|
||||
mUserValue.Replace(mHasUserValue, Type(), type, value);
|
||||
@ -831,7 +829,7 @@ class Pref {
|
||||
MOZ_ASSERT(*p == ':');
|
||||
p++; // move past the ':' preceding the default value
|
||||
|
||||
dom::MaybePrefValue maybeDefaultValue;
|
||||
Maybe<dom::PrefValue> maybeDefaultValue;
|
||||
if (*p != ':') {
|
||||
dom::PrefValue defaultValue;
|
||||
p = PrefValue::Deserialize(type, p, &maybeDefaultValue);
|
||||
@ -840,7 +838,7 @@ class Pref {
|
||||
MOZ_ASSERT(*p == ':');
|
||||
p++; // move past the ':' between the default and user values
|
||||
|
||||
dom::MaybePrefValue maybeUserValue;
|
||||
Maybe<dom::PrefValue> maybeUserValue;
|
||||
if (*p != '\n') {
|
||||
dom::PrefValue userValue;
|
||||
p = PrefValue::Deserialize(type, p, &maybeUserValue);
|
||||
|
@ -445,7 +445,7 @@ void nsIOService::NotifySocketProcessPrefsChanged(const char *aName) {
|
||||
return;
|
||||
}
|
||||
|
||||
dom::Pref pref(nsCString(aName), /* isLocked */ false, null_t(), null_t());
|
||||
dom::Pref pref(nsCString(aName), /* isLocked */ false, Nothing(), Nothing());
|
||||
Preferences::GetPreference(&pref);
|
||||
auto sendPrefUpdate = [pref]() {
|
||||
Unused << gIOService->mSocketProcess->GetActor()->SendPreferenceUpdate(
|
||||
|
Loading…
Reference in New Issue
Block a user