Commit 86b10204 authored by Karolina Soltys's avatar Karolina Soltys Committed by Commit Bot

[scheduler] Migrating UI thread Handlers to PostTask.

Bug: 863341
Change-Id: I85344234e260c41c6aea326fa2d1e31ce2012c90
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1541248Reviewed-by: default avatarAlex Clarke <alexclarke@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Karolina Soltys <ksolt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#645287}
parent d7cf0afc
......@@ -10,8 +10,6 @@ import android.app.Service;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
......@@ -23,6 +21,7 @@ import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.task.PostTask;
import org.chromium.chrome.browser.banners.AppDetailsDelegate;
import org.chromium.chrome.browser.customtabs.CustomTabsConnection;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
......@@ -63,6 +62,7 @@ import org.chromium.components.download.DownloadCollectionBridge;
import org.chromium.components.signin.AccountManagerDelegate;
import org.chromium.components.signin.SystemAccountManagerDelegate;
import org.chromium.content_public.browser.RenderFrameHost;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.policy.AppRestrictionsProvider;
import org.chromium.policy.CombinedPolicyProvider;
import org.chromium.services.service_manager.InterfaceRegistry;
......@@ -97,7 +97,7 @@ public abstract class AppHooks {
* @param callback Callback that should receive the results of the AndroidEdu device check.
*/
public void checkIsAndroidEduDevice(final AndroidEduOwnerCheckCallback callback) {
new Handler(Looper.getMainLooper()).post(() -> callback.onSchoolCheckDone(false));
PostTask.postTask(UiThreadTaskTraits.DEFAULT, () -> callback.onSchoolCheckDone(false));
}
/**
......
......@@ -6,10 +6,11 @@ package org.chromium.chrome.browser.crash;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Handler;
import org.chromium.base.NonThreadSafe;
import org.chromium.base.task.PostTask;
import org.chromium.components.minidump_uploader.util.CrashReportingPermissionManager;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.net.ConnectionType;
import org.chromium.net.NetworkChangeNotifier;
......@@ -55,7 +56,7 @@ class MinidumpUploadRetry implements NetworkChangeNotifier.ConnectionTypeObserve
static void scheduleRetry(Context context, CrashReportingPermissionManager permissionManager) {
// NetworkChangeNotifier is not thread safe. We will post to UI thread
// instead since that's where it fires off notification changes.
new Handler(context.getMainLooper()).post(new Scheduler(context, permissionManager));
PostTask.postTask(UiThreadTaskTraits.DEFAULT, new Scheduler(context, permissionManager));
}
private MinidumpUploadRetry(
......
......@@ -13,12 +13,13 @@ import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.RotateDrawable;
import android.graphics.drawable.ScaleDrawable;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.Nullable;
import android.support.graphics.drawable.Animatable2Compat;
import android.support.v7.graphics.drawable.DrawableWrapper;
import org.chromium.base.task.PostTask;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import java.util.concurrent.atomic.AtomicBoolean;
/**
......@@ -151,13 +152,11 @@ public class AutoAnimatorDrawable extends DrawableWrapper {
}
private static final class AutoRestarterCompat extends Animatable2Compat.AnimationCallback {
private final Handler mHandler = new Handler(Looper.getMainLooper());
// Animatable2Compat.AnimationCallback implementation.
@Override
public void onAnimationEnd(Drawable drawable) {
if (!(drawable instanceof Animatable)) return;
mHandler.post(() -> {
PostTask.postTask(UiThreadTaskTraits.DEFAULT, () -> {
if (drawable.isVisible()) ((Animatable) drawable).start();
});
}
......
......@@ -5,13 +5,13 @@
package org.chromium.chrome.browser.init;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.task.PostTask;
import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import java.util.ArrayList;
import java.util.List;
......@@ -26,7 +26,6 @@ class NativeInitializationController {
private static final String TAG = "NativeInitializationController";
private final ChromeActivityNativeDelegate mActivityDelegate;
private final Handler mHandler;
private boolean mOnStartPending;
private boolean mOnResumePending;
......@@ -60,7 +59,6 @@ class NativeInitializationController {
* @param activityDelegate The activity delegate for the owning activity.
*/
public NativeInitializationController(ChromeActivityNativeDelegate activityDelegate) {
mHandler = new Handler(Looper.getMainLooper());
mActivityDelegate = activityDelegate;
}
......@@ -110,12 +108,9 @@ class NativeInitializationController {
// Allow the UI thread to continue its initialization - so that this call back
// doesn't block priority work on the UI thread until it's idle.
mHandler.post(new Runnable() {
@Override
public void run() {
PostTask.postTask(UiThreadTaskTraits.DEFAULT, () -> {
if (mActivityDelegate.isActivityFinishingOrDestroyed()) return;
mActivityDelegate.onCreateWithNative();
}
});
}
}
......
......@@ -9,8 +9,6 @@ import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
......@@ -24,11 +22,13 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.ObserverList;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.task.PostTask;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.omaha.UpdateStatusProvider.UpdateInteractionSource;
import org.chromium.chrome.browser.omaha.UpdateStatusProvider.UpdateState;
import org.chromium.chrome.browser.omaha.UpdateStatusProvider.UpdateStatus;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.content_public.browser.UiThreadTaskTraits;
/**
* Contains logic related to displaying app menu badge and a special menu item for information
......@@ -118,8 +118,6 @@ public class UpdateMenuItemHelper {
private final ObserverList<Runnable> mObservers = new ObserverList<>();
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final Callback<UpdateStatusProvider.UpdateStatus> mUpdateCallback = status -> {
mStatus = status;
handleStateChanged();
......@@ -159,7 +157,7 @@ public class UpdateMenuItemHelper {
if (!mObservers.addObserver(observer)) return;
if (mStatus != null) {
mHandler.post(() -> {
PostTask.postTask(UiThreadTaskTraits.DEFAULT, () -> {
if (mObservers.hasObserver(observer)) observer.run();
});
return;
......
......@@ -10,8 +10,6 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.StatFs;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
......@@ -32,11 +30,13 @@ import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.task.AsyncTask;
import org.chromium.base.task.AsyncTask.Status;
import org.chromium.base.task.PostTask;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.omaha.inline.InlineUpdateController;
import org.chromium.chrome.browser.omaha.inline.InlineUpdateControllerFactory;
import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
import org.chromium.chrome.browser.util.ConversionUtils;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import java.io.File;
import java.lang.annotation.Retention;
......@@ -131,7 +131,6 @@ public class UpdateStatusProvider implements ActivityStateListener {
}
}
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final ObserverList<Callback<UpdateStatus>> mObservers = new ObserverList<>();
private final InlineUpdateController mInlineController;
......@@ -160,7 +159,7 @@ public class UpdateStatusProvider implements ActivityStateListener {
mObservers.addObserver(observer);
if (mStatus != null) {
mHandler.post(() -> observer.onResult(mStatus));
PostTask.postTask(UiThreadTaskTraits.DEFAULT, () -> observer.onResult(mStatus));
} else {
if (mOmahaQuery.getStatus() == Status.PENDING) {
mOmahaQuery.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
......@@ -324,7 +323,6 @@ public class UpdateStatusProvider implements ActivityStateListener {
}
private static final class UpdateQuery extends AsyncTask<UpdateStatus> {
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final Context mContext = ContextUtils.getApplicationContext();
private final Runnable mCallback;
......@@ -348,7 +346,7 @@ public class UpdateStatusProvider implements ActivityStateListener {
@Override
protected void onPostExecute(UpdateStatus result) {
mStatus = result;
mHandler.post(mCallback);
PostTask.postTask(UiThreadTaskTraits.DEFAULT, mCallback);
}
private UpdateStatus getTestStatus() {
......
......@@ -16,7 +16,9 @@ import com.google.android.play.core.install.model.AppUpdateType;
import com.google.android.play.core.tasks.Task;
import org.chromium.base.ContextUtils;
import org.chromium.base.task.PostTask;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.ui.widget.Toast;
import java.lang.annotation.Retention;
......@@ -149,7 +151,6 @@ public class FakeAppUpdateManagerWrapper extends FakeAppUpdateManager {
}
}
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final @Type int mType;
private final EventHandler mEventHandler;
......@@ -185,7 +186,7 @@ public class FakeAppUpdateManagerWrapper extends FakeAppUpdateManager {
resultCode = Activity.RESULT_OK;
}
mHandler.postDelayed(() -> {
PostTask.postDelayedTask(UiThreadTaskTraits.DEFAULT, () -> {
triggerDialogResponse((ChromeActivity) activity, requestCode, resultCode);
}, STEP_DELAY_MS);
......
......@@ -5,11 +5,11 @@
package org.chromium.chrome.browser.omaha.inline;
import android.app.Activity;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.Nullable;
import org.chromium.base.task.PostTask;
import org.chromium.chrome.browser.omaha.UpdateStatusProvider;
import org.chromium.content_public.browser.UiThreadTaskTraits;
/**
* An update controller that does nothing. This is used if the inline update experiment has
......@@ -18,7 +18,7 @@ import org.chromium.chrome.browser.omaha.UpdateStatusProvider;
class NoopInlineUpdateController implements InlineUpdateController {
NoopInlineUpdateController(Runnable callback) {
// Do a one-off post since the state will never change.
new Handler(Looper.getMainLooper()).post(callback);
PostTask.postTask(UiThreadTaskTraits.DEFAULT, callback);
}
@Override
......
......@@ -6,8 +6,6 @@ package org.chromium.chrome.browser.omaha.inline;
import android.app.Activity;
import android.content.IntentSender.SendIntentException;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
......@@ -82,8 +80,6 @@ public class PlayInlineUpdateController
private static final int RESULT_IN_APP_UPDATE_FAILED = 1;
private static final int REQUEST_CODE = 8123;
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final Runnable mCallback;
private final AppUpdateManager mAppUpdateManager;
......
......@@ -7,17 +7,17 @@ package org.chromium.chrome.browser.upgrade;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.ContextUtils;
import org.chromium.base.task.PostTask;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.tabmodel.DocumentModeAssassin;
import org.chromium.chrome.browser.tabmodel.DocumentModeAssassin.DocumentModeAssassinObserver;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.content_public.browser.UiThreadTaskTraits;
/**
* Activity that interrupts launch and shows that users are being upgraded to a new version of
......@@ -32,7 +32,6 @@ public class UpgradeActivity extends AppCompatActivity {
private static final long MIN_MS_TO_DISPLAY_ACTIVITY = 3000;
private static final long INVALID_TIMESTAMP = -1;
private final Handler mHandler;
private final DocumentModeAssassinObserver mObserver;
private Intent mIntentToFireAfterUpgrade;
......@@ -49,8 +48,6 @@ public class UpgradeActivity extends AppCompatActivity {
}
public UpgradeActivity() {
mHandler = new Handler(Looper.getMainLooper());
mObserver = new DocumentModeAssassinObserver() {
@Override
public void onStageChange(int newStage) {
......@@ -61,12 +58,8 @@ public class UpgradeActivity extends AppCompatActivity {
// while other Observers are being alerted.
long msElapsed = System.currentTimeMillis() - mStartTimestamp;
long msRemaining = Math.max(0, MIN_MS_TO_DISPLAY_ACTIVITY - msElapsed);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
continueApplicationLaunch();
}
}, msRemaining);
PostTask.postDelayedTask(UiThreadTaskTraits.DEFAULT,
() -> { continueApplicationLaunch(); }, msRemaining);
}
};
}
......
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