From f250f9cceaf7cbf3e54bdfe43491755d778b2574 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 4 Mar 2013 21:10:59 +0000 Subject: [PATCH] Fix geolocation initialization race condition. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1117 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- cef1/libcef/geolocation_client.cc | 21 +++++++++++++-------- cef1/libcef/geolocation_client.h | 2 ++ cef1/libcef/geolocation_impl.cc | 2 ++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cef1/libcef/geolocation_client.cc b/cef1/libcef/geolocation_client.cc index 5985347dc..d1feaef71 100644 --- a/cef1/libcef/geolocation_client.cc +++ b/cef1/libcef/geolocation_client.cc @@ -142,6 +142,18 @@ CefGeolocationClient::CefGeolocationClient(CefBrowserImpl* browser) CefGeolocationClient::~CefGeolocationClient() {} +// static +void CefGeolocationClient::InitializeEnvironment() { + // GeolocationArbitrator uses ContentClient to retrieve the AccessTokenStore. + // Simulate the necessary interfaces here. + if (!content::GetContentClient()) { + static CefContentClient content_client; + static CefContentBrowserClient browser_client; + content_client.set_browser_for_testing(&browser_client); + content::SetContentClient(&content_client); + } +} + void CefGeolocationClient::geolocationDestroyed() { DCHECK(CefThread::CurrentlyOn(CefThread::UI)); @@ -243,14 +255,7 @@ void CefGeolocationClient::cancelPermissionRequest( void CefGeolocationClient::OnStartUpdating(bool enable_high_accuracy) { DCHECK(CefThread::CurrentlyOn(CefThread::IO)); - // GeolocationArbitrator uses ContentClient to retrieve the AccessTokenStore. - // Simulate the necessary interfaces here. - if (!content::GetContentClient()) { - static CefContentClient content_client; - static CefContentBrowserClient browser_client; - content_client.set_browser_for_testing(&browser_client); - content::SetContentClient(&content_client); - } + InitializeEnvironment(); if (!location_provider_) location_provider_ = content::GeolocationProvider::GetInstance(); diff --git a/cef1/libcef/geolocation_client.h b/cef1/libcef/geolocation_client.h index 2d4be04b3..26665208c 100644 --- a/cef1/libcef/geolocation_client.h +++ b/cef1/libcef/geolocation_client.h @@ -37,6 +37,8 @@ class CefGeolocationClient explicit CefGeolocationClient(CefBrowserImpl* browser); virtual ~CefGeolocationClient(); + static void InitializeEnvironment(); + private: friend class CefGeolocationCallbackImpl; diff --git a/cef1/libcef/geolocation_impl.cc b/cef1/libcef/geolocation_impl.cc index b0792bea7..e5fd884ff 100644 --- a/cef1/libcef/geolocation_impl.cc +++ b/cef1/libcef/geolocation_impl.cc @@ -6,6 +6,7 @@ #include "libcef/cef_context.h" #include "libcef/cef_thread.h" #include "libcef/cef_time_util.h" +#include "libcef/geolocation_client.h" #include "base/logging.h" #include "content/browser/geolocation/geolocation_provider.h" #include "content/public/common/geoposition.h" @@ -66,6 +67,7 @@ bool CefGetGeolocation(CefRefPtr callback) { } if (CefThread::CurrentlyOn(CefThread::IO)) { + CefGeolocationClient::InitializeEnvironment(); content::GeolocationProvider* provider = content::GeolocationProvider::GetInstance(); if (provider) {