Chromium Code Reviews| Index: android_webview/browser/aw_browser_context.cc |
| diff --git a/android_webview/browser/aw_browser_context.cc b/android_webview/browser/aw_browser_context.cc |
| index 9700645683e3a551ed056b8cae2a4e66a8bee5a0..64f62ba32297303fcab45f6d4dc973f6a7b112a2 100644 |
| --- a/android_webview/browser/aw_browser_context.cc |
| +++ b/android_webview/browser/aw_browser_context.cc |
| @@ -23,6 +23,8 @@ |
| #include "content/public/browser/web_contents.h" |
| #include "net/url_request/url_request_context.h" |
| +using content::BrowserThread; |
| + |
| namespace android_webview { |
| namespace { |
| @@ -41,11 +43,11 @@ class AwResourceContext : public content::ResourceContext { |
| // content::ResourceContext implementation. |
| virtual net::HostResolver* GetHostResolver() OVERRIDE { |
| - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| return getter_->GetURLRequestContext()->host_resolver(); |
| } |
| virtual net::URLRequestContext* GetRequestContext() OVERRIDE { |
| - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| return getter_->GetURLRequestContext(); |
| } |
| virtual bool AllowMicAccess(const GURL& origin) OVERRIDE { |
| @@ -70,7 +72,8 @@ AwBrowserContext::AwBrowserContext( |
| JniDependencyFactory* native_factory) |
| : context_storage_path_(path), |
| native_factory_(native_factory), |
| - user_pref_service_ready_(false) { |
| + user_pref_service_ready_(false), |
| + form_database_service_creation_(false, false) { |
| DCHECK(g_browser_context == NULL); |
| g_browser_context = this; |
| } |
| @@ -145,10 +148,27 @@ AwQuotaManagerBridge* AwBrowserContext::GetQuotaManagerBridge() { |
| return quota_manager_bridge_.get(); |
| } |
| +void AwBrowserContext::CreateFormDatabaseServiceOnUiThread() { |
| + form_database_service_.reset( |
| + new AwFormDatabaseService(context_storage_path_)); |
|
joth
2013/09/05 00:59:10
just call this "new AwFormDatabaseService" from Aw
sgurun-gerrit only
2013/09/05 02:58:45
Done.
|
| + form_database_service_creation_.Signal(); |
| +} |
| + |
| +// Protect it since there are two initialization paths, one through |
| +// WebViewDatabase and the the other through AwContents. |
| AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { |
| + base::AutoLock lock(form_database_lock_); |
| + |
| if (!form_database_service_) { |
| - form_database_service_.reset( |
| - new AwFormDatabaseService(context_storage_path_)); |
| + // AwFormDatabaseService has to be created on UI thread. |
| + if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| + CreateFormDatabaseServiceOnUiThread(); |
| + } else { |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(&AwBrowserContext::CreateFormDatabaseServiceOnUiThread, |
| + base::Unretained(this))); |
| + form_database_service_creation_.Wait(); |
| + } |
| } |
| return form_database_service_.get(); |
| } |