From ba08f77938581708c2d5c31279b80a0748c0755c Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 22 Jun 2010 15:20:38 +0000 Subject: [PATCH] Create and destroy the base::AtExitManager on the UI thread. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@85 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/context.cc | 9 +++++++++ libcef/context.h | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/libcef/context.cc b/libcef/context.cc index 5179d1a79..06d2ce603 100644 --- a/libcef/context.cc +++ b/libcef/context.cc @@ -231,6 +231,9 @@ DWORD WINAPI ThreadHandlerUI(LPVOID lpParam) { CefContext *pContext = static_cast(lpParam); + // AtExitManager is scoped to the UI thread. + base::AtExitManager at_exit_manager; + if (!pContext->DoInitialize()) return 1; @@ -258,6 +261,8 @@ CefContext::CefContext() messageloopui_ = NULL; in_transition_ = false; webprefs_ = NULL; + statstable_ = NULL; + at_exit_manager_ = NULL; hinstance_ = ::GetModuleHandle(NULL); next_browser_id_ = 1; webkit_init_ = NULL; @@ -267,6 +272,8 @@ CefContext::~CefContext() { // Just in case CefShutdown() isn't called Shutdown(); + if(at_exit_manager_) + delete at_exit_manager_; } bool CefContext::Initialize(bool multi_threaded_message_loop, @@ -366,6 +373,8 @@ bool CefContext::Initialize(bool multi_threaded_message_loop, DCHECK(hthreadui_ != NULL); DCHECK(idthreadui_ != 0); } else { + // AtExitManager is scoped to the context. + at_exit_manager_ = new base::AtExitManager; if (!DoInitialize()) { // TODO: Process initialization errors } diff --git a/libcef/context.h b/libcef/context.h index 9d003315d..7959f0655 100644 --- a/libcef/context.h +++ b/libcef/context.h @@ -80,8 +80,10 @@ protected: StatsTable* statstable_; std::wstring cache_path_; - // Initialize the AtExitManager to avoid asserts and possible memory leaks. - base::AtExitManager at_exit_manager_; + // AtExitManager will be scoped to the context when running in single threaded + // message loop mode. + base::AtExitManager* at_exit_manager_; + // WebKit implementation class. BrowserWebKitInit* webkit_init_;