From 87b1942db3bfe2dd9d3a07f15c7abd854ddd1785 Mon Sep 17 00:00:00 2001 From: "tommi@chromium.org" Date: Fri, 13 Nov 2009 20:05:21 +0000 Subject: Fix a race condition in InitializeAndPatchProtocolsIfNeeded as discovered by MAD. TEST=Should fix the issue MAD saw when starting up and tearing down the host browser in quick succession. Please see bug description. BUG=27641 Review URL: http://codereview.chromium.org/387049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31935 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome_frame/bho.cc | 28 ++++++++++++++++++---------- chrome_frame/bho.h | 5 ++++- chrome_frame/chrome_tab.cc | 4 ++-- 3 files changed, 24 insertions(+), 13 deletions(-) (limited to 'chrome_frame') diff --git a/chrome_frame/bho.cc b/chrome_frame/bho.cc index f18cc3e..9fff456 100644 --- a/chrome_frame/bho.cc +++ b/chrome_frame/bho.cc @@ -247,19 +247,27 @@ Bho* Bho::GetCurrentThreadBhoInstance() { return bho_current_thread_instance_.Pointer()->Get(); } -void PatchHelper::InitializeAndPatchProtocolsIfNeeded() { - if (state_ != UNKNOWN) - return; +bool PatchHelper::InitializeAndPatchProtocolsIfNeeded() { + bool ret = false; - HttpNegotiatePatch::Initialize(); + _pAtlModule->m_csStaticDataInitAndTypeInfo.Lock(); - bool patch_protocol = GetConfigBool(true, kPatchProtocols); - if (patch_protocol) { - ProtocolSinkWrap::PatchProtocolHandlers(); - state_ = PATCH_PROTOCOL; - } else { - state_ = PATCH_IBROWSER; + if (state_ == UNKNOWN) { + HttpNegotiatePatch::Initialize(); + + bool patch_protocol = GetConfigBool(true, kPatchProtocols); + if (patch_protocol) { + ProtocolSinkWrap::PatchProtocolHandlers(); + state_ = PATCH_PROTOCOL; + } else { + state_ = PATCH_IBROWSER; + } + ret = true; } + + _pAtlModule->m_csStaticDataInitAndTypeInfo.Unlock(); + + return ret; } void PatchHelper::PatchBrowserService(IBrowserService* browser_service) { diff --git a/chrome_frame/bho.h b/chrome_frame/bho.h index b5b6ec5..2838fec 100644 --- a/chrome_frame/bho.h +++ b/chrome_frame/bho.h @@ -30,7 +30,10 @@ class PatchHelper { return state_; } - void InitializeAndPatchProtocolsIfNeeded(); + // Returns true if protocols were patched, false if patching has already + // been done. + bool InitializeAndPatchProtocolsIfNeeded(); + void PatchBrowserService(IBrowserService* p); void UnpatchIfNeeded(); protected: diff --git a/chrome_frame/chrome_tab.cc b/chrome_frame/chrome_tab.cc index 01d862a..39436f4 100644 --- a/chrome_frame/chrome_tab.cc +++ b/chrome_frame/chrome_tab.cc @@ -259,8 +259,8 @@ STDAPI DllCanUnloadNow() { // Returns a class factory to create an object of the requested type STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) { - if (g_patch_helper.state() == PatchHelper::UNKNOWN) { - g_patch_helper.InitializeAndPatchProtocolsIfNeeded(); + if (g_patch_helper.InitializeAndPatchProtocolsIfNeeded()) { + // We should only get here once. UrlMkSetSessionOption(URLMON_OPTION_USERAGENT_REFRESH, NULL, 0, 0); } -- cgit v1.1