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

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

Issue 1474483004: WebView Metrics client implementation (Chromium part) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.android_webview;
6
7 import android.content.Context;
8 import android.webkit.ValueCallback;
9
10 import org.chromium.base.Log;
11 import org.chromium.base.annotations.JNINamespace;
12
13 import java.lang.reflect.InvocationTargetException;
14
15 /**
16 * Java twin of the homonymous C++ class. The Java side is only responsible for
17 * switching metrics on and off. Since the setting is a platform feature, it
18 * must be obtained through PlatformServiceBridge.
19 */
20 @JNINamespace("android_webview")
21 public class AwMetricsServiceClient {
22 private static final String TAG = "AwMetricsServiceCli-";
sgurun-gerrit only 2015/12/11 00:06:45 "AwMetricsServiceClient"
paulmiller 2015/12/18 00:15:49 I'd prefer that too, but there's a length limit.
23 private static final String GMAIL = "com.google.android.gm";
sgurun-gerrit only 2015/12/11 00:06:46 let's move this logic to the bridge
paulmiller 2015/12/18 00:15:49 Are you sure? The Gmail detection is specific to M
24 private static final String PLATFORM_SERVICE_BRIDGE =
25 "com.android.webview.chromium.PlatformServiceBridgeGoogle";
26
27 private PlatformServiceBridge mPlatformServiceBridge;
28
29 public AwMetricsServiceClient(Context applicationContext) {
30 mPlatformServiceBridge = getPlatformServiceBridge(applicationContext);
31
32 mPlatformServiceBridge.setMetricsSettingListener(new ValueCallback<Boole an>() {
33 public void onReceiveValue(Boolean enabled) {
34 nativeSetMetricsEnabled(enabled.booleanValue());
35 }
36 });
37 }
38
39 private static PlatformServiceBridge getPlatformServiceBridge(Context applic ationContext) {
40 // If this is gmail, try to get the Google service bridge.
41 if (GMAIL.equals(applicationContext.getPackageName())) {
sgurun-gerrit only 2015/12/11 00:06:46 same, move this to the bridge.
42 try {
43 Class<?> cls = Class.forName(PLATFORM_SERVICE_BRIDGE);
44 return (PlatformServiceBridge) cls.getDeclaredConstructor(Contex t.class)
45 .newInstance(applicationContext);
46 } catch (InvocationTargetException e) {
47 Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + " (invoc ation):",
sgurun-gerrit only 2015/12/11 00:06:46 not an error. This is actually a reasonable state
paulmiller 2015/12/18 00:15:50 I think that'll actually be a ClassNotFoundExcepti
48 e.getCause());
49 } catch (Exception e) {
sgurun-gerrit only 2015/12/11 00:06:45 I don't think you can put a blanket exception here
paulmiller 2015/12/18 00:15:49 fixed
50 Log.e(TAG, "Failed to get " + PLATFORM_SERVICE_BRIDGE + ":", e);
sgurun-gerrit only 2015/12/11 00:06:46 rather than repeating the Log.e, use a boolean to
paulmiller 2015/12/18 00:15:49 But I want to log InvocationTargetException differ
51 }
52 }
53
54 // If this is not gmail or getting the preferred service
55 // bridge failed, get the generic service bridge.
sgurun-gerrit only 2015/12/11 00:06:46 remove the gmail comment.
paulmiller 2015/12/18 00:15:49 fixed
56 return new PlatformServiceBridge();
57 }
58
59 public static native void nativeSetMetricsEnabled(boolean enabled);
60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698