summaryrefslogtreecommitdiffstats
path: root/core/java/android/webkit
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2012-09-20 13:18:59 -0700
committerJohn Reck <jreck@google.com>2012-09-20 15:25:16 -0700
commit9f9d34552f53c534141584a5ad4a8a49ad7939dc (patch)
tree88f99d0babbe1caab44b49446ba9aabda877c7c8 /core/java/android/webkit
parent4dd3c3797060b35c8e6ebbbdd164c17c6db7b5ec (diff)
downloadframeworks_base-9f9d34552f53c534141584a5ad4a8a49ad7939dc.zip
frameworks_base-9f9d34552f53c534141584a5ad4a8a49ad7939dc.tar.gz
frameworks_base-9f9d34552f53c534141584a5ad4a8a49ad7939dc.tar.bz2
Use less static synchronized
Bug: 6482144 Change-Id: I86161e3298101c10a112add406615001561e649e
Diffstat (limited to 'core/java/android/webkit')
-rw-r--r--core/java/android/webkit/WebViewDatabase.java2
-rw-r--r--core/java/android/webkit/WebViewDatabaseClassic.java13
-rw-r--r--core/java/android/webkit/WebViewFactory.java49
3 files changed, 35 insertions, 29 deletions
diff --git a/core/java/android/webkit/WebViewDatabase.java b/core/java/android/webkit/WebViewDatabase.java
index 62ec0d5..5597259 100644
--- a/core/java/android/webkit/WebViewDatabase.java
+++ b/core/java/android/webkit/WebViewDatabase.java
@@ -40,7 +40,7 @@ public class WebViewDatabase {
protected WebViewDatabase() {
}
- public static synchronized WebViewDatabase getInstance(Context context) {
+ public static WebViewDatabase getInstance(Context context) {
return WebViewFactory.getProvider().getWebViewDatabase(context);
}
diff --git a/core/java/android/webkit/WebViewDatabaseClassic.java b/core/java/android/webkit/WebViewDatabaseClassic.java
index c804b90..be01028 100644
--- a/core/java/android/webkit/WebViewDatabaseClassic.java
+++ b/core/java/android/webkit/WebViewDatabaseClassic.java
@@ -52,6 +52,7 @@ final class WebViewDatabaseClassic extends WebViewDatabase {
// implemented for b/5265606.
private static WebViewDatabaseClassic sInstance = null;
+ private static final Object sInstanceLock = new Object();
private static SQLiteDatabase sDatabase = null;
@@ -99,7 +100,7 @@ final class WebViewDatabaseClassic extends WebViewDatabase {
// Initially true until the background thread completes.
private boolean mInitialized = false;
- WebViewDatabaseClassic(final Context context) {
+ private WebViewDatabaseClassic(final Context context) {
JniUtil.setContext(context);
new Thread() {
@Override
@@ -111,11 +112,13 @@ final class WebViewDatabaseClassic extends WebViewDatabase {
// Singleton only, use getInstance()
}
- public static synchronized WebViewDatabaseClassic getInstance(Context context) {
- if (sInstance == null) {
- sInstance = new WebViewDatabaseClassic(context);
+ public static WebViewDatabaseClassic getInstance(Context context) {
+ synchronized (sInstanceLock) {
+ if (sInstance == null) {
+ sInstance = new WebViewDatabaseClassic(context);
+ }
+ return sInstance;
}
- return sInstance;
}
private synchronized void init(Context context) {
diff --git a/core/java/android/webkit/WebViewFactory.java b/core/java/android/webkit/WebViewFactory.java
index 2fc9b39..b833a01 100644
--- a/core/java/android/webkit/WebViewFactory.java
+++ b/core/java/android/webkit/WebViewFactory.java
@@ -41,36 +41,39 @@ class WebViewFactory {
// Cache the factory both for efficiency, and ensure any one process gets all webviews from the
// same provider.
private static WebViewFactoryProvider sProviderInstance;
+ private static final Object sProviderLock = new Object();
- static synchronized WebViewFactoryProvider getProvider() {
- // For now the main purpose of this function (and the factory abstraction) is to keep
- // us honest and minimize usage of WebViewClassic internals when binding the proxy.
- if (sProviderInstance != null) return sProviderInstance;
+ static WebViewFactoryProvider getProvider() {
+ synchronized (sProviderLock) {
+ // For now the main purpose of this function (and the factory abstraction) is to keep
+ // us honest and minimize usage of WebViewClassic internals when binding the proxy.
+ if (sProviderInstance != null) return sProviderInstance;
- // For debug builds, we allow a system property to specify that we should use the
- // Chromium powered WebView. This enables us to switch between implementations
- // at runtime. For user (release) builds, don't allow this.
- if (Build.IS_DEBUGGABLE && SystemProperties.getBoolean("webview.use_chromium", false)) {
- StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
- try {
- sProviderInstance = loadChromiumProvider();
- if (DEBUG) Log.v(LOGTAG, "Loaded Chromium provider: " + sProviderInstance);
- } finally {
- StrictMode.setThreadPolicy(oldPolicy);
+ // For debug builds, we allow a system property to specify that we should use the
+ // Chromium powered WebView. This enables us to switch between implementations
+ // at runtime. For user (release) builds, don't allow this.
+ if (Build.IS_DEBUGGABLE && SystemProperties.getBoolean("webview.use_chromium", false)) {
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
+ try {
+ sProviderInstance = loadChromiumProvider();
+ if (DEBUG) Log.v(LOGTAG, "Loaded Chromium provider: " + sProviderInstance);
+ } finally {
+ StrictMode.setThreadPolicy(oldPolicy);
+ }
}
- }
- if (sProviderInstance == null) {
- if (DEBUG) Log.v(LOGTAG, "Falling back to default provider: "
- + DEFAULT_WEBVIEW_FACTORY);
- sProviderInstance = getFactoryByName(DEFAULT_WEBVIEW_FACTORY,
- WebViewFactory.class.getClassLoader());
if (sProviderInstance == null) {
- if (DEBUG) Log.v(LOGTAG, "Falling back to explicit linkage");
- sProviderInstance = new WebViewClassic.Factory();
+ if (DEBUG) Log.v(LOGTAG, "Falling back to default provider: "
+ + DEFAULT_WEBVIEW_FACTORY);
+ sProviderInstance = getFactoryByName(DEFAULT_WEBVIEW_FACTORY,
+ WebViewFactory.class.getClassLoader());
+ if (sProviderInstance == null) {
+ if (DEBUG) Log.v(LOGTAG, "Falling back to explicit linkage");
+ sProviderInstance = new WebViewClassic.Factory();
+ }
}
+ return sProviderInstance;
}
- return sProviderInstance;
}
// TODO: This allows us to have the legacy and Chromium WebView coexist for development