Bug 1569526 - Don't use default values as fallbacks for VarCache prefs. r=froydnj

This patch changes how a VarCache pref works when deleted (in some cases) --
the VarCache variable keeps its existing value instead of being reset to a
pre-specified default.

In bug 1570212 I have made sure that no VarCache prefs exhibit this behaviour
in practice any more, so this change should not affect functionality. There is
an assertion that checks this.

The next patch will take advantage of this change by removing the need to
store the pre-specified defaults, which will save memory.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nicholas Nethercote 2019-08-09 00:59:34 +00:00
Родитель 1765f44b34
Коммит ec0336e701
1 изменённых файлов: 19 добавлений и 2 удалений

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

@ -4472,8 +4472,25 @@ struct Internals {
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>>());
StripAtomic<T> value;
nsresult rv = GetPrefValue(aPref, &value, PrefValueKind::User);
if (NS_SUCCEEDED(rv)) {
*static_cast<T*>(cache->mCacheLocation) = value;
} else {
// GetPrefValue() can fail if the update is caused by the pref being
// deleted. In that case the mirror variable will be untouched, thus
// keeping the value it had prior to the deletion. (Note that this case
// won't happen for a deletion via DeleteBranch() unless bug 343600 is
// fixed, but it will happen for a deletion via ClearUserPref().)
//
// This is a case we want to avoid in general because it's a bit unclear
// what value the mirror variable should take; hence the assertion
// failure. Once all VarCache prefs are removed in favour of static prefs
// (bug 1448219) the plan is to mark static prefs as undeletable and this
// case will become impossible.
NS_WARNING(nsPrintfCString("VarChanged failure: %s\n", aPref).get());
MOZ_ASSERT(false);
}
}
template <typename T>