Bug 1634437 - Dispatch NativeInit as an idle runnable on Linux r=heycam

EnsureInit takes a long time to run on Linux, in addition to it's
timing, it also runs within a critical path of MSG_ConstructBrowser.
Scheduling it as an idle runnable gives it a chance to run
before MSG_ConstructBrowser.

Differential Revision: https://phabricator.services.mozilla.com/D83230
This commit is contained in:
sefeng 2020-11-12 20:04:53 +00:00
parent d02e12b394
commit f1c6f1d2ea

View File

@ -13,6 +13,7 @@
#include "ContentChild.h"
#include "GeckoProfiler.h"
#include "HandlerServiceChild.h"
#include "nsXPLookAndFeel.h"
#include "mozilla/Attributes.h"
#include "mozilla/BackgroundHangMonitor.h"
#include "mozilla/BenchmarkStorageChild.h"
@ -620,6 +621,16 @@ mozilla::ipc::IPCResult ContentChild::RecvSetXPCOMProcessAttributes(
return IPC_OK();
}
class nsGtkNativeInitRunnable : public Runnable {
public:
nsGtkNativeInitRunnable() : Runnable("nsGtkNativeInitRunnable") {}
NS_IMETHOD Run() override {
LookAndFeel::NativeInit();
return NS_OK;
}
};
bool ContentChild::Init(MessageLoop* aIOLoop, base::ProcessId aParentPid,
const char* aParentBuildID,
UniquePtr<IPC::Channel> aChannel, uint64_t aChildID,
@ -1219,6 +1230,14 @@ void ContentChild::InitXPCOM(
// background thread since we'll likely need database information very soon.
BackgroundChild::Startup();
#ifdef MOZ_WIDGET_GTK
// LookAndFeel::NativeInit takes a long time to run on Linux, here we schedule
// it as soon as possible after BackgroundChild::Startup to give
// it chance to run ahead of ConstructBrowser
nsCOMPtr<nsIRunnable> event = new nsGtkNativeInitRunnable();
NS_DispatchToMainThreadQueue(event.forget(), EventQueuePriority::Idle);
#endif
#if defined(XP_WIN)
// DLL services untrusted modules processing depends on
// BackgroundChild::Startup having been called