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_impl.h" | 5 #include "content/child/child_thread_impl.h" |
6 | 6 |
7 #include <signal.h> | 7 #include <signal.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 } | 258 } |
259 | 259 |
260 ChildThreadImpl::Options::Builder::Builder() { | 260 ChildThreadImpl::Options::Builder::Builder() { |
261 } | 261 } |
262 | 262 |
263 ChildThreadImpl::Options::Builder& | 263 ChildThreadImpl::Options::Builder& |
264 ChildThreadImpl::Options::Builder::InBrowserProcess( | 264 ChildThreadImpl::Options::Builder::InBrowserProcess( |
265 const InProcessChildThreadParams& params) { | 265 const InProcessChildThreadParams& params) { |
266 options_.browser_process_io_runner = params.io_runner(); | 266 options_.browser_process_io_runner = params.io_runner(); |
267 options_.channel_name = params.channel_name(); | 267 options_.channel_name = params.channel_name(); |
268 options_.in_process_message_pipe_handle = params.handle(); | 268 options_.in_process_ipc_token = params.ipc_token(); |
269 options_.in_process_application_token = params.application_token(); | 269 options_.in_process_application_token = params.application_token(); |
270 return *this; | 270 return *this; |
271 } | 271 } |
272 | 272 |
273 ChildThreadImpl::Options::Builder& | 273 ChildThreadImpl::Options::Builder& |
274 ChildThreadImpl::Options::Builder::UseMojoChannel(bool use_mojo_channel) { | 274 ChildThreadImpl::Options::Builder::UseMojoChannel(bool use_mojo_channel) { |
275 options_.use_mojo_channel = use_mojo_channel; | 275 options_.use_mojo_channel = use_mojo_channel; |
276 return *this; | 276 return *this; |
277 } | 277 } |
278 | 278 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 Init(options); | 328 Init(options); |
329 } | 329 } |
330 | 330 |
331 scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() { | 331 scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() { |
332 if (IsInBrowserProcess()) | 332 if (IsInBrowserProcess()) |
333 return browser_process_io_runner_; | 333 return browser_process_io_runner_; |
334 return ChildProcess::current()->io_task_runner(); | 334 return ChildProcess::current()->io_task_runner(); |
335 } | 335 } |
336 | 336 |
337 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel, | 337 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel, |
338 mojo::ScopedMessagePipeHandle handle) { | 338 const std::string& ipc_token) { |
339 bool create_pipe_now = true; | 339 bool create_pipe_now = true; |
340 if (use_mojo_channel) { | 340 if (use_mojo_channel) { |
341 VLOG(1) << "Mojo is enabled on child"; | 341 VLOG(1) << "Mojo is enabled on child"; |
| 342 mojo::ScopedMessagePipeHandle handle; |
342 if (!IsInBrowserProcess()) { | 343 if (!IsInBrowserProcess()) { |
343 DCHECK(!handle.is_valid()); | 344 DCHECK(!handle.is_valid()); |
344 handle = mojo::edk::CreateChildMessagePipe( | 345 handle = mojo::edk::CreateChildMessagePipe( |
345 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 346 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
346 switches::kMojoChannelToken)); | 347 switches::kMojoChannelToken)); |
| 348 } else { |
| 349 handle = mojo::edk::CreateChildMessagePipe(ipc_token); |
347 } | 350 } |
348 DCHECK(handle.is_valid()); | 351 DCHECK(handle.is_valid()); |
349 channel_->Init(IPC::ChannelMojo::CreateClientFactory(std::move(handle)), | 352 channel_->Init(IPC::ChannelMojo::CreateClientFactory(std::move(handle)), |
350 create_pipe_now); | 353 create_pipe_now); |
351 return; | 354 return; |
352 } | 355 } |
353 | 356 |
354 VLOG(1) << "Mojo is disabled on child"; | 357 VLOG(1) << "Mojo is disabled on child"; |
355 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); | 358 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); |
356 } | 359 } |
(...skipping 26 matching lines...) Expand all Loading... |
383 mojo_ipc_support_.reset(new IPC::ScopedIPCSupport(GetIOTaskRunner())); | 386 mojo_ipc_support_.reset(new IPC::ScopedIPCSupport(GetIOTaskRunner())); |
384 InitializeMojoIPCChannel(); | 387 InitializeMojoIPCChannel(); |
385 } | 388 } |
386 | 389 |
387 if (MojoShellConnectionImpl::Get()) { | 390 if (MojoShellConnectionImpl::Get()) { |
388 base::ElapsedTimer timer; | 391 base::ElapsedTimer timer; |
389 MojoShellConnectionImpl::Get()->BindToRequestFromCommandLine(); | 392 MojoShellConnectionImpl::Get()->BindToRequestFromCommandLine(); |
390 UMA_HISTOGRAM_TIMES("Mojo.Shell.ChildConnectionTime", timer.Elapsed()); | 393 UMA_HISTOGRAM_TIMES("Mojo.Shell.ChildConnectionTime", timer.Elapsed()); |
391 } | 394 } |
392 | 395 |
393 mojo_application_.reset(new MojoApplication(GetIOTaskRunner())); | 396 mojo_application_.reset(new MojoApplication()); |
394 std::string mojo_application_token; | 397 std::string mojo_application_token; |
395 if (!IsInBrowserProcess()) { | 398 if (!IsInBrowserProcess()) { |
396 mojo_application_token = | 399 mojo_application_token = |
397 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 400 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
398 switches::kMojoApplicationChannelToken); | 401 switches::kMojoApplicationChannelToken); |
399 } else { | 402 } else { |
400 mojo_application_token = options.in_process_application_token; | 403 mojo_application_token = options.in_process_application_token; |
401 } | 404 } |
402 if (!mojo_application_token.empty()) | 405 if (!mojo_application_token.empty()) |
403 mojo_application_->InitWithToken(mojo_application_token); | 406 mojo_application_->InitWithToken(mojo_application_token); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 // and single-process mode. | 462 // and single-process mode. |
460 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) | 463 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) |
461 channel_->AddFilter(new SuicideOnChannelErrorFilter()); | 464 channel_->AddFilter(new SuicideOnChannelErrorFilter()); |
462 #endif | 465 #endif |
463 | 466 |
464 // Add filters passed here via options. | 467 // Add filters passed here via options. |
465 for (auto startup_filter : options.startup_filters) { | 468 for (auto startup_filter : options.startup_filters) { |
466 channel_->AddFilter(startup_filter); | 469 channel_->AddFilter(startup_filter); |
467 } | 470 } |
468 | 471 |
469 ConnectChannel( | 472 ConnectChannel(options.use_mojo_channel, options.in_process_ipc_token); |
470 options.use_mojo_channel, | |
471 mojo::MakeScopedHandle(options.in_process_message_pipe_handle)); | |
472 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); | 473 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); |
473 if (broker && !broker->IsPrivilegedBroker()) | 474 if (broker && !broker->IsPrivilegedBroker()) |
474 broker->RegisterBrokerCommunicationChannel(channel_.get()); | 475 broker->RegisterBrokerCommunicationChannel(channel_.get()); |
475 | 476 |
476 int connection_timeout = kConnectionTimeoutS; | 477 int connection_timeout = kConnectionTimeoutS; |
477 std::string connection_override = | 478 std::string connection_override = |
478 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 479 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
479 switches::kIPCConnectionTimeout); | 480 switches::kIPCConnectionTimeout); |
480 if (!connection_override.empty()) { | 481 if (!connection_override.empty()) { |
481 int temp; | 482 int temp; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 return nullptr; | 604 return nullptr; |
604 } | 605 } |
605 } else { | 606 } else { |
606 // Send is allowed to fail during shutdown. Return null in this case. | 607 // Send is allowed to fail during shutdown. Return null in this case. |
607 return nullptr; | 608 return nullptr; |
608 } | 609 } |
609 return shared_buf; | 610 return shared_buf; |
610 } | 611 } |
611 | 612 |
612 bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) { | 613 bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) { |
613 if (mojo_application_->OnMessageReceived(msg)) | |
614 return true; | |
615 | |
616 // Resource responses are sent to the resource dispatcher. | 614 // Resource responses are sent to the resource dispatcher. |
617 if (resource_dispatcher_->OnMessageReceived(msg)) | 615 if (resource_dispatcher_->OnMessageReceived(msg)) |
618 return true; | 616 return true; |
619 if (websocket_dispatcher_->OnMessageReceived(msg)) | 617 if (websocket_dispatcher_->OnMessageReceived(msg)) |
620 return true; | 618 return true; |
621 if (file_system_dispatcher_->OnMessageReceived(msg)) | 619 if (file_system_dispatcher_->OnMessageReceived(msg)) |
622 return true; | 620 return true; |
623 | 621 |
624 bool handled = true; | 622 bool handled = true; |
625 IPC_BEGIN_MESSAGE_MAP(ChildThreadImpl, msg) | 623 IPC_BEGIN_MESSAGE_MAP(ChildThreadImpl, msg) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 void ChildThreadImpl::EnsureConnected() { | 718 void ChildThreadImpl::EnsureConnected() { |
721 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 719 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
722 base::Process::Current().Terminate(0, false); | 720 base::Process::Current().Terminate(0, false); |
723 } | 721 } |
724 | 722 |
725 bool ChildThreadImpl::IsInBrowserProcess() const { | 723 bool ChildThreadImpl::IsInBrowserProcess() const { |
726 return browser_process_io_runner_; | 724 return browser_process_io_runner_; |
727 } | 725 } |
728 | 726 |
729 } // namespace content | 727 } // namespace content |
OLD | NEW |