@@ -41,36 +41,39 @@ class WebViewFactory {
4141 // Cache the factory both for efficiency, and ensure any one process gets all webviews from the
4242 // same provider.
4343 private static WebViewFactoryProvider sProviderInstance ;
44+ private static final Object sProviderLock = new Object ();
4445
45- static synchronized WebViewFactoryProvider getProvider () {
46- // For now the main purpose of this function (and the factory abstraction) is to keep
47- // us honest and minimize usage of WebViewClassic internals when binding the proxy.
48- if (sProviderInstance != null ) return sProviderInstance ;
46+ static WebViewFactoryProvider getProvider () {
47+ synchronized (sProviderLock ) {
48+ // For now the main purpose of this function (and the factory abstraction) is to keep
49+ // us honest and minimize usage of WebViewClassic internals when binding the proxy.
50+ if (sProviderInstance != null ) return sProviderInstance ;
4951
50- // For debug builds, we allow a system property to specify that we should use the
51- // Chromium powered WebView. This enables us to switch between implementations
52- // at runtime. For user (release) builds, don't allow this.
53- if (Build .IS_DEBUGGABLE && SystemProperties .getBoolean ("webview.use_chromium" , false )) {
54- StrictMode .ThreadPolicy oldPolicy = StrictMode .allowThreadDiskReads ();
55- try {
56- sProviderInstance = loadChromiumProvider ();
57- if (DEBUG ) Log .v (LOGTAG , "Loaded Chromium provider: " + sProviderInstance );
58- } finally {
59- StrictMode .setThreadPolicy (oldPolicy );
52+ // For debug builds, we allow a system property to specify that we should use the
53+ // Chromium powered WebView. This enables us to switch between implementations
54+ // at runtime. For user (release) builds, don't allow this.
55+ if (Build .IS_DEBUGGABLE && SystemProperties .getBoolean ("webview.use_chromium" , false )) {
56+ StrictMode .ThreadPolicy oldPolicy = StrictMode .allowThreadDiskReads ();
57+ try {
58+ sProviderInstance = loadChromiumProvider ();
59+ if (DEBUG ) Log .v (LOGTAG , "Loaded Chromium provider: " + sProviderInstance );
60+ } finally {
61+ StrictMode .setThreadPolicy (oldPolicy );
62+ }
6063 }
61- }
6264
63- if (sProviderInstance == null ) {
64- if (DEBUG ) Log .v (LOGTAG , "Falling back to default provider: "
65- + DEFAULT_WEBVIEW_FACTORY );
66- sProviderInstance = getFactoryByName (DEFAULT_WEBVIEW_FACTORY ,
67- WebViewFactory .class .getClassLoader ());
6865 if (sProviderInstance == null ) {
69- if (DEBUG ) Log .v (LOGTAG , "Falling back to explicit linkage" );
70- sProviderInstance = new WebViewClassic .Factory ();
66+ if (DEBUG ) Log .v (LOGTAG , "Falling back to default provider: "
67+ + DEFAULT_WEBVIEW_FACTORY );
68+ sProviderInstance = getFactoryByName (DEFAULT_WEBVIEW_FACTORY ,
69+ WebViewFactory .class .getClassLoader ());
70+ if (sProviderInstance == null ) {
71+ if (DEBUG ) Log .v (LOGTAG , "Falling back to explicit linkage" );
72+ sProviderInstance = new WebViewClassic .Factory ();
73+ }
7174 }
75+ return sProviderInstance ;
7276 }
73- return sProviderInstance ;
7477 }
7578
7679 // TODO: This allows us to have the legacy and Chromium WebView coexist for development
0 commit comments