Bug 1624675 - Don't post on UI thread if already on the UI thread. r=snorp

Differential Revision: https://phabricator.services.mozilla.com/D68434

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Agi Sferro 2020-03-27 21:20:19 +00:00
Родитель 6f962cb12a
Коммит acf3564168
11 изменённых файлов: 36 добавлений и 25 удалений

Просмотреть файл

@ -147,7 +147,7 @@ public class AndroidGamepadManager {
@WrapForJNI
private static void start(final Context context) {
ThreadUtils.postToUiThread(new Runnable() {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
doStart(context);
@ -166,7 +166,7 @@ public class AndroidGamepadManager {
@WrapForJNI
private static void stop(final Context context) {
ThreadUtils.postToUiThread(new Runnable() {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
doStop(context);
@ -186,7 +186,7 @@ public class AndroidGamepadManager {
@WrapForJNI
private static void onGamepadAdded(final int deviceId, final int serviceId) {
ThreadUtils.postToUiThread(new Runnable() {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
handleGamepadAdded(deviceId, serviceId);

Просмотреть файл

@ -1674,7 +1674,7 @@ public class GeckoAppShell {
@WrapForJNI(calledFrom = "gecko")
private static void enableNetworkNotifications() {
ThreadUtils.postToUiThread(new Runnable() {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
GeckoNetworkManager.getInstance().enableNotifications();
@ -1684,7 +1684,7 @@ public class GeckoAppShell {
@WrapForJNI(calledFrom = "gecko")
private static void disableNetworkNotifications() {
ThreadUtils.postToUiThread(new Runnable() {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
GeckoNetworkManager.getInstance().disableNotifications();

Просмотреть файл

@ -204,7 +204,7 @@ public class GeckoScreenOrientation {
if (ThreadUtils.isOnUiThread()) {
notifier.run();
} else {
ThreadUtils.postToUiThread(notifier);
ThreadUtils.runOnUiThread(notifier);
}
}

Просмотреть файл

@ -132,7 +132,7 @@ public class PermissionBlock {
}
if (mOnUiThread && !ThreadUtils.isOnUiThread()) {
ThreadUtils.postToUiThread(runnable);
ThreadUtils.runOnUiThread(runnable);
} else if (mOnBackgroundThread && !ThreadUtils.isOnBackgroundThread()) {
ThreadUtils.postToBackgroundThread(runnable);
} else {

Просмотреть файл

@ -83,7 +83,7 @@ public class GeckoServiceChildProcess extends Service {
final int crashAnnotationFd = crashAnnotationPfd != null ?
crashAnnotationPfd.detachFd() : -1;
ThreadUtils.postToUiThread(new Runnable() {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
if (crashHandlerService != null) {

Просмотреть файл

@ -90,6 +90,22 @@ public final class ThreadUtils {
return sUiHandler;
}
/**
* Runs the provided runnable on the UI thread. If this method is called on the UI thread
* the runnable will be executed synchronously.
*
* @param runnable the runnable to be executed.
*/
public static void runOnUiThread(final Runnable runnable) {
// We're on the UI thread already, let's just run this
if (isOnUiThread()) {
runnable.run();
return;
}
postToUiThread(runnable);
}
public static void postToUiThread(final Runnable runnable) {
sUiHandler.post(runnable);
}

Просмотреть файл

@ -1486,7 +1486,7 @@ import android.view.inputmethod.EditorInfo;
assertOnIcThread();
}
ThreadUtils.postToUiThread(new Runnable() {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
if (DEBUG) {
@ -1624,7 +1624,7 @@ import android.view.inputmethod.EditorInfo;
// mSoftInputReentrancyGuard is needed to ensure that between the different paths,
// the soft input is only toggled exactly once.
ThreadUtils.postToUiThread(new Runnable() {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
final int reentrancyGuard = mSoftInputReentrancyGuard.decrementAndGet();

Просмотреть файл

@ -450,7 +450,7 @@ import java.lang.reflect.Proxy;
@Override // SessionTextInput.EditableListener
public void onDefaultKeyEvent(final KeyEvent event) {
ThreadUtils.postToUiThread(new Runnable() {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
GeckoInputConnection.this.performDefaultKeyAction(event);

Просмотреть файл

@ -204,7 +204,7 @@ public final class GeckoRuntime implements Parcelable {
final URI actual = URI.create(baseUrl).resolve(url);
GeckoResult<String> result = new GeckoResult<>();
// perform the onOpenWindow call in the UI thread
ThreadUtils.postToUiThread(() -> {
ThreadUtils.runOnUiThread(() -> {
sRuntime
.mServiceWorkerDelegate
.onOpenWindow(actual.toString())
@ -672,9 +672,9 @@ public final class GeckoRuntime implements Parcelable {
}
@WrapForJNI
@UiThread
@AnyThread
private void notifyOnShow(final WebNotification notification) {
ThreadUtils.getUiHandler().post(() -> {
ThreadUtils.runOnUiThread(() -> {
if (mNotificationDelegate != null) {
mNotificationDelegate.onShowNotification(notification);
}
@ -682,9 +682,9 @@ public final class GeckoRuntime implements Parcelable {
}
@WrapForJNI
@UiThread
@AnyThread
private void notifyOnClose(final WebNotification notification) {
ThreadUtils.getUiHandler().post(() -> {
ThreadUtils.runOnUiThread(() -> {
if (mNotificationDelegate != null) {
mNotificationDelegate.onCloseNotification(notification);
}

Просмотреть файл

@ -1667,7 +1667,7 @@ public class GeckoSession implements Parcelable {
final GeckoResult<AllowOrDeny> result = new GeckoResult<>();
ThreadUtils.getUiHandler().post(() -> {
ThreadUtils.runOnUiThread(() -> {
final GeckoResult<AllowOrDeny> delegateResult =
delegate.onLoadRequest(this, request);
@ -1998,7 +1998,7 @@ public class GeckoSession implements Parcelable {
mEventDispatcher.dispatch("GeckoView:FlushSessionState", null);
}
ThreadUtils.postToUiThread(
ThreadUtils.runOnUiThread(
() -> getAutofillSupport().onActiveChanged(active)
);
}
@ -5637,12 +5637,7 @@ public class GeckoSession implements Parcelable {
// Delay calling onCompositorReady to avoid deadlock due
// to synchronous call to the compositor.
ThreadUtils.postToUiThread(new Runnable() {
@Override
public void run() {
onCompositorReady();
}
});
ThreadUtils.postToUiThread(this::onCompositorReady);
break;
}

Просмотреть файл

@ -970,7 +970,7 @@ public class SessionAccessibility {
@WrapForJNI(calledFrom = "gecko", stubName = "SendEvent")
private void sendEventNative(final int eventType, final int sourceId, final int className, final GeckoBundle eventData) {
ThreadUtils.postToUiThread(new Runnable() {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
sendEvent(eventType, sourceId, className, eventData);