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

Side by Side Diff: android_webview/java/src/org/chromium/android_webview/PlatformServiceBridge.java

Issue 2628863004: [Android WebView] Ensure we have user consent before uploading minidumps (Closed)
Patch Set: 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 12
12 import java.lang.reflect.InvocationTargetException; 13 import java.lang.reflect.InvocationTargetException;
13 14
14 /** 15 /**
15 * 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
16 * 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.
17 */ 18 */
18 public class PlatformServiceBridge { 19 public class PlatformServiceBridge implements UserConsentInterface {
19 private static final String TAG = "PlatformServiceBrid-"; 20 private static final String TAG = "PlatformServiceBrid-";
20 private static final String PLATFORM_SERVICE_BRIDGE = 21 private static final String PLATFORM_SERVICE_BRIDGE =
21 "com.android.webview.chromium.PlatformServiceBridgeGoogle"; 22 "com.android.webview.chromium.PlatformServiceBridgeGoogle";
22 23
23 private static PlatformServiceBridge sInstance; 24 private static PlatformServiceBridge sInstance;
24 25
25 protected PlatformServiceBridge() {} 26 protected PlatformServiceBridge() {}
26 27
27 public static PlatformServiceBridge getInstance(Context applicationContext) { 28 public static PlatformServiceBridge getInstance(Context appContext) {
29 ThreadUtils.assertOnUiThread(); // Avoid race conditions on sInstance.
30
28 if (sInstance != null) { 31 if (sInstance != null) {
29 return sInstance; 32 return sInstance;
30 } 33 }
31 34
32 // Try to get a specialized service bridge. 35 // Try to get a specialized service bridge.
33 try { 36 try {
34 Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE); 37 Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE);
35 sInstance = (PlatformServiceBridge) cls.getDeclaredConstructor(Conte xt.class) 38 sInstance = (PlatformServiceBridge) cls.getDeclaredConstructor(Conte xt.class)
36 .newInstance(applicationContext); 39 .newInstance(appContext);
37 return sInstance; 40 return sInstance;
38 } catch (ClassNotFoundException e) { 41 } catch (ClassNotFoundException e) {
39 // This is not an error; it just means this device doesn't have spec ialized services. 42 // This is not an error; it just means this device doesn't have spec ialized services.
40 } catch (IllegalAccessException | IllegalArgumentException | Instantiati onException 43 } catch (IllegalAccessException | IllegalArgumentException | Instantiati onException
41 | NoSuchMethodException e) { 44 | NoSuchMethodException e) {
42 Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + ": " + e); 45 Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + ": " + e);
43 } catch (InvocationTargetException e) { 46 } catch (InvocationTargetException e) {
44 Log.e(TAG, "Failed invocation to get " + PLATFORM_SERVICE_BRIDGE + " :", e.getCause()); 47 Log.e(TAG, "Failed invocation to get " + PLATFORM_SERVICE_BRIDGE + " :", e.getCause());
45 } 48 }
46 49
47 // Otherwise, get the generic service bridge. 50 // Otherwise, get the generic service bridge.
48 sInstance = new PlatformServiceBridge(); 51 sInstance = new PlatformServiceBridge();
49 return sInstance; 52 return sInstance;
50 } 53 }
51 54
52 // Try to enable WebView to use Google Play Services (a.k.a. GMS) APIs. Retu rn true on success. 55 // TODO(paulmiller): remove; replaced by canUseGms
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
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() {
57 return false; 57 return false;
58 } 58 }
59 59
60 public void setMetricsSettingListener(ValueCallback<Boolean> callback) {} 60 // Can WebView use Google Play Services (a.k.a. GMS)?
61 public boolean canUseGms() {
62 return false;
63 }
64
65 @Override
66 public boolean userConsentInterfaceAvailable() {
67 return canUseGms();
68 }
69
70 // Overriding implementations may call "callback" asynchronously. For simpli city (and not
71 // because of any technical limitation) we require that "queryMetricsSetting " and "callback"
72 // both get called on WebView's UI thread.
73 public void queryMetricsSetting(ValueCallback<Boolean> callback) {
74 ThreadUtils.assertOnUiThread();
75 callback.onReceiveValue(false);
76 }
77
78 @Override
79 public void userConsents(ValueCallback<Boolean> callback) {
80 queryMetricsSetting(callback);
81 }
61 } 82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698