OLD | NEW |
---|---|
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 | 11 |
12 import java.lang.reflect.InvocationTargetException; | 12 import java.lang.reflect.InvocationTargetException; |
13 | 13 |
14 /** | 14 /** |
15 * This class manages platform-specific services. (i.e. Google Services) The pla tform | 15 * This class manages platform-specific services. (i.e. Google Services) The pla tform |
16 * should extend this class and use this base class to fetch their specialized v ersion. | 16 * should extend this class and use this base class to fetch their specialized v ersion. |
17 */ | 17 */ |
18 public class PlatformServiceBridge { | 18 public class PlatformServiceBridge { |
19 private static final String TAG = "PlatformServiceBrid-"; | 19 private static final String TAG = "PlatformServiceBrid-"; |
20 private static final String PLATFORM_SERVICE_BRIDGE = | 20 private static final String PLATFORM_SERVICE_BRIDGE = |
21 "com.android.webview.chromium.PlatformServiceBridgeGoogle"; | 21 "com.android.webview.chromium.PlatformServiceBridgeGoogle"; |
22 | 22 |
23 private static PlatformServiceBridge sInstance; | 23 private static PlatformServiceBridge sInstance; |
24 | 24 |
25 protected PlatformServiceBridge() {} | 25 protected PlatformServiceBridge() {} |
26 | 26 |
27 public static PlatformServiceBridge getInstance(Context applicationContext) { | 27 public static PlatformServiceBridge getInstance(Context appContext) { |
28 if (sInstance != null) { | 28 if (sInstance != null) { |
29 return sInstance; | 29 return sInstance; |
30 } | 30 } |
31 | 31 |
32 // Try to get a specialized service bridge. | 32 // Try to get a specialized service bridge. |
33 try { | 33 try { |
34 Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE); | 34 Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE); |
35 sInstance = (PlatformServiceBridge) cls.getDeclaredConstructor(Conte xt.class) | 35 sInstance = (PlatformServiceBridge) cls.getDeclaredConstructor(Conte xt.class) |
36 .newInstance(applicationContext); | 36 .newInstance(appContext); |
37 return sInstance; | 37 return sInstance; |
38 } catch (ClassNotFoundException e) { | 38 } catch (ClassNotFoundException e) { |
39 // This is not an error; it just means this device doesn't have spec ialized services. | 39 // This is not an error; it just means this device doesn't have spec ialized services. |
40 } catch (IllegalAccessException | IllegalArgumentException | Instantiati onException | 40 } catch (IllegalAccessException | IllegalArgumentException | Instantiati onException |
41 | NoSuchMethodException e) { | 41 | NoSuchMethodException e) { |
42 Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + ": " + e); | 42 Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + ": " + e); |
43 } catch (InvocationTargetException e) { | 43 } catch (InvocationTargetException e) { |
44 Log.e(TAG, "Failed invocation to get " + PLATFORM_SERVICE_BRIDGE + " :", e.getCause()); | 44 Log.e(TAG, "Failed invocation to get " + PLATFORM_SERVICE_BRIDGE + " :", e.getCause()); |
45 } | 45 } |
46 | 46 |
47 // Otherwise, get the generic service bridge. | 47 // Otherwise, get the generic service bridge. |
48 sInstance = new PlatformServiceBridge(); | 48 sInstance = new PlatformServiceBridge(); |
49 return sInstance; | 49 return sInstance; |
50 } | 50 } |
51 | 51 |
52 // Try to enable WebView to use Google Play Services (a.k.a. GMS) APIs. Retu rn true on success. | 52 // Try to enable WebView to use Google Play Services (a.k.a. GMS) APIs. Retu rn true on success. |
53 // Do not use GMS APIs before this has returned true, or if it returns false . This can be called | 53 // Do not use GMS APIs before this has returned true, or if it returns false . This can be called |
54 // from multiple threads, so long as no thread uses GMS APIs before at least one call has | 54 // from multiple threads, so long as no thread uses GMS APIs before at least one call has |
55 // returned true. (The easy way is for each thread to wait for its own call to return true.) | 55 // returned true. (The easy way is for each thread to wait for its own call to return true.) |
56 public boolean tryEnableGms() { | 56 public boolean tryEnableGms() { |
sgurun-gerrit only
2017/01/04 00:31:53
remove this method.
| |
57 return false; | 57 return false; |
58 } | 58 } |
59 | 59 |
60 public void setMetricsSettingListener(ValueCallback<Boolean> callback) {} | 60 // Overriding implementations may call "callback" asynchronously, but they m ust still call |
gsennton
2017/01/04 10:09:55
So we will use this method by spawning a new threa
paulmiller
2017/01/04 18:12:41
You could do that. I don't. See the AwMetricsServi
gsennton
2017/01/04 18:35:04
Well, I think we (silent feedback) would want to w
paulmiller
2017/01/04 18:45:00
If the worker thread is persistent, yes, that woul
gsennton
2017/01/04 20:31:01
Oops, I meant waiting in the worker thread as in s
sgurun-gerrit only
2017/01/04 20:33:05
As far as I remember GMSCore always calls you back
paulmiller
2017/01/04 22:26:12
By default, GMS calls back on the app's UI thread.
| |
61 // "callback" on the same thread on which "queryMetricsEnabled" was called. | |
62 public void queryMetricsEnabled(ValueCallback<Boolean> callback) { | |
sgurun-gerrit only
2017/01/04 00:05:24
I prefer allowMetricsService() as the method name.
paulmiller
2017/01/04 00:10:15
Why is that? That sounds like we're setting someth
sgurun-gerrit only
2017/01/04 00:31:53
queryMetricsValue could be better choice. queryMet
paulmiller
2017/01/04 00:54:40
How about "queryMetricsSetting"? That's slightly m
| |
63 callback.onReceiveValue(false); | |
64 } | |
61 } | 65 } |
OLD | NEW |