// implemented for b/5265606.
private static WebViewDatabaseClassic sInstance = null;
+ private static final Object sInstanceLock = new Object();
private static SQLiteDatabase sDatabase = null;
// 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
// 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) {
// 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