Skip to content

Commit

Permalink
chrome: Move ThreadProfiler initialization to the UI thread (fixes #3465
Browse files Browse the repository at this point in the history
)

ThreadProfiler::CreateAndStartOnMainThread and SetMainThreadTaskRunnerImpl
should be called on the same thread.
  • Loading branch information
magreenblatt committed Mar 14, 2023
1 parent 178a44b commit 0a2c7a1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions libcef/browser/main_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ bool CefMainRunner::ContentMainRun(bool* initialized,

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

Expand Down
8 changes: 4 additions & 4 deletions libcef/common/chrome/chrome_main_runner_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ void ChromeMainRunnerDelegate::BeforeMainThreadInitialize(
#else
base::CommandLine::Init(args.argc, args.argv);
#endif

sampling_profiler_ = std::make_unique<MainThreadStackSamplingProfiler>();
}

void ChromeMainRunnerDelegate::BeforeMainMessageLoopRun(
Expand Down Expand Up @@ -70,14 +68,16 @@ bool ChromeMainRunnerDelegate::HandleMainMessageLoopQuit() {
return true;
}

void ChromeMainRunnerDelegate::BeforeUIThreadInitialize() {
sampling_profiler_ = std::make_unique<MainThreadStackSamplingProfiler>();
}

void ChromeMainRunnerDelegate::AfterUIThreadShutdown() {
static_cast<ChromeContentBrowserClient*>(
CefAppManager::Get()->GetContentClient()->browser())
->CleanupOnUIThread();
main_delegate_->CleanupOnUIThread();
}

void ChromeMainRunnerDelegate::AfterMainThreadShutdown() {
sampling_profiler_.reset();
}

Expand Down
2 changes: 1 addition & 1 deletion libcef/common/chrome/chrome_main_runner_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class ChromeMainRunnerDelegate : public CefMainRunnerDelegate {
void BeforeMainThreadInitialize(const CefMainArgs& args) override;
void BeforeMainMessageLoopRun(base::RunLoop* run_loop) override;
bool HandleMainMessageLoopQuit() override;
void BeforeUIThreadInitialize() override;
void AfterUIThreadShutdown() override;
void AfterMainThreadShutdown() override;
void BeforeExecuteProcess(const CefMainArgs& args) override;
void AfterExecuteProcess() override;

Expand Down
1 change: 1 addition & 0 deletions libcef/common/main_runner_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CefMainRunnerDelegate {
virtual void BeforeMainThreadRun() {}
virtual void BeforeMainMessageLoopRun(base::RunLoop* run_loop) {}
virtual bool HandleMainMessageLoopQuit() { return false; }
virtual void BeforeUIThreadInitialize() {}
virtual void AfterUIThreadInitialize() {}
virtual void AfterUIThreadShutdown() {}
virtual void BeforeMainThreadShutdown() {}
Expand Down

0 comments on commit 0a2c7a1

Please sign in to comment.