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

Side by Side 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, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 package com.android.webview.chromium; 5 package com.android.webview.chromium;
6 6
7 import android.Manifest; 7 import android.Manifest;
8 import android.app.ActivityManager; 8 import android.app.ActivityManager;
9 import android.content.ComponentCallbacks2; 9 import android.content.ComponentCallbacks2;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 18 matching lines...) Expand all
29 29
30 import com.android.webview.chromium.WebViewDelegateFactory.WebViewDelegate; 30 import com.android.webview.chromium.WebViewDelegateFactory.WebViewDelegate;
31 31
32 import org.chromium.android_webview.AwBrowserContext; 32 import org.chromium.android_webview.AwBrowserContext;
33 import org.chromium.android_webview.AwBrowserProcess; 33 import org.chromium.android_webview.AwBrowserProcess;
34 import org.chromium.android_webview.AwContents; 34 import org.chromium.android_webview.AwContents;
35 import org.chromium.android_webview.AwContentsClient; 35 import org.chromium.android_webview.AwContentsClient;
36 import org.chromium.android_webview.AwContentsStatics; 36 import org.chromium.android_webview.AwContentsStatics;
37 import org.chromium.android_webview.AwCookieManager; 37 import org.chromium.android_webview.AwCookieManager;
38 import org.chromium.android_webview.AwDevToolsServer; 38 import org.chromium.android_webview.AwDevToolsServer;
39 import org.chromium.android_webview.AwGeolocationPermissions;
39 import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy; 40 import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy;
40 import org.chromium.android_webview.AwQuotaManagerBridge; 41 import org.chromium.android_webview.AwQuotaManagerBridge;
41 import org.chromium.android_webview.AwResource; 42 import org.chromium.android_webview.AwResource;
42 import org.chromium.android_webview.AwSettings; 43 import org.chromium.android_webview.AwSettings;
44 import org.chromium.android_webview.HttpAuthDatabase;
43 import org.chromium.android_webview.R; 45 import org.chromium.android_webview.R;
44 import org.chromium.android_webview.ResourcesContextWrapperFactory; 46 import org.chromium.android_webview.ResourcesContextWrapperFactory;
47 import org.chromium.base.BuildConfig;
45 import org.chromium.base.CommandLine; 48 import org.chromium.base.CommandLine;
46 import org.chromium.base.ContextUtils; 49 import org.chromium.base.ContextUtils;
47 import org.chromium.base.MemoryPressureListener; 50 import org.chromium.base.MemoryPressureListener;
48 import org.chromium.base.PathService; 51 import org.chromium.base.PathService;
49 import org.chromium.base.PathUtils; 52 import org.chromium.base.PathUtils;
50 import org.chromium.base.ThreadUtils; 53 import org.chromium.base.ThreadUtils;
51 import org.chromium.base.TraceEvent; 54 import org.chromium.base.TraceEvent;
52 import org.chromium.base.annotations.SuppressFBWarnings; 55 import org.chromium.base.annotations.SuppressFBWarnings;
53 import org.chromium.base.library_loader.LibraryLoader; 56 import org.chromium.base.library_loader.LibraryLoader;
54 import org.chromium.base.library_loader.LibraryProcessType; 57 import org.chromium.base.library_loader.LibraryProcessType;
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 boolean hasStarted() { 375 boolean hasStarted() {
373 return mStarted; 376 return mStarted;
374 } 377 }
375 378
376 void startYourEngines(boolean onMainThread) { 379 void startYourEngines(boolean onMainThread) {
377 synchronized (mLock) { 380 synchronized (mLock) {
378 ensureChromiumStartedLocked(onMainThread); 381 ensureChromiumStartedLocked(onMainThread);
379 } 382 }
380 } 383 }
381 384
382 AwBrowserContext getBrowserContext() { 385 // Only on UI thread.
383 synchronized (mLock) { 386 AwBrowserContext getBrowserContextOnUiThread() {
384 return getBrowserContextLocked(); 387 assert mStarted;
388 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
389 throw new RuntimeException(
390 "getBrowserContextOnUiThread called on " + Thread.currentThr ead());
385 } 391 }
386 }
387 392
388 private AwBrowserContext getBrowserContextLocked() {
389 assert Thread.holdsLock(mLock);
390 assert mStarted;
391 if (mBrowserContext == null) { 393 if (mBrowserContext == null) {
392 mBrowserContext = 394 mBrowserContext =
393 new AwBrowserContext(mWebViewPrefs, ContextUtils.getApplicat ionContext()); 395 new AwBrowserContext(mWebViewPrefs, ContextUtils.getApplicat ionContext());
394 } 396 }
395 return mBrowserContext; 397 return mBrowserContext;
396 } 398 }
397 399
398 private void setWebContentsDebuggingEnabled(boolean enable) { 400 private void setWebContentsDebuggingEnabled(boolean enable) {
399 if (Looper.myLooper() != ThreadUtils.getUiThreadLooper()) { 401 if (Looper.myLooper() != ThreadUtils.getUiThreadLooper()) {
400 throw new RuntimeException( 402 throw new RuntimeException(
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 public WebViewProvider createWebView(WebView webView, WebView.PrivateAccess privateAccess) { 477 public WebViewProvider createWebView(WebView webView, WebView.PrivateAccess privateAccess) {
476 return new WebViewChromium(this, webView, privateAccess); 478 return new WebViewChromium(this, webView, privateAccess);
477 } 479 }
478 480
479 @Override 481 @Override
480 public GeolocationPermissions getGeolocationPermissions() { 482 public GeolocationPermissions getGeolocationPermissions() {
481 synchronized (mLock) { 483 synchronized (mLock) {
482 if (mGeolocationPermissions == null) { 484 if (mGeolocationPermissions == null) {
483 ensureChromiumStartedLocked(true); 485 ensureChromiumStartedLocked(true);
484 mGeolocationPermissions = new GeolocationPermissionsAdapter( 486 mGeolocationPermissions = new GeolocationPermissionsAdapter(
485 getBrowserContextLocked().getGeolocationPermissions()); 487 runOnUiThreadBlocking(new Callable<AwGeolocationPermissi ons>() {
488 @Override
489 public AwGeolocationPermissions call() {
490 return getBrowserContextOnUiThread().getGeolocat ionPermissions();
491 }
492 }));
486 } 493 }
487 } 494 }
488 return mGeolocationPermissions; 495 return mGeolocationPermissions;
489 } 496 }
490 497
491 @Override 498 @Override
492 public CookieManager getCookieManager() { 499 public CookieManager getCookieManager() {
493 synchronized (mLock) { 500 synchronized (mLock) {
494 if (mCookieManager == null) { 501 if (mCookieManager == null) {
495 mCookieManager = new CookieManagerAdapter(new AwCookieManager()) ; 502 mCookieManager = new CookieManagerAdapter(new AwCookieManager()) ;
boliu 2016/07/27 05:30:26 AwCookieManager is thread safe, right?
Torne 2016/07/28 11:47:12 Yes, this explicitly works from any thread.
496 } 503 }
497 } 504 }
498 return mCookieManager; 505 return mCookieManager;
499 } 506 }
500 507
501 @Override 508 @Override
502 public android.webkit.WebIconDatabase getWebIconDatabase() { 509 public android.webkit.WebIconDatabase getWebIconDatabase() {
503 synchronized (mLock) { 510 synchronized (mLock) {
504 if (mWebIconDatabase == null) { 511 if (mWebIconDatabase == null) {
505 ensureChromiumStartedLocked(true); 512 ensureChromiumStartedLocked(true);
506 mWebIconDatabase = new WebIconDatabaseAdapter(); 513 mWebIconDatabase = new WebIconDatabaseAdapter();
507 } 514 }
508 } 515 }
509 return mWebIconDatabase; 516 return mWebIconDatabase;
510 } 517 }
511 518
512 @Override 519 @Override
513 public WebStorage getWebStorage() { 520 public WebStorage getWebStorage() {
514 synchronized (mLock) { 521 synchronized (mLock) {
515 if (mWebStorage == null) { 522 if (mWebStorage == null) {
516 ensureChromiumStartedLocked(true); 523 ensureChromiumStartedLocked(true);
517 mWebStorage = new WebStorageAdapter(AwQuotaManagerBridge.getInst ance()); 524 mWebStorage = new WebStorageAdapter(
525 runOnUiThreadBlocking(new Callable<AwQuotaManagerBridge> () {
526 @Override
527 public AwQuotaManagerBridge call() {
528 return AwQuotaManagerBridge.getInstance();
529 }
530 }));
518 } 531 }
519 } 532 }
520 return mWebStorage; 533 return mWebStorage;
521 } 534 }
522 535
523 @Override 536 @Override
524 public WebViewDatabase getWebViewDatabase(Context context) { 537 public WebViewDatabase getWebViewDatabase(final Context context) {
525 synchronized (mLock) { 538 synchronized (mLock) {
526 if (mWebViewDatabase == null) { 539 if (mWebViewDatabase == null) {
527 ensureChromiumStartedLocked(true); 540 ensureChromiumStartedLocked(true);
528 AwBrowserContext browserContext = getBrowserContextLocked();
529 mWebViewDatabase = new WebViewDatabaseAdapter( 541 mWebViewDatabase = new WebViewDatabaseAdapter(
530 browserContext.getHttpAuthDatabase(context)); 542 runOnUiThreadBlocking(new Callable<HttpAuthDatabase>() {
543 @Override
544 public HttpAuthDatabase call() {
545 return getBrowserContextOnUiThread().getHttpAuth Database(context);
546 }
547 }));
531 } 548 }
532 } 549 }
533 return mWebViewDatabase; 550 return mWebViewDatabase;
534 } 551 }
535 552
536 WebViewDelegate getWebViewDelegate() { 553 WebViewDelegate getWebViewDelegate() {
537 return mWebViewDelegate; 554 return mWebViewDelegate;
538 } 555 }
539 } 556 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698