From 3b23cc1815621292da9812a2677b45f192d09a42 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 29 Mar 2012 16:51:31 +0000 Subject: [PATCH] Fix race condition in CefCookieManagerImpl constructor (issue #542). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@556 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/cookie_manager_impl.cc | 26 ++++++++++++-------------- libcef/cookie_manager_impl.h | 6 +----- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/libcef/cookie_manager_impl.cc b/libcef/cookie_manager_impl.cc index 3f68ca960..0e65002d3 100644 --- a/libcef/cookie_manager_impl.cc +++ b/libcef/cookie_manager_impl.cc @@ -66,18 +66,14 @@ class VisitCookiesCallback : public base::RefCounted { } // namespace -CefCookieManagerImpl::CefCookieManagerImpl() - : is_global_(true) { - cookie_monster_ = - static_cast( - _Context->request_context()->cookie_store()); - DCHECK(cookie_monster_); -} - - // Creates a new cookie monster with storage at the specified |path|. -CefCookieManagerImpl::CefCookieManagerImpl(const CefString& path) - :is_global_(false) { - SetStoragePath(path); +CefCookieManagerImpl::CefCookieManagerImpl(bool is_global) + : is_global_(is_global) { + if (is_global) { + cookie_monster_ = + static_cast( + _Context->request_context()->cookie_store()); + DCHECK(cookie_monster_); + } } CefCookieManagerImpl::~CefCookieManagerImpl() { @@ -239,7 +235,7 @@ CefRefPtr CefCookieManager::GetGlobalManager() { return NULL; } - return new CefCookieManagerImpl(); + return new CefCookieManagerImpl(true); } // static @@ -251,5 +247,7 @@ CefRefPtr CefCookieManager::CreateManager( return NULL; } - return new CefCookieManagerImpl(path); + CefRefPtr manager(new CefCookieManagerImpl(false)); + manager->SetStoragePath(path); + return manager; } diff --git a/libcef/cookie_manager_impl.h b/libcef/cookie_manager_impl.h index de582bfb2..186a49603 100644 --- a/libcef/cookie_manager_impl.h +++ b/libcef/cookie_manager_impl.h @@ -12,11 +12,7 @@ // Implementation of the CefCookieManager interface. class CefCookieManagerImpl : public CefCookieManager { public: - // Creates a new reference to the existing global cookie monster. - CefCookieManagerImpl(); - - // Creates a new cookie monster with storage at the specified |path|. - explicit CefCookieManagerImpl(const CefString& path); + CefCookieManagerImpl(bool is_global); ~CefCookieManagerImpl();