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

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java

Issue 183183011: Move atrace enabling code from Chrome to WebView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update findbugs (remove an obsolete exception rule) Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/android/java/src/org/chromium/base/TraceEvent.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java b/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java
index 6f6404aa5e21eb274bb758c0c8584b10ba71e73d..b3aa4f8a859b1ce420bf717d27fef4a4add8e98f 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java
@@ -5,18 +5,25 @@
package org.chromium.android_webview;
import android.content.Context;
+import android.os.Build;
+import android.util.Log;
import org.chromium.base.PathUtils;
import org.chromium.base.ThreadUtils;
+import org.chromium.base.TraceEvent;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.library_loader.ProcessInitException;
import org.chromium.content.browser.BrowserStartupController;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
/**
* Wrapper for the steps needed to initialize the java and native sides of webview chromium.
*/
public abstract class AwBrowserProcess {
private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "webview";
+ private static final String TAG = "AwBrowserProcess";
/**
* Loads the native library, and performs basic static construction of objects needed
@@ -27,11 +34,58 @@ public abstract class AwBrowserProcess {
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
try {
LibraryLoader.loadNow();
+ initTraceEvent();
} catch (ProcessInitException e) {
throw new RuntimeException("Cannot load WebView", e);
}
}
+ // TODO(benm): Move this function into WebView code in Android tree to avoid reflection.
+ private static void initTraceEvent() {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return;
+
+ try {
+ final Class<?> traceClass = Class.forName("android.os.Trace");
+ final long traceTagView = traceClass.getField("TRACE_TAG_WEBVIEW").getLong(null);
+
+ final Class<?> systemPropertiesClass = Class.forName("android.os.SystemProperties");
+ final Method systemPropertiesGetLongMethod = systemPropertiesClass.getDeclaredMethod(
+ "getLong", String.class, Long.TYPE);
+ final Method addChangeCallbackMethod = systemPropertiesClass.getDeclaredMethod(
+ "addChangeCallback", Runnable.class);
+
+ // Won't reach here if any of the above reflect lookups fail.
+ addChangeCallbackMethod.invoke(null, new Runnable() {
+ @Override
+ public void run() {
+ try {
+ long enabledFlags = (Long) systemPropertiesGetLongMethod.invoke(
+ null, "debug.atrace.tags.enableflags", 0);
+ TraceEvent.setATraceEnabled((enabledFlags & traceTagView) != 0);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "systemPropertyChanged", e);
+ } catch (IllegalAccessException e) {
+ Log.e(TAG, "systemPropertyChanged", e);
+ } catch (InvocationTargetException e) {
+ Log.e(TAG, "systemPropertyChanged", e);
+ }
+ }
+ });
+ } catch (ClassNotFoundException e) {
+ Log.e(TAG, "initTraceEvent", e);
+ } catch (NoSuchMethodException e) {
+ Log.e(TAG, "initTraceEvent", e);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "initTraceEvent", e);
+ } catch (IllegalAccessException e) {
+ Log.e(TAG, "initTraceEvent", e);
+ } catch (InvocationTargetException e) {
+ Log.e(TAG, "initTraceEvent", e);
+ } catch (NoSuchFieldException e) {
+ Log.e(TAG, "initTraceEvent", e);
+ }
+ }
+
/**
* Starts the chromium browser process running within this process. Creates threads
* and performs other per-app resource allocations; must not be called from zygote.
« no previous file with comments | « no previous file | base/android/java/src/org/chromium/base/TraceEvent.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698