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

Unified Diff: android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java

Issue 2180423003: aw: Fix FactoryProvider threading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
diff --git a/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java b/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
index 96120eabb8d59acc5f29df72cee5096f9eee9f32..ff466cee33a437991098af2070f984cf7778778d 100644
--- a/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
+++ b/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
@@ -36,12 +36,15 @@ import org.chromium.android_webview.AwContentsClient;
import org.chromium.android_webview.AwContentsStatics;
import org.chromium.android_webview.AwCookieManager;
import org.chromium.android_webview.AwDevToolsServer;
+import org.chromium.android_webview.AwGeolocationPermissions;
import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy;
import org.chromium.android_webview.AwQuotaManagerBridge;
import org.chromium.android_webview.AwResource;
import org.chromium.android_webview.AwSettings;
+import org.chromium.android_webview.HttpAuthDatabase;
import org.chromium.android_webview.R;
import org.chromium.android_webview.ResourcesContextWrapperFactory;
+import org.chromium.base.BuildConfig;
import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils;
import org.chromium.base.MemoryPressureListener;
@@ -379,15 +382,14 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
}
}
- AwBrowserContext getBrowserContext() {
- synchronized (mLock) {
- return getBrowserContextLocked();
+ // Only on UI thread.
+ AwBrowserContext getBrowserContextOnUiThread() {
+ assert mStarted;
+ if (BuildConfig.IS_DEBUG && !ThreadUtils.runningOnUiThread()) {
boliu 2016/07/27 05:30:26 the new way to do asserts..
boliu 2016/07/28 01:32:15 I'll rebase this onto https://codereview.chromium.
Torne 2016/07/28 11:47:12 So not objecting to this, but where did this "come
boliu 2016/07/28 13:49:38 Oh I just copied Ted's CL here: https://codereview
+ throw new RuntimeException(
+ "getBrowserContextOnUiThread called on " + Thread.currentThread());
}
- }
- private AwBrowserContext getBrowserContextLocked() {
- assert Thread.holdsLock(mLock);
- assert mStarted;
if (mBrowserContext == null) {
mBrowserContext =
new AwBrowserContext(mWebViewPrefs, ContextUtils.getApplicationContext());
@@ -482,7 +484,12 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
if (mGeolocationPermissions == null) {
ensureChromiumStartedLocked(true);
mGeolocationPermissions = new GeolocationPermissionsAdapter(
- getBrowserContextLocked().getGeolocationPermissions());
+ runOnUiThreadBlocking(new Callable<AwGeolocationPermissions>() {
+ @Override
+ public AwGeolocationPermissions call() {
+ return getBrowserContextOnUiThread().getGeolocationPermissions();
+ }
+ }));
}
}
return mGeolocationPermissions;
@@ -514,20 +521,30 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
synchronized (mLock) {
if (mWebStorage == null) {
ensureChromiumStartedLocked(true);
- mWebStorage = new WebStorageAdapter(AwQuotaManagerBridge.getInstance());
+ mWebStorage = new WebStorageAdapter(
+ runOnUiThreadBlocking(new Callable<AwQuotaManagerBridge>() {
+ @Override
+ public AwQuotaManagerBridge call() {
+ return AwQuotaManagerBridge.getInstance();
+ }
+ }));
}
}
return mWebStorage;
}
@Override
- public WebViewDatabase getWebViewDatabase(Context context) {
+ public WebViewDatabase getWebViewDatabase(final Context context) {
synchronized (mLock) {
if (mWebViewDatabase == null) {
ensureChromiumStartedLocked(true);
- AwBrowserContext browserContext = getBrowserContextLocked();
mWebViewDatabase = new WebViewDatabaseAdapter(
- browserContext.getHttpAuthDatabase(context));
+ runOnUiThreadBlocking(new Callable<HttpAuthDatabase>() {
+ @Override
+ public HttpAuthDatabase call() {
+ return getBrowserContextOnUiThread().getHttpAuthDatabase(context);
+ }
+ }));
}
}
return mWebViewDatabase;

Powered by Google App Engine
This is Rietveld 408576698