diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-20 22:20:20 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-20 22:20:20 +0000 |
commit | f717ea6403554cc60a5dd9312fe585cdf64a8815 (patch) | |
tree | 523186875fe4c36bcc1c6905b3da36943a174318 /chrome/common/child_thread.cc | |
parent | e74b81de4f2785b5cff5cb0cc85e76b3d434248e (diff) | |
download | chromium_src-f717ea6403554cc60a5dd9312fe585cdf64a8815.zip chromium_src-f717ea6403554cc60a5dd9312fe585cdf64a8815.tar.gz chromium_src-f717ea6403554cc60a5dd9312fe585cdf64a8815.tar.bz2 |
Switch the first thread in a child process to be the main thread, and make the IO thread be the second thread. The change is needed for plugins on mac.
Review URL: http://codereview.chromium.org/149558
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21117 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/child_thread.cc')
-rw-r--r-- | chrome/common/child_thread.cc | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/chrome/common/child_thread.cc b/chrome/common/child_thread.cc index 4c97b72..db3c4c5 100644 --- a/chrome/common/child_thread.cc +++ b/chrome/common/child_thread.cc @@ -9,19 +9,14 @@ #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" -// 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_); +ChildThread::ChildThread() + : check_with_browser_before_shutdown_(false), + message_loop_(MessageLoop::current()) { channel_name_ = WideToASCII( CommandLine::ForCurrentProcess()->GetSwitchValue( switches::kProcessChannelID)); @@ -31,17 +26,41 @@ ChildThread::ChildThread(Thread::Options options) 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 -bool ChildThread::Run() { - return StartWithOptions(options_); + // 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(); } void ChildThread::OnChannelError() { - owner_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); + MessageLoop::current()->Quit(); } bool ChildThread::Send(IPC::Message* msg) { @@ -76,7 +95,7 @@ void ChildThread::OnMessageReceived(const IPC::Message& msg) { } if (msg.type() == PluginProcessMsg_Shutdown::ID) { - owner_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); + MessageLoop::current()->Quit(); return; } @@ -88,33 +107,12 @@ void ChildThread::OnMessageReceived(const IPC::Message& msg) { } ChildThread* ChildThread::current() { - 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(); + return ChildProcess::current()->main_thread(); } void ChildThread::OnProcessFinalRelease() { if (!check_with_browser_before_shutdown_) { - owner_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); + MessageLoop::current()->Quit(); return; } |