summaryrefslogtreecommitdiffstats
path: root/chrome/common/child_thread.cc
diff options
context:
space:
mode:
authornsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-23 17:33:22 +0000
committernsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-23 17:33:22 +0000
commit9291ed107d2031cea55f324431ffee8d7bae1416 (patch)
tree5c1d8e6d992aa324f099062b0f85e3945fdfe761 /chrome/common/child_thread.cc
parentfefa8b29191ffd7730f7d3428697408bf979e6ee (diff)
downloadchromium_src-9291ed107d2031cea55f324431ffee8d7bae1416.zip
chromium_src-9291ed107d2031cea55f324431ffee8d7bae1416.tar.gz
chromium_src-9291ed107d2031cea55f324431ffee8d7bae1416.tar.bz2
Revert 21355 because it might be causing all the new
crashes on reliability. It also seems to be causing valgrind error. Original change: 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/159274 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21398 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/child_thread.cc')
-rw-r--r--chrome/common/child_thread.cc80
1 files changed, 37 insertions, 43 deletions
diff --git a/chrome/common/child_thread.cc b/chrome/common/child_thread.cc
index 9168570..1b7ef75 100644
--- a/chrome/common/child_thread.cc
+++ b/chrome/common/child_thread.cc
@@ -8,68 +8,41 @@
#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 "ipc/ipc_switches.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) {
@@ -104,7 +77,7 @@ void ChildThread::OnMessageReceived(const IPC::Message& msg) {
}
if (msg.type() == PluginProcessMsg_Shutdown::ID) {
- MessageLoop::current()->Quit();
+ owner_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask());
return;
}
@@ -116,12 +89,33 @@ void ChildThread::OnMessageReceived(const IPC::Message& msg) {
}
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;
}