Index: chrome/common/child_thread.cc |
=================================================================== |
--- chrome/common/child_thread.cc (revision 21215) |
+++ chrome/common/child_thread.cc (working copy) |
@@ -9,66 +9,39 @@ |
#include "chrome/common/child_process.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/ipc_logging.h" |
-#include "chrome/common/notification_service.h" |
#include "chrome/common/plugin_messages.h" |
#include "webkit/glue/webkit_glue.h" |
-ChildThread::ChildThread() { |
+// V8 needs a 1MB stack size. |
+const size_t ChildThread::kV8StackSize = 1024 * 1024; |
+ |
+ChildThread::ChildThread(Thread::Options options) |
+ : Thread("Chrome_ChildThread"), |
+ owner_loop_(MessageLoop::current()), |
+ options_(options), |
+ check_with_browser_before_shutdown_(false) { |
+ DCHECK(owner_loop_); |
channel_name_ = WideToASCII( |
CommandLine::ForCurrentProcess()->GetSwitchValue( |
switches::kProcessChannelID)); |
- Init(); |
-} |
-ChildThread::ChildThread(const std::string channel_name) |
- : channel_name_(channel_name) { |
- Init(); |
-} |
- |
-void ChildThread::Init() { |
- check_with_browser_before_shutdown_ = false; |
- message_loop_ = MessageLoop::current(); |
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserAgent)) { |
webkit_glue::SetUserAgent(WideToUTF8( |
CommandLine::ForCurrentProcess()->GetSwitchValue( |
switches::kUserAgent))); |
} |
- |
- channel_.reset(new IPC::SyncChannel(channel_name_, |
- IPC::Channel::MODE_CLIENT, this, NULL, |
- ChildProcess::current()->io_message_loop(), true, |
- ChildProcess::current()->GetShutDownEvent())); |
-#ifdef IPC_MESSAGE_LOG_ENABLED |
- IPC::Logging::current()->SetIPCSender(this); |
-#endif |
- |
- resource_dispatcher_.reset(new ResourceDispatcher(this)); |
- |
- // When running in unit tests, there is already a NotificationService object. |
- // Since only one can exist at a time per thread, check first. |
- if (!NotificationService::current()) |
- notification_service_.reset(new NotificationService); |
} |
ChildThread::~ChildThread() { |
-#ifdef IPC_MESSAGE_LOG_ENABLED |
- IPC::Logging::current()->SetIPCSender(NULL); |
-#endif |
+} |
- // The ChannelProxy object caches a pointer to the IPC thread, so need to |
- // reset it as it's not guaranteed to outlive this object. |
- // NOTE: this also has the side-effect of not closing the main IPC channel to |
- // the browser process. This is needed because this is the signal that the |
- // browser uses to know that this process has died, so we need it to be alive |
- // until this process is shut down, and the OS closes the handle |
- // automatically. We used to watch the object handle on Windows to do this, |
- // but it wasn't possible to do so on POSIX. |
- channel_->ClearIPCMessageLoop(); |
+bool ChildThread::Run() { |
+ return StartWithOptions(options_); |
} |
void ChildThread::OnChannelError() { |
- MessageLoop::current()->Quit(); |
+ owner_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
} |
bool ChildThread::Send(IPC::Message* msg) { |
@@ -103,7 +76,7 @@ |
} |
if (msg.type() == PluginProcessMsg_Shutdown::ID) { |
- MessageLoop::current()->Quit(); |
+ owner_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
return; |
} |
@@ -115,12 +88,33 @@ |
} |
ChildThread* ChildThread::current() { |
- return ChildProcess::current()->main_thread(); |
+ return ChildProcess::current()->child_thread(); |
} |
+void ChildThread::Init() { |
+ channel_.reset(new IPC::SyncChannel(channel_name_, |
+ IPC::Channel::MODE_CLIENT, this, NULL, owner_loop_, true, |
+ ChildProcess::current()->GetShutDownEvent())); |
+#ifdef IPC_MESSAGE_LOG_ENABLED |
+ IPC::Logging::current()->SetIPCSender(this); |
+#endif |
+ |
+ resource_dispatcher_.reset(new ResourceDispatcher(this)); |
+} |
+ |
+void ChildThread::CleanUp() { |
+#ifdef IPC_MESSAGE_LOG_ENABLED |
+ IPC::Logging::current()->SetIPCSender(NULL); |
+#endif |
+ // Need to destruct the SyncChannel to the browser before we go away because |
+ // it caches a pointer to this thread. |
+ channel_.reset(); |
+ resource_dispatcher_.reset(); |
+} |
+ |
void ChildThread::OnProcessFinalRelease() { |
if (!check_with_browser_before_shutdown_) { |
- MessageLoop::current()->Quit(); |
+ owner_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
return; |
} |