Closed Bug 1474618 Opened 6 years ago Closed 6 years ago

Change GeckoResult dispatch behavior to allow for synchronous ops on UI thread

Categories

(GeckoView :: General, defect, P1)

59 Branch
defect

Tracking

(firefox-esr52 wontfix, firefox-esr60 wontfix, firefox61 wontfix, firefox62 fixed, firefox63 fixed)

RESOLVED FIXED
mozilla63
Tracking Status
firefox-esr52 --- wontfix
firefox-esr60 --- wontfix
firefox61 --- wontfix
firefox62 --- fixed
firefox63 --- fixed

People

(Reporter: snorp, Assigned: snorp)

Details

(Whiteboard: [geckoview:klar:p1])

Attachments

(1 file)

Right now Focus calls saveState() from a background thread. It then waits for that to complete on the UI thread with a CountDownLatch. With the change to GeckoResult that isn't possible anymore because GeckoResult always dispatches listeners on the UI thread -- which is blocked waiting on the CountDownLatch.

The easiest solution is to change GeckoResult to dispatch on the thread where the result was created. I think this also may be closer to what app developers expect.
Comment on attachment 8991035 [details]
Bug 1474618 - Dispatch GeckoResult listeners on thread where we were created

https://reviewboard.mozilla.org/r/256026/#review262870

::: mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoResult.java:32
(Diff revision 1)
>      /**
>       * This constructs an incomplete GeckoResult. Call {@link #complete(Object)} or
>       * {@link #completeExceptionally(Throwable)} in order to fulfill the result.
>       */
>      public GeckoResult() {
> +        mHandler = new Handler();

I think we may want to cache these in a static map at some point, but we're not creating GeckoResults at a rate where it will matter yet.
Comment on attachment 8991035 [details]
Bug 1474618 - Dispatch GeckoResult listeners on thread where we were created

https://reviewboard.mozilla.org/r/256026/#review262924

LGTM
Attachment #8991035 - Flags: review?(droeh) → review+
Assignee: nobody → snorp
Priority: -- → P1
Comment on attachment 8991035 [details]
Bug 1474618 - Dispatch GeckoResult listeners on thread where we were created

https://reviewboard.mozilla.org/r/256026/#review263426

::: mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoResult.java:32
(Diff revision 1)
>      /**
>       * This constructs an incomplete GeckoResult. Call {@link #complete(Object)} or
>       * {@link #completeExceptionally(Throwable)} in order to fulfill the result.
>       */
>      public GeckoResult() {
> +        mHandler = new Handler();

I think we should at least check the most common case of the UI thread and use `ThreadUtils.sUiThread` in that case.

::: mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoResult.java:32
(Diff revision 1)
>      /**
>       * This constructs an incomplete GeckoResult. Call {@link #complete(Object)} or
>       * {@link #completeExceptionally(Throwable)} in order to fulfill the result.
>       */
>      public GeckoResult() {
> +        mHandler = new Handler();

Now that callbacks are no longer guaranteed on the UI thread, we should assert in `GeckoSession`'s `then` callbacks that we're on the UI thread because those callbacks still expect the UI thread.
Attachment #8991035 - Flags: review?(nchen) → review+
[geckoview:klar:p1] because this is a Focus+GV blocker.
Whiteboard: [geckoview:klar:p1]
Pushed by jwillcox@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/58c3113b9020
Dispatch GeckoResult listeners on thread where we were created r=jchen,droeh
https://hg.mozilla.org/mozilla-central/rev/58c3113b9020
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 63
Comment on attachment 8991035 [details]
Bug 1474618 - Dispatch GeckoResult listeners on thread where we were created

Approval Request Comment
[Feature/Bug causing the regression]: GeckoView
[User impact if declined]: Unable to save state in Focus
[Is this code covered by automated tests?]: Yes
[Has the fix been verified in Nightly?]: Yes
[Needs manual test from QE? If yes, steps to reproduce]: No
[List of other uplifts needed for the feature/fix]: None
[Is the change risky?]: No
[Why is the change risky/not risky?]: Only affects GeckoView
[String changes made/needed]: None
Attachment #8991035 - Flags: approval-mozilla-beta?
Comment on attachment 8991035 [details]
Bug 1474618 - Dispatch GeckoResult listeners on thread where we were created

Geckoview only change, let's uplift to beta.
Attachment #8991035 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Product: Firefox for Android → GeckoView
Version: Firefox 59 → 59 Branch
Target Milestone: Firefox 63 → mozilla63
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: