diff options
author | Michal Klocek <michal.klocek@qt.io> | 2021-02-15 08:40:24 +0100 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2021-02-16 23:56:46 +0100 |
commit | 827cbb1ff490b6b2da3bf71c6adac0956a6c3261 (patch) | |
tree | b19bb28a55c1a8b4185938880456d3d43e9fd576 /src/core/web_engine_context.cpp | |
parent | 1a2db07cac97db7c3609cf223e807fa62e178a9f (diff) |
Fix crashes on BrowserContext destruction
When destroying WebEngineProile we send notifications like
content::BrowserContext::NotifyWillBeDestroyed, this works well
with global profile where there is no more render process around,
moreover we still pump ui messages before we destroy profile. However,
with user profiles we destruct BorwserContext and there can be still
RenderProcessHost using it. Flush messages before running
BrowserContext destructor.
Change-Id: I4d8cda2bc1e2ae3dc0781bf3570a36db7d07223a
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/web_engine_context.cpp')
-rw-r--r-- | src/core/web_engine_context.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index 863b46a57..41db33cd4 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -354,6 +354,15 @@ void WebEngineContext::removeProfileAdapter(ProfileAdapter *profileAdapter) m_profileAdapters.removeAll(profileAdapter); } +void WebEngineContext::flushMessages() +{ + if (!m_destroyed) { + base::MessagePump::Delegate *delegate = static_cast< + base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl *>( + WebEngineContext::current()->m_runLoop->delegate_); + while (delegate->DoWork().is_immediate()) { } + } +} void WebEngineContext::destroy() { if (m_devtoolsServer) @@ -364,20 +373,17 @@ void WebEngineContext::destroy() m_webrtcLogUploader->Shutdown(); #endif - base::MessagePump::Delegate *delegate = - static_cast<base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl *>( - m_runLoop->delegate_); // Normally the GPU thread is shut down when the GpuProcessHost is destroyed // on IO thread (triggered by ~BrowserMainRunner). But by that time the UI // task runner is not working anymore so we need to do this earlier. cleanupVizProcess(); while (waitForViz) { - while (delegate->DoWork().is_immediate()) { } + flushMessages(); QThread::msleep(50); } destroyGpuProcess(); // Flush the UI message loop before quitting. - while (delegate->DoWork().is_immediate()) { } + flushMessages(); #if QT_CONFIG(webengine_printing_and_pdf) // Kill print job manager early as it has a content::NotificationRegistrar @@ -399,7 +405,7 @@ void WebEngineContext::destroy() // Handle any events posted by browser-context shutdown. // This should deliver all nessesery calls of DeleteSoon from PostTask - while (delegate->DoWork().is_immediate()) { } + flushMessages(); m_devtoolsServer.reset(); m_runLoop->AfterRun(); |