summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--lib/web_engine_context.cpp24
-rw-r--r--lib/web_engine_context.h10
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<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()
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<WebEngineContext> {
public:
static scoped_refptr<WebEngineContext> current();
@@ -59,6 +66,9 @@ private:
~WebEngineContext();
scoped_ptr<base::RunLoop> m_runLoop;
+ scoped_ptr<ContentMainDelegateQt> m_mainDelegate;
+ scoped_ptr<content::ContentMainRunner> m_contentRunner;
+ scoped_ptr<content::BrowserMainRunner> m_browserRunner;
};
#endif