Commit bc7fb7d7 authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

Fix crash when Background Memory metrics task is scheduled immediately.

It is scheduled with a random delay between 0ms and 59999ms. When it is
exactly 0, the delayed task is actually executed as a regular task,
and since it is scheduled just before the task that starts native,
it runs without native, causing a crash.

Moving recordMemoryUsageWithRandomDelay() to after native is initialized
fixes the issue.

https://chromium-review.googlesource.com/c/chromium/src/+/1880172 fixed
this issue incorrectly. This is a corrected version.

Bug: 1017130
Change-Id: Ia79a4c3dcf639ffc01d1eacbfe53d082419c8ed7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1884272Reviewed-by: default avatarMohamed Heikal <mheikal@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710011}
parent 31a68bd2
......@@ -129,19 +129,23 @@ public abstract class NativeBackgroundTask implements BackgroundTask {
final Runnable rescheduleRunnable) {
if (isNativeLoadedInFullBrowserMode()) {
mRunningInServiceManagerOnlyMode = false;
recordMetrics();
BackgroundTaskSchedulerExternalUma.reportNativeTaskStarted(
mTaskId, mRunningInServiceManagerOnlyMode);
recordMemoryUsageWithRandomDelay(mRunningInServiceManagerOnlyMode);
PostTask.postTask(UiThreadTaskTraits.DEFAULT, startWithNativeRunnable);
return;
}
boolean wasInServiceManagerOnlyMode = isNativeLoadedInServiceManagerOnlyMode();
mRunningInServiceManagerOnlyMode = supportsServiceManagerOnly();
recordMetrics();
BackgroundTaskSchedulerExternalUma.reportNativeTaskStarted(
mTaskId, mRunningInServiceManagerOnlyMode);
final BrowserParts parts = new EmptyBrowserParts() {
@Override
public void finishNativeInitialization() {
PostTask.postTask(UiThreadTaskTraits.DEFAULT, startWithNativeRunnable);
recordMemoryUsageWithRandomDelay(mRunningInServiceManagerOnlyMode);
}
@Override
public boolean startServiceManagerOnly() {
......@@ -257,12 +261,6 @@ public abstract class NativeBackgroundTask implements BackgroundTask {
return getBrowserStartupController().isRunningInServiceManagerMode();
}
private void recordMetrics() {
BackgroundTaskSchedulerExternalUma.reportNativeTaskStarted(
mTaskId, mRunningInServiceManagerOnlyMode);
recordMemoryUsageWithRandomDelay(mRunningInServiceManagerOnlyMode);
}
@VisibleForTesting
protected BrowserStartupController getBrowserStartupController() {
return BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment