| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/child_thread.h" | 5 #include "content/common/child_thread.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "content/common/child_process.h" | 10 #include "content/common/child_process.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 Init(); | 28 Init(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 ChildThread::ChildThread(const std::string& channel_name) | 31 ChildThread::ChildThread(const std::string& channel_name) |
| 32 : channel_name_(channel_name) { | 32 : channel_name_(channel_name) { |
| 33 Init(); | 33 Init(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void ChildThread::Init() { | 36 void ChildThread::Init() { |
| 37 check_with_browser_before_shutdown_ = false; | 37 check_with_browser_before_shutdown_ = false; |
| 38 is_waiting_to_shutdown_ = false; |
| 38 on_channel_error_called_ = false; | 39 on_channel_error_called_ = false; |
| 39 message_loop_ = MessageLoop::current(); | 40 message_loop_ = MessageLoop::current(); |
| 40 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserAgent)) { | 41 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserAgent)) { |
| 41 webkit_glue::SetUserAgent( | 42 webkit_glue::SetUserAgent( |
| 42 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 43 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 43 switches::kUserAgent)); | 44 switches::kUserAgent)); |
| 44 } | 45 } |
| 45 | 46 |
| 46 channel_.reset(new IPC::SyncChannel(channel_name_, | 47 channel_.reset(new IPC::SyncChannel(channel_name_, |
| 47 IPC::Channel::MODE_CLIENT, this, | 48 IPC::Channel::MODE_CLIENT, this, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 178 |
| 178 bool ChildThread::OnControlMessageReceived(const IPC::Message& msg) { | 179 bool ChildThread::OnControlMessageReceived(const IPC::Message& msg) { |
| 179 return false; | 180 return false; |
| 180 } | 181 } |
| 181 | 182 |
| 182 void ChildThread::OnAskBeforeShutdown() { | 183 void ChildThread::OnAskBeforeShutdown() { |
| 183 check_with_browser_before_shutdown_ = true; | 184 check_with_browser_before_shutdown_ = true; |
| 184 } | 185 } |
| 185 | 186 |
| 186 void ChildThread::OnShutdown() { | 187 void ChildThread::OnShutdown() { |
| 187 MessageLoop::current()->Quit(); | 188 if (is_waiting_to_shutdown_) |
| 189 MessageLoop::current()->Quit(); |
| 188 } | 190 } |
| 189 | 191 |
| 190 #if defined(IPC_MESSAGE_LOG_ENABLED) | 192 #if defined(IPC_MESSAGE_LOG_ENABLED) |
| 191 void ChildThread::OnSetIPCLoggingEnabled(bool enable) { | 193 void ChildThread::OnSetIPCLoggingEnabled(bool enable) { |
| 192 if (enable) | 194 if (enable) |
| 193 IPC::Logging::GetInstance()->Enable(); | 195 IPC::Logging::GetInstance()->Enable(); |
| 194 else | 196 else |
| 195 IPC::Logging::GetInstance()->Disable(); | 197 IPC::Logging::GetInstance()->Disable(); |
| 196 } | 198 } |
| 197 #endif // IPC_MESSAGE_LOG_ENABLED | 199 #endif // IPC_MESSAGE_LOG_ENABLED |
| 198 | 200 |
| 199 ChildThread* ChildThread::current() { | 201 ChildThread* ChildThread::current() { |
| 200 return ChildProcess::current()->main_thread(); | 202 return ChildProcess::current()->main_thread(); |
| 201 } | 203 } |
| 202 | 204 |
| 203 void ChildThread::OnProcessFinalRelease() { | 205 void ChildThread::OnProcessFinalRelease() { |
| 204 if (on_channel_error_called_ || !check_with_browser_before_shutdown_) { | 206 if (on_channel_error_called_ || !check_with_browser_before_shutdown_) { |
| 205 MessageLoop::current()->Quit(); | 207 MessageLoop::current()->Quit(); |
| 206 return; | 208 return; |
| 207 } | 209 } |
| 208 | 210 |
| 209 // The child process shutdown sequence is a request response based mechanism, | 211 // The child process shutdown sequence is a request response based mechanism, |
| 210 // where we send out an initial feeler request to the child process host | 212 // where we send out an initial feeler request to the child process host |
| 211 // instance in the browser to verify if it's ok to shutdown the child process. | 213 // instance in the browser to verify if it's ok to shutdown the child process. |
| 212 // The browser then sends back a response if it's ok to shutdown. | 214 // The browser then sends back a response if it's ok to shutdown. |
| 215 is_waiting_to_shutdown_ = true; |
| 213 Send(new ChildProcessHostMsg_ShutdownRequest); | 216 Send(new ChildProcessHostMsg_ShutdownRequest); |
| 214 } | 217 } |
| 218 |
| 219 void ChildThread::AbortProcessShutdown() { |
| 220 is_waiting_to_shutdown_ = false; |
| 221 MessageLoop::current()->CancelQuit(); |
| 222 } |
| OLD | NEW |