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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 base::MessageLoop::current()->Quit(); | 193 base::MessageLoop::current()->Quit(); |
194 } | 194 } |
195 | 195 |
196 #endif | 196 #endif |
197 | 197 |
198 } // namespace | 198 } // namespace |
199 | 199 |
200 ChildThread::Options::Options() | 200 ChildThread::Options::Options() |
201 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 201 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
202 switches::kProcessChannelID)), | 202 switches::kProcessChannelID)), |
203 use_mojo_channel(false) {} | 203 use_mojo_channel(false), |
| 204 in_browser_process(false) { |
| 205 } |
204 | 206 |
205 ChildThread::Options::Options(bool mojo) | 207 ChildThread::Options::Options(bool mojo) |
206 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 208 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
207 switches::kProcessChannelID)), | 209 switches::kProcessChannelID)), |
208 use_mojo_channel(mojo) {} | 210 use_mojo_channel(mojo), |
| 211 in_browser_process(true) { |
| 212 } |
209 | 213 |
| 214 ChildThread::Options::Options(std::string name, bool mojo) |
| 215 : channel_name(name), use_mojo_channel(mojo), in_browser_process(true) { |
| 216 } |
| 217 |
| 218 ChildThread::Options::~Options() { |
| 219 } |
210 | 220 |
211 ChildThread::ChildThreadMessageRouter::ChildThreadMessageRouter( | 221 ChildThread::ChildThreadMessageRouter::ChildThreadMessageRouter( |
212 IPC::Sender* sender) | 222 IPC::Sender* sender) |
213 : sender_(sender) {} | 223 : sender_(sender) {} |
214 | 224 |
215 bool ChildThread::ChildThreadMessageRouter::Send(IPC::Message* msg) { | 225 bool ChildThread::ChildThreadMessageRouter::Send(IPC::Message* msg) { |
216 return sender_->Send(msg); | 226 return sender_->Send(msg); |
217 } | 227 } |
218 | 228 |
219 ChildThread::ChildThread() | 229 ChildThread::ChildThread() |
220 : router_(this), | 230 : router_(this), |
221 in_browser_process_(false), | 231 in_browser_process_(false), |
222 channel_connected_factory_(this) { | 232 channel_connected_factory_(this) { |
223 Init(Options()); | 233 Init(Options()); |
224 } | 234 } |
225 | 235 |
226 ChildThread::ChildThread(const Options& options) | 236 ChildThread::ChildThread(const Options& options) |
227 : router_(this), | 237 : router_(this), |
228 in_browser_process_(true), | 238 in_browser_process_(options.in_browser_process), |
229 channel_connected_factory_(this) { | 239 channel_connected_factory_(this) { |
230 Init(options); | 240 Init(options); |
231 } | 241 } |
232 | 242 |
233 scoped_ptr<IPC::SyncChannel> ChildThread::CreateChannel(bool use_mojo_channel) { | 243 void ChildThread::ConnectChannel(bool use_mojo_channel) { |
| 244 bool create_pipe_now = true; |
234 if (use_mojo_channel) { | 245 if (use_mojo_channel) { |
235 VLOG(1) << "Mojo is enabled on child"; | 246 VLOG(1) << "Mojo is enabled on child"; |
236 return IPC::SyncChannel::Create( | 247 channel_->Init(IPC::ChannelMojo::CreateClientFactory(channel_name_), |
237 IPC::ChannelMojo::CreateClientFactory(channel_name_), | 248 create_pipe_now); |
238 this, | 249 return; |
239 ChildProcess::current()->io_message_loop_proxy(), | |
240 true, | |
241 ChildProcess::current()->GetShutDownEvent()); | |
242 } | 250 } |
243 | 251 |
244 VLOG(1) << "Mojo is disabled on child"; | 252 VLOG(1) << "Mojo is disabled on child"; |
245 return IPC::SyncChannel::Create( | 253 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); |
246 channel_name_, | |
247 IPC::Channel::MODE_CLIENT, | |
248 this, | |
249 ChildProcess::current()->io_message_loop_proxy(), | |
250 true, | |
251 ChildProcess::current()->GetShutDownEvent()); | |
252 } | 254 } |
253 | 255 |
254 void ChildThread::Init(const Options& options) { | 256 void ChildThread::Init(const Options& options) { |
255 channel_name_ = options.channel_name; | 257 channel_name_ = options.channel_name; |
256 | 258 |
257 g_lazy_tls.Pointer()->Set(this); | 259 g_lazy_tls.Pointer()->Set(this); |
258 on_channel_error_called_ = false; | 260 on_channel_error_called_ = false; |
259 message_loop_ = base::MessageLoop::current(); | 261 message_loop_ = base::MessageLoop::current(); |
260 #ifdef IPC_MESSAGE_LOG_ENABLED | 262 #ifdef IPC_MESSAGE_LOG_ENABLED |
261 // We must make sure to instantiate the IPC Logger *before* we create the | 263 // We must make sure to instantiate the IPC Logger *before* we create the |
262 // channel, otherwise we can get a callback on the IO thread which creates | 264 // channel, otherwise we can get a callback on the IO thread which creates |
263 // the logger, and the logger does not like being created on the IO thread. | 265 // the logger, and the logger does not like being created on the IO thread. |
264 IPC::Logging::GetInstance(); | 266 IPC::Logging::GetInstance(); |
265 #endif | 267 #endif |
266 channel_ = CreateChannel(options.use_mojo_channel); | 268 channel_ = IPC::SyncChannel::Create( |
| 269 this, ChildProcess::current()->io_message_loop_proxy(), |
| 270 ChildProcess::current()->GetShutDownEvent()); |
267 #ifdef IPC_MESSAGE_LOG_ENABLED | 271 #ifdef IPC_MESSAGE_LOG_ENABLED |
268 if (!in_browser_process_) | 272 if (!in_browser_process_) |
269 IPC::Logging::GetInstance()->SetIPCSender(this); | 273 IPC::Logging::GetInstance()->SetIPCSender(this); |
270 #endif | 274 #endif |
271 | 275 |
272 mojo_application_.reset(new MojoApplication); | 276 mojo_application_.reset(new MojoApplication); |
273 | 277 |
274 sync_message_filter_ = | 278 sync_message_filter_ = |
275 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); | 279 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); |
276 thread_safe_sender_ = new ThreadSafeSender( | 280 thread_safe_sender_ = new ThreadSafeSender( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 power_monitor_source.Pass())); | 335 power_monitor_source.Pass())); |
332 } | 336 } |
333 | 337 |
334 #if defined(OS_POSIX) | 338 #if defined(OS_POSIX) |
335 // Check that --process-type is specified so we don't do this in unit tests | 339 // Check that --process-type is specified so we don't do this in unit tests |
336 // and single-process mode. | 340 // and single-process mode. |
337 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) | 341 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) |
338 channel_->AddFilter(new SuicideOnChannelErrorFilter()); | 342 channel_->AddFilter(new SuicideOnChannelErrorFilter()); |
339 #endif | 343 #endif |
340 | 344 |
| 345 // Add filters passed here via options. |
| 346 for (auto startup_filter : options.startup_filters) { |
| 347 channel_->AddFilter(startup_filter); |
| 348 } |
| 349 |
| 350 ConnectChannel(options.use_mojo_channel); |
| 351 |
341 int connection_timeout = kConnectionTimeoutS; | 352 int connection_timeout = kConnectionTimeoutS; |
342 std::string connection_override = | 353 std::string connection_override = |
343 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 354 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
344 switches::kIPCConnectionTimeout); | 355 switches::kIPCConnectionTimeout); |
345 if (!connection_override.empty()) { | 356 if (!connection_override.empty()) { |
346 int temp; | 357 int temp; |
347 if (base::StringToInt(connection_override, &temp)) | 358 if (base::StringToInt(connection_override, &temp)) |
348 connection_timeout = temp; | 359 connection_timeout = temp; |
349 } | 360 } |
350 | 361 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 | 618 |
608 void ChildThread::OnProcessBackgrounded(bool background) { | 619 void ChildThread::OnProcessBackgrounded(bool background) { |
609 // Set timer slack to maximum on main thread when in background. | 620 // Set timer slack to maximum on main thread when in background. |
610 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; | 621 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; |
611 if (background) | 622 if (background) |
612 timer_slack = base::TIMER_SLACK_MAXIMUM; | 623 timer_slack = base::TIMER_SLACK_MAXIMUM; |
613 base::MessageLoop::current()->SetTimerSlack(timer_slack); | 624 base::MessageLoop::current()->SetTimerSlack(timer_slack); |
614 } | 625 } |
615 | 626 |
616 } // namespace content | 627 } // namespace content |
OLD | NEW |