Chromium Code Reviews| 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 "base/allocator/allocator_extension.h" | 7 #include "base/allocator/allocator_extension.h" |
| 8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 | 126 |
| 127 void QuitMainThreadMessageLoop() { | 127 void QuitMainThreadMessageLoop() { |
| 128 base::MessageLoop::current()->Quit(); | 128 base::MessageLoop::current()->Quit(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 #endif | 131 #endif |
| 132 | 132 |
| 133 } // namespace | 133 } // namespace |
| 134 | 134 |
| 135 ChildThread::ChildThread() | 135 ChildThread::ChildThread() |
| 136 : channel_connected_factory_(this) { | 136 : channel_connected_factory_(this), |
| 137 in_browser_process_(false) { | |
| 137 channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 138 channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 138 switches::kProcessChannelID); | 139 switches::kProcessChannelID); |
| 139 Init(); | 140 Init(); |
| 140 } | 141 } |
| 141 | 142 |
| 142 ChildThread::ChildThread(const std::string& channel_name) | 143 ChildThread::ChildThread(const std::string& channel_name) |
| 143 : channel_name_(channel_name), | 144 : channel_name_(channel_name), |
| 144 channel_connected_factory_(this) { | 145 channel_connected_factory_(this), |
| 146 in_browser_process_(true) { | |
| 145 Init(); | 147 Init(); |
| 146 } | 148 } |
| 147 | 149 |
| 148 void ChildThread::Init() { | 150 void ChildThread::Init() { |
| 149 g_lazy_tls.Pointer()->Set(this); | 151 g_lazy_tls.Pointer()->Set(this); |
| 150 on_channel_error_called_ = false; | 152 on_channel_error_called_ = false; |
| 151 message_loop_ = base::MessageLoop::current(); | 153 message_loop_ = base::MessageLoop::current(); |
| 152 #ifdef IPC_MESSAGE_LOG_ENABLED | 154 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 153 // We must make sure to instantiate the IPC Logger *before* we create the | 155 // We must make sure to instantiate the IPC Logger *before* we create the |
| 154 // channel, otherwise we can get a callback on the IO thread which creates | 156 // channel, otherwise we can get a callback on the IO thread which creates |
| 155 // the logger, and the logger does not like being created on the IO thread. | 157 // the logger, and the logger does not like being created on the IO thread. |
| 156 IPC::Logging::GetInstance(); | 158 IPC::Logging::GetInstance(); |
| 157 #endif | 159 #endif |
| 158 channel_.reset( | 160 channel_.reset( |
| 159 new IPC::SyncChannel(channel_name_, | 161 new IPC::SyncChannel(channel_name_, |
| 160 IPC::Channel::MODE_CLIENT, | 162 IPC::Channel::MODE_CLIENT, |
| 161 this, | 163 this, |
| 162 ChildProcess::current()->io_message_loop_proxy(), | 164 ChildProcess::current()->io_message_loop_proxy(), |
| 163 true, | 165 true, |
| 164 ChildProcess::current()->GetShutDownEvent())); | 166 ChildProcess::current()->GetShutDownEvent())); |
| 165 #ifdef IPC_MESSAGE_LOG_ENABLED | 167 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 166 IPC::Logging::GetInstance()->SetIPCSender(this); | 168 if (!in_browser_process_) |
| 169 IPC::Logging::GetInstance()->SetIPCSender(this); | |
| 167 #endif | 170 #endif |
| 168 | 171 |
| 169 sync_message_filter_ = | 172 sync_message_filter_ = |
| 170 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); | 173 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); |
| 171 thread_safe_sender_ = new ThreadSafeSender( | 174 thread_safe_sender_ = new ThreadSafeSender( |
| 172 base::MessageLoopProxy::current().get(), sync_message_filter_.get()); | 175 base::MessageLoopProxy::current().get(), sync_message_filter_.get()); |
| 173 | 176 |
| 174 resource_dispatcher_.reset(new ResourceDispatcher(this)); | 177 resource_dispatcher_.reset(new ResourceDispatcher(this)); |
| 175 socket_stream_dispatcher_.reset(new SocketStreamDispatcher()); | 178 socket_stream_dispatcher_.reset(new SocketStreamDispatcher()); |
| 176 websocket_dispatcher_.reset(new WebSocketDispatcher); | 179 websocket_dispatcher_.reset(new WebSocketDispatcher); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 void ChildThread::OnChannelConnected(int32 peer_pid) { | 280 void ChildThread::OnChannelConnected(int32 peer_pid) { |
| 278 channel_connected_factory_.InvalidateWeakPtrs(); | 281 channel_connected_factory_.InvalidateWeakPtrs(); |
| 279 } | 282 } |
| 280 | 283 |
| 281 void ChildThread::OnChannelError() { | 284 void ChildThread::OnChannelError() { |
| 282 set_on_channel_error_called(true); | 285 set_on_channel_error_called(true); |
| 283 base::MessageLoop::current()->Quit(); | 286 base::MessageLoop::current()->Quit(); |
| 284 } | 287 } |
| 285 | 288 |
| 286 bool ChildThread::Send(IPC::Message* msg) { | 289 bool ChildThread::Send(IPC::Message* msg) { |
| 287 DCHECK(base::MessageLoop::current() == message_loop()); | 290 DCHECK(in_browser_process_ || base::MessageLoop::current() == message_loop()); |
|
jam
2013/10/24 16:49:04
why is this needed?
| |
| 288 if (!channel_) { | 291 if (!channel_) { |
| 289 delete msg; | 292 delete msg; |
| 290 return false; | 293 return false; |
| 291 } | 294 } |
| 292 | 295 |
| 293 return channel_->Send(msg); | 296 return channel_->Send(msg); |
| 294 } | 297 } |
| 295 | 298 |
| 296 void ChildThread::AddRoute(int32 routing_id, IPC::Listener* listener) { | 299 void ChildThread::AddRoute(int32 routing_id, IPC::Listener* listener) { |
| 297 DCHECK(base::MessageLoop::current() == message_loop()); | 300 DCHECK(base::MessageLoop::current() == message_loop()); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 // inflight that would addref it. | 479 // inflight that would addref it. |
| 477 Send(new ChildProcessHostMsg_ShutdownRequest); | 480 Send(new ChildProcessHostMsg_ShutdownRequest); |
| 478 } | 481 } |
| 479 | 482 |
| 480 void ChildThread::EnsureConnected() { | 483 void ChildThread::EnsureConnected() { |
| 481 LOG(INFO) << "ChildThread::EnsureConnected()"; | 484 LOG(INFO) << "ChildThread::EnsureConnected()"; |
| 482 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); | 485 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); |
| 483 } | 486 } |
| 484 | 487 |
| 485 } // namespace content | 488 } // namespace content |
| OLD | NEW |