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 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 // and single-process mode. | 531 // and single-process mode. |
532 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) | 532 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) |
533 channel_->AddFilter(new SuicideOnChannelErrorFilter()); | 533 channel_->AddFilter(new SuicideOnChannelErrorFilter()); |
534 #endif | 534 #endif |
535 | 535 |
536 // Add filters passed here via options. | 536 // Add filters passed here via options. |
537 for (auto* startup_filter : options.startup_filters) { | 537 for (auto* startup_filter : options.startup_filters) { |
538 channel_->AddFilter(startup_filter); | 538 channel_->AddFilter(startup_filter); |
539 } | 539 } |
540 | 540 |
541 channel_->AddAssociatedInterface( | |
542 base::Bind(&ChildThreadImpl::OnRouteProviderRequest, | |
543 base::Unretained(this))); | |
544 | |
545 ConnectChannel(); | 541 ConnectChannel(); |
546 | 542 |
547 // This must always be done after ConnectChannel, because ConnectChannel() may | 543 // This must always be done after ConnectChannel, because ConnectChannel() may |
548 // add a ConnectionFilter to the connection. | 544 // add a ConnectionFilter to the connection. |
549 if (options.auto_start_service_manager_connection && | 545 if (options.auto_start_service_manager_connection && |
550 service_manager_connection_) { | 546 service_manager_connection_) { |
551 StartServiceManagerConnection(); | 547 StartServiceManagerConnection(); |
552 } | 548 } |
553 | 549 |
554 int connection_timeout = kConnectionTimeoutS; | 550 int connection_timeout = kConnectionTimeoutS; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 | 743 |
748 if (handled) | 744 if (handled) |
749 return true; | 745 return true; |
750 | 746 |
751 if (msg.routing_id() == MSG_ROUTING_CONTROL) | 747 if (msg.routing_id() == MSG_ROUTING_CONTROL) |
752 return OnControlMessageReceived(msg); | 748 return OnControlMessageReceived(msg); |
753 | 749 |
754 return router_.OnMessageReceived(msg); | 750 return router_.OnMessageReceived(msg); |
755 } | 751 } |
756 | 752 |
| 753 void ChildThreadImpl::OnAssociatedInterfaceRequest( |
| 754 const std::string& interface_name, |
| 755 mojo::ScopedInterfaceEndpointHandle handle) { |
| 756 if (interface_name == mojom::RouteProvider::Name_) { |
| 757 DCHECK(!route_provider_binding_.is_bound()); |
| 758 mojom::RouteProviderAssociatedRequest request; |
| 759 request.Bind(std::move(handle)); |
| 760 route_provider_binding_.Bind(std::move(request)); |
| 761 } else { |
| 762 LOG(ERROR) << "Request for unknown Channel-associated interface: " |
| 763 << interface_name; |
| 764 } |
| 765 } |
| 766 |
757 void ChildThreadImpl::StartServiceManagerConnection() { | 767 void ChildThreadImpl::StartServiceManagerConnection() { |
758 DCHECK(service_manager_connection_); | 768 DCHECK(service_manager_connection_); |
759 service_manager_connection_->Start(); | 769 service_manager_connection_->Start(); |
760 // We don't care about storing the id, since if this pipe closes we're toast. | 770 // We don't care about storing the id, since if this pipe closes we're toast. |
761 service_manager_connection_->AddOnConnectHandler( | 771 service_manager_connection_->AddOnConnectHandler( |
762 base::Bind(&ChildThreadImpl::OnServiceConnect, | 772 base::Bind(&ChildThreadImpl::OnServiceConnect, |
763 weak_factory_.GetWeakPtr())); | 773 weak_factory_.GetWeakPtr())); |
764 } | 774 } |
765 | 775 |
766 bool ChildThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { | 776 bool ChildThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 // race conditions if the process refcount is 0 but there's an IPC message | 845 // race conditions if the process refcount is 0 but there's an IPC message |
836 // inflight that would addref it. | 846 // inflight that would addref it. |
837 Send(new ChildProcessHostMsg_ShutdownRequest); | 847 Send(new ChildProcessHostMsg_ShutdownRequest); |
838 } | 848 } |
839 | 849 |
840 void ChildThreadImpl::EnsureConnected() { | 850 void ChildThreadImpl::EnsureConnected() { |
841 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 851 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
842 base::Process::Current().Terminate(0, false); | 852 base::Process::Current().Terminate(0, false); |
843 } | 853 } |
844 | 854 |
845 void ChildThreadImpl::OnRouteProviderRequest( | |
846 mojom::RouteProviderAssociatedRequest request) { | |
847 DCHECK(!route_provider_binding_.is_bound()); | |
848 route_provider_binding_.Bind(std::move(request)); | |
849 } | |
850 | |
851 void ChildThreadImpl::GetRoute( | 855 void ChildThreadImpl::GetRoute( |
852 int32_t routing_id, | 856 int32_t routing_id, |
853 mojom::AssociatedInterfaceProviderAssociatedRequest request) { | 857 mojom::AssociatedInterfaceProviderAssociatedRequest request) { |
854 associated_interface_provider_bindings_.AddBinding( | 858 associated_interface_provider_bindings_.AddBinding( |
855 this, std::move(request), | 859 this, std::move(request), |
856 reinterpret_cast<void*>(static_cast<uintptr_t>(routing_id))); | 860 reinterpret_cast<void*>(static_cast<uintptr_t>(routing_id))); |
857 } | 861 } |
858 | 862 |
859 void ChildThreadImpl::GetAssociatedInterface( | 863 void ChildThreadImpl::GetAssociatedInterface( |
860 const std::string& name, | 864 const std::string& name, |
(...skipping 14 matching lines...) Expand all Loading... |
875 connected_to_browser_ = true; | 879 connected_to_browser_ = true; |
876 child_info_ = local_info; | 880 child_info_ = local_info; |
877 browser_info_ = remote_info; | 881 browser_info_ = remote_info; |
878 } | 882 } |
879 | 883 |
880 bool ChildThreadImpl::IsInBrowserProcess() const { | 884 bool ChildThreadImpl::IsInBrowserProcess() const { |
881 return static_cast<bool>(browser_process_io_runner_); | 885 return static_cast<bool>(browser_process_io_runner_); |
882 } | 886 } |
883 | 887 |
884 } // namespace content | 888 } // namespace content |
OLD | NEW |