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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.android_webview; 5 package org.chromium.android_webview;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.webkit.ValueCallback; 8 import android.webkit.ValueCallback;
9 9
10 import org.chromium.base.Log; 10 import org.chromium.base.Log;
11 import org.chromium.base.ThreadUtils; 11 import org.chromium.base.ThreadUtils;
12 12
13 import java.lang.reflect.InvocationTargetException; 13 import java.lang.reflect.InvocationTargetException;
14 14
15 /** 15 /**
16 * This class manages platform-specific services. (i.e. Google Services) The pla tform 16 * This class manages platform-specific services. (i.e. Google Services) The pla tform
17 * should extend this class and use this base class to fetch their specialized v ersion. 17 * should extend this class and use this base class to fetch their specialized v ersion.
18 */ 18 */
19 public class PlatformServiceBridge { 19 public class PlatformServiceBridge {
20 private static final String TAG = "PlatformServiceBrid-"; 20 private static final String TAG = "PlatformServiceBrid-";
21 private static final String PLATFORM_SERVICE_BRIDGE = 21 private static final String PLATFORM_SERVICE_BRIDGE =
22 "com.android.webview.chromium.PlatformServiceBridgeGoogle"; 22 "com.android.webview.chromium.PlatformServiceBridgeGoogle";
23 23
24 private static final Object sInstanceLock = new Object();
24 private static PlatformServiceBridge sInstance; 25 private static PlatformServiceBridge sInstance;
25 26
26 protected PlatformServiceBridge() {} 27 protected PlatformServiceBridge() {}
27 28
28 public static PlatformServiceBridge getInstance(Context appContext) { 29 public static PlatformServiceBridge getInstance(Context appContext) {
29 ThreadUtils.assertOnUiThread(); // Avoid race conditions on sInstance. 30 // TODO(timvolodine): consider removing the lock, crbug.com/681805.
31 synchronized (sInstanceLock) {
32 if (sInstance != null) {
33 return sInstance;
34 }
30 35
31 if (sInstance != null) { 36 // Try to get a specialized service bridge.
32 return sInstance; 37 try {
38 Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE);
39 sInstance = (PlatformServiceBridge) cls.getDeclaredConstructor(C ontext.class)
40 .newInstance(appContext);
41 return sInstance;
42 } catch (ClassNotFoundException e) {
43 // This is not an error; it just means this device doesn't have specialized
44 // services.
45 } catch (IllegalAccessException | IllegalArgumentException | Instant iationException
46 | NoSuchMethodException e) {
47 Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + ": " + e );
48 } catch (InvocationTargetException e) {
49 Log.e(TAG, "Failed invocation to get " + PLATFORM_SERVICE_BRIDGE + ":",
50 e.getCause());
51 }
52
53 // Otherwise, get the generic service bridge.
54 sInstance = new PlatformServiceBridge();
33 } 55 }
34
35 // Try to get a specialized service bridge.
36 try {
37 Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE);
38 sInstance = (PlatformServiceBridge) cls.getDeclaredConstructor(Conte xt.class)
39 .newInstance(appContext);
40 return sInstance;
41 } catch (ClassNotFoundException e) {
42 // This is not an error; it just means this device doesn't have spec ialized services.
43 } catch (IllegalAccessException | IllegalArgumentException | Instantiati onException
44 | NoSuchMethodException e) {
45 Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + ": " + e);
46 } catch (InvocationTargetException e) {
47 Log.e(TAG, "Failed invocation to get " + PLATFORM_SERVICE_BRIDGE + " :", e.getCause());
48 }
49
50 // Otherwise, get the generic service bridge.
51 sInstance = new PlatformServiceBridge();
52 return sInstance; 56 return sInstance;
53 } 57 }
54 58
55 // TODO(paulmiller): remove; replaced by canUseGms 59 // TODO(paulmiller): remove; replaced by canUseGms
56 public boolean tryEnableGms() { 60 public boolean tryEnableGms() {
57 return false; 61 return false;
58 } 62 }
59 63
60 // Can WebView use Google Play Services (a.k.a. GMS)? 64 // Can WebView use Google Play Services (a.k.a. GMS)?
61 public boolean canUseGms() { 65 public boolean canUseGms() {
62 return false; 66 return false;
63 } 67 }
64 68
65 // Overriding implementations may call "callback" asynchronously. For simpli city (and not 69 // Overriding implementations may call "callback" asynchronously. For simpli city (and not
66 // because of any technical limitation) we require that "queryMetricsSetting " and "callback" 70 // because of any technical limitation) we require that "queryMetricsSetting " and "callback"
67 // both get called on WebView's UI thread. 71 // both get called on WebView's UI thread.
68 public void queryMetricsSetting(ValueCallback<Boolean> callback) { 72 public void queryMetricsSetting(ValueCallback<Boolean> callback) {
69 ThreadUtils.assertOnUiThread(); 73 ThreadUtils.assertOnUiThread();
70 callback.onReceiveValue(false); 74 callback.onReceiveValue(false);
71 } 75 }
72 } 76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698