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

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

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

Powered by Google App Engine
This is Rietveld 408576698