diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-23 00:25:06 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-23 00:25:06 +0000 |
commit | f784592cd075d7866c74e410833768c8b6f9b622 (patch) | |
tree | 8512d6dc402faef8df803c7ff07ba5b77eecda3f /chrome/common/child_thread.cc | |
parent | a63f220009f90657fc1070d4a9bde26726deb6b4 (diff) | |
download | chromium_src-f784592cd075d7866c74e410833768c8b6f9b622.zip chromium_src-f784592cd075d7866c74e410833768c8b6f9b622.tar.gz chromium_src-f784592cd075d7866c74e410833768c8b6f9b622.tar.bz2 |
Switch the first thread in a child process to be the main thread, and make theIO thread be the second thread. The change is needed for plugins on mac.
Review URL: http://codereview.chromium.org/155944
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21355 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/child_thread.cc')
-rw-r--r-- | chrome/common/child_thread.cc | 80 |
1 files changed, 43 insertions, 37 deletions
diff --git a/chrome/common/child_thread.cc b/chrome/common/child_thread.cc index 15a98b3..e2f7c5f 100644 --- a/chrome/common/child_thread.cc +++ b/chrome/common/child_thread.cc @@ -8,40 +8,67 @@ #include "base/command_line.h" #include "chrome/common/child_process.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/notification_service.h" #include "chrome/common/plugin_messages.h" #include "ipc/ipc_logging.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() { 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 -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 +103,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 +115,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; } |