| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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/child/websocket_dispatcher.h" | 52 #include "content/child/websocket_dispatcher.h" |
| 53 #include "content/child/websocket_message_filter.h" | 53 #include "content/child/websocket_message_filter.h" |
| 54 #include "content/common/child_process_messages.h" | 54 #include "content/common/child_process_messages.h" |
| 55 #include "content/common/in_process_child_thread_params.h" | 55 #include "content/common/in_process_child_thread_params.h" |
| 56 #include "content/public/common/connection_filter.h" |
| 56 #include "content/public/common/content_switches.h" | 57 #include "content/public/common/content_switches.h" |
| 57 #include "content/public/common/mojo_channel_switches.h" | 58 #include "content/public/common/mojo_channel_switches.h" |
| 58 #include "content/public/common/mojo_shell_connection.h" | 59 #include "content/public/common/mojo_shell_connection.h" |
| 59 #include "ipc/attachment_broker.h" | 60 #include "ipc/attachment_broker.h" |
| 60 #include "ipc/attachment_broker_unprivileged.h" | 61 #include "ipc/attachment_broker_unprivileged.h" |
| 61 #include "ipc/ipc_channel_mojo.h" | 62 #include "ipc/ipc_channel_mojo.h" |
| 62 #include "ipc/ipc_logging.h" | 63 #include "ipc/ipc_logging.h" |
| 63 #include "ipc/ipc_platform_file.h" | 64 #include "ipc/ipc_platform_file.h" |
| 64 #include "ipc/ipc_switches.h" | 65 #include "ipc/ipc_switches.h" |
| 65 #include "ipc/ipc_sync_channel.h" | 66 #include "ipc/ipc_sync_channel.h" |
| 66 #include "ipc/ipc_sync_message_filter.h" | 67 #include "ipc/ipc_sync_message_filter.h" |
| 67 #include "mojo/edk/embedder/embedder.h" | 68 #include "mojo/edk/embedder/embedder.h" |
| 68 #include "mojo/edk/embedder/named_platform_channel_pair.h" | 69 #include "mojo/edk/embedder/named_platform_channel_pair.h" |
| 69 #include "mojo/edk/embedder/platform_channel_pair.h" | 70 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 70 #include "mojo/edk/embedder/scoped_ipc_support.h" | 71 #include "mojo/edk/embedder/scoped_ipc_support.h" |
| 72 #include "services/shell/public/cpp/connection.h" |
| 71 #include "services/shell/public/cpp/interface_provider.h" | 73 #include "services/shell/public/cpp/interface_provider.h" |
| 72 #include "services/shell/public/cpp/interface_registry.h" | 74 #include "services/shell/public/cpp/interface_registry.h" |
| 73 #include "services/shell/runner/common/client_util.h" | 75 #include "services/shell/runner/common/client_util.h" |
| 74 | 76 |
| 75 #if defined(OS_POSIX) | 77 #if defined(OS_POSIX) |
| 76 #include "base/posix/global_descriptors.h" | 78 #include "base/posix/global_descriptors.h" |
| 77 #include "content/public/common/content_descriptors.h" | 79 #include "content/public/common/content_descriptors.h" |
| 78 #endif | 80 #endif |
| 79 | 81 |
| 80 using tracked_objects::ThreadData; | 82 using tracked_objects::ThreadData; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 #endif | 252 #endif |
| 251 // Mojo isn't supported on all child process types. | 253 // Mojo isn't supported on all child process types. |
| 252 // TODO(crbug.com/604282): Support Mojo in the remaining processes. | 254 // TODO(crbug.com/604282): Support Mojo in the remaining processes. |
| 253 if (!platform_channel.is_valid()) | 255 if (!platform_channel.is_valid()) |
| 254 return; | 256 return; |
| 255 mojo::edk::SetParentPipeHandle(std::move(platform_channel)); | 257 mojo::edk::SetParentPipeHandle(std::move(platform_channel)); |
| 256 } | 258 } |
| 257 | 259 |
| 258 } // namespace | 260 } // namespace |
| 259 | 261 |
| 262 class ChildThreadImpl::ChildThreadConnectionFilter |
| 263 : public ConnectionFilter, |
| 264 public shell::InterfaceFactory<IPC::mojom::Bootstrap> { |
| 265 public: |
| 266 explicit ChildThreadConnectionFilter(ChildThreadImpl* impl) |
| 267 : child_thread_impl_(impl) {} |
| 268 ~ChildThreadConnectionFilter() override {} |
| 269 |
| 270 private: |
| 271 // ConnectionFilter: |
| 272 bool OnConnect(shell::Connection* connection, |
| 273 shell::Connector* connector) override { |
| 274 connection->GetInterfaceRegistry()->AddInterface<IPC::mojom::Bootstrap>( |
| 275 this); |
| 276 return true; |
| 277 } |
| 278 |
| 279 // shell::InterfaceFactory<IPC::mojom::Bootstrap>: |
| 280 void Create(shell::Connection* connection, |
| 281 IPC::mojom::BootstrapRequest request) override { |
| 282 // TODO: bind channel. |
| 283 LOG(WARNING) << "Hello, World!"; |
| 284 child_thread_impl_->ConnectMojoChannel(std::move(request)); |
| 285 } |
| 286 |
| 287 ChildThreadImpl* child_thread_impl_; |
| 288 |
| 289 DISALLOW_COPY_AND_ASSIGN(ChildThreadConnectionFilter); |
| 290 }; |
| 291 |
| 260 ChildThread* ChildThread::Get() { | 292 ChildThread* ChildThread::Get() { |
| 261 return ChildThreadImpl::current(); | 293 return ChildThreadImpl::current(); |
| 262 } | 294 } |
| 263 | 295 |
| 264 ChildThreadImpl::Options::Options() | 296 ChildThreadImpl::Options::Options() |
| 265 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 297 : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 266 switches::kProcessChannelID)), | 298 switches::kProcessChannelID)), |
| 267 use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch( | 299 use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 268 switches::kMojoChannelToken)), | 300 switches::kMojoChannelToken)), |
| 269 auto_start_mojo_shell_connection(true) { | 301 auto_start_mojo_shell_connection(true) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 IPC::ChannelMojo::CreateClientFactory( | 413 IPC::ChannelMojo::CreateClientFactory( |
| 382 std::move(handle), ChildProcess::current()->io_task_runner()), | 414 std::move(handle), ChildProcess::current()->io_task_runner()), |
| 383 create_pipe_now); | 415 create_pipe_now); |
| 384 return; | 416 return; |
| 385 } | 417 } |
| 386 | 418 |
| 387 VLOG(1) << "Mojo is disabled on child"; | 419 VLOG(1) << "Mojo is disabled on child"; |
| 388 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); | 420 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); |
| 389 } | 421 } |
| 390 | 422 |
| 423 void ChildThreadImpl::ConnectMojoChannel(IPC::mojom::BootstrapRequest request) { |
| 424 channel_->Init( |
| 425 IPC::ChannelMojo::CreateClientFactory( |
| 426 request.PassMessagePipe(), ChildProcess::current()->io_task_runner()), |
| 427 true); |
| 428 } |
| 429 |
| 391 void ChildThreadImpl::Init(const Options& options) { | 430 void ChildThreadImpl::Init(const Options& options) { |
| 392 channel_name_ = options.channel_name; | 431 channel_name_ = options.channel_name; |
| 393 | 432 |
| 394 g_lazy_tls.Pointer()->Set(this); | 433 g_lazy_tls.Pointer()->Set(this); |
| 395 on_channel_error_called_ = false; | 434 on_channel_error_called_ = false; |
| 396 message_loop_ = base::MessageLoop::current(); | 435 message_loop_ = base::MessageLoop::current(); |
| 397 #ifdef IPC_MESSAGE_LOG_ENABLED | 436 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 398 // We must make sure to instantiate the IPC Logger *before* we create the | 437 // We must make sure to instantiate the IPC Logger *before* we create the |
| 399 // channel, otherwise we can get a callback on the IO thread which creates | 438 // channel, otherwise we can get a callback on the IO thread which creates |
| 400 // the logger, and the logger does not like being created on the IO thread. | 439 // the logger, and the logger does not like being created on the IO thread. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 424 } else { | 463 } else { |
| 425 mojo_application_token = options.in_process_application_token; | 464 mojo_application_token = options.in_process_application_token; |
| 426 } | 465 } |
| 427 if (!mojo_application_token.empty()) { | 466 if (!mojo_application_token.empty()) { |
| 428 mojo::ScopedMessagePipeHandle handle = | 467 mojo::ScopedMessagePipeHandle handle = |
| 429 mojo::edk::CreateChildMessagePipe(mojo_application_token); | 468 mojo::edk::CreateChildMessagePipe(mojo_application_token); |
| 430 DCHECK(handle.is_valid()); | 469 DCHECK(handle.is_valid()); |
| 431 mojo_shell_connection_ = MojoShellConnection::Create( | 470 mojo_shell_connection_ = MojoShellConnection::Create( |
| 432 mojo::MakeRequest<shell::mojom::Service>(std::move(handle)), | 471 mojo::MakeRequest<shell::mojom::Service>(std::move(handle)), |
| 433 GetIOTaskRunner()); | 472 GetIOTaskRunner()); |
| 473 mojo_shell_connection_->AddConnectionFilter( |
| 474 base::WrapUnique(new ChildThreadConnectionFilter(this))); |
| 434 | 475 |
| 435 // TODO(rockot): Remove this once all child-to-browser interface connections | 476 // TODO(rockot): Remove this once all child-to-browser interface connections |
| 436 // are made via a Connector rather than directly through an | 477 // are made via a Connector rather than directly through an |
| 437 // InterfaceProvider, and all exposed interfaces are exposed via a | 478 // InterfaceProvider, and all exposed interfaces are exposed via a |
| 438 // ConnectionFilter. | 479 // ConnectionFilter. |
| 439 mojo_shell_connection_->SetupInterfaceRequestProxies( | 480 mojo_shell_connection_->SetupInterfaceRequestProxies( |
| 440 GetInterfaceRegistry(), GetRemoteInterfaces()); | 481 GetInterfaceRegistry(), GetRemoteInterfaces()); |
| 441 | 482 |
| 442 if (options.auto_start_mojo_shell_connection) | 483 if (options.auto_start_mojo_shell_connection) |
| 443 StartMojoShellConnection(); | 484 StartMojoShellConnection(); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 void ChildThreadImpl::EnsureConnected() { | 827 void ChildThreadImpl::EnsureConnected() { |
| 787 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 828 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
| 788 base::Process::Current().Terminate(0, false); | 829 base::Process::Current().Terminate(0, false); |
| 789 } | 830 } |
| 790 | 831 |
| 791 bool ChildThreadImpl::IsInBrowserProcess() const { | 832 bool ChildThreadImpl::IsInBrowserProcess() const { |
| 792 return static_cast<bool>(browser_process_io_runner_); | 833 return static_cast<bool>(browser_process_io_runner_); |
| 793 } | 834 } |
| 794 | 835 |
| 795 } // namespace content | 836 } // namespace content |
| OLD | NEW |