Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // Represents the browser side of the browser <--> renderer communication | 5 // Represents the browser side of the browser <--> renderer communication |
| 6 // channel. There will be one RenderProcessHost per renderer process. | 6 // channel. There will be one RenderProcessHost per renderer process. |
| 7 | 7 |
| 8 #include "content/browser/renderer_host/render_process_host_impl.h" | 8 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 RenderProcessHostImpl::RenderProcessHostImpl( | 676 RenderProcessHostImpl::RenderProcessHostImpl( |
| 677 BrowserContext* browser_context, | 677 BrowserContext* browser_context, |
| 678 StoragePartitionImpl* storage_partition_impl, | 678 StoragePartitionImpl* storage_partition_impl, |
| 679 bool is_for_guests_only) | 679 bool is_for_guests_only) |
| 680 : fast_shutdown_started_(false), | 680 : fast_shutdown_started_(false), |
| 681 deleting_soon_(false), | 681 deleting_soon_(false), |
| 682 #ifndef NDEBUG | 682 #ifndef NDEBUG |
| 683 is_self_deleted_(false), | 683 is_self_deleted_(false), |
| 684 #endif | 684 #endif |
| 685 pending_views_(0), | 685 pending_views_(0), |
| 686 child_token_(mojo::edk::GenerateRandomToken()), | |
| 687 service_worker_ref_count_(0), | 686 service_worker_ref_count_(0), |
| 688 shared_worker_ref_count_(0), | 687 shared_worker_ref_count_(0), |
| 689 is_worker_ref_count_disabled_(false), | 688 is_worker_ref_count_disabled_(false), |
| 690 route_provider_binding_(this), | 689 route_provider_binding_(this), |
| 691 associated_interface_provider_bindings_( | 690 associated_interface_provider_bindings_( |
| 692 mojo::BindingSetDispatchMode::WITH_CONTEXT), | 691 mojo::BindingSetDispatchMode::WITH_CONTEXT), |
| 693 visible_widgets_(0), | 692 visible_widgets_(0), |
| 694 is_process_backgrounded_(false), | 693 is_process_backgrounded_(false), |
| 695 is_initialized_(false), | |
| 696 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 694 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
| 697 browser_context_(browser_context), | 695 browser_context_(browser_context), |
| 698 storage_partition_impl_(storage_partition_impl), | 696 storage_partition_impl_(storage_partition_impl), |
| 699 sudden_termination_allowed_(true), | 697 sudden_termination_allowed_(true), |
| 700 ignore_input_events_(false), | 698 ignore_input_events_(false), |
| 701 is_for_guests_only_(is_for_guests_only), | 699 is_for_guests_only_(is_for_guests_only), |
| 702 gpu_observer_registered_(false), | 700 gpu_observer_registered_(false), |
| 703 delayed_cleanup_needed_(false), | 701 delayed_cleanup_needed_(false), |
| 704 within_process_died_observer_(false), | 702 within_process_died_observer_(false), |
| 705 power_monitor_broadcaster_(this), | 703 power_monitor_broadcaster_(this), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 // single process modes, the global attachment broker is the privileged | 744 // single process modes, the global attachment broker is the privileged |
| 747 // attachment broker, rather than an unprivileged attachment broker. | 745 // attachment broker, rather than an unprivileged attachment broker. |
| 748 #if defined(OS_MACOSX) | 746 #if defined(OS_MACOSX) |
| 749 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( | 747 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( |
| 750 MachBroker::GetInstance()); | 748 MachBroker::GetInstance()); |
| 751 #else | 749 #else |
| 752 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); | 750 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); |
| 753 #endif // defined(OS_MACOSX) | 751 #endif // defined(OS_MACOSX) |
| 754 #endif // USE_ATTACHMENT_BROKER | 752 #endif // USE_ATTACHMENT_BROKER |
| 755 | 753 |
| 756 scoped_refptr<base::SequencedTaskRunner> io_task_runner = | 754 InitializeChannelProxy(); |
| 757 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); | |
| 758 shell::Connector* connector = | |
| 759 BrowserContext::GetConnectorFor(browser_context_); | |
| 760 // Some embedders may not initialize Mojo or the shell connector for a browser | |
| 761 // context (e.g. Android WebView)... so just fall back to the per-process | |
| 762 // connector. | |
| 763 if (!connector) { | |
| 764 // Additionally, some test code may not initialize the process-wide | |
| 765 // ServiceManagerConnection prior to this point. This class of test code | |
| 766 // doesn't care about render processes so we can initialize a dummy one. | |
| 767 if (!ServiceManagerConnection::GetForProcess()) { | |
| 768 shell::mojom::ServiceRequest request = mojo::GetProxy(&test_service_); | |
| 769 ServiceManagerConnection::SetForProcess(ServiceManagerConnection::Create( | |
| 770 std::move(request), io_task_runner)); | |
| 771 } | |
| 772 connector = ServiceManagerConnection::GetForProcess()->GetConnector(); | |
| 773 } | |
| 774 child_connection_.reset(new ChildConnection( | |
| 775 kRendererServiceName, | |
| 776 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector, | |
| 777 io_task_runner)); | |
| 778 } | 755 } |
| 779 | 756 |
| 780 // static | 757 // static |
| 781 void RenderProcessHostImpl::ShutDownInProcessRenderer() { | 758 void RenderProcessHostImpl::ShutDownInProcessRenderer() { |
| 782 DCHECK(g_run_renderer_in_process_); | 759 DCHECK(g_run_renderer_in_process_); |
| 783 | 760 |
| 784 switch (g_all_hosts.Pointer()->size()) { | 761 switch (g_all_hosts.Pointer()->size()) { |
| 785 case 0: | 762 case 0: |
| 786 return; | 763 return; |
| 787 case 1: { | 764 case 1: { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 | 798 |
| 822 if (gpu_observer_registered_) { | 799 if (gpu_observer_registered_) { |
| 823 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); | 800 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); |
| 824 gpu_observer_registered_ = false; | 801 gpu_observer_registered_ = false; |
| 825 } | 802 } |
| 826 | 803 |
| 827 #if USE_ATTACHMENT_BROKER | 804 #if USE_ATTACHMENT_BROKER |
| 828 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | 805 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( |
| 829 channel_.get()); | 806 channel_.get()); |
| 830 #endif | 807 #endif |
| 831 // We may have some unsent messages at this point, but that's OK. | 808 |
| 809 is_dead_ = true; | |
| 832 channel_.reset(); | 810 channel_.reset(); |
| 833 queued_messages_ = MessageQueue{}; | |
| 834 | 811 |
| 835 UnregisterHost(GetID()); | 812 UnregisterHost(GetID()); |
| 836 | 813 |
| 837 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 814 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 838 switches::kDisableGpuShaderDiskCache)) { | 815 switches::kDisableGpuShaderDiskCache)) { |
| 839 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 816 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 840 base::Bind(&RemoveShaderInfo, GetID())); | 817 base::Bind(&RemoveShaderInfo, GetID())); |
| 841 } | 818 } |
| 842 } | 819 } |
| 843 | 820 |
| 844 void RenderProcessHostImpl::EnableSendQueue() { | |
| 845 is_initialized_ = false; | |
| 846 } | |
| 847 | |
| 848 bool RenderProcessHostImpl::Init() { | 821 bool RenderProcessHostImpl::Init() { |
| 849 // calling Init() more than once does nothing, this makes it more convenient | 822 // calling Init() more than once does nothing, this makes it more convenient |
| 850 // for the view host which may not be sure in some cases | 823 // for the view host which may not be sure in some cases |
| 851 if (channel_) | 824 if (HasConnection()) |
| 852 return true; | 825 return true; |
| 853 | 826 |
| 827 is_dead_ = false; | |
| 828 | |
| 854 base::CommandLine::StringType renderer_prefix; | 829 base::CommandLine::StringType renderer_prefix; |
| 855 // A command prefix is something prepended to the command line of the spawned | 830 // A command prefix is something prepended to the command line of the spawned |
| 856 // process. | 831 // process. |
| 857 const base::CommandLine& browser_command_line = | 832 const base::CommandLine& browser_command_line = |
| 858 *base::CommandLine::ForCurrentProcess(); | 833 *base::CommandLine::ForCurrentProcess(); |
| 859 renderer_prefix = | 834 renderer_prefix = |
| 860 browser_command_line.GetSwitchValueNative(switches::kRendererCmdPrefix); | 835 browser_command_line.GetSwitchValueNative(switches::kRendererCmdPrefix); |
| 861 | 836 |
| 862 #if defined(OS_LINUX) | 837 #if defined(OS_LINUX) |
| 863 int flags = renderer_prefix.empty() ? ChildProcessHost::CHILD_ALLOW_SELF | 838 int flags = renderer_prefix.empty() ? ChildProcessHost::CHILD_ALLOW_SELF |
| 864 : ChildProcessHost::CHILD_NORMAL; | 839 : ChildProcessHost::CHILD_NORMAL; |
| 865 #else | 840 #else |
| 866 int flags = ChildProcessHost::CHILD_NORMAL; | 841 int flags = ChildProcessHost::CHILD_NORMAL; |
| 867 #endif | 842 #endif |
| 868 | 843 |
| 869 // Find the renderer before creating the channel so if this fails early we | 844 // Find the renderer before creating the channel so if this fails early we |
| 870 // return without creating the channel. | 845 // return without creating the channel. |
| 871 base::FilePath renderer_path = ChildProcessHost::GetChildPath(flags); | 846 base::FilePath renderer_path = ChildProcessHost::GetChildPath(flags); |
| 872 if (renderer_path.empty()) | 847 if (renderer_path.empty()) |
| 873 return false; | 848 return false; |
| 874 | 849 |
| 875 channel_connected_ = false; | |
| 876 sent_render_process_ready_ = false; | 850 sent_render_process_ready_ = false; |
| 877 | 851 |
| 878 // Setup the IPC channel. | 852 // Unpause the Channel briefly. This will be paused again below if we launch a |
| 879 channel_ = CreateChannelProxy(); | 853 // real child process. Note that messages may be sent in the short window |
| 880 | 854 // between now and then (e.g. in response to RenderProcessWillLaunch) and we |
| 881 // Note that Channel send is effectively paused and unpaused at various points | 855 // depend on those messages being sent right away. |
| 882 // during startup, and existing code relies on a fragile relative message | |
| 883 // ordering resulting from some early messages being queued until process | |
| 884 // launch while others are sent immediately. | |
| 885 // | 856 // |
| 886 // We acquire a few associated interface proxies here -- before the channel is | 857 // |channel_| must always be non-null here: either it was initialized in |
| 887 // paused -- to ensure that subsequent initialization messages on those | 858 // the constructor, or in the most recent call to ProcessDied(). |
| 888 // interfaces behave properly. Specifically, this avoids the risk of an | 859 DCHECK(channel_); |
| 889 // interface being requested while the Channel is paused, effectively | 860 channel_->Unpause(false /* flush */); |
| 890 // blocking the transmission of a subsequent message on the interface which | |
| 891 // may be sent while the Channel is unpaused. | |
| 892 // | |
| 893 // See OnProcessLaunched() for some additional details of this somewhat | |
| 894 // surprising behavior. | |
| 895 channel_->GetRemoteAssociatedInterface(&remote_route_provider_); | |
| 896 | |
| 897 std::unique_ptr<AssociatedInterfaceHolder<mojom::Renderer>> holder = | |
| 898 base::MakeUnique<AssociatedInterfaceHolder<mojom::Renderer>>(); | |
| 899 channel_->GetRemoteAssociatedInterface(&holder->proxy()); | |
| 900 SetUserData(kRendererInterfaceKeyName, holder.release()); | |
| 901 | 861 |
| 902 // Call the embedder first so that their IPC filters have priority. | 862 // Call the embedder first so that their IPC filters have priority. |
| 903 GetContentClient()->browser()->RenderProcessWillLaunch(this); | 863 GetContentClient()->browser()->RenderProcessWillLaunch(this); |
| 904 | 864 |
| 905 #if !defined(OS_MACOSX) | 865 #if !defined(OS_MACOSX) |
| 906 // Intentionally delay the hang monitor creation after the first renderer | 866 // Intentionally delay the hang monitor creation after the first renderer |
| 907 // is created. On Mac audio thread is the UI thread, a hang monitor is not | 867 // is created. On Mac audio thread is the UI thread, a hang monitor is not |
| 908 // necessary or recommended. | 868 // necessary or recommended. |
| 909 media::AudioManager::StartHangMonitorIfNeeded( | 869 media::AudioManager::StartHangMonitorIfNeeded( |
| 910 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 870 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 966 // at this stage. | 926 // at this stage. |
| 967 child_process_launcher_.reset(new ChildProcessLauncher( | 927 child_process_launcher_.reset(new ChildProcessLauncher( |
| 968 new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, | 928 new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, |
| 969 GetID(), this, child_token_, | 929 GetID(), this, child_token_, |
| 970 base::Bind(&RenderProcessHostImpl::OnMojoError, id_))); | 930 base::Bind(&RenderProcessHostImpl::OnMojoError, id_))); |
| 971 channel_->Pause(); | 931 channel_->Pause(); |
| 972 | 932 |
| 973 fast_shutdown_started_ = false; | 933 fast_shutdown_started_ = false; |
| 974 } | 934 } |
| 975 | 935 |
| 976 // Push any pending messages to the channel now. Note that if the child | |
| 977 // process is still launching, the channel will be paused and outgoing | |
| 978 // messages will be queued internally by the channel. | |
| 979 while (!queued_messages_.empty()) { | |
| 980 channel_->Send(queued_messages_.front().release()); | |
| 981 queued_messages_.pop(); | |
| 982 } | |
| 983 | |
| 984 if (!gpu_observer_registered_) { | 936 if (!gpu_observer_registered_) { |
| 985 gpu_observer_registered_ = true; | 937 gpu_observer_registered_ = true; |
| 986 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); | 938 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); |
| 987 } | 939 } |
| 988 | 940 |
| 989 power_monitor_broadcaster_.Init(); | 941 power_monitor_broadcaster_.Init(); |
| 990 | 942 |
| 991 is_initialized_ = true; | 943 is_initialized_ = true; |
| 992 init_time_ = base::TimeTicks::Now(); | 944 init_time_ = base::TimeTicks::Now(); |
| 993 return true; | 945 return true; |
| 994 } | 946 } |
| 995 | 947 |
| 996 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy() { | 948 void RenderProcessHostImpl::InitializeChannelProxy() { |
| 997 scoped_refptr<base::SingleThreadTaskRunner> runner = | 949 // Generate a token used to identify the new child process. |
| 950 child_token_ = mojo::edk::GenerateRandomToken(); | |
| 951 | |
| 952 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = | |
| 998 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); | 953 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); |
| 954 | |
| 955 // Acquire a Connector which will route connections to a new instance of the | |
| 956 // renderer service. | |
| 957 shell::Connector* connector = | |
| 958 BrowserContext::GetConnectorFor(browser_context_); | |
| 959 if (!connector) { | |
| 960 // Note that some embedders (e.g. Android WebView) may not initialize a | |
| 961 // Connector per BrowserContext. In those cases we fall back to the | |
| 962 // browser-wide Connector. | |
| 963 if (!ServiceManagerConnection::GetForProcess()) { | |
| 964 // Additionally, some test code may not initialize the process-wide | |
| 965 // ServiceManagerConnection prior to this point. This class of test code | |
| 966 // doesn't care about render processes, so we can initialize a dummy | |
| 967 // connection. | |
| 968 shell::mojom::ServiceRequest request = mojo::GetProxy(&test_service_); | |
| 969 ServiceManagerConnection::SetForProcess(ServiceManagerConnection::Create( | |
| 970 std::move(request), io_task_runner)); | |
| 971 } | |
| 972 connector = ServiceManagerConnection::GetForProcess()->GetConnector(); | |
| 973 } | |
| 974 | |
| 975 // Establish a ServiceManager connection for the new render service instance. | |
| 976 child_connection_.reset(new ChildConnection( | |
| 977 kRendererServiceName, | |
| 978 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector, | |
| 979 io_task_runner)); | |
| 980 | |
| 981 // Send an interface request to bootstrap the IPC::Channel. Note that this | |
| 982 // request will happily sit on the pipe until the process is launched and | |
| 983 // connected to the ServiceManager. We take the other end immediately and | |
| 984 // plug it into a new ChannelProxy. | |
| 999 IPC::mojom::ChannelBootstrapPtr bootstrap; | 985 IPC::mojom::ChannelBootstrapPtr bootstrap; |
| 1000 GetRemoteInterfaces()->GetInterface(&bootstrap); | 986 GetRemoteInterfaces()->GetInterface(&bootstrap); |
| 1001 std::unique_ptr<IPC::ChannelFactory> channel_factory = | 987 std::unique_ptr<IPC::ChannelFactory> channel_factory = |
| 1002 IPC::ChannelMojo::CreateServerFactory( | 988 IPC::ChannelMojo::CreateServerFactory( |
| 1003 bootstrap.PassInterface().PassHandle(), runner); | 989 bootstrap.PassInterface().PassHandle(), io_task_runner); |
| 1004 | 990 |
| 1005 std::unique_ptr<IPC::ChannelProxy> channel; | 991 #if USE_ATTACHMENT_BROKER |
| 992 if (channel_) { | |
| 993 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | |
| 994 channel_.get()); | |
| 995 } | |
| 996 #endif | |
| 997 | |
| 998 channel_.reset(); | |
| 999 channel_connected_ = false; | |
| 1000 | |
| 1006 // Do NOT expand ifdef or run time condition checks here! Synchronous | 1001 // Do NOT expand ifdef or run time condition checks here! Synchronous |
| 1007 // IPCs from browser process are banned. It is only narrowly allowed | 1002 // IPCs from browser process are banned. It is only narrowly allowed |
| 1008 // for Android WebView to maintain backward compatibility. | 1003 // for Android WebView to maintain backward compatibility. |
| 1009 // See crbug.com/526842 for details. | 1004 // See crbug.com/526842 for details. |
| 1010 #if defined(OS_ANDROID) | 1005 #if defined(OS_ANDROID) |
| 1011 if (GetContentClient()->UsingSynchronousCompositing()) | 1006 if (GetContentClient()->UsingSynchronousCompositing()) { |
| 1012 channel = IPC::SyncChannel::Create(this, runner.get(), &never_signaled_); | 1007 channel_ = IPC::SyncChannel::Create( |
| 1008 this, io_task_runner.get(), &never_signaled_); | |
| 1009 } | |
| 1013 #endif // OS_ANDROID | 1010 #endif // OS_ANDROID |
| 1014 if (!channel) | 1011 if (!channel_) |
| 1015 channel.reset(new IPC::ChannelProxy(this, runner.get())); | 1012 channel_.reset(new IPC::ChannelProxy(this, io_task_runner.get())); |
| 1016 #if USE_ATTACHMENT_BROKER | 1013 #if USE_ATTACHMENT_BROKER |
| 1017 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( | 1014 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( |
| 1018 channel.get(), runner); | 1015 channel_.get(), io_task_runner); |
| 1019 #endif | 1016 #endif |
| 1020 channel->Init(std::move(channel_factory), true /* create_pipe_now */); | 1017 channel_->Init(std::move(channel_factory), true /* create_pipe_now */); |
| 1021 | 1018 |
| 1022 return channel; | 1019 // Note that Channel send is effectively paused and unpaused at various points |
| 1020 // during startup, and existing code relies on a fragile relative message | |
| 1021 // ordering resulting from some early messages being queued until process | |
| 1022 // launch while others are sent immediately. See https://goo.gl/REW75h for | |
| 1023 // details. | |
| 1024 // | |
| 1025 // We acquire a few associated interface proxies here -- before the channel is | |
| 1026 // paused -- to ensure that subsequent initialization messages on those | |
| 1027 // interfaces behave properly. Specifically, this avoids the risk of an | |
| 1028 // interface being requested while the Channel is paused, which could | |
| 1029 // effectively and undesirably block the transmission of a subsequent message | |
| 1030 // on that interface while the Channel is unpaused. | |
| 1031 // | |
| 1032 // See OnProcessLaunched() for some additional details of this somewhat | |
| 1033 // surprising behavior. | |
| 1034 channel_->GetRemoteAssociatedInterface(&remote_route_provider_); | |
| 1035 | |
| 1036 std::unique_ptr<AssociatedInterfaceHolder<mojom::Renderer>> holder = | |
| 1037 base::MakeUnique<AssociatedInterfaceHolder<mojom::Renderer>>(); | |
| 1038 channel_->GetRemoteAssociatedInterface(&holder->proxy()); | |
| 1039 SetUserData(kRendererInterfaceKeyName, holder.release()); | |
| 1040 | |
| 1041 // We start the Channel in a paused state. It will be briefly unpaused again | |
| 1042 // in Init() if applicable, before process launch is initiated. | |
| 1043 channel_->Pause(); | |
| 1023 } | 1044 } |
| 1024 | 1045 |
| 1025 void RenderProcessHostImpl::CreateMessageFilters() { | 1046 void RenderProcessHostImpl::CreateMessageFilters() { |
| 1026 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1047 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1027 AddFilter(new ResourceSchedulerFilter(GetID())); | 1048 AddFilter(new ResourceSchedulerFilter(GetID())); |
| 1028 MediaInternals* media_internals = MediaInternals::GetInstance(); | 1049 MediaInternals* media_internals = MediaInternals::GetInstance(); |
| 1029 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages | 1050 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages |
| 1030 // from guests. | 1051 // from guests. |
| 1031 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( | 1052 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( |
| 1032 new BrowserPluginMessageFilter(GetID())); | 1053 new BrowserPluginMessageFilter(GetID())); |
| (...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1942 | 1963 |
| 1943 ProcessDied(false /* already_dead */, nullptr); | 1964 ProcessDied(false /* already_dead */, nullptr); |
| 1944 return true; | 1965 return true; |
| 1945 } | 1966 } |
| 1946 | 1967 |
| 1947 bool RenderProcessHostImpl::Send(IPC::Message* msg) { | 1968 bool RenderProcessHostImpl::Send(IPC::Message* msg) { |
| 1948 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send"); | 1969 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send"); |
| 1949 | 1970 |
| 1950 std::unique_ptr<IPC::Message> message(msg); | 1971 std::unique_ptr<IPC::Message> message(msg); |
| 1951 | 1972 |
| 1973 // |channel_| is only null after Cleanup(), at which point we don't care about | |
| 1974 // delivering any messages. | |
| 1975 if (!channel_) | |
| 1976 return false; | |
| 1977 | |
| 1952 #if !defined(OS_ANDROID) | 1978 #if !defined(OS_ANDROID) |
| 1953 DCHECK(!message->is_sync()); | 1979 DCHECK(!message->is_sync()); |
| 1954 #endif | 1980 #else |
| 1981 if (message->is_sync()) { | |
| 1982 // HACK: trying to track down unit_tests hangs on Andoird bots. Reject ALL | |
| 1983 // sync IPC. Do not commit this! | |
|
ncarter (slow)
2016/10/13 21:40:28
Don't commit this!
| |
| 1984 if (std::string().empty()) | |
| 1985 return false; | |
| 1955 | 1986 |
| 1956 if (!channel_) { | 1987 // If Init() hasn't been called yet [either since construction or since the |
| 1957 #if defined(OS_ANDROID) | 1988 // last call to ProcessDied()] we avoid blocking on sync IPC. |
| 1958 if (message->is_sync()) | 1989 if (!HasConnection()) |
| 1959 return false; | 1990 return false; |
| 1960 #endif | |
| 1961 if (!is_initialized_) { | |
| 1962 queued_messages_.emplace(std::move(message)); | |
| 1963 return true; | |
| 1964 } | |
| 1965 return false; | |
| 1966 } | |
| 1967 | 1991 |
| 1968 #if defined(OS_ANDROID) | 1992 // Likewise if we've called Init() but process launch has not yet completed, |
| 1969 if (child_process_launcher_.get() && child_process_launcher_->IsStarting() && | 1993 // we still avoid blocking on sync IPC. |
| 1970 message->is_sync()) { | 1994 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) |
| 1971 return false; | 1995 return false; |
| 1972 } | 1996 } |
| 1973 #endif | 1997 #endif |
| 1974 | 1998 |
| 1975 return channel_->Send(message.release()); | 1999 return channel_->Send(message.release()); |
| 1976 } | 2000 } |
| 1977 | 2001 |
| 1978 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { | 2002 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { |
| 1979 // If we're about to be deleted, or have initiated the fast shutdown sequence, | 2003 // If we're about to be deleted, or have initiated the fast shutdown sequence, |
| 1980 // we ignore incoming messages. | 2004 // we ignore incoming messages. |
| 1981 | 2005 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2075 bool RenderProcessHostImpl::InSameStoragePartition( | 2099 bool RenderProcessHostImpl::InSameStoragePartition( |
| 2076 StoragePartition* partition) const { | 2100 StoragePartition* partition) const { |
| 2077 return storage_partition_impl_ == partition; | 2101 return storage_partition_impl_ == partition; |
| 2078 } | 2102 } |
| 2079 | 2103 |
| 2080 int RenderProcessHostImpl::GetID() const { | 2104 int RenderProcessHostImpl::GetID() const { |
| 2081 return id_; | 2105 return id_; |
| 2082 } | 2106 } |
| 2083 | 2107 |
| 2084 bool RenderProcessHostImpl::HasConnection() const { | 2108 bool RenderProcessHostImpl::HasConnection() const { |
| 2085 return channel_.get() != NULL; | 2109 return is_initialized_ && !is_dead_; |
| 2086 } | 2110 } |
| 2087 | 2111 |
| 2088 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { | 2112 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
| 2089 ignore_input_events_ = ignore_input_events; | 2113 ignore_input_events_ = ignore_input_events; |
| 2090 } | 2114 } |
| 2091 | 2115 |
| 2092 bool RenderProcessHostImpl::IgnoreInputEvents() const { | 2116 bool RenderProcessHostImpl::IgnoreInputEvents() const { |
| 2093 return ignore_input_events_; | 2117 return ignore_input_events_; |
| 2094 } | 2118 } |
| 2095 | 2119 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2137 UMA_HISTOGRAM_COUNTS("Render.Workers.MaxWorkerCountInRendererProcess", | 2161 UMA_HISTOGRAM_COUNTS("Render.Workers.MaxWorkerCountInRendererProcess", |
| 2138 max_worker_count_); | 2162 max_worker_count_); |
| 2139 } | 2163 } |
| 2140 | 2164 |
| 2141 // We cannot clean up twice; if this fails, there is an issue with our | 2165 // We cannot clean up twice; if this fails, there is an issue with our |
| 2142 // control flow. | 2166 // control flow. |
| 2143 DCHECK(!deleting_soon_); | 2167 DCHECK(!deleting_soon_); |
| 2144 | 2168 |
| 2145 DCHECK_EQ(0, pending_views_); | 2169 DCHECK_EQ(0, pending_views_); |
| 2146 | 2170 |
| 2147 // If |channel_| is still valid, the process associated with this | 2171 // If the process associated with this RenderProcessHost is still alive, |
| 2148 // RenderProcessHost is still alive. Notify all observers that the process | 2172 // notify all observers that the process has exited cleanly, even though it |
| 2149 // has exited cleanly, even though it will be destroyed a bit later. | 2173 // will be destroyed a bit later. Observers shouldn't rely on this process |
| 2150 // Observers shouldn't rely on this process anymore. | 2174 // anymore. |
| 2151 if (channel_.get()) { | 2175 if (HasConnection()) { |
| 2152 FOR_EACH_OBSERVER( | 2176 FOR_EACH_OBSERVER( |
| 2153 RenderProcessHostObserver, observers_, | 2177 RenderProcessHostObserver, observers_, |
| 2154 RenderProcessExited(this, base::TERMINATION_STATUS_NORMAL_TERMINATION, | 2178 RenderProcessExited(this, base::TERMINATION_STATUS_NORMAL_TERMINATION, |
| 2155 0)); | 2179 0)); |
| 2156 } | 2180 } |
| 2157 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2181 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
| 2158 RenderProcessHostDestroyed(this)); | 2182 RenderProcessHostDestroyed(this)); |
| 2159 NotificationService::current()->Notify( | 2183 NotificationService::current()->Notify( |
| 2160 NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 2184 NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 2161 Source<RenderProcessHost>(this), NotificationService::NoDetails()); | 2185 Source<RenderProcessHost>(this), NotificationService::NoDetails()); |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2671 // FrameHostMsg_RenderProcessGone with status | 2695 // FrameHostMsg_RenderProcessGone with status |
| 2672 // TERMINATION_STATUS_STILL_RUNNING, since this will break WebContentsImpl | 2696 // TERMINATION_STATUS_STILL_RUNNING, since this will break WebContentsImpl |
| 2673 // logic. | 2697 // logic. |
| 2674 status = base::TERMINATION_STATUS_PROCESS_CRASHED; | 2698 status = base::TERMINATION_STATUS_PROCESS_CRASHED; |
| 2675 } | 2699 } |
| 2676 } | 2700 } |
| 2677 | 2701 |
| 2678 RendererClosedDetails details(status, exit_code); | 2702 RendererClosedDetails details(status, exit_code); |
| 2679 | 2703 |
| 2680 child_process_launcher_.reset(); | 2704 child_process_launcher_.reset(); |
| 2681 #if USE_ATTACHMENT_BROKER | 2705 is_dead_ = true; |
| 2682 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | |
| 2683 channel_.get()); | |
| 2684 #endif | |
| 2685 channel_.reset(); | |
| 2686 queued_messages_ = MessageQueue{}; | |
| 2687 | 2706 |
| 2688 // Clear all cached associated interface proxies as well, since these are | 2707 // Clear all cached associated interface proxies as well, since these are |
| 2689 // effectively bound to the lifetime of the Channel. | 2708 // effectively bound to the lifetime of the Channel. |
| 2690 remote_route_provider_.reset(); | 2709 remote_route_provider_.reset(); |
| 2691 RemoveUserData(kRendererInterfaceKeyName); | 2710 RemoveUserData(kRendererInterfaceKeyName); |
| 2692 | 2711 |
| 2693 UpdateProcessPriority(); | 2712 UpdateProcessPriority(); |
| 2694 DCHECK(!is_process_backgrounded_); | 2713 DCHECK(!is_process_backgrounded_); |
| 2695 | 2714 |
| 2696 // RenderProcessExited observers and RenderProcessGone handlers might | |
| 2697 // navigate or perform other actions that require a connection. Ensure that | |
| 2698 // there is one before calling them. | |
| 2699 child_token_ = mojo::edk::GenerateRandomToken(); | |
| 2700 shell::Connector* connector = | |
| 2701 BrowserContext::GetConnectorFor(browser_context_); | |
| 2702 if (!connector) | |
| 2703 connector = ServiceManagerConnection::GetForProcess()->GetConnector(); | |
| 2704 child_connection_.reset(new ChildConnection( | |
| 2705 kRendererServiceName, | |
| 2706 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector, | |
| 2707 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); | |
| 2708 | |
| 2709 within_process_died_observer_ = true; | 2715 within_process_died_observer_ = true; |
| 2710 NotificationService::current()->Notify( | 2716 NotificationService::current()->Notify( |
| 2711 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2717 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
| 2712 Details<RendererClosedDetails>(&details)); | 2718 Details<RendererClosedDetails>(&details)); |
| 2713 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2719 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
| 2714 RenderProcessExited(this, status, exit_code)); | 2720 RenderProcessExited(this, status, exit_code)); |
| 2715 within_process_died_observer_ = false; | 2721 within_process_died_observer_ = false; |
| 2716 | 2722 |
| 2717 message_port_message_filter_ = NULL; | 2723 message_port_message_filter_ = NULL; |
| 2718 | 2724 |
| 2719 DCHECK(!channel_); | |
| 2720 RemoveUserData(kSessionStorageHolderKey); | 2725 RemoveUserData(kSessionStorageHolderKey); |
| 2721 | 2726 |
| 2722 IDMap<IPC::Listener>::iterator iter(&listeners_); | 2727 IDMap<IPC::Listener>::iterator iter(&listeners_); |
| 2723 while (!iter.IsAtEnd()) { | 2728 while (!iter.IsAtEnd()) { |
| 2724 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( | 2729 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( |
| 2725 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); | 2730 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); |
| 2726 iter.Advance(); | 2731 iter.Advance(); |
| 2727 } | 2732 } |
| 2728 | 2733 |
| 2734 // Initialize a new ChannelProxy in case this host is re-used for a new | |
| 2735 // process. This ensures that new messages can be sent on the host ASAP (even | |
| 2736 // before Init()) and they'll eventually reach the new process. | |
| 2737 InitializeChannelProxy(); | |
| 2738 | |
| 2729 // It's possible that one of the calls out to the observers might have caused | 2739 // It's possible that one of the calls out to the observers might have caused |
| 2730 // this object to be no longer needed. | 2740 // this object to be no longer needed. |
| 2731 if (delayed_cleanup_needed_) | 2741 if (delayed_cleanup_needed_) |
| 2732 Cleanup(); | 2742 Cleanup(); |
| 2733 | 2743 |
| 2734 // This object is not deleted at this point and might be reused later. | 2744 // This object is not deleted at this point and might be reused later. |
| 2735 // TODO(darin): clean this up | 2745 // TODO(darin): clean this up |
| 2736 } | 2746 } |
| 2737 | 2747 |
| 2738 size_t RenderProcessHost::GetActiveViewCount() { | 2748 size_t RenderProcessHost::GetActiveViewCount() { |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3029 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 3039 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
| 3030 | 3040 |
| 3031 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 3041 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias |
| 3032 // enough information here so that we can determine what the bad message was. | 3042 // enough information here so that we can determine what the bad message was. |
| 3033 base::debug::Alias(&error); | 3043 base::debug::Alias(&error); |
| 3034 bad_message::ReceivedBadMessage(render_process_id, | 3044 bad_message::ReceivedBadMessage(render_process_id, |
| 3035 bad_message::RPH_MOJO_PROCESS_ERROR); | 3045 bad_message::RPH_MOJO_PROCESS_ERROR); |
| 3036 } | 3046 } |
| 3037 | 3047 |
| 3038 } // namespace content | 3048 } // namespace content |
| OLD | NEW |