Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(619)

Issue 772123002: [Android] Java Bridge: handle requests from Java Script on the background thread (Closed)

Created:
6 years ago by mnaganov (inactive)
Modified:
6 years ago
Reviewers:
benm (inactive), Sami
CC:
chromium-reviews, darin-cc_chromium.org, jam
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Project:
chromium
Visibility:
Public.

Description

[Android] Java Bridge: handle requests from Java Script on the background thread This allows the page code that calls into injected objects methods to run even if the browser UI thread is blocked (in WebView, the browser UI thread is the main app thread, and sometimes people use synchronization primitives there that wait on some action performed by the injected object, see the bug for an example). In this CL, we make the minimal required amount of changes in order to simplify cherry-picking into older branches. A cleanup CL (or CLs) will follow. High-level description of changes: 1. We intercept messages from renderers on the IO thread using BrowserMessageFilter and handle Java Bridge messages entirely on the background thread. This implies the following changes: 2. GinJavaBridgeDispatcherHost has become RefCountedThreadSafe (via BrowserMessageFilter) 3. We have to use route IDs of RenderFrameHosts instead of pointers to them, as we can't access RFHs from IO or background threads. 4. Objects registry is now accessed from UI and background threads, and we have to use locking. We can't anymore restrict access to the registry to a single thread. This also means we can't anymore implement the registry using IDMap, as it is explicitly non-thread-safe. 5. A lot of code was removed, as we now serve synchronous requests from renderers without inter-thread hopping! 6. Of course, a new regression test has been added that now passes. BUG=438255 Committed: https://crrev.com/a4b0d4cc0b9780aecd3e23a94293b2e3002baf7e Cr-Commit-Position: refs/heads/master@{#307460}

Patch Set 1 #

Patch Set 2 : Fixed AwJavaBridgeTest.testDestroyFromJavaObject and FindBugs warning #

Patch Set 3 : Fix causes for test crashes #

Patch Set 4 : Fixed remaining crashes, added 2 WebViews test, made it pass #

Total comments: 8

Patch Set 5 : Comments addressed, removed reliance on the Notifications service, added one more test #

Patch Set 6 : Add the filter in more places, and make sure that the channel is present #

Total comments: 2

Patch Set 7 : Addressed benm's comment #

Total comments: 12

Patch Set 8 : Addressed Sami's comments #

Total comments: 4

Patch Set 9 : Addressed more Sami's comments #

Messages

