chrome: Move ThreadProfiler initialization to the UI thread (fixes #3465)

ThreadProfiler::CreateAndStartOnMainThread and SetMainThreadTaskRunnerImpl
should be called on the same thread.
This commit is contained in:
Marshall Greenblatt 2023-03-14 15:12:03 -04:00
parent 178a44bd18
commit 0a2c7a1070
4 changed files with 8 additions and 5 deletions

View File

@ -394,6 +394,7 @@ bool CefMainRunner::ContentMainRun(bool* initialized,
if (!CreateUIThread(base::BindOnce( if (!CreateUIThread(base::BindOnce(
[](CefMainRunner* runner, base::WaitableEvent* event) { [](CefMainRunner* runner, base::WaitableEvent* event) {
runner->main_delegate_->BeforeUIThreadInitialize();
content::ContentMainRun(runner->main_runner_.get()); content::ContentMainRun(runner->main_runner_.get());
event->Signal(); event->Signal();
}, },
@ -408,6 +409,7 @@ bool CefMainRunner::ContentMainRun(bool* initialized,
uithread_startup_event.Wait(); uithread_startup_event.Wait();
} else { } else {
*initialized = true; *initialized = true;
main_delegate_->BeforeUIThreadInitialize();
content::ContentMainRun(main_runner_.get()); content::ContentMainRun(main_runner_.get());
} }

View File

@ -40,8 +40,6 @@ void ChromeMainRunnerDelegate::BeforeMainThreadInitialize(
#else #else
base::CommandLine::Init(args.argc, args.argv); base::CommandLine::Init(args.argc, args.argv);
#endif #endif
sampling_profiler_ = std::make_unique<MainThreadStackSamplingProfiler>();
} }
void ChromeMainRunnerDelegate::BeforeMainMessageLoopRun( void ChromeMainRunnerDelegate::BeforeMainMessageLoopRun(
@ -70,14 +68,16 @@ bool ChromeMainRunnerDelegate::HandleMainMessageLoopQuit() {
return true; return true;
} }
void ChromeMainRunnerDelegate::BeforeUIThreadInitialize() {
sampling_profiler_ = std::make_unique<MainThreadStackSamplingProfiler>();
}
void ChromeMainRunnerDelegate::AfterUIThreadShutdown() { void ChromeMainRunnerDelegate::AfterUIThreadShutdown() {
static_cast<ChromeContentBrowserClient*>( static_cast<ChromeContentBrowserClient*>(
CefAppManager::Get()->GetContentClient()->browser()) CefAppManager::Get()->GetContentClient()->browser())
->CleanupOnUIThread(); ->CleanupOnUIThread();
main_delegate_->CleanupOnUIThread(); main_delegate_->CleanupOnUIThread();
}
void ChromeMainRunnerDelegate::AfterMainThreadShutdown() {
sampling_profiler_.reset(); sampling_profiler_.reset();
} }

View File

@ -35,8 +35,8 @@ class ChromeMainRunnerDelegate : public CefMainRunnerDelegate {
void BeforeMainThreadInitialize(const CefMainArgs& args) override; void BeforeMainThreadInitialize(const CefMainArgs& args) override;
void BeforeMainMessageLoopRun(base::RunLoop* run_loop) override; void BeforeMainMessageLoopRun(base::RunLoop* run_loop) override;
bool HandleMainMessageLoopQuit() override; bool HandleMainMessageLoopQuit() override;
void BeforeUIThreadInitialize() override;
void AfterUIThreadShutdown() override; void AfterUIThreadShutdown() override;
void AfterMainThreadShutdown() override;
void BeforeExecuteProcess(const CefMainArgs& args) override; void BeforeExecuteProcess(const CefMainArgs& args) override;
void AfterExecuteProcess() override; void AfterExecuteProcess() override;

View File

@ -24,6 +24,7 @@ class CefMainRunnerDelegate {
virtual void BeforeMainThreadRun() {} virtual void BeforeMainThreadRun() {}
virtual void BeforeMainMessageLoopRun(base::RunLoop* run_loop) {} virtual void BeforeMainMessageLoopRun(base::RunLoop* run_loop) {}
virtual bool HandleMainMessageLoopQuit() { return false; } virtual bool HandleMainMessageLoopQuit() { return false; }
virtual void BeforeUIThreadInitialize() {}
virtual void AfterUIThreadInitialize() {} virtual void AfterUIThreadInitialize() {}
virtual void AfterUIThreadShutdown() {} virtual void AfterUIThreadShutdown() {}
virtual void BeforeMainThreadShutdown() {} virtual void BeforeMainThreadShutdown() {}