0

Javaless Renderer: Avoid unnecessary JNI for background startup tracing

In our move towards a renderer without Java, we need to remove existing
usages of Java from the renderer.

getBackgroundStartupTracingFlag is always false outside of the browser
process, so this should have no net effect.

Bug: 391360180
Change-Id: I8b10b729e346ef4f50110d7578a5799a48ad9c6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6227233
Auto-Submit: Sam Maier <smaier@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Etienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1415702}
This commit is contained in:
Sam Maier
2025-02-04 11:20:14 -08:00
committed by Chromium LUCI CQ
parent e95dcc93f5
commit 02058471c8
3 changed files with 11 additions and 4 deletions

@ -109,7 +109,7 @@ static void JNI_EarlyTraceEvent_RecordEarlyAsyncEndEvent(JNIEnv* env,
perfetto::Track(static_cast<uint64_t>(id)));
}
bool GetBackgroundStartupTracingFlag() {
bool GetBackgroundStartupTracingFlagFromJava() {
JNIEnv* env = jni_zero::AttachCurrentThread();
return base::android::Java_EarlyTraceEvent_getBackgroundStartupTracingFlag(
env);

@ -12,7 +12,7 @@ namespace android {
// Returns true if background startup tracing flag was set on the previous
// startup.
BASE_EXPORT bool GetBackgroundStartupTracingFlag();
BASE_EXPORT bool GetBackgroundStartupTracingFlagFromJava();
// Sets a flag to chrome application preferences to enable startup tracing next
// time the app is started.

@ -328,8 +328,15 @@ bool TraceStartupConfig::EnableFromConfigFile() {
bool TraceStartupConfig::EnableFromBackgroundTracing() {
bool enabled = false;
#if BUILDFLAG(IS_ANDROID)
// Tests can enable this value.
enabled |= base::android::GetBackgroundStartupTracingFlag();
// We only enable background startup tracing in the browser process. We must
// avoid calling JNI in the renderer process - see crbug.com/391360180.
// kProcessType is hardcoded ("type") as we cannot depend on content/.
if (base::CommandLine::ForCurrentProcess()
->GetSwitchValueASCII("type")
.empty()) {
// Tests can enable this value.
enabled |= base::android::GetBackgroundStartupTracingFlagFromJava();
}
#else
// TODO(ssid): Implement saving setting to preference for next startup.
#endif