diff options
author | Michal Klocek <michal.klocek@qt.io> | 2018-04-18 18:48:06 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2018-05-18 14:11:07 +0000 |
commit | 5de729e706abc915f342e8e94fbdc6a493f5a49b (patch) | |
tree | b96a31b48fe7dbeb5602563fe0f86b13e1756bc9 /src | |
parent | e11d897bd2a87d4d3870fdc4b3c120cd1f15231d (diff) |
Minor. Do cosmetics for web_engine_context
Change-Id: I00f174ed23013b9094077fa6de2504c8e870827c
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/web_engine_context.cpp | 60 | ||||
-rw-r--r-- | src/core/web_engine_context.h | 7 |
2 files changed, 34 insertions, 33 deletions
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index 922846fff..af22c5e7f 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -117,23 +117,6 @@ QT_END_NAMESPACE namespace { -scoped_refptr<QtWebEngineCore::WebEngineContext> sContext; -static bool s_destroyed = false; - -void destroyContext() -{ - // Destroy WebEngineContext before its static pointer is zeroed and destructor called. - // Before destroying MessageLoop via destroying BrowserMainRunner destructor - // WebEngineContext's pointer is used. - sContext->destroy(); -#if !defined(NDEBUG) - if (!sContext->HasOneRef()) - qWarning("WebEngineContext leaked on exit, likely due to leaked WebEngine View or Page"); -#endif - sContext = nullptr; - s_destroyed = true; -} - #ifndef QT_NO_OPENGL bool usingANGLE() { @@ -197,6 +180,9 @@ bool usingSoftwareDynamicGL() #endif } +scoped_refptr<QtWebEngineCore::WebEngineContext> WebEngineContext::m_handle; +bool WebEngineContext::m_destroyed = false; + void WebEngineContext::destroyBrowserContext() { if (m_defaultBrowserContext) @@ -214,9 +200,7 @@ void WebEngineContext::destroy() // Delete the global object and thus custom profiles m_defaultBrowserContext.reset(); - delete m_globalQObject; - m_globalQObject = nullptr; - + m_globalQObject.reset(); // Handle any events posted by browser-context shutdown. while (delegate->DoWork()) { } @@ -231,7 +215,7 @@ void WebEngineContext::destroy() m_browserRunner.reset(); // Drop the false reference. - sContext->Release(); + m_handle->Release(); } WebEngineContext::~WebEngineContext() @@ -244,29 +228,43 @@ WebEngineContext::~WebEngineContext() WebEngineContext *WebEngineContext::current() { - if (s_destroyed) + if (m_destroyed) return nullptr; - if (!sContext.get()) { - sContext = new WebEngineContext(); + if (!m_handle.get()) { + m_handle = new WebEngineContext(); // Make sure that we ramp down Chromium before QApplication destroys its X connection, etc. - qAddPostRoutine(destroyContext); - // Add a false reference so there is no race between unreferencing sContext and a global QApplication. - sContext->AddRef(); + qAddPostRoutine(WebEngineContext::destroyContextPostRoutine); + // Add a false reference so there is no race between unreferencing m_handle and a global QApplication. + m_handle->AddRef(); } - return sContext.get(); + return m_handle.get(); } BrowserContextAdapter *WebEngineContext::defaultBrowserContext() { - Q_ASSERT(!s_destroyed); + Q_ASSERT(!m_destroyed); if (!m_defaultBrowserContext) m_defaultBrowserContext.reset(new BrowserContextAdapter(QStringLiteral("Default"))); - return m_defaultBrowserContext.data(); + return m_defaultBrowserContext.get(); } QObject *WebEngineContext::globalQObject() { - return m_globalQObject; + return m_globalQObject.get(); +} + +void WebEngineContext::destroyContextPostRoutine() +{ + // Destroy WebEngineContext before its static pointer is zeroed and destructor called. + // Before destroying MessageLoop via destroying BrowserMainRunner destructor + // WebEngineContext's pointer is used. + m_handle->destroy(); +#if !defined(NDEBUG) + if (!m_handle->HasOneRef()) + qWarning("WebEngineContext leaked on exit, likely due to leaked WebEngine View or Page"); +#endif + m_handle = nullptr; + m_destroyed = true; } #ifndef CHROMIUM_VERSION diff --git a/src/core/web_engine_context.h b/src/core/web_engine_context.h index 63dbe9f23..7e9d546a4 100644 --- a/src/core/web_engine_context.h +++ b/src/core/web_engine_context.h @@ -79,6 +79,7 @@ bool usingSoftwareDynamicGL(); class WebEngineContext : public base::RefCounted<WebEngineContext> { public: static WebEngineContext *current(); + static void destroyContextPostRoutine(); BrowserContextAdapter *defaultBrowserContext(); @@ -99,12 +100,14 @@ private: std::unique_ptr<ContentMainDelegateQt> m_mainDelegate; std::unique_ptr<content::ContentMainRunner> m_contentRunner; std::unique_ptr<content::BrowserMainRunner> m_browserRunner; - QObject* m_globalQObject; - QScopedPointer<BrowserContextAdapter> m_defaultBrowserContext; + std::unique_ptr<QObject> m_globalQObject; + std::unique_ptr<BrowserContextAdapter> m_defaultBrowserContext; std::unique_ptr<DevToolsServerQt> m_devtoolsServer; #if BUILDFLAG(ENABLE_BASIC_PRINTING) std::unique_ptr<printing::PrintJobManager> m_printJobManager; #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) + static scoped_refptr<QtWebEngineCore::WebEngineContext> m_handle; + static bool m_destroyed; }; } // namespace |