| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 : sender_(sender) {} | 198 : sender_(sender) {} |
| 198 | 199 |
| 199 bool ChildThread::ChildThreadMessageRouter::Send(IPC::Message* msg) { | 200 bool ChildThread::ChildThreadMessageRouter::Send(IPC::Message* msg) { |
| 200 return sender_->Send(msg); | 201 return sender_->Send(msg); |
| 201 } | 202 } |
| 202 | 203 |
| 203 ChildThread::ChildThread() | 204 ChildThread::ChildThread() |
| 204 : router_(this), | 205 : router_(this), |
| 205 channel_connected_factory_(this), | 206 channel_connected_factory_(this), |
| 206 in_browser_process_(false) { | 207 in_browser_process_(false) { |
| 207 channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 208 InitOptions options; |
| 209 options.channel_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 208 switches::kProcessChannelID); | 210 switches::kProcessChannelID); |
| 209 Init(); | 211 Init(options); |
| 210 } | 212 } |
| 211 | 213 |
| 212 ChildThread::ChildThread(const std::string& channel_name) | 214 ChildThread::ChildThread(const InitOptions& options) |
| 213 : channel_name_(channel_name), | 215 : router_(this), |
| 214 router_(this), | |
| 215 channel_connected_factory_(this), | 216 channel_connected_factory_(this), |
| 216 in_browser_process_(true) { | 217 in_browser_process_(true) { |
| 217 Init(); | 218 Init(options); |
| 218 } | 219 } |
| 219 | 220 |
| 220 void ChildThread::Init() { | 221 scoped_ptr<IPC::SyncChannel> ChildThread::CreateChannel(bool use_mojo_channel) { |
| 222 if (use_mojo_channel) { |
| 223 VLOG(1) << "Mojo is enabled on child"; |
| 224 return IPC::SyncChannel::Create( |
| 225 IPC::ChannelMojo::CreateBuilder( |
| 226 channel_name_, |
| 227 IPC::Channel::MODE_CLIENT, |
| 228 ChildProcess::current()->io_message_loop_proxy()), |
| 229 this, |
| 230 ChildProcess::current()->io_message_loop_proxy(), |
| 231 true, |
| 232 ChildProcess::current()->GetShutDownEvent()); |
| 233 } else { |
| 234 VLOG(1) << "Mojo is disabled on child"; |
| 235 return IPC::SyncChannel::Create( |
| 236 channel_name_, |
| 237 IPC::Channel::MODE_CLIENT, |
| 238 this, |
| 239 ChildProcess::current()->io_message_loop_proxy(), |
| 240 true, |
| 241 ChildProcess::current()->GetShutDownEvent()); |
| 242 } |
| 243 } |
| 244 |
| 245 void ChildThread::Init(const InitOptions& options) { |
| 246 channel_name_ = options.channel_name; |
| 247 |
| 221 g_lazy_tls.Pointer()->Set(this); | 248 g_lazy_tls.Pointer()->Set(this); |
| 222 on_channel_error_called_ = false; | 249 on_channel_error_called_ = false; |
| 223 message_loop_ = base::MessageLoop::current(); | 250 message_loop_ = base::MessageLoop::current(); |
| 224 #ifdef IPC_MESSAGE_LOG_ENABLED | 251 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 225 // We must make sure to instantiate the IPC Logger *before* we create the | 252 // 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 | 253 // 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. | 254 // the logger, and the logger does not like being created on the IO thread. |
| 228 IPC::Logging::GetInstance(); | 255 IPC::Logging::GetInstance(); |
| 229 #endif | 256 #endif |
| 230 channel_ = | 257 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 | 258 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 238 if (!in_browser_process_) | 259 if (!in_browser_process_) |
| 239 IPC::Logging::GetInstance()->SetIPCSender(this); | 260 IPC::Logging::GetInstance()->SetIPCSender(this); |
| 240 #endif | 261 #endif |
| 241 | 262 |
| 242 mojo_application_.reset(new MojoApplication); | 263 mojo_application_.reset(new MojoApplication); |
| 243 | 264 |
| 244 sync_message_filter_ = | 265 sync_message_filter_ = |
| 245 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); | 266 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); |
| 246 thread_safe_sender_ = new ThreadSafeSender( | 267 thread_safe_sender_ = new ThreadSafeSender( |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 base::MessageLoop::current()->SetTimerSlack(timer_slack); | 589 base::MessageLoop::current()->SetTimerSlack(timer_slack); |
| 569 | 590 |
| 570 #ifdef OS_WIN | 591 #ifdef OS_WIN |
| 571 // Windows Vista+ has a fancy process backgrounding mode that can only be set | 592 // Windows Vista+ has a fancy process backgrounding mode that can only be set |
| 572 // from within the process. | 593 // from within the process. |
| 573 base::Process::Current().SetProcessBackgrounded(background); | 594 base::Process::Current().SetProcessBackgrounded(background); |
| 574 #endif // OS_WIN | 595 #endif // OS_WIN |
| 575 } | 596 } |
| 576 | 597 |
| 577 } // namespace content | 598 } // namespace content |
| OLD | NEW |