summaryrefslogtreecommitdiffstats
path: root/lib/web_engine_context.cpp
diff options
context:
space:
mode:
authorAndras Becsi <andras.becsi@digia.com>2013-07-09 11:18:30 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2013-07-09 13:54:31 +0200
commitdccb12ef0d2746a3112e04848ee831aaeda0a0da (patch)
treec638d6bbf7955eff17e85647180cb20124765452 /lib/web_engine_context.cpp
parent895ddf680e1f9fc8a01f40fb569a6f58bc99196a (diff)
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 <simon.hausmann@digia.com>
Diffstat (limited to 'lib/web_engine_context.cpp')
-rw-r--r--lib/web_engine_context.cpp24
1 files changed, 10 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<ContentBrowserClientQt> 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> WebEngineContext::current()