Closed Bug 1063120 Opened 10 years ago Closed 10 years ago

HelperApps.jsm can get stuck in the event loop

Categories

(Firefox for Android Graveyard :: General, defect)

All
Android
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 35

People

(Reporter: jchen, Assigned: jchen)

References

Details

Attachments

(2 files)

HelperApps.jsm includes a synchronous call [1] that sends a message to Java and waits for the response by spinning the event loop. However, spinning the event loop this way is not very reliable, as we can end up waiting for more events even after our event has run. The result is that the call ends up taking much longer than needed, up to several hundred milliseconds.

[1] http://mxr.mozilla.org/mozilla-central/source/mobile/android/modules/HelperApps.jsm#207
Add a JNI method that notifys Gecko observers on the main thread, outside of the event loop.
Attachment #8486640 - Flags: review?(snorp)
If we are on the Gecko thread already and we are responding to JS, we should repond synchronously. This avoids the need to spinning the event loop in some cases, which doesn't work reliably.
Attachment #8486645 - Flags: review?(bnicholson)
Comment on attachment 8486640 [details] [diff] [review]
Add synchronous method to notify Gecko observer (v1)

Review of attachment 8486640 [details] [diff] [review]:
-----------------------------------------------------------------

looks good with nits

::: mobile/android/base/GeckoAppShell.java
@@ +448,5 @@
>      // Tell the Gecko event loop that an event is available.
>      public static native void notifyGeckoOfEvent(GeckoEvent event);
>  
> +    // Synchronously notify a Gecko observer; must be called from Gecko thread.
> +    public static native void notifyGeckoObserver(String subject, String data);

Can we call it notifyObservers? Seems redundant to put Gecko in there. And the nsIObserver method is pluralized.
Attachment #8486640 - Flags: review?(snorp) → review+
Comment on attachment 8486645 [details] [diff] [review]
Synchronously respond to Gecko requests if running on Gecko thread (v1)

Review of attachment 8486645 [details] [diff] [review]:
-----------------------------------------------------------------

I guess we need to be careful to avoid situations where
1) Gecko issues a request,
2) the Java-side listener fires a broadcast message inside the request handler,
3) the Gecko-side request callback assumes the message from #2 has been handled.
Attachment #8486645 - Flags: review?(bnicholson) → review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/19598e50a751
https://hg.mozilla.org/integration/mozilla-inbound/rev/986e8a9f6195

(In reply to James Willcox (:snorp) (jwillcox@mozilla.com) from comment #3)
> Comment on attachment 8486640 [details] [diff] [review]
> Add synchronous method to notify Gecko observer (v1)
> 
> Can we call it notifyObservers? Seems redundant to put Gecko in there. And
> the nsIObserver method is pluralized.

I kept "Gecko" to remind people that it's for the Gecko thread only.

(In reply to Brian Nicholson (:bnicholson) from comment #4)
> Comment on attachment 8486645 [details] [diff] [review]
> Synchronously respond to Gecko requests if running on Gecko thread (v1)
> 
> Review of attachment 8486645 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> I guess we need to be careful to avoid situations where
> 1) Gecko issues a request,
> 2) the Java-side listener fires a broadcast message inside the request
> handler,
> 3) the Gecko-side request callback assumes the message from #2 has been
> handled.

True. I don't think we want this behavior in any case though; we should combine the two broadcasts in one.
https://hg.mozilla.org/mozilla-central/rev/19598e50a751
https://hg.mozilla.org/mozilla-central/rev/986e8a9f6195
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 35
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: