Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(972)

Side by Side Diff: android_webview/browser/aw_browser_context.cc

Issue 23803005: Fix threading issues in aw form database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/browser/aw_browser_context.h" 5 #include "android_webview/browser/aw_browser_context.h"
6 6
7 #include "android_webview/browser/aw_form_database_service.h" 7 #include "android_webview/browser/aw_form_database_service.h"
8 #include "android_webview/browser/aw_pref_store.h" 8 #include "android_webview/browser/aw_pref_store.h"
9 #include "android_webview/browser/aw_quota_manager_bridge.h" 9 #include "android_webview/browser/aw_quota_manager_bridge.h"
10 #include "android_webview/browser/jni_dependency_factory.h" 10 #include "android_webview/browser/jni_dependency_factory.h"
11 #include "android_webview/browser/net/aw_url_request_context_getter.h" 11 #include "android_webview/browser/net/aw_url_request_context_getter.h"
12 #include "android_webview/browser/net/init_native_callback.h" 12 #include "android_webview/browser/net/init_native_callback.h"
13 #include "base/prefs/pref_registry_simple.h" 13 #include "base/prefs/pref_registry_simple.h"
14 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
15 #include "base/prefs/pref_service_builder.h" 15 #include "base/prefs/pref_service_builder.h"
16 #include "components/autofill/core/common/autofill_pref_names.h" 16 #include "components/autofill/core/common/autofill_pref_names.h"
17 #include "components/user_prefs/user_prefs.h" 17 #include "components/user_prefs/user_prefs.h"
18 #include "components/visitedlink/browser/visitedlink_master.h" 18 #include "components/visitedlink/browser/visitedlink_master.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/cookie_store_factory.h" 20 #include "content/public/browser/cookie_store_factory.h"
21 #include "content/public/browser/resource_context.h" 21 #include "content/public/browser/resource_context.h"
22 #include "content/public/browser/storage_partition.h" 22 #include "content/public/browser/storage_partition.h"
23 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
24 #include "net/url_request/url_request_context.h" 24 #include "net/url_request/url_request_context.h"
25 25
26 using content::BrowserThread;
27
26 namespace android_webview { 28 namespace android_webview {
27 29
28 namespace { 30 namespace {
29 31
30 // Shows notifications which correspond to PersistentPrefStore's reading errors. 32 // Shows notifications which correspond to PersistentPrefStore's reading errors.
31 void HandleReadError(PersistentPrefStore::PrefReadError error) { 33 void HandleReadError(PersistentPrefStore::PrefReadError error) {
32 } 34 }
33 35
34 class AwResourceContext : public content::ResourceContext { 36 class AwResourceContext : public content::ResourceContext {
35 public: 37 public:
36 explicit AwResourceContext(net::URLRequestContextGetter* getter) 38 explicit AwResourceContext(net::URLRequestContextGetter* getter)
37 : getter_(getter) { 39 : getter_(getter) {
38 DCHECK(getter_); 40 DCHECK(getter_);
39 } 41 }
40 virtual ~AwResourceContext() {} 42 virtual ~AwResourceContext() {}
41 43
42 // content::ResourceContext implementation. 44 // content::ResourceContext implementation.
43 virtual net::HostResolver* GetHostResolver() OVERRIDE { 45 virtual net::HostResolver* GetHostResolver() OVERRIDE {
44 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
45 return getter_->GetURLRequestContext()->host_resolver(); 47 return getter_->GetURLRequestContext()->host_resolver();
46 } 48 }
47 virtual net::URLRequestContext* GetRequestContext() OVERRIDE { 49 virtual net::URLRequestContext* GetRequestContext() OVERRIDE {
48 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
49 return getter_->GetURLRequestContext(); 51 return getter_->GetURLRequestContext();
50 } 52 }
51 virtual bool AllowMicAccess(const GURL& origin) OVERRIDE { 53 virtual bool AllowMicAccess(const GURL& origin) OVERRIDE {
52 return false; 54 return false;
53 } 55 }
54 virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE { 56 virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE {
55 return false; 57 return false;
56 } 58 }
57 59
58 private: 60 private:
59 net::URLRequestContextGetter* getter_; 61 net::URLRequestContextGetter* getter_;
60 62
61 DISALLOW_COPY_AND_ASSIGN(AwResourceContext); 63 DISALLOW_COPY_AND_ASSIGN(AwResourceContext);
62 }; 64 };
63 65
64 AwBrowserContext* g_browser_context = NULL; 66 AwBrowserContext* g_browser_context = NULL;
65 67
66 } // namespace 68 } // namespace
67 69
68 AwBrowserContext::AwBrowserContext( 70 AwBrowserContext::AwBrowserContext(
69 const base::FilePath path, 71 const base::FilePath path,
70 JniDependencyFactory* native_factory) 72 JniDependencyFactory* native_factory)
71 : context_storage_path_(path), 73 : context_storage_path_(path),
72 native_factory_(native_factory), 74 native_factory_(native_factory),
73 user_pref_service_ready_(false) { 75 user_pref_service_ready_(false),
76 form_database_service_creation_(false, false) {
74 DCHECK(g_browser_context == NULL); 77 DCHECK(g_browser_context == NULL);
75 g_browser_context = this; 78 g_browser_context = this;
76 } 79 }
77 80
78 AwBrowserContext::~AwBrowserContext() { 81 AwBrowserContext::~AwBrowserContext() {
79 DCHECK(g_browser_context == this); 82 DCHECK(g_browser_context == this);
80 g_browser_context = NULL; 83 g_browser_context = NULL;
81 } 84 }
82 85
83 // static 86 // static
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 141 }
139 142
140 AwQuotaManagerBridge* AwBrowserContext::GetQuotaManagerBridge() { 143 AwQuotaManagerBridge* AwBrowserContext::GetQuotaManagerBridge() {
141 if (!quota_manager_bridge_) { 144 if (!quota_manager_bridge_) {
142 quota_manager_bridge_.reset( 145 quota_manager_bridge_.reset(
143 native_factory_->CreateAwQuotaManagerBridge(this)); 146 native_factory_->CreateAwQuotaManagerBridge(this));
144 } 147 }
145 return quota_manager_bridge_.get(); 148 return quota_manager_bridge_.get();
146 } 149 }
147 150
151 void AwBrowserContext::CreateFormDatabaseServiceOnUiThread() {
152 form_database_service_.reset(
153 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.
154 form_database_service_creation_.Signal();
155 }
156
157 // Protect it since there are two initialization paths, one through
158 // WebViewDatabase and the the other through AwContents.
148 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() { 159 AwFormDatabaseService* AwBrowserContext::GetFormDatabaseService() {
160 base::AutoLock lock(form_database_lock_);
161
149 if (!form_database_service_) { 162 if (!form_database_service_) {
150 form_database_service_.reset( 163 // AwFormDatabaseService has to be created on UI thread.
151 new AwFormDatabaseService(context_storage_path_)); 164 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
165 CreateFormDatabaseServiceOnUiThread();
166 } else {
167 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
168 base::Bind(&AwBrowserContext::CreateFormDatabaseServiceOnUiThread,
169 base::Unretained(this)));
170 form_database_service_creation_.Wait();
171 }
152 } 172 }
153 return form_database_service_.get(); 173 return form_database_service_.get();
154 } 174 }
155 175
156 // Create user pref service for autofill functionality. 176 // Create user pref service for autofill functionality.
157 void AwBrowserContext::CreateUserPrefServiceIfNecessary() { 177 void AwBrowserContext::CreateUserPrefServiceIfNecessary() {
158 if (user_pref_service_ready_) 178 if (user_pref_service_ready_)
159 return; 179 return;
160 180
161 user_pref_service_ready_ = true; 181 user_pref_service_ready_ = true;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 274
255 void AwBrowserContext::RebuildTable( 275 void AwBrowserContext::RebuildTable(
256 const scoped_refptr<URLEnumerator>& enumerator) { 276 const scoped_refptr<URLEnumerator>& enumerator) {
257 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client 277 // Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client
258 // can change in the lifetime of this WebView and may not yet be set here. 278 // can change in the lifetime of this WebView and may not yet be set here.
259 // Therefore this initialization path is not used. 279 // Therefore this initialization path is not used.
260 enumerator->OnComplete(true); 280 enumerator->OnComplete(true);
261 } 281 }
262 282
263 } // namespace android_webview 283 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698