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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 if (!handled && msg.is_sync()) { | 371 if (!handled && msg.is_sync()) { |
372 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); | 372 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); |
373 reply->set_reply_error(); | 373 reply->set_reply_error(); |
374 Send(reply); | 374 Send(reply); |
375 } | 375 } |
376 #endif | 376 #endif |
377 return handled; | 377 return handled; |
378 } | 378 } |
379 | 379 |
380 ChildThreadImpl::ChildThreadImpl() | 380 ChildThreadImpl::ChildThreadImpl() |
381 : router_(this), | 381 : route_provider_binding_(this), |
| 382 associated_interface_provider_bindings_( |
| 383 mojo::BindingSetDispatchMode::WITH_CONTEXT), |
| 384 router_(this), |
382 channel_connected_factory_( | 385 channel_connected_factory_( |
383 new base::WeakPtrFactory<ChildThreadImpl>(this)), | 386 new base::WeakPtrFactory<ChildThreadImpl>(this)), |
384 weak_factory_(this) { | 387 weak_factory_(this) { |
385 Init(Options::Builder().Build()); | 388 Init(Options::Builder().Build()); |
386 } | 389 } |
387 | 390 |
388 ChildThreadImpl::ChildThreadImpl(const Options& options) | 391 ChildThreadImpl::ChildThreadImpl(const Options& options) |
389 : router_(this), | 392 : route_provider_binding_(this), |
| 393 associated_interface_provider_bindings_( |
| 394 mojo::BindingSetDispatchMode::WITH_CONTEXT), |
| 395 router_(this), |
390 browser_process_io_runner_(options.browser_process_io_runner), | 396 browser_process_io_runner_(options.browser_process_io_runner), |
391 channel_connected_factory_( | 397 channel_connected_factory_( |
392 new base::WeakPtrFactory<ChildThreadImpl>(this)), | 398 new base::WeakPtrFactory<ChildThreadImpl>(this)), |
393 weak_factory_(this) { | 399 weak_factory_(this) { |
394 Init(options); | 400 Init(options); |
395 } | 401 } |
396 | 402 |
397 scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() { | 403 scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() { |
398 if (IsInBrowserProcess()) | 404 if (IsInBrowserProcess()) |
399 return browser_process_io_runner_; | 405 return browser_process_io_runner_; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 for (auto* startup_filter : options.startup_filters) { | 565 for (auto* startup_filter : options.startup_filters) { |
560 channel_->AddFilter(startup_filter); | 566 channel_->AddFilter(startup_filter); |
561 } | 567 } |
562 | 568 |
563 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); | 569 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); |
564 if (broker && !broker->IsPrivilegedBroker()) | 570 if (broker && !broker->IsPrivilegedBroker()) |
565 broker->RegisterBrokerCommunicationChannel(channel_.get()); | 571 broker->RegisterBrokerCommunicationChannel(channel_.get()); |
566 | 572 |
567 ConnectChannel(options.use_mojo_channel); | 573 ConnectChannel(options.use_mojo_channel); |
568 | 574 |
| 575 channel_->AddAssociatedInterface( |
| 576 base::Bind(&ChildThreadImpl::OnRouteProviderRequest, |
| 577 base::Unretained(this))); |
| 578 |
569 // This must always be done after ConnectChannel, because ConnectChannel() may | 579 // This must always be done after ConnectChannel, because ConnectChannel() may |
570 // add a ConnectionFilter to the connection. | 580 // add a ConnectionFilter to the connection. |
571 if (options.auto_start_mojo_shell_connection && mojo_shell_connection_) | 581 if (options.auto_start_mojo_shell_connection && mojo_shell_connection_) |
572 StartMojoShellConnection(); | 582 StartMojoShellConnection(); |
573 | 583 |
574 int connection_timeout = kConnectionTimeoutS; | 584 int connection_timeout = kConnectionTimeoutS; |
575 std::string connection_override = | 585 std::string connection_override = |
576 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 586 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
577 switches::kIPCConnectionTimeout); | 587 switches::kIPCConnectionTimeout); |
578 if (!connection_override.empty()) { | 588 if (!connection_override.empty()) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 | 695 |
686 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { | 696 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { |
687 if (browser_connection_) | 697 if (browser_connection_) |
688 return browser_connection_->GetRemoteInterfaces(); | 698 return browser_connection_->GetRemoteInterfaces(); |
689 | 699 |
690 if (!remote_interfaces_.get()) | 700 if (!remote_interfaces_.get()) |
691 remote_interfaces_.reset(new shell::InterfaceProvider); | 701 remote_interfaces_.reset(new shell::InterfaceProvider); |
692 return remote_interfaces_.get(); | 702 return remote_interfaces_.get(); |
693 } | 703 } |
694 | 704 |
| 705 mojom::RouteProvider* ChildThreadImpl::GetRemoteRouteProvider() { |
| 706 if (!remote_route_provider_) { |
| 707 DCHECK(channel_); |
| 708 channel_->GetRemoteAssociatedInterface(&remote_route_provider_); |
| 709 } |
| 710 return remote_route_provider_.get(); |
| 711 } |
| 712 |
695 IPC::MessageRouter* ChildThreadImpl::GetRouter() { | 713 IPC::MessageRouter* ChildThreadImpl::GetRouter() { |
696 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); | 714 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); |
697 return &router_; | 715 return &router_; |
698 } | 716 } |
699 | 717 |
700 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( | 718 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( |
701 size_t buf_size) { | 719 size_t buf_size) { |
702 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); | 720 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); |
703 return AllocateSharedMemory(buf_size, this, nullptr); | 721 return AllocateSharedMemory(buf_size, this, nullptr); |
704 } | 722 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 // race conditions if the process refcount is 0 but there's an IPC message | 860 // race conditions if the process refcount is 0 but there's an IPC message |
843 // inflight that would addref it. | 861 // inflight that would addref it. |
844 Send(new ChildProcessHostMsg_ShutdownRequest); | 862 Send(new ChildProcessHostMsg_ShutdownRequest); |
845 } | 863 } |
846 | 864 |
847 void ChildThreadImpl::EnsureConnected() { | 865 void ChildThreadImpl::EnsureConnected() { |
848 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 866 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
849 base::Process::Current().Terminate(0, false); | 867 base::Process::Current().Terminate(0, false); |
850 } | 868 } |
851 | 869 |
| 870 void ChildThreadImpl::OnRouteProviderRequest( |
| 871 mojom::RouteProviderAssociatedRequest request) { |
| 872 DCHECK(!route_provider_binding_.is_bound()); |
| 873 route_provider_binding_.Bind(std::move(request)); |
| 874 } |
| 875 |
| 876 void ChildThreadImpl::GetRoute( |
| 877 int32_t routing_id, |
| 878 mojom::AssociatedInterfaceProviderAssociatedRequest request) { |
| 879 associated_interface_provider_bindings_.AddBinding( |
| 880 this, std::move(request), |
| 881 reinterpret_cast<void*>(static_cast<uintptr_t>(routing_id))); |
| 882 } |
| 883 |
| 884 void ChildThreadImpl::GetAssociatedInterface( |
| 885 const std::string& name, |
| 886 mojom::AssociatedInterfaceAssociatedRequest request) { |
| 887 int32_t routing_id = static_cast<int32_t>(reinterpret_cast<uintptr_t>( |
| 888 associated_interface_provider_bindings_.dispatch_context())); |
| 889 router_.GetRoute(routing_id)->OnAssociatedInterfaceRequest( |
| 890 name, request.PassHandle()); |
| 891 } |
| 892 |
852 bool ChildThreadImpl::IsInBrowserProcess() const { | 893 bool ChildThreadImpl::IsInBrowserProcess() const { |
853 return static_cast<bool>(browser_process_io_runner_); | 894 return static_cast<bool>(browser_process_io_runner_); |
854 } | 895 } |
855 | 896 |
856 } // namespace content | 897 } // namespace content |
OLD | NEW |