From dccb12ef0d2746a3112e04848ee831aaeda0a0da Mon Sep 17 00:00:00 2001 From: Andras Becsi Date: Tue, 9 Jul 2013 11:18:30 +0200 Subject: Do not leak singletons in WebEngineContext Prevent leaking ContentMainDelegateQt, ContentMainRunner and BrowserMainRunner in WebEngineContext so that resources are cleaned up and corresponding notifications are executed. Change-Id: Ib4a13b5e739ed0e60c90bf721a943a3ad19c206c Reviewed-by: Simon Hausmann --- lib/web_engine_context.cpp | 24 ++++++++++-------------- lib/web_engine_context.h | 10 ++++++++++ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/web_engine_context.cpp b/lib/web_engine_context.cpp index 6428165a1..ecd4b6643 100644 --- a/lib/web_engine_context.cpp +++ b/lib/web_engine_context.cpp @@ -91,6 +91,8 @@ static QByteArray subProcessPath() { return processPath; } +} // namespace + class ContentMainDelegateQt : public content::ContentMainDelegate { public: @@ -112,9 +114,10 @@ private: scoped_ptr m_browserClient; }; -} // namespace - WebEngineContext::WebEngineContext() + : m_mainDelegate(new ContentMainDelegateQt) + , m_contentRunner(content::ContentMainRunner::Create()) + , m_browserRunner(content::BrowserMainRunner::Create()) { Q_ASSERT(!sContext); sContext = this; @@ -136,18 +139,8 @@ WebEngineContext::WebEngineContext() CommandLine::Init(args.size(), argv); - static content::ContentMainRunner *runner = 0; - if (!runner) { - runner = content::ContentMainRunner::Create(); - runner->Initialize(0, 0, new ContentMainDelegateQt); - } - - static content::BrowserMainRunner *browserRunner = 0; - if (!browserRunner) { - browserRunner = content::BrowserMainRunner::Create(); - browserRunner->Initialize(content::MainFunctionParams(*CommandLine::ForCurrentProcess())); - } - + m_contentRunner->Initialize(0, 0, m_mainDelegate.get()); + m_browserRunner->Initialize(content::MainFunctionParams(*CommandLine::ForCurrentProcess())); // Once the MessageLoop has been created, attach a top-level RunLoop. m_runLoop.reset(new base::RunLoop); @@ -160,6 +153,9 @@ WebEngineContext::~WebEngineContext() Q_ASSERT(sContext == this); sContext = 0; + + m_browserRunner.reset(); + m_contentRunner.reset(); } scoped_refptr WebEngineContext::current() diff --git a/lib/web_engine_context.h b/lib/web_engine_context.h index 2bf20ac4b..2b349b29b 100644 --- a/lib/web_engine_context.h +++ b/lib/web_engine_context.h @@ -49,6 +49,13 @@ namespace base { class RunLoop; } +namespace content { +class BrowserMainRunner; +class ContentMainRunner; +} + +class ContentMainDelegateQt; + class WebEngineContext : public base::RefCounted { public: static scoped_refptr current(); @@ -59,6 +66,9 @@ private: ~WebEngineContext(); scoped_ptr m_runLoop; + scoped_ptr m_mainDelegate; + scoped_ptr m_contentRunner; + scoped_ptr m_browserRunner; }; #endif -- cgit v1.2.3