Index: content/browser/renderer_host/java/java_bridge_dispatcher_host.cc |
diff --git a/content/browser/renderer_host/java/java_bridge_dispatcher_host.cc b/content/browser/renderer_host/java/java_bridge_dispatcher_host.cc |
index 51335e092418918cef8988adc1ab8b4b3d4d4642..d07dd3b9ca1cd9334f81ced0dd72eb7b964b57ee 100644 |
--- a/content/browser/renderer_host/java/java_bridge_dispatcher_host.cc |
+++ b/content/browser/renderer_host/java/java_bridge_dispatcher_host.cc |
@@ -5,7 +5,8 @@ |
#include "content/browser/renderer_host/java/java_bridge_dispatcher_host.h" |
#include "base/bind.h" |
-#include "content/browser/renderer_host/browser_render_process_host.h" |
+#include "base/lazy_instance.h" |
+#include "base/threading/thread.h" |
#include "content/browser/renderer_host/java/java_bridge_channel_host.h" |
#include "content/browser/renderer_host/render_view_host.h" |
#include "content/common/child_process.h" |
@@ -17,6 +18,19 @@ |
using content::BrowserThread; |
+namespace { |
+struct ThreadLazyInstanceTraits |
+ : public base::DefaultLazyInstanceTraits<base::Thread> { |
+ static base::Thread* New(void* instance) { |
+ base::Thread* thread = new (instance) base::Thread("Java Bridge"); |
joth
2011/12/09 16:26:09
nit: "JavaBridge"
some tools may not be so smart w
Steve Block
2011/12/09 17:36:27
Done.
|
+ thread->Start(); |
+ return thread; |
+ } |
+}; |
joth
2011/12/09 16:26:09
my own preference would be to make your own Thread
Steve Block
2011/12/09 17:36:27
Done.
|
+base::LazyInstance<base::Thread, ThreadLazyInstanceTraits> g_background_thread = |
+ LAZY_INSTANCE_INITIALIZER; |
joth
2011/12/09 16:26:09
I wasn't clear in my previous comment, but lazy in
Steve Block
2011/12/09 17:36:27
re AtExitManager - yes, the JavaBridge should be g
|
+} // namespace |
+ |
JavaBridgeDispatcherHost::JavaBridgeDispatcherHost( |
RenderViewHost* render_view_host) |
: RenderViewHostObserver(render_view_host), |
@@ -62,13 +76,7 @@ bool JavaBridgeDispatcherHost::OnMessageReceived(const IPC::Message& msg) { |
} |
void JavaBridgeDispatcherHost::OnGetChannelHandle(IPC::Message* reply_msg) { |
- if (RenderProcessHost::run_renderer_in_process()) { |
- // TODO(steveblock): Fix Java Bridge with in-process renderer. See |
- // http://code.google.com/p/chromium/issues/detail?id=106838 |
- CHECK(false) << "Java Bridge does not support in-process renderer"; |
- } |
- BrowserThread::PostTask( |
- BrowserThread::WEBKIT, |
+ g_background_thread.Get().message_loop()->PostTask( |
FROM_HERE, |
base::Bind(&JavaBridgeDispatcherHost::GetChannelHandle, this, reply_msg)); |
} |
@@ -85,11 +93,11 @@ void JavaBridgeDispatcherHost::GetChannelHandle(IPC::Message* reply_msg) { |
void JavaBridgeDispatcherHost::CreateNPVariantParam(NPObject* object, |
NPVariant_Param* param) { |
- // The JavaBridgeChannelHost needs to be created on the WEBKIT thread, as |
+ // The JavaBridgeChannelHost needs to be created on the background thread, as |
// that is where Java objects will live, and CreateNPVariantParam() needs the |
// channel to create the NPObjectStub. To avoid blocking here until the |
// channel is ready, create the NPVariant_Param by hand, then post a message |
- // to the WEBKIT thread to set up the channel and create the corresponding |
+ // to the background thread to set up the channel and create the corresponding |
// NPObjectStub. Post that message before doing any IPC, to make sure that |
// the channel and object proxies are ready before responses are received |
// from the renderer. |
@@ -101,8 +109,7 @@ void JavaBridgeDispatcherHost::CreateNPVariantParam(NPObject* object, |
param->npobject_routing_id = route_id; |
WebKit::WebBindings::retainObject(object); |
- BrowserThread::PostTask( |
- BrowserThread::WEBKIT, |
+ g_background_thread.Get().message_loop()->PostTask( |
FROM_HERE, |
base::Bind(&JavaBridgeDispatcherHost::CreateObjectStub, this, object, |
route_id)); |
@@ -110,8 +117,7 @@ void JavaBridgeDispatcherHost::CreateNPVariantParam(NPObject* object, |
void JavaBridgeDispatcherHost::CreateObjectStub(NPObject* object, |
int route_id) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
- |
+ DCHECK_EQ(g_background_thread.Get().message_loop(), MessageLoop::current()); |
if (!channel_) { |
channel_ = JavaBridgeChannelHost::GetJavaBridgeChannelHost( |
render_view_host()->process()->id(), |