From 9fd169d16c08cc4bb1abab548f6491a72d743818 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 30 Nov 2011 17:00:24 +0000 Subject: [PATCH] Fix crash on shutdown due to CefProcess not being destroyed immediately (issue #277). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@400 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/cef_context.cc | 6 +++--- libcef/cef_context.h | 4 ++-- libcef/cef_process.cc | 5 ----- libcef/cef_process.h | 5 +---- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/libcef/cef_context.cc b/libcef/cef_context.cc index 0bd4e46e0..8350fbc1a 100644 --- a/libcef/cef_context.cc +++ b/libcef/cef_context.cc @@ -855,7 +855,7 @@ bool CefContext::Initialize(const CefSettings& settings, crypto::EnsureNSPRInit(); #endif - process_ = new CefProcess(settings_.multi_threaded_message_loop); + process_.reset(new CefProcess(settings_.multi_threaded_message_loop)); process_->CreateChildThreads(); initialized_ = true; @@ -889,7 +889,7 @@ void CefContext::Shutdown() browser_shutdown_event.Wait(); // Delete the process to destroy the child threads. - process_ = NULL; + process_.reset(NULL); // Block until UI thread shutdown is complete. uithread_shutdown_event.Wait(); @@ -898,7 +898,7 @@ void CefContext::Shutdown() UIT_FinishShutdown(NULL, NULL); // Delete the process to destroy the child threads. - process_ = NULL; + process_.reset(NULL); } } diff --git a/libcef/cef_context.h b/libcef/cef_context.h index d8c05de58..ae4535f91 100644 --- a/libcef/cef_context.h +++ b/libcef/cef_context.h @@ -40,7 +40,7 @@ public: // Returns true if the context is shutting down. bool shutting_down() { return shutting_down_; } - scoped_refptr process() { return process_; } + CefProcess* process() { return process_.get(); } bool AddBrowser(CefRefPtr browser); bool RemoveBrowser(CefRefPtr browser); @@ -88,7 +88,7 @@ private: bool shutting_down_; // Manages the various process threads. - scoped_refptr process_; + scoped_ptr process_; // Initialize the AtExitManager on the main application thread to avoid // asserts and possible memory leaks. diff --git a/libcef/cef_process.cc b/libcef/cef_process.cc index dc3e46135..d33aedefb 100644 --- a/libcef/cef_process.cc +++ b/libcef/cef_process.cc @@ -11,8 +11,6 @@ #include "base/synchronization/waitable_event.h" #include "base/threading/thread.h" -CefProcess* g_cef_process = NULL; - // Class used to process events on the current message loop. class CefMessageLoopForUI : public MessageLoopForUI { @@ -67,7 +65,6 @@ CefProcess::CefProcess(bool multi_threaded_message_loop) created_ui_thread_(false), created_io_thread_(false), created_file_thread_(false) { - g_cef_process = this; } CefProcess::~CefProcess() { @@ -87,8 +84,6 @@ CefProcess::~CefProcess() { // Terminate the message loop. ui_message_loop_.reset(); } - - g_cef_process = NULL; } void CefProcess::DoMessageLoopIteration() { diff --git a/libcef/cef_process.h b/libcef/cef_process.h index c472a7d66..84d6cffa7 100644 --- a/libcef/cef_process.h +++ b/libcef/cef_process.h @@ -32,8 +32,7 @@ class CefMessageLoopForUI; // NOT THREAD SAFE, call only from the main thread. // These functions shouldn't return NULL unless otherwise noted. -class CefProcess : public base::RefCounted, - public base::NonThreadSafe { +class CefProcess : public base::NonThreadSafe { public: CefProcess(bool multi_threaded_message_loop); virtual ~CefProcess(); @@ -116,6 +115,4 @@ class CefProcess : public base::RefCounted, DISALLOW_COPY_AND_ASSIGN(CefProcess); }; -extern CefProcess* g_cef_process; - #endif // _CEF_PROCESS_H