| 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.ContextUtils; | |
| 11 import org.chromium.base.Log; | 10 import org.chromium.base.Log; |
| 12 import org.chromium.base.ThreadUtils; | 11 import org.chromium.base.ThreadUtils; |
| 13 | 12 |
| 14 import java.lang.reflect.InvocationTargetException; | 13 import java.lang.reflect.InvocationTargetException; |
| 15 | 14 |
| 16 /** | 15 /** |
| 17 * 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 |
| 18 * 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. |
| 19 */ | 18 */ |
| 20 public class PlatformServiceBridge { | 19 public class PlatformServiceBridge { |
| 21 private static final String TAG = "PlatformServiceBrid-"; | 20 private static final String TAG = "PlatformServiceBrid-"; |
| 22 private static final String PLATFORM_SERVICE_BRIDGE = | 21 private static final String PLATFORM_SERVICE_BRIDGE = |
| 23 "com.android.webview.chromium.PlatformServiceBridgeGoogle"; | 22 "com.android.webview.chromium.PlatformServiceBridgeGoogle"; |
| 24 | 23 |
| 25 // Only written by getOrCreateInstance on the UI thread (aside from injectIn
stance, for | 24 // Only written by getOrCreateInstance on the UI thread (aside from injectIn
stance, for |
| 26 // testing), but read by getInstance on arbitrary threads. | 25 // testing), but read by getInstance on arbitrary threads. |
| 27 private static volatile PlatformServiceBridge sInstance; | 26 private static volatile PlatformServiceBridge sInstance; |
| 28 | 27 |
| 29 protected PlatformServiceBridge() {} | 28 protected PlatformServiceBridge() {} |
| 30 | 29 |
| 31 public static PlatformServiceBridge getOrCreateInstance() { | 30 public static PlatformServiceBridge getOrCreateInstance(Context context) { |
| 32 // Just to avoid race conditions on sInstance - nothing special about th
e UI thread. | 31 // Just to avoid race conditions on sInstance - nothing special about th
e UI thread. |
| 33 ThreadUtils.assertOnUiThread(); | 32 ThreadUtils.assertOnUiThread(); |
| 34 | 33 |
| 35 if (sInstance != null) return sInstance; | 34 if (sInstance != null) return sInstance; |
| 36 | 35 |
| 37 // Try to get a specialized service bridge. | 36 // Try to get a specialized service bridge. |
| 38 try { | 37 try { |
| 39 Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE); | 38 Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE); |
| 40 sInstance = (PlatformServiceBridge) cls.getDeclaredConstructor(Conte
xt.class) | 39 sInstance = (PlatformServiceBridge) cls.getDeclaredConstructor(Conte
xt.class) |
| 41 .newInstance(ContextUtils.getApplicationContext(
)); | 40 .newInstance(context); |
| 42 return sInstance; | 41 return sInstance; |
| 43 } catch (ClassNotFoundException e) { | 42 } catch (ClassNotFoundException e) { |
| 44 // This is not an error; it just means this device doesn't have spec
ialized | 43 // This is not an error; it just means this device doesn't have spec
ialized |
| 45 // services. | 44 // services. |
| 46 } catch (IllegalAccessException | IllegalArgumentException | Instantiati
onException | 45 } catch (IllegalAccessException | IllegalArgumentException | Instantiati
onException |
| 47 | NoSuchMethodException e) { | 46 | NoSuchMethodException e) { |
| 48 Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + ": " + e); | 47 Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + ": " + e); |
| 49 } catch (InvocationTargetException e) { | 48 } catch (InvocationTargetException e) { |
| 50 Log.e(TAG, "Failed invocation to get " + PLATFORM_SERVICE_BRIDGE + "
:", e.getCause()); | 49 Log.e(TAG, "Failed invocation to get " + PLATFORM_SERVICE_BRIDGE + "
:", e.getCause()); |
| 51 } | 50 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 80 // because of any technical limitation) we require that "queryMetricsSetting
" and "callback" | 79 // because of any technical limitation) we require that "queryMetricsSetting
" and "callback" |
| 81 // both get called on WebView's UI thread. | 80 // both get called on WebView's UI thread. |
| 82 public void queryMetricsSetting(ValueCallback<Boolean> callback) { | 81 public void queryMetricsSetting(ValueCallback<Boolean> callback) { |
| 83 ThreadUtils.assertOnUiThread(); | 82 ThreadUtils.assertOnUiThread(); |
| 84 callback.onReceiveValue(false); | 83 callback.onReceiveValue(false); |
| 85 } | 84 } |
| 86 | 85 |
| 87 // Takes an uncompressed, serialized UMA proto and logs it via a platform-sp
ecific mechanism. | 86 // Takes an uncompressed, serialized UMA proto and logs it via a platform-sp
ecific mechanism. |
| 88 public void logMetrics(byte[] data) {} | 87 public void logMetrics(byte[] data) {} |
| 89 } | 88 } |
| OLD | NEW |