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

Issue 8834013: Fix a race condition in the Java Bridge when adding objects (Closed)

Created:
9 years ago by Steve Block
Modified:
9 years ago
Reviewers:
joth, jam
CC:
chromium-reviews, joi+watch-content_chromium.org, darin-cc_chromium.org, jam, dpranke-watch+content_chromium.org
Visibility:
Public.

Description

Fix a race condition in the Java Bridge when adding objects JavaBridgeDispatcherHost::AddNamedObject() currently has a race condition, as it posts to the WEBKIT thread before sending the injected object to the renderer. See bug for details. To fix this, JavaBridgeDispatcherHost::AddNamedObject() now creates the NPVariant_Param synchronously, and immediately sends this to the renderer. This requires use of a route ID generator which is shared with the JavaBridgeChannelHost. Creation of the JavaBridgeChannelHost and the corresponding NPObjectStub is done asynchronously on the WEBKIT thread. This means that the channel handle is not available when the Java Bridge is first initialized in the renderer. To overcome this, the renderer obtains it from the browser with a new sync IPC call. - RenderViewImpl - OnJavaBridgeInit() no longer supplies a channel handle. - JavaBridgeDispatcher - Lazily gets channel handle from browser. - JavaBridgeDispatcherHost - Now a RVH obsever to provide channel handle. Uses shared route ID generator to synchronously create the NPVariant_Param when a new object is injected. Creates the JavaBridgeChannelHost and the corresponding NPObjectStub asynchronously on the WEBKIT thread. - JavaBridgeChannelHost - Shares a route ID generator with the JavaBridgeDispatcherHost. BUG=106691 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=113802

Patch Set 1 #

Patch Set 2 : Fix typo #

Total comments: 9

Patch Set 3 : Make route ID generator a plain static method #

Patch Set 4 : Fixed rebase #

Total comments: 6

Patch Set 5 : Fixed nits #

Total comments: 9
Unified diffs Side-by-side diffs Delta from patch set Stats (+149 lines, -63 lines) Patch
M content/browser/renderer_host/java/java_bridge_channel_host.h View 1 2 2 chunks +10 lines, -1 line 0 comments Download
M content/browser/renderer_host/java/java_bridge_channel_host.cc View 1 2 3 chunks +10 lines, -3 lines 2 comments Download
M content/browser/renderer_host/java/java_bridge_dispatcher_host.h View 1 2 2 chunks +22 lines, -5 lines 4 comments Download
M content/browser/renderer_host/java/java_bridge_dispatcher_host.cc View 1 2 3 4 4 chunks +82 lines, -44 lines 3 comments Download
M content/common/java_bridge_messages.h View 1 2 3 4 2 chunks +5 lines, -2 lines 0 comments Download
M content/renderer/java/java_bridge_dispatcher.h View 2 chunks +3 lines, -2 lines 0 comments Download
M content/renderer/java/java_bridge_dispatcher.cc View 1 2 3 4 2 chunks +14 lines, -2 lines 0 comments Download
M content/renderer/render_view_impl.h View 1 chunk +1 line, -1 line 0 comments Download
M content/renderer/render_view_impl.cc View 1 chunk +2 lines, -3 lines 0 comments Download

Messages

Total messages: 8 (0 generated)
Steve Block
9 years ago (2011-12-07 13:17:54 UTC) #1
joth
couple quick comments. I don't think I quite understood the comment in the CL description ...
9 years ago (2011-12-07 14:49:07 UTC) #2
Steve Block
http://codereview.chromium.org/8834013/diff/1001/content/browser/renderer_host/java/java_bridge_channel_host.cc File content/browser/renderer_host/java/java_bridge_channel_host.cc (right): http://codereview.chromium.org/8834013/diff/1001/content/browser/renderer_host/java/java_bridge_channel_host.cc#newcode28 content/browser/renderer_host/java/java_bridge_channel_host.cc:28: static base::subtle::AtomicWord last_id = 0; On 2011/12/07 14:49:09, joth ...
9 years ago (2011-12-07 16:47:44 UTC) #3
jam
don't have the java code in my head atm, I defer to joth for that. ...
9 years ago (2011-12-07 22:07:03 UTC) #4
Steve Block
http://codereview.chromium.org/8834013/diff/9003/content/browser/renderer_host/java/java_bridge_dispatcher_host.cc File content/browser/renderer_host/java/java_bridge_dispatcher_host.cc (right): http://codereview.chromium.org/8834013/diff/9003/content/browser/renderer_host/java/java_bridge_dispatcher_host.cc#newcode23 content/browser/renderer_host/java/java_bridge_dispatcher_host.cc:23: , is_renderer_initialized_(false) { On 2011/12/07 22:07:03, John Abd-El-Malek wrote: ...
9 years ago (2011-12-08 11:17:56 UTC) #5
Steve Block
http://codereview.chromium.org/8834013/diff/16001/content/browser/renderer_host/java/java_bridge_dispatcher_host.cc File content/browser/renderer_host/java/java_bridge_dispatcher_host.cc (right): http://codereview.chromium.org/8834013/diff/16001/content/browser/renderer_host/java/java_bridge_dispatcher_host.cc#newcode67 content/browser/renderer_host/java/java_bridge_dispatcher_host.cc:67: if (RenderProcessHost::run_renderer_in_process()) { Given the ongoing discussion about renderer-in-process ...
9 years ago (2011-12-08 13:46:03 UTC) #6
joth
LGTM http://codereview.chromium.org/8834013/diff/16001/content/browser/renderer_host/java/java_bridge_channel_host.cc File content/browser/renderer_host/java/java_bridge_channel_host.cc (right): http://codereview.chromium.org/8834013/diff/16001/content/browser/renderer_host/java/java_bridge_channel_host.cc#newcode46 content/browser/renderer_host/java/java_bridge_channel_host.cc:46: return base::subtle::Barrier_AtomicIncrement(&g_last_id, 1); I'll stick my head out ...
9 years ago (2011-12-08 18:15:45 UTC) #7
Steve Block
9 years ago (2011-12-09 12:27:31 UTC) #8
http://codereview.chromium.org/8834013/diff/16001/content/browser/renderer_ho...
File content/browser/renderer_host/java/java_bridge_channel_host.cc (right):

http://codereview.chromium.org/8834013/diff/16001/content/browser/renderer_ho...
content/browser/renderer_host/java/java_bridge_channel_host.cc:46: return
base::subtle::Barrier_AtomicIncrement(&g_last_id, 1);
On 2011/12/08 18:15:46, joth wrote:
> I'll stick my head out and say NoBarrier is fine here. (It generally is for
> sequence numbers; see AtomicSequenceNumber)
> 
> you _could_ use AtomicSequenceNumber. But then you'd need a LazyInstance.
Which
> would then re-insert the (half) memory barrier on each access. :-)

Done.

http://codereview.chromium.org/8834013/diff/16001/content/browser/renderer_ho...
File content/browser/renderer_host/java/java_bridge_dispatcher_host.cc (right):

http://codereview.chromium.org/8834013/diff/16001/content/browser/renderer_ho...
content/browser/renderer_host/java/java_bridge_dispatcher_host.cc:67: if
(RenderProcessHost::run_renderer_in_process()) {
Added a TODO.

http://codereview.chromium.org/8834013/diff/16001/content/browser/renderer_ho...
File content/browser/renderer_host/java/java_bridge_dispatcher_host.h (right):

http://codereview.chromium.org/8834013/diff/16001/content/browser/renderer_ho...
content/browser/renderer_host/java/java_bridge_dispatcher_host.h:19: typedef
_NPVariant NPVariant;
On 2011/12/08 18:15:46, joth wrote:
> these two not needed? (_NPVariant & NPVariant)

Done.

http://codereview.chromium.org/8834013/diff/16001/content/browser/renderer_ho...
content/browser/renderer_host/java/java_bridge_dispatcher_host.h:27: public
base::RefCountedThreadSafe<JavaBridgeDispatcherHost> {
On 2011/12/08 18:15:46, joth wrote:
> nit: I *think* we tend to put ABCs before interfaces. (not that it's always
that
> clear)

Done.

Powered by Google App Engine
This is Rietveld 408576698