Total messages: 21 (3 generated)
mnaganov (inactive)
6 years ago (2014-12-02 17:00:14 UTC) #2
mnaganov (inactive)
Ben, PTAL! Now your test should pass :)
6 years ago (2014-12-03 16:11:15 UTC) #3
mnaganov (inactive)
On 2014/12/03 16:11:15, mnaganov (cr) wrote: > Ben, PTAL! Now your test should pass :) ...
6 years ago (2014-12-04 11:36:22 UTC) #4
mnaganov (inactive)
On 2014/12/04 11:36:22, mnaganov (cr) wrote: > On 2014/12/03 16:11:15, mnaganov (cr) wrote: > > ...
6 years ago (2014-12-04 14:32:45 UTC) #5
mnaganov (inactive)
On 2014/12/04 14:32:45, mnaganov (cr) wrote: > On 2014/12/04 11:36:22, mnaganov (cr) wrote: > > ...
6 years ago (2014-12-04 18:15:21 UTC) #6
benm (inactive)
Thanks Mikhail, overall this sounds good to me. Just a couple of questions and documentation ...
6 years ago (2014-12-05 17:09:33 UTC) #7
mnaganov (inactive)
Thank, Ben! When testing this version in a system WebView, I have discovered an issue ...
6 years ago (2014-12-05 18:07:40 UTC) #8
benm (inactive)
lgtm % extra docs https://codereview.chromium.org/772123002/diff/100001/content/browser/android/java/gin_java_bridge_dispatcher_host.h File content/browser/android/java/gin_java_bridge_dispatcher_host.h (right): https://codereview.chromium.org/772123002/diff/100001/content/browser/android/java/gin_java_bridge_dispatcher_host.h#newcode76 content/browser/android/java/gin_java_bridge_dispatcher_host.h:76: void TryAddingBrowserFilter(); can you document ...
6 years ago (2014-12-08 15:45:03 UTC) #9
mnaganov (inactive)
https://codereview.chromium.org/772123002/diff/100001/content/browser/android/java/gin_java_bridge_dispatcher_host.h File content/browser/android/java/gin_java_bridge_dispatcher_host.h (right): https://codereview.chromium.org/772123002/diff/100001/content/browser/android/java/gin_java_bridge_dispatcher_host.h#newcode76 content/browser/android/java/gin_java_bridge_dispatcher_host.h:76: void TryAddingBrowserFilter(); On 2014/12/08 15:45:03, benm wrote: > can ...
6 years ago (2014-12-08 16:14:04 UTC) #10
benm (inactive)
lgtm
6 years ago (2014-12-08 16:16:40 UTC) #11
mnaganov (inactive)
Sami, can you please take a look at content/browser/android. The essence of the change is ...
6 years ago (2014-12-08 16:17:57 UTC) #13
Sami
https://codereview.chromium.org/772123002/diff/120001/content/browser/android/java/gin_java_bound_object.h File content/browser/android/java/gin_java_bound_object.h (right): https://codereview.chromium.org/772123002/diff/120001/content/browser/android/java/gin_java_bound_object.h#newcode65 content/browser/android/java/gin_java_bound_object.h:65: const std::set<int32> holders); nit: Could this be a const ...
6 years ago (2014-12-08 18:52:31 UTC) #14
mnaganov (inactive)
https://codereview.chromium.org/772123002/diff/120001/content/browser/android/java/gin_java_bound_object.h File content/browser/android/java/gin_java_bound_object.h (right): https://codereview.chromium.org/772123002/diff/120001/content/browser/android/java/gin_java_bound_object.h#newcode65 content/browser/android/java/gin_java_bound_object.h:65: const std::set<int32> holders); On 2014/12/08 18:52:31, Sami wrote: > ...
6 years ago (2014-12-09 10:23:55 UTC) #15
Sami
Thanks Mikhail. lgtm, although I had one DCHECK suggestion. https://codereview.chromium.org/772123002/diff/140001/content/browser/android/java/gin_java_bridge_dispatcher_host.cc File content/browser/android/java/gin_java_bridge_dispatcher_host.cc (right): https://codereview.chromium.org/772123002/diff/140001/content/browser/android/java/gin_java_bridge_dispatcher_host.cc#newcode382 content/browser/android/java/gin_java_bridge_dispatcher_host.cc:382: ...
6 years ago (2014-12-09 11:33:51 UTC) #16
mnaganov (inactive)
Thanks, Sami! https://codereview.chromium.org/772123002/diff/140001/content/browser/android/java/gin_java_bridge_dispatcher_host.cc File content/browser/android/java/gin_java_bridge_dispatcher_host.cc (right): https://codereview.chromium.org/772123002/diff/140001/content/browser/android/java/gin_java_bridge_dispatcher_host.cc#newcode382 content/browser/android/java/gin_java_bridge_dispatcher_host.cc:382: int GinJavaBridgeDispatcherHost::GetCurrentRoutingID() { On 2014/12/09 11:33:51, Sami ...
6 years ago (2014-12-09 12:37:11 UTC) #17
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/772123002/160001
6 years ago (2014-12-09 12:39:41 UTC) #19
commit-bot: I haz the power
Committed patchset #9 (id:160001)
6 years ago (2014-12-09 13:30:17 UTC) #20
commit-bot: I haz the power
6 years ago (2014-12-09 13:31:17 UTC) #21
Message was sent while issue was closed.
Patchset 9 (id:??) landed as
https://crrev.com/a4b0d4cc0b9780aecd3e23a94293b2e3002baf7e
Cr-Commit-Position: refs/heads/master@{#307460}

Powered by Google App Engine
This is Rietveld 408576698