diff options
author | wangxianzhu@chromium.org <wangxianzhu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-11 10:57:38 +0000 |
---|---|---|
committer | wangxianzhu@chromium.org <wangxianzhu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-11 10:57:38 +0000 |
commit | 4c062e6ece5d5795e85a5de581a53e2ac78ed785 (patch) | |
tree | 5b31758dabae521653f401dac3ff7421c817f69a /android_webview | |
parent | 6995685584d436f5a2397791a42338c9535bb9bb (diff) | |
download | chromium_src-4c062e6ece5d5795e85a5de581a53e2ac78ed785.zip chromium_src-4c062e6ece5d5795e85a5de581a53e2ac78ed785.tar.gz chromium_src-4c062e6ece5d5795e85a5de581a53e2ac78ed785.tar.bz2 |
Move atrace enabling code from Chrome to WebView
According to discussions, we decided to disable atrace for Chrome
because of the inaccuracy of timing in the trace due to the overhead
of atrace.
As WebView still needs atrace, move the atrace enabling code into
AwBrowserProcess.
BUG=trace-viewer:454 (https://code.google.com/p/trace-viewer/issues/detail?id=454)
Review URL: https://codereview.chromium.org/183183011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256186 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r-- | android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java | 54 |
1 files changed, 54 insertions, 0 deletions
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 6f6404a..b3aa4f8 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. |