зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1672097 - Part 2: Cache FullLookAndFeel data. r=karlt
This avoids us doing the full work of ExtractData every time a new content process is created. That work is probably not super expensive, but without this caching it does trip up browser/base/content/test/performance/browser_preferences_usage.js due to looking up a non-mirrored pref. Differential Revision: https://phabricator.services.mozilla.com/D98990
This commit is contained in:
Родитель
1c539d280e
Коммит
6b2ba19c4c
|
@ -1488,7 +1488,7 @@ void ContentParent::BroadcastFontListChanged() {
|
|||
|
||||
static LookAndFeelData GetLookAndFeelData() {
|
||||
if (StaticPrefs::widget_remote_look_and_feel_AtStartup()) {
|
||||
return RemoteLookAndFeel::ExtractData();
|
||||
return *RemoteLookAndFeel::ExtractData();
|
||||
}
|
||||
return LookAndFeel::GetCache();
|
||||
}
|
||||
|
|
|
@ -126,32 +126,42 @@ char16_t RemoteLookAndFeel::GetPasswordCharacterImpl() {
|
|||
bool RemoteLookAndFeel::GetEchoPasswordImpl() { return mTables.passwordEcho(); }
|
||||
|
||||
// static
|
||||
FullLookAndFeel RemoteLookAndFeel::ExtractData() {
|
||||
const FullLookAndFeel* RemoteLookAndFeel::ExtractData() {
|
||||
MOZ_ASSERT(XRE_IsParentProcess(),
|
||||
"Only parent processes should be extracting LookAndFeel data");
|
||||
FullLookAndFeel lf{};
|
||||
|
||||
if (sCachedTables) {
|
||||
return sCachedTables;
|
||||
}
|
||||
|
||||
static bool sInitialized = false;
|
||||
if (!sInitialized) {
|
||||
sInitialized = true;
|
||||
ClearOnShutdown(&sCachedTables);
|
||||
}
|
||||
|
||||
FullLookAndFeel* lf = new FullLookAndFeel{};
|
||||
nsXPLookAndFeel* impl = nsXPLookAndFeel::GetInstance();
|
||||
|
||||
impl->WithThemeConfiguredForContent([&]() {
|
||||
for (auto id : MakeEnumeratedRange(IntID::End)) {
|
||||
int32_t theInt;
|
||||
nsresult rv = impl->NativeGetInt(id, theInt);
|
||||
AddToMap(&lf.ints(), &lf.intMap(),
|
||||
AddToMap(&lf->ints(), &lf->intMap(),
|
||||
NS_SUCCEEDED(rv) ? Some(theInt) : Nothing{});
|
||||
}
|
||||
|
||||
for (auto id : MakeEnumeratedRange(FloatID::End)) {
|
||||
float theFloat;
|
||||
nsresult rv = impl->NativeGetFloat(id, theFloat);
|
||||
AddToMap(&lf.floats(), &lf.floatMap(),
|
||||
AddToMap(&lf->floats(), &lf->floatMap(),
|
||||
NS_SUCCEEDED(rv) ? Some(theFloat) : Nothing{});
|
||||
}
|
||||
|
||||
for (auto id : MakeEnumeratedRange(ColorID::End)) {
|
||||
nscolor theColor;
|
||||
nsresult rv = impl->NativeGetColor(id, theColor);
|
||||
AddToMap(&lf.colors(), &lf.colorMap(),
|
||||
AddToMap(&lf->colors(), &lf->colorMap(),
|
||||
NS_SUCCEEDED(rv) ? Some(theColor) : Nothing{});
|
||||
}
|
||||
|
||||
|
@ -184,14 +194,25 @@ FullLookAndFeel RemoteLookAndFeel::ExtractData() {
|
|||
#endif
|
||||
maybeFont = Some(std::move(font));
|
||||
}
|
||||
AddToMap(&lf.fonts(), &lf.fontMap(), std::move(maybeFont));
|
||||
AddToMap(&lf->fonts(), &lf->fontMap(), std::move(maybeFont));
|
||||
}
|
||||
|
||||
lf.passwordChar() = impl->GetPasswordCharacterImpl();
|
||||
lf.passwordEcho() = impl->GetEchoPasswordImpl();
|
||||
lf->passwordChar() = impl->GetPasswordCharacterImpl();
|
||||
lf->passwordEcho() = impl->GetEchoPasswordImpl();
|
||||
});
|
||||
|
||||
return lf;
|
||||
// This assignment to sCachedTables must be done after the
|
||||
// WithThemeConfiguredForContent call, since it can end up calling RefreshImpl
|
||||
// on the LookAndFeel, which will clear out sCachedTables.
|
||||
sCachedTables = lf;
|
||||
return sCachedTables;
|
||||
}
|
||||
|
||||
void RemoteLookAndFeel::ClearCachedData() {
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
sCachedTables = nullptr;
|
||||
}
|
||||
|
||||
StaticAutoPtr<FullLookAndFeel> RemoteLookAndFeel::sCachedTables;
|
||||
|
||||
} // namespace mozilla::widget
|
||||
|
|
|
@ -42,10 +42,28 @@ class RemoteLookAndFeel final : public nsXPLookAndFeel {
|
|||
//
|
||||
// This is called in the parent process to obtain the data to send down to
|
||||
// content processes when they are created (and when the OS theme changes).
|
||||
static FullLookAndFeel ExtractData();
|
||||
//
|
||||
// Note that the pointer returned from here is only valid until the next time
|
||||
// ClearCachedData is called.
|
||||
static const FullLookAndFeel* ExtractData();
|
||||
|
||||
// Clears any cached extracted data from the platform's default LookAndFeel
|
||||
// implementation.
|
||||
//
|
||||
// This is called in the parent process when the default LookAndFeel is
|
||||
// refreshed, to invalidate sCachedTables.
|
||||
static void ClearCachedData();
|
||||
|
||||
private:
|
||||
FullLookAndFeel mTables;
|
||||
|
||||
// A cached copy of the data extracted by ExtractData.
|
||||
//
|
||||
// Storing this lets us avoid doing most of the work of ExtractData each
|
||||
// time we create a new content process.
|
||||
//
|
||||
// Only used in the parent process.
|
||||
static StaticAutoPtr<FullLookAndFeel> sCachedTables;
|
||||
};
|
||||
|
||||
} // namespace mozilla::widget
|
||||
|
|
|
@ -1012,6 +1012,11 @@ void nsXPLookAndFeel::RefreshImpl() {
|
|||
for (i = 0; i < uint32_t(ColorID::End); ++i) {
|
||||
InitColorFromPref(i);
|
||||
}
|
||||
|
||||
// Clear any cached FullLookAndFeel data, which is now invalid.
|
||||
if (XRE_IsParentProcess()) {
|
||||
widget::RemoteLookAndFeel::ClearCachedData();
|
||||
}
|
||||
}
|
||||
|
||||
widget::LookAndFeelCache nsXPLookAndFeel::GetCacheImpl() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче