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

Side by Side Diff: content/browser/renderer_host/java/java_bridge_dispatcher_host.cc

Issue 8890018: Update Java Bridge to use its own thread in the browser process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host.h" 5 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/browser/renderer_host/browser_render_process_host.h" 8 #include "content/browser/renderer_host/browser_render_process_host.h"
9 #include "content/browser/renderer_host/java/java_bridge_channel_host.h" 9 #include "content/browser/renderer_host/java/java_bridge_channel_host.h"
10 #include "content/browser/renderer_host/render_view_host.h" 10 #include "content/browser/renderer_host/render_view_host.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 bool handled = true; 55 bool handled = true;
56 IPC_BEGIN_MESSAGE_MAP(JavaBridgeDispatcherHost, msg) 56 IPC_BEGIN_MESSAGE_MAP(JavaBridgeDispatcherHost, msg)
57 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle, 57 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
58 OnGetChannelHandle) 58 OnGetChannelHandle)
59 IPC_MESSAGE_UNHANDLED(handled = false) 59 IPC_MESSAGE_UNHANDLED(handled = false)
60 IPC_END_MESSAGE_MAP() 60 IPC_END_MESSAGE_MAP()
61 return handled; 61 return handled;
62 } 62 }
63 63
64 void JavaBridgeDispatcherHost::OnGetChannelHandle(IPC::Message* reply_msg) { 64 void JavaBridgeDispatcherHost::OnGetChannelHandle(IPC::Message* reply_msg) {
65 // In renderer-in-process mode, this sync IPC is coming from the WEBKIT 65 BrowserThread::PostTask(
66 // thread, so we can't post to the WEBKIT thread. 66 BrowserThread::JAVA_BRIDGE,
67 if (RenderProcessHost::run_renderer_in_process()) { 67 FROM_HERE,
68 GetChannelHandle(reply_msg); 68 base::Bind(&JavaBridgeDispatcherHost::GetChannelHandle, this,
69 } else { 69 reply_msg));
70 BrowserThread::PostTask(
71 BrowserThread::WEBKIT,
72 FROM_HERE,
73 base::Bind(&JavaBridgeDispatcherHost::GetChannelHandle, this,
74 reply_msg));
75 }
76 } 70 }
77 71
78 void JavaBridgeDispatcherHost::GetChannelHandle(IPC::Message* reply_msg) { 72 void JavaBridgeDispatcherHost::GetChannelHandle(IPC::Message* reply_msg) {
79 // The channel creates the channel handle based on the renderer ID we passed 73 // The channel creates the channel handle based on the renderer ID we passed
80 // to GetJavaBridgeChannelHost() and, on POSIX, the file descriptor used by 74 // to GetJavaBridgeChannelHost() and, on POSIX, the file descriptor used by
81 // the underlying channel. 75 // the underlying channel.
82 JavaBridgeHostMsg_GetChannelHandle::WriteReplyParams( 76 JavaBridgeHostMsg_GetChannelHandle::WriteReplyParams(
83 reply_msg, 77 reply_msg,
84 channel_->channel_handle()); 78 channel_->channel_handle());
85 Send(reply_msg); 79 Send(reply_msg);
86 } 80 }
87 81
88 void JavaBridgeDispatcherHost::CreateNPVariantParam(NPObject* object, 82 void JavaBridgeDispatcherHost::CreateNPVariantParam(NPObject* object,
89 NPVariant_Param* param) { 83 NPVariant_Param* param) {
90 // The JavaBridgeChannelHost needs to be created on the WEBKIT thread, as 84 // The JavaBridgeChannelHost needs to be created on the JAVA_BRIDGE thread, as
91 // that is where Java objects will live, and CreateNPVariantParam() needs the 85 // that is where Java objects will live, and CreateNPVariantParam() needs the
92 // channel to create the NPObjectStub. To avoid blocking here until the 86 // channel to create the NPObjectStub. To avoid blocking here until the
93 // channel is ready, create the NPVariant_Param by hand, then post a message 87 // channel is ready, create the NPVariant_Param by hand, then post a message
94 // to the WEBKIT thread to set up the channel and create the corresponding 88 // to the JAVA_BRIDGE thread to set up the channel and create the
95 // NPObjectStub. Post that message before doing any IPC, to make sure that 89 // corresponding NPObjectStub. Post that message before doing any IPC, to
96 // the channel and object proxies are ready before responses are received 90 // make sure that the channel and object proxies are ready before responses
97 // from the renderer. 91 // are received from the renderer.
98 92
99 // Create an NPVariantParam suitable for serialization over IPC from our 93 // Create an NPVariantParam suitable for serialization over IPC from our
100 // NPVariant. See CreateNPVariantParam() in npobject_utils. 94 // NPVariant. See CreateNPVariantParam() in npobject_utils.
101 param->type = NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID; 95 param->type = NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID;
102 int route_id = JavaBridgeChannelHost::ThreadsafeGenerateRouteID(); 96 int route_id = JavaBridgeChannelHost::ThreadsafeGenerateRouteID();
103 param->npobject_routing_id = route_id; 97 param->npobject_routing_id = route_id;
104 98
105 WebKit::WebBindings::retainObject(object); 99 WebKit::WebBindings::retainObject(object);
106 BrowserThread::PostTask( 100 BrowserThread::PostTask(
107 BrowserThread::WEBKIT, 101 BrowserThread::JAVA_BRIDGE,
108 FROM_HERE, 102 FROM_HERE,
109 base::Bind(&JavaBridgeDispatcherHost::CreateObjectStub, this, object, 103 base::Bind(&JavaBridgeDispatcherHost::CreateObjectStub, this, object,
110 route_id)); 104 route_id));
111 } 105 }
112 106
113 void JavaBridgeDispatcherHost::CreateObjectStub(NPObject* object, 107 void JavaBridgeDispatcherHost::CreateObjectStub(NPObject* object,
114 int route_id) { 108 int route_id) {
115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::JAVA_BRIDGE));
116 110
117 if (!channel_) { 111 if (!channel_) {
118 channel_ = JavaBridgeChannelHost::GetJavaBridgeChannelHost( 112 channel_ = JavaBridgeChannelHost::GetJavaBridgeChannelHost(
119 render_view_host()->process()->id(), 113 render_view_host()->process()->id(),
120 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); 114 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
121 } 115 }
122 116
123 // We don't need the containing window or the page URL, as we don't do 117 // We don't need the containing window or the page URL, as we don't do
124 // re-entrant sync IPC. 118 // re-entrant sync IPC.
125 new NPObjectStub(object, channel_, route_id, 0, GURL()); 119 new NPObjectStub(object, channel_, route_id, 0, GURL());
126 // The NPObjectStub takes a reference to the NPObject. Release the ref added 120 // The NPObjectStub takes a reference to the NPObject. Release the ref added
127 // in CreateNPVariantParam(). 121 // in CreateNPVariantParam().
128 WebKit::WebBindings::releaseObject(object); 122 WebKit::WebBindings::releaseObject(object);
129 } 123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698