Fix race condition where the items on ResourceContext's UserData map were rewritten to the same value as they were read on the IO thread.

BUG=115678
Review URL: https://chromiumcodereview.appspot.com/9466031

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123794 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc
index 4f27824..5a74bedb 100644
--- a/content/browser/browser_context.cc
+++ b/content/browser/browser_context.cc
@@ -92,7 +92,7 @@
       kAppCacheServicKeyName,
       new UserDataAdapter<ChromeAppCacheService>(appcache_service));
 
-  EnsureResourceContextInitialized(context);
+  InitializeResourceContext(context);
 
   // Check first to avoid memory leak in unittests.
   if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
@@ -169,7 +169,13 @@
 }
 
 void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) {
-  content::EnsureResourceContextInitialized(context);
+  // This will be enough to tickle initialization of BrowserContext if
+  // necessary, which initializes ResourceContext. The reason we don't call
+  // ResourceContext::InitializeResourceContext directly here is that if
+  // ResourceContext ends up initializing it will call back into BrowserContext
+  // and when that call return it'll end rewriting its UserData map (with the
+  // same value) but this causes a race condition. See http://crbug.com/115678.
+  CreateQuotaManagerAndClients(context);
 }
 
 void BrowserContext::SaveSessionState(BrowserContext* browser_context) {