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

Unified Diff: android_webview/java/src/org/chromium/android_webview/PlatformServiceBridge.java

Issue 2635693002: [WebView] initial webview-side implementation of safebrowsing (Closed)
Patch Set: rename lock, add crbug comment Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: android_webview/java/src/org/chromium/android_webview/PlatformServiceBridge.java
diff --git a/android_webview/java/src/org/chromium/android_webview/PlatformServiceBridge.java b/android_webview/java/src/org/chromium/android_webview/PlatformServiceBridge.java
index b41d09121b8dfaabb5185221137e20e13bf72594..3f906a92b23f8a32e33da48e231f68bbab223b70 100644
--- a/android_webview/java/src/org/chromium/android_webview/PlatformServiceBridge.java
+++ b/android_webview/java/src/org/chromium/android_webview/PlatformServiceBridge.java
@@ -21,34 +21,38 @@ public class PlatformServiceBridge {
private static final String PLATFORM_SERVICE_BRIDGE =
"com.android.webview.chromium.PlatformServiceBridgeGoogle";
+ private static final Object sInstanceLock = new Object();
private static PlatformServiceBridge sInstance;
protected PlatformServiceBridge() {}
public static PlatformServiceBridge getInstance(Context appContext) {
- ThreadUtils.assertOnUiThread(); // Avoid race conditions on sInstance.
+ // TODO(timvolodine): consider removing the lock, crbug.com/681805.
+ synchronized (sInstanceLock) {
+ if (sInstance != null) {
+ return sInstance;
+ }
- if (sInstance != null) {
- return sInstance;
- }
+ // Try to get a specialized service bridge.
+ try {
+ Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE);
+ sInstance = (PlatformServiceBridge) cls.getDeclaredConstructor(Context.class)
+ .newInstance(appContext);
+ return sInstance;
+ } catch (ClassNotFoundException e) {
+ // This is not an error; it just means this device doesn't have specialized
+ // services.
+ } catch (IllegalAccessException | IllegalArgumentException | InstantiationException
+ | NoSuchMethodException e) {
+ Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + ": " + e);
+ } catch (InvocationTargetException e) {
+ Log.e(TAG, "Failed invocation to get " + PLATFORM_SERVICE_BRIDGE + ":",
+ e.getCause());
+ }
- // Try to get a specialized service bridge.
- try {
- Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE);
- sInstance = (PlatformServiceBridge) cls.getDeclaredConstructor(Context.class)
- .newInstance(appContext);
- return sInstance;
- } catch (ClassNotFoundException e) {
- // This is not an error; it just means this device doesn't have specialized services.
- } catch (IllegalAccessException | IllegalArgumentException | InstantiationException
- | NoSuchMethodException e) {
- Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + ": " + e);
- } catch (InvocationTargetException e) {
- Log.e(TAG, "Failed invocation to get " + PLATFORM_SERVICE_BRIDGE + ":", e.getCause());
+ // Otherwise, get the generic service bridge.
+ sInstance = new PlatformServiceBridge();
}
-
- // Otherwise, get the generic service bridge.
- sInstance = new PlatformServiceBridge();
return sInstance;
}

Powered by Google App Engine
This is Rietveld 408576698