Skip to content

Commit e6ff478

Browse files
jreckAndroid (Google) Code Review
authored andcommitted
Merge "Use less static synchronized" into jb-mr1-dev
2 parents a21ad1a + 9f9d345 commit e6ff478

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

api/current.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27471,7 +27471,7 @@ package android.webkit {
2747127471
method public void clearFormData();
2747227472
method public void clearHttpAuthUsernamePassword();
2747327473
method public void clearUsernamePassword();
27474-
method public static synchronized android.webkit.WebViewDatabase getInstance(android.content.Context);
27474+
method public static android.webkit.WebViewDatabase getInstance(android.content.Context);
2747527475
method public boolean hasFormData();
2747627476
method public boolean hasHttpAuthUsernamePassword();
2747727477
method public boolean hasUsernamePassword();

core/java/android/webkit/WebViewDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class WebViewDatabase {
4040
protected WebViewDatabase() {
4141
}
4242

43-
public static synchronized WebViewDatabase getInstance(Context context) {
43+
public static WebViewDatabase getInstance(Context context) {
4444
return WebViewFactory.getProvider().getWebViewDatabase(context);
4545
}
4646

core/java/android/webkit/WebViewDatabaseClassic.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ final class WebViewDatabaseClassic extends WebViewDatabase {
5252
// implemented for b/5265606.
5353

5454
private static WebViewDatabaseClassic sInstance = null;
55+
private static final Object sInstanceLock = new Object();
5556

5657
private static SQLiteDatabase sDatabase = null;
5758

@@ -99,7 +100,7 @@ final class WebViewDatabaseClassic extends WebViewDatabase {
99100
// Initially true until the background thread completes.
100101
private boolean mInitialized = false;
101102

102-
WebViewDatabaseClassic(final Context context) {
103+
private WebViewDatabaseClassic(final Context context) {
103104
JniUtil.setContext(context);
104105
new Thread() {
105106
@Override
@@ -111,11 +112,13 @@ public void run() {
111112
// Singleton only, use getInstance()
112113
}
113114

114-
public static synchronized WebViewDatabaseClassic getInstance(Context context) {
115-
if (sInstance == null) {
116-
sInstance = new WebViewDatabaseClassic(context);
115+
public static WebViewDatabaseClassic getInstance(Context context) {
116+
synchronized (sInstanceLock) {
117+
if (sInstance == null) {
118+
sInstance = new WebViewDatabaseClassic(context);
119+
}
120+
return sInstance;
117121
}
118-
return sInstance;
119122
}
120123

121124
private synchronized void init(Context context) {

core/java/android/webkit/WebViewFactory.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)