| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/child/child_thread.h" | 5 #include "content/child/child_thread.h" |
| 6 | 6 |
| 7 #include <signal.h> | 7 #include <signal.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "content/child/service_worker/service_worker_message_filter.h" | 41 #include "content/child/service_worker/service_worker_message_filter.h" |
| 42 #include "content/child/socket_stream_dispatcher.h" | 42 #include "content/child/socket_stream_dispatcher.h" |
| 43 #include "content/child/thread_safe_sender.h" | 43 #include "content/child/thread_safe_sender.h" |
| 44 #include "content/child/websocket_dispatcher.h" | 44 #include "content/child/websocket_dispatcher.h" |
| 45 #include "content/common/child_process_messages.h" | 45 #include "content/common/child_process_messages.h" |
| 46 #include "content/public/common/content_switches.h" | 46 #include "content/public/common/content_switches.h" |
| 47 #include "ipc/ipc_logging.h" | 47 #include "ipc/ipc_logging.h" |
| 48 #include "ipc/ipc_switches.h" | 48 #include "ipc/ipc_switches.h" |
| 49 #include "ipc/ipc_sync_channel.h" | 49 #include "ipc/ipc_sync_channel.h" |
| 50 #include "ipc/ipc_sync_message_filter.h" | 50 #include "ipc/ipc_sync_message_filter.h" |
| 51 #include "ipc/mojo/ipc_channel_mojo.h" |
| 51 | 52 |
| 52 #if defined(OS_WIN) | 53 #if defined(OS_WIN) |
| 53 #include "content/common/handle_enumerator_win.h" | 54 #include "content/common/handle_enumerator_win.h" |
| 54 #endif | 55 #endif |
| 55 | 56 |
| 56 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) | 57 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) |
| 57 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" | 58 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" |
| 58 #endif | 59 #endif |
| 59 | 60 |
| 60 using tracked_objects::ThreadData; | 61 using tracked_objects::ThreadData; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 g_lazy_child_thread_cv = LAZY_INSTANCE_INITIALIZER; | 186 g_lazy_child_thread_cv = LAZY_INSTANCE_INITIALIZER; |
| 186 | 187 |
| 187 void QuitMainThreadMessageLoop() { | 188 void QuitMainThreadMessageLoop() { |
| 188 base::MessageLoop::current()->Quit(); | 189 base::MessageLoop::current()->Quit(); |
| 189 } | 190 } |
| 190 | 191 |
| 191 #endif | 192 #endif |
| 192 | 193 |
| 193 } // namespace | 194 } // namespace |
| 194 | 195 |
| 196 ChildThread::Options::Options() |
| 197 : channel_name(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 198 switches::kProcessChannelID)), |
| 199 use_mojo_channel(false) {} |
| 200 |
| 201 ChildThread::Options::Options(bool mojo) |
| 202 : channel_name(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 203 switches::kProcessChannelID)), |
| 204 use_mojo_channel(mojo) {} |
| 205 |
| 206 |
| 195 ChildThread::ChildThreadMessageRouter::ChildThreadMessageRouter( | 207 ChildThread::ChildThreadMessageRouter::ChildThreadMessageRouter( |
| 196 IPC::Sender* sender) | 208 IPC::Sender* sender) |
| 197 : sender_(sender) {} | 209 : sender_(sender) {} |
| 198 | 210 |
| 199 bool ChildThread::ChildThreadMessageRouter::Send(IPC::Message* msg) { | 211 bool ChildThread::ChildThreadMessageRouter::Send(IPC::Message* msg) { |
| 200 return sender_->Send(msg); | 212 return sender_->Send(msg); |
| 201 } | 213 } |
| 202 | 214 |
| 203 ChildThread::ChildThread() | 215 ChildThread::ChildThread() |
| 204 : router_(this), | 216 : router_(this), |
| 205 channel_connected_factory_(this), | 217 channel_connected_factory_(this), |
| 206 in_browser_process_(false) { | 218 in_browser_process_(false) { |
| 207 channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 219 Init(Options()); |
| 208 switches::kProcessChannelID); | |
| 209 Init(); | |
| 210 } | 220 } |
| 211 | 221 |
| 212 ChildThread::ChildThread(const std::string& channel_name) | 222 ChildThread::ChildThread(const Options& options) |
| 213 : channel_name_(channel_name), | 223 : router_(this), |
| 214 router_(this), | |
| 215 channel_connected_factory_(this), | 224 channel_connected_factory_(this), |
| 216 in_browser_process_(true) { | 225 in_browser_process_(true) { |
| 217 Init(); | 226 Init(options); |
| 218 } | 227 } |
| 219 | 228 |
| 220 void ChildThread::Init() { | 229 scoped_ptr<IPC::SyncChannel> ChildThread::CreateChannel(bool use_mojo_channel) { |
| 230 if (use_mojo_channel) { |
| 231 VLOG(1) << "Mojo is enabled on child"; |
| 232 return IPC::SyncChannel::Create( |
| 233 IPC::ChannelMojo::CreateFactory( |
| 234 channel_name_, |
| 235 IPC::Channel::MODE_CLIENT, |
| 236 ChildProcess::current()->io_message_loop_proxy()), |
| 237 this, |
| 238 ChildProcess::current()->io_message_loop_proxy(), |
| 239 true, |
| 240 ChildProcess::current()->GetShutDownEvent()); |
| 241 } |
| 242 |
| 243 VLOG(1) << "Mojo is disabled on child"; |
| 244 return IPC::SyncChannel::Create( |
| 245 channel_name_, |
| 246 IPC::Channel::MODE_CLIENT, |
| 247 this, |
| 248 ChildProcess::current()->io_message_loop_proxy(), |
| 249 true, |
| 250 ChildProcess::current()->GetShutDownEvent()); |
| 251 } |
| 252 |
| 253 void ChildThread::Init(const Options& options) { |
| 254 channel_name_ = options.channel_name; |
| 255 |
| 221 g_lazy_tls.Pointer()->Set(this); | 256 g_lazy_tls.Pointer()->Set(this); |
| 222 on_channel_error_called_ = false; | 257 on_channel_error_called_ = false; |
| 223 message_loop_ = base::MessageLoop::current(); | 258 message_loop_ = base::MessageLoop::current(); |
| 224 #ifdef IPC_MESSAGE_LOG_ENABLED | 259 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 225 // We must make sure to instantiate the IPC Logger *before* we create the | 260 // We must make sure to instantiate the IPC Logger *before* we create the |
| 226 // channel, otherwise we can get a callback on the IO thread which creates | 261 // channel, otherwise we can get a callback on the IO thread which creates |
| 227 // the logger, and the logger does not like being created on the IO thread. | 262 // the logger, and the logger does not like being created on the IO thread. |
| 228 IPC::Logging::GetInstance(); | 263 IPC::Logging::GetInstance(); |
| 229 #endif | 264 #endif |
| 230 channel_ = | 265 channel_ = CreateChannel(options.use_mojo_channel); |
| 231 IPC::SyncChannel::Create(channel_name_, | |
| 232 IPC::Channel::MODE_CLIENT, | |
| 233 this, | |
| 234 ChildProcess::current()->io_message_loop_proxy(), | |
| 235 true, | |
| 236 ChildProcess::current()->GetShutDownEvent()); | |
| 237 #ifdef IPC_MESSAGE_LOG_ENABLED | 266 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 238 if (!in_browser_process_) | 267 if (!in_browser_process_) |
| 239 IPC::Logging::GetInstance()->SetIPCSender(this); | 268 IPC::Logging::GetInstance()->SetIPCSender(this); |
| 240 #endif | 269 #endif |
| 241 | 270 |
| 242 mojo_application_.reset(new MojoApplication); | 271 mojo_application_.reset(new MojoApplication); |
| 243 | 272 |
| 244 sync_message_filter_ = | 273 sync_message_filter_ = |
| 245 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); | 274 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); |
| 246 thread_safe_sender_ = new ThreadSafeSender( | 275 thread_safe_sender_ = new ThreadSafeSender( |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 // inflight that would addref it. | 582 // inflight that would addref it. |
| 554 Send(new ChildProcessHostMsg_ShutdownRequest); | 583 Send(new ChildProcessHostMsg_ShutdownRequest); |
| 555 } | 584 } |
| 556 | 585 |
| 557 void ChildThread::EnsureConnected() { | 586 void ChildThread::EnsureConnected() { |
| 558 VLOG(0) << "ChildThread::EnsureConnected()"; | 587 VLOG(0) << "ChildThread::EnsureConnected()"; |
| 559 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); | 588 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); |
| 560 } | 589 } |
| 561 | 590 |
| 562 } // namespace content | 591 } // namespace content |
| OLD | NEW |