diff options
author | paulmiller <paulmiller@chromium.org> | 2016-01-04 16:50:19 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-05 00:51:20 +0000 |
commit | 5bc628b55810289b6ebb269da47642b929eaf42d (patch) | |
tree | f05214cca24a1c5d209c0d82b234c54944188e5b /android_webview/java/src/org | |
parent | aa1c4ced03fe5890aa8cd2e330b939ee3accf02a (diff) | |
download | chromium_src-5bc628b55810289b6ebb269da47642b929eaf42d.zip chromium_src-5bc628b55810289b6ebb269da47642b929eaf42d.tar.gz chromium_src-5bc628b55810289b6ebb269da47642b929eaf42d.tar.bz2 |
WebView Metrics client implementation (Chromium part)
BUG=546754
Review URL: https://codereview.chromium.org/1474483004
Cr-Commit-Position: refs/heads/master@{#367433}
Diffstat (limited to 'android_webview/java/src/org')
3 files changed, 88 insertions, 0 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwBrowserContext.java b/android_webview/java/src/org/chromium/android_webview/AwBrowserContext.java index ea5a637..3d62926 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwBrowserContext.java +++ b/android_webview/java/src/org/chromium/android_webview/AwBrowserContext.java @@ -26,9 +26,11 @@ public class AwBrowserContext { private AwFormDatabase mFormDatabase; private HttpAuthDatabase mHttpAuthDatabase; private AwMessagePortService mMessagePortService; + private AwMetricsServiceClient mMetricsServiceClient; public AwBrowserContext(SharedPreferences sharedPreferences, Context applicationContext) { mSharedPreferences = sharedPreferences; + mMetricsServiceClient = new AwMetricsServiceClient(applicationContext); } public AwGeolocationPermissions getGeolocationPermissions() { @@ -59,6 +61,10 @@ public class AwBrowserContext { return mMessagePortService; } + public AwMetricsServiceClient getMetricsServiceClient() { + return mMetricsServiceClient; + } + /** * @see android.webkit.WebView#pauseTimers() */ diff --git a/android_webview/java/src/org/chromium/android_webview/AwMetricsServiceClient.java b/android_webview/java/src/org/chromium/android_webview/AwMetricsServiceClient.java new file mode 100644 index 0000000..7775fb2 --- /dev/null +++ b/android_webview/java/src/org/chromium/android_webview/AwMetricsServiceClient.java @@ -0,0 +1,29 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.android_webview; + +import android.content.Context; +import android.webkit.ValueCallback; + +import org.chromium.base.annotations.JNINamespace; + +/** + * Java twin of the homonymous C++ class. The Java side is only responsible for + * switching metrics on and off. Since the setting is a platform feature, it + * must be obtained through PlatformServiceBridge. + */ +@JNINamespace("android_webview") +public class AwMetricsServiceClient { + public AwMetricsServiceClient(Context applicationContext) { + PlatformServiceBridge.getInstance(applicationContext) + .setMetricsSettingListener(new ValueCallback<Boolean>() { + public void onReceiveValue(Boolean enabled) { + nativeSetMetricsEnabled(enabled); + } + }); + } + + public static native void nativeSetMetricsEnabled(boolean enabled); +} diff --git a/android_webview/java/src/org/chromium/android_webview/PlatformServiceBridge.java b/android_webview/java/src/org/chromium/android_webview/PlatformServiceBridge.java new file mode 100644 index 0000000..4051c23 --- /dev/null +++ b/android_webview/java/src/org/chromium/android_webview/PlatformServiceBridge.java @@ -0,0 +1,53 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.android_webview; + +import android.content.Context; +import android.webkit.ValueCallback; + +import org.chromium.base.Log; + +import java.lang.reflect.InvocationTargetException; + +/** + * This class manages platform-specific services. (i.e. Google Services) The platform + * should extend this class and use this base class to fetch their specialized version. + */ +public class PlatformServiceBridge { + private static final String TAG = "PlatformServiceBrid-"; + private static final String PLATFORM_SERVICE_BRIDGE = + "com.android.webview.chromium.PlatformServiceBridgeGoogle"; + + private static PlatformServiceBridge sInstance; + + protected PlatformServiceBridge() {} + + public static PlatformServiceBridge getInstance(Context applicationContext) { + if (sInstance != null) { + return sInstance; + } + + // Try to get a specialized service bridge. + try { + Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE); + sInstance = (PlatformServiceBridge) cls.getDeclaredConstructor(Context.class) + .newInstance(applicationContext); + return sInstance; + } catch (ClassNotFoundException e) { + // This is not an error; it just means this device doesn't have specialized services. + } catch (IllegalAccessException | IllegalArgumentException | InstantiationException + | NoSuchMethodException e) { + Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + ": " + e); + } catch (InvocationTargetException e) { + Log.e(TAG, "Failed invocation to get " + PLATFORM_SERVICE_BRIDGE + ":", e.getCause()); + } + + // Otherwise, get the generic service bridge. + sInstance = new PlatformServiceBridge(); + return sInstance; + } + + public void setMetricsSettingListener(ValueCallback<Boolean> callback) {} +} |