| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "content/child/power_monitor_broadcast_source.h" | 45 #include "content/child/power_monitor_broadcast_source.h" |
| 46 #include "content/child/push_messaging/push_dispatcher.h" | 46 #include "content/child/push_messaging/push_dispatcher.h" |
| 47 #include "content/child/quota_dispatcher.h" | 47 #include "content/child/quota_dispatcher.h" |
| 48 #include "content/child/quota_message_filter.h" | 48 #include "content/child/quota_message_filter.h" |
| 49 #include "content/child/resource_dispatcher.h" | 49 #include "content/child/resource_dispatcher.h" |
| 50 #include "content/child/service_worker/service_worker_message_filter.h" | 50 #include "content/child/service_worker/service_worker_message_filter.h" |
| 51 #include "content/child/thread_safe_sender.h" | 51 #include "content/child/thread_safe_sender.h" |
| 52 #include "content/common/child_process_messages.h" | 52 #include "content/common/child_process_messages.h" |
| 53 #include "content/common/in_process_child_thread_params.h" | 53 #include "content/common/in_process_child_thread_params.h" |
| 54 #include "content/common/mojo/constants.h" | 54 #include "content/common/mojo/constants.h" |
| 55 #include "content/public/common/connection_filter.h" | |
| 56 #include "content/public/common/content_switches.h" | 55 #include "content/public/common/content_switches.h" |
| 57 #include "content/public/common/mojo_channel_switches.h" | 56 #include "content/public/common/mojo_channel_switches.h" |
| 58 #include "content/public/common/mojo_shell_connection.h" | 57 #include "content/public/common/mojo_shell_connection.h" |
| 59 #include "ipc/attachment_broker.h" | 58 #include "ipc/attachment_broker.h" |
| 60 #include "ipc/attachment_broker_unprivileged.h" | 59 #include "ipc/attachment_broker_unprivileged.h" |
| 61 #include "ipc/ipc_channel_mojo.h" | 60 #include "ipc/ipc_channel_mojo.h" |
| 62 #include "ipc/ipc_logging.h" | 61 #include "ipc/ipc_logging.h" |
| 63 #include "ipc/ipc_platform_file.h" | 62 #include "ipc/ipc_platform_file.h" |
| 64 #include "ipc/ipc_switches.h" | 63 #include "ipc/ipc_switches.h" |
| 65 #include "ipc/ipc_sync_channel.h" | 64 #include "ipc/ipc_sync_channel.h" |
| 66 #include "ipc/ipc_sync_message_filter.h" | 65 #include "ipc/ipc_sync_message_filter.h" |
| 67 #include "mojo/edk/embedder/embedder.h" | 66 #include "mojo/edk/embedder/embedder.h" |
| 68 #include "mojo/edk/embedder/named_platform_channel_pair.h" | 67 #include "mojo/edk/embedder/named_platform_channel_pair.h" |
| 69 #include "mojo/edk/embedder/platform_channel_pair.h" | 68 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 70 #include "mojo/edk/embedder/scoped_ipc_support.h" | 69 #include "mojo/edk/embedder/scoped_ipc_support.h" |
| 71 #include "services/shell/public/cpp/connector.h" | 70 #include "services/shell/public/cpp/connector.h" |
| 72 #include "services/shell/public/cpp/interface_factory.h" | |
| 73 #include "services/shell/public/cpp/interface_provider.h" | 71 #include "services/shell/public/cpp/interface_provider.h" |
| 74 #include "services/shell/public/cpp/interface_registry.h" | 72 #include "services/shell/public/cpp/interface_registry.h" |
| 75 #include "services/shell/runner/common/client_util.h" | 73 #include "services/shell/runner/common/client_util.h" |
| 76 | 74 |
| 77 #if defined(OS_POSIX) | 75 #if defined(OS_POSIX) |
| 78 #include "base/posix/global_descriptors.h" | 76 #include "base/posix/global_descriptors.h" |
| 79 #include "content/public/common/content_descriptors.h" | 77 #include "content/public/common/content_descriptors.h" |
| 80 #endif | 78 #endif |
| 81 | 79 |
| 82 using tracked_objects::ThreadData; | 80 using tracked_objects::ThreadData; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 platform_channel.reset(mojo::edk::PlatformHandle( | 248 platform_channel.reset(mojo::edk::PlatformHandle( |
| 251 base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel))); | 249 base::GlobalDescriptors::GetInstance()->Get(kMojoIPCChannel))); |
| 252 #endif | 250 #endif |
| 253 // Mojo isn't supported on all child process types. | 251 // Mojo isn't supported on all child process types. |
| 254 // TODO(crbug.com/604282): Support Mojo in the remaining processes. | 252 // TODO(crbug.com/604282): Support Mojo in the remaining processes. |
| 255 if (!platform_channel.is_valid()) | 253 if (!platform_channel.is_valid()) |
| 256 return; | 254 return; |
| 257 mojo::edk::SetParentPipeHandle(std::move(platform_channel)); | 255 mojo::edk::SetParentPipeHandle(std::move(platform_channel)); |
| 258 } | 256 } |
| 259 | 257 |
| 260 class ChannelBootstrapFilter | |
| 261 : public ConnectionFilter, | |
| 262 public shell::InterfaceFactory<IPC::mojom::ChannelBootstrap> { | |
| 263 public: | |
| 264 explicit ChannelBootstrapFilter(IPC::mojom::ChannelBootstrapPtrInfo bootstrap) | |
| 265 : bootstrap_(std::move(bootstrap)) {} | |
| 266 | |
| 267 private: | |
| 268 // ConnectionFilter: | |
| 269 bool OnConnect(shell::Connection* connection, | |
| 270 shell::Connector* connector) override { | |
| 271 if (connection->GetRemoteIdentity().name() != kBrowserMojoApplicationName) | |
| 272 return false; | |
| 273 | |
| 274 connection->AddInterface<IPC::mojom::ChannelBootstrap>(this); | |
| 275 return true; | |
| 276 } | |
| 277 | |
| 278 // shell::InterfaceFactory<IPC::mojom::ChannelBootstrap>: | |
| 279 void Create(const shell::Identity& remote_identity, | |
| 280 IPC::mojom::ChannelBootstrapRequest request) override { | |
| 281 DCHECK(bootstrap_.is_valid()); | |
| 282 mojo::FuseInterface(std::move(request), std::move(bootstrap_)); | |
| 283 } | |
| 284 | |
| 285 IPC::mojom::ChannelBootstrapPtrInfo bootstrap_; | |
| 286 | |
| 287 DISALLOW_COPY_AND_ASSIGN(ChannelBootstrapFilter); | |
| 288 }; | |
| 289 | |
| 290 } // namespace | 258 } // namespace |
| 291 | 259 |
| 292 ChildThread* ChildThread::Get() { | 260 ChildThread* ChildThread::Get() { |
| 293 return ChildThreadImpl::current(); | 261 return ChildThreadImpl::current(); |
| 294 } | 262 } |
| 295 | 263 |
| 296 ChildThreadImpl::Options::Options() | 264 ChildThreadImpl::Options::Options() |
| 297 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 265 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 298 switches::kProcessChannelID)), | 266 switches::kProcessChannelID)), |
| 299 use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch( | 267 use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 if (IsInBrowserProcess()) | 368 if (IsInBrowserProcess()) |
| 401 return browser_process_io_runner_; | 369 return browser_process_io_runner_; |
| 402 return ChildProcess::current()->io_task_runner(); | 370 return ChildProcess::current()->io_task_runner(); |
| 403 } | 371 } |
| 404 | 372 |
| 405 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel, | 373 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel, |
| 406 const std::string& ipc_token) { | 374 const std::string& ipc_token) { |
| 407 bool create_pipe_now = true; | 375 bool create_pipe_now = true; |
| 408 if (use_mojo_channel) { | 376 if (use_mojo_channel) { |
| 409 VLOG(1) << "Mojo is enabled on child"; | 377 VLOG(1) << "Mojo is enabled on child"; |
| 410 std::string channel_token; | |
| 411 mojo::ScopedMessagePipeHandle handle; | 378 mojo::ScopedMessagePipeHandle handle; |
| 412 if (!IsInBrowserProcess()) { | 379 if (!IsInBrowserProcess()) { |
| 413 channel_token = | 380 DCHECK(!handle.is_valid()); |
| 381 handle = mojo::edk::CreateChildMessagePipe( |
| 414 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 382 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 415 switches::kMojoChannelToken); | 383 switches::kMojoChannelToken)); |
| 416 } else { | 384 } else { |
| 417 channel_token = ipc_token; | 385 handle = mojo::edk::CreateChildMessagePipe(ipc_token); |
| 418 } | 386 } |
| 419 | |
| 420 if (!channel_token.empty()) { | |
| 421 // TODO(rockot): Remove all paths which lead to this branch. The Channel | |
| 422 // connection should always be established by a shell connection from the | |
| 423 // browser. http://crbug.com/623396. | |
| 424 handle = mojo::edk::CreateChildMessagePipe(channel_token); | |
| 425 } else { | |
| 426 DCHECK(mojo_shell_connection_); | |
| 427 IPC::mojom::ChannelBootstrapPtr bootstrap; | |
| 428 handle = mojo::GetProxy(&bootstrap).PassMessagePipe(); | |
| 429 mojo_shell_connection_->AddConnectionFilter( | |
| 430 base::MakeUnique<ChannelBootstrapFilter>(bootstrap.PassInterface())); | |
| 431 } | |
| 432 | |
| 433 DCHECK(handle.is_valid()); | 387 DCHECK(handle.is_valid()); |
| 434 channel_->Init( | 388 channel_->Init( |
| 435 IPC::ChannelMojo::CreateClientFactory( | 389 IPC::ChannelMojo::CreateClientFactory( |
| 436 std::move(handle), ChildProcess::current()->io_task_runner()), | 390 std::move(handle), ChildProcess::current()->io_task_runner()), |
| 437 create_pipe_now); | 391 create_pipe_now); |
| 438 return; | 392 return; |
| 439 } | 393 } |
| 440 | 394 |
| 441 VLOG(1) << "Mojo is disabled on child"; | 395 VLOG(1) << "Mojo is disabled on child"; |
| 442 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); | 396 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 } else { | 450 } else { |
| 497 remote_interfaces = GetRemoteInterfaces(); | 451 remote_interfaces = GetRemoteInterfaces(); |
| 498 } | 452 } |
| 499 | 453 |
| 500 // TODO(rockot): Remove this once all child-to-browser interface connections | 454 // TODO(rockot): Remove this once all child-to-browser interface connections |
| 501 // are made via a Connector rather than directly through an | 455 // are made via a Connector rather than directly through an |
| 502 // InterfaceProvider, and all exposed interfaces are exposed via a | 456 // InterfaceProvider, and all exposed interfaces are exposed via a |
| 503 // ConnectionFilter. | 457 // ConnectionFilter. |
| 504 mojo_shell_connection_->SetupInterfaceRequestProxies( | 458 mojo_shell_connection_->SetupInterfaceRequestProxies( |
| 505 GetInterfaceRegistry(), remote_interfaces); | 459 GetInterfaceRegistry(), remote_interfaces); |
| 460 |
| 461 if (options.auto_start_mojo_shell_connection) |
| 462 StartMojoShellConnection(); |
| 506 } | 463 } |
| 507 | 464 |
| 508 sync_message_filter_ = channel_->CreateSyncMessageFilter(); | 465 sync_message_filter_ = channel_->CreateSyncMessageFilter(); |
| 509 thread_safe_sender_ = new ThreadSafeSender( | 466 thread_safe_sender_ = new ThreadSafeSender( |
| 510 message_loop_->task_runner(), sync_message_filter_.get()); | 467 message_loop_->task_runner(), sync_message_filter_.get()); |
| 511 | 468 |
| 512 resource_dispatcher_.reset(new ResourceDispatcher( | 469 resource_dispatcher_.reset(new ResourceDispatcher( |
| 513 this, message_loop()->task_runner())); | 470 this, message_loop()->task_runner())); |
| 514 file_system_dispatcher_.reset(new FileSystemDispatcher()); | 471 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
| 515 | 472 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 #endif | 518 #endif |
| 562 | 519 |
| 563 // Add filters passed here via options. | 520 // Add filters passed here via options. |
| 564 for (auto* startup_filter : options.startup_filters) { | 521 for (auto* startup_filter : options.startup_filters) { |
| 565 channel_->AddFilter(startup_filter); | 522 channel_->AddFilter(startup_filter); |
| 566 } | 523 } |
| 567 | 524 |
| 568 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); | 525 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); |
| 569 if (broker && !broker->IsPrivilegedBroker()) | 526 if (broker && !broker->IsPrivilegedBroker()) |
| 570 broker->RegisterBrokerCommunicationChannel(channel_.get()); | 527 broker->RegisterBrokerCommunicationChannel(channel_.get()); |
| 571 | |
| 572 ConnectChannel(options.use_mojo_channel, options.in_process_ipc_token); | 528 ConnectChannel(options.use_mojo_channel, options.in_process_ipc_token); |
| 573 | 529 |
| 574 // This must always be done after ConnectChannel, because ConnectChannel() may | |
| 575 // add a ConnectionFilter to the connection. | |
| 576 if (options.auto_start_mojo_shell_connection && mojo_shell_connection_) | |
| 577 StartMojoShellConnection(); | |
| 578 | |
| 579 int connection_timeout = kConnectionTimeoutS; | 530 int connection_timeout = kConnectionTimeoutS; |
| 580 std::string connection_override = | 531 std::string connection_override = |
| 581 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 532 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 582 switches::kIPCConnectionTimeout); | 533 switches::kIPCConnectionTimeout); |
| 583 if (!connection_override.empty()) { | 534 if (!connection_override.empty()) { |
| 584 int temp; | 535 int temp; |
| 585 if (base::StringToInt(connection_override, &temp)) | 536 if (base::StringToInt(connection_override, &temp)) |
| 586 connection_timeout = temp; | 537 connection_timeout = temp; |
| 587 } | 538 } |
| 588 | 539 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 void ChildThreadImpl::EnsureConnected() { | 803 void ChildThreadImpl::EnsureConnected() { |
| 853 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 804 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
| 854 base::Process::Current().Terminate(0, false); | 805 base::Process::Current().Terminate(0, false); |
| 855 } | 806 } |
| 856 | 807 |
| 857 bool ChildThreadImpl::IsInBrowserProcess() const { | 808 bool ChildThreadImpl::IsInBrowserProcess() const { |
| 858 return static_cast<bool>(browser_process_io_runner_); | 809 return static_cast<bool>(browser_process_io_runner_); |
| 859 } | 810 } |
| 860 | 811 |
| 861 } // namespace content | 812 } // namespace content |
| OLD | NEW |