From 943bfb91031ed35b8d56f6daba94f35bddd011d8 Mon Sep 17 00:00:00 2001
From: Marshall Greenblatt <magreenblatt@gmail.com>
Date: Wed, 8 May 2013 18:21:18 +0000
Subject: [PATCH] Fix race condition during V8 proxy initialization (issue
 #912).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1252 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
---
 libcef/browser/browser_main.cc | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libcef/browser/browser_main.cc b/libcef/browser/browser_main.cc
index 707488949..d07b3ea83 100644
--- a/libcef/browser/browser_main.cc
+++ b/libcef/browser/browser_main.cc
@@ -93,16 +93,19 @@ int CefBrowserMainParts::PreCreateThreads() {
 void CefBrowserMainParts::PreMainMessageLoopRun() {
   browser_context_.reset(new CefBrowserContext());
 
-  // Initialize the request context getter.
-  _Context->set_request_context(browser_context_->GetRequestContext());
-
-  // Initialize proxy configuration service.
+  // Initialize the proxy configuration service. This needs to occur before
+  // CefURLRequestContextGetter::GetURLRequestContext() is called for the
+  // first time.
   ChromeProxyConfigService* chrome_proxy_config_service =
       ProxyServiceFactory::CreateProxyConfigService();
   proxy_config_service_.reset(chrome_proxy_config_service);
   pref_proxy_config_tracker_->SetChromeProxyConfigService(
       chrome_proxy_config_service);
 
+  // Initialize the request context getter. This indirectly triggers a call
+  // to CefURLRequestContextGetter::GetURLRequestContext() on the IO thread.
+  _Context->set_request_context(browser_context_->GetRequestContext());
+
   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
   if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
     std::string port_str =