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