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. | |
| 832 channel_.reset(); | |
| 833 queued_messages_ = MessageQueue{}; | |
| 834 | 808 |
| 835 UnregisterHost(GetID()); | 809 UnregisterHost(GetID()); |
| 836 | 810 |
| 837 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 811 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 838 switches::kDisableGpuShaderDiskCache)) { | 812 switches::kDisableGpuShaderDiskCache)) { |
| 839 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 813 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 840 base::Bind(&RemoveShaderInfo, GetID())); | 814 base::Bind(&RemoveShaderInfo, GetID())); |
| 841 } | 815 } |
| 842 } | 816 } |
| 843 | 817 |
| 844 void RenderProcessHostImpl::EnableSendQueue() { | |
| 845 is_initialized_ = false; | |
|
ncarter (slow)
2016/10/12 23:32:42
I'd never thought deeply about this function befor
Ken Rockot(use gerrit already)
2016/10/12 23:56:05
Yes, RPHI is full of surprises :)
| |
| 846 } | |
| 847 | |
| 848 bool RenderProcessHostImpl::Init() { | 818 bool RenderProcessHostImpl::Init() { |
| 849 // calling Init() more than once does nothing, this makes it more convenient | 819 // 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 | 820 // for the view host which may not be sure in some cases |
| 851 if (channel_) | 821 if (HasConnection()) |
| 852 return true; | 822 return true; |
| 853 | 823 |
| 824 is_dead_ = false; | |
| 825 | |
| 854 base::CommandLine::StringType renderer_prefix; | 826 base::CommandLine::StringType renderer_prefix; |
| 855 // A command prefix is something prepended to the command line of the spawned | 827 // A command prefix is something prepended to the command line of the spawned |
| 856 // process. | 828 // process. |
| 857 const base::CommandLine& browser_command_line = | 829 const base::CommandLine& browser_command_line = |
| 858 *base::CommandLine::ForCurrentProcess(); | 830 *base::CommandLine::ForCurrentProcess(); |
| 859 renderer_prefix = | 831 renderer_prefix = |
| 860 browser_command_line.GetSwitchValueNative(switches::kRendererCmdPrefix); | 832 browser_command_line.GetSwitchValueNative(switches::kRendererCmdPrefix); |
| 861 | 833 |
| 862 #if defined(OS_LINUX) | 834 #if defined(OS_LINUX) |
| 863 int flags = renderer_prefix.empty() ? ChildProcessHost::CHILD_ALLOW_SELF | 835 int flags = renderer_prefix.empty() ? ChildProcessHost::CHILD_ALLOW_SELF |
| 864 : ChildProcessHost::CHILD_NORMAL; | 836 : ChildProcessHost::CHILD_NORMAL; |
| 865 #else | 837 #else |
| 866 int flags = ChildProcessHost::CHILD_NORMAL; | 838 int flags = ChildProcessHost::CHILD_NORMAL; |
| 867 #endif | 839 #endif |
| 868 | 840 |
| 869 // Find the renderer before creating the channel so if this fails early we | 841 // Find the renderer before creating the channel so if this fails early we |
| 870 // return without creating the channel. | 842 // return without creating the channel. |
| 871 base::FilePath renderer_path = ChildProcessHost::GetChildPath(flags); | 843 base::FilePath renderer_path = ChildProcessHost::GetChildPath(flags); |
| 872 if (renderer_path.empty()) | 844 if (renderer_path.empty()) |
| 873 return false; | 845 return false; |
| 874 | 846 |
| 875 channel_connected_ = false; | |
| 876 sent_render_process_ready_ = false; | 847 sent_render_process_ready_ = false; |
| 877 | 848 |
| 878 // Setup the IPC channel. | 849 // Unpause the Channel briefly. This will be paused again below if we launch a |
| 879 channel_ = CreateChannelProxy(); | 850 // real child process. Note that messages may be sent in the short window |
| 880 | 851 // 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 | 852 // 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 // | 853 // |
| 886 // We acquire a few associated interface proxies here -- before the channel is | 854 // |channel_| must always be non-null here: either it was initialized in |
| 887 // paused -- to ensure that subsequent initialization messages on those | 855 // the constructor, or in the most recent call to ProcessDied(). |
| 888 // interfaces behave properly. Specifically, this avoids the risk of an | 856 DCHECK(channel_); |
| 889 // interface being requested while the Channel is paused, effectively | 857 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 | 858 |
| 902 // Call the embedder first so that their IPC filters have priority. | 859 // Call the embedder first so that their IPC filters have priority. |
| 903 GetContentClient()->browser()->RenderProcessWillLaunch(this); | 860 GetContentClient()->browser()->RenderProcessWillLaunch(this); |
| 904 | 861 |
| 905 #if !defined(OS_MACOSX) | 862 #if !defined(OS_MACOSX) |
| 906 // Intentionally delay the hang monitor creation after the first renderer | 863 // 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 | 864 // is created. On Mac audio thread is the UI thread, a hang monitor is not |
| 908 // necessary or recommended. | 865 // necessary or recommended. |
| 909 media::AudioManager::StartHangMonitorIfNeeded( | 866 media::AudioManager::StartHangMonitorIfNeeded( |
| 910 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 867 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 966 // at this stage. | 923 // at this stage. |
| 967 child_process_launcher_.reset(new ChildProcessLauncher( | 924 child_process_launcher_.reset(new ChildProcessLauncher( |
| 968 new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, | 925 new RendererSandboxedProcessLauncherDelegate(channel_.get()), cmd_line, |
| 969 GetID(), this, child_token_, | 926 GetID(), this, child_token_, |
| 970 base::Bind(&RenderProcessHostImpl::OnMojoError, id_))); | 927 base::Bind(&RenderProcessHostImpl::OnMojoError, id_))); |
| 971 channel_->Pause(); | 928 channel_->Pause(); |
| 972 | 929 |
| 973 fast_shutdown_started_ = false; | 930 fast_shutdown_started_ = false; |
| 974 } | 931 } |
| 975 | 932 |
| 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_) { | 933 if (!gpu_observer_registered_) { |
| 985 gpu_observer_registered_ = true; | 934 gpu_observer_registered_ = true; |
| 986 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); | 935 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); |
| 987 } | 936 } |
| 988 | 937 |
| 989 power_monitor_broadcaster_.Init(); | 938 power_monitor_broadcaster_.Init(); |
| 990 | 939 |
| 991 is_initialized_ = true; | 940 is_initialized_ = true; |
| 992 init_time_ = base::TimeTicks::Now(); | 941 init_time_ = base::TimeTicks::Now(); |
| 993 return true; | 942 return true; |
| 994 } | 943 } |
| 995 | 944 |
| 996 std::unique_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy() { | 945 void RenderProcessHostImpl::InitializeChannelProxy() { |
| 997 scoped_refptr<base::SingleThreadTaskRunner> runner = | 946 // Generate a token used to identify the new child process. |
| 947 child_token_ = mojo::edk::GenerateRandomToken(); | |
| 948 | |
| 949 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = | |
| 998 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); | 950 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); |
| 951 | |
| 952 // Acquire a Connector which will route connections to a new instance of the | |
| 953 // renderer service. | |
| 954 shell::Connector* connector = | |
| 955 BrowserContext::GetConnectorFor(browser_context_); | |
| 956 if (!connector) { | |
| 957 // Note that some embedders (e.g. Android WebView) may not initialize a | |
| 958 // Connector per BrowserContext. In those cases we fall back to the | |
| 959 // browser-wide Connector. | |
| 960 if (!ServiceManagerConnection::GetForProcess()) { | |
| 961 // Additionally, some test code may not initialize the process-wide | |
| 962 // ServiceManagerConnection prior to this point. This class of test code | |
| 963 // doesn't care about render processes, so we can initialize a dummy | |
| 964 // connection. | |
| 965 shell::mojom::ServiceRequest request = mojo::GetProxy(&test_service_); | |
| 966 ServiceManagerConnection::SetForProcess(ServiceManagerConnection::Create( | |
| 967 std::move(request), io_task_runner)); | |
| 968 } | |
| 969 connector = ServiceManagerConnection::GetForProcess()->GetConnector(); | |
| 970 } | |
| 971 | |
| 972 // Establish a ServiceManager connection for the new render service instance. | |
| 973 child_connection_.reset(new ChildConnection( | |
| 974 kRendererServiceName, | |
| 975 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector, | |
|
ncarter (slow)
2016/10/12 23:32:42
Is instance_id_ needed for correctness, if we gene
Ken Rockot(use gerrit already)
2016/10/12 23:56:05
It is needed for correctness. These two identifier
| |
| 976 io_task_runner)); | |
| 977 | |
| 978 // Send an interface request to bootstrap the IPC::Channel. Note that this | |
| 979 // request will happily sit on the pipe until the process is launched and | |
| 980 // connected to the ServiceManager. We take the other end immediately and | |
| 981 // plug it into a new ChannelProxy. | |
| 999 IPC::mojom::ChannelBootstrapPtr bootstrap; | 982 IPC::mojom::ChannelBootstrapPtr bootstrap; |
| 1000 GetRemoteInterfaces()->GetInterface(&bootstrap); | 983 GetRemoteInterfaces()->GetInterface(&bootstrap); |
| 1001 std::unique_ptr<IPC::ChannelFactory> channel_factory = | 984 std::unique_ptr<IPC::ChannelFactory> channel_factory = |
| 1002 IPC::ChannelMojo::CreateServerFactory( | 985 IPC::ChannelMojo::CreateServerFactory( |
| 1003 bootstrap.PassInterface().PassHandle(), runner); | 986 bootstrap.PassInterface().PassHandle(), io_task_runner); |
| 1004 | 987 |
| 1005 std::unique_ptr<IPC::ChannelProxy> channel; | 988 #if USE_ATTACHMENT_BROKER |
| 989 if (channel_) { | |
| 990 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | |
| 991 channel_.get()); | |
| 992 } | |
| 993 #endif | |
| 994 | |
| 995 channel_.reset(); | |
| 996 channel_connected_ = false; | |
| 997 | |
| 1006 // Do NOT expand ifdef or run time condition checks here! Synchronous | 998 // Do NOT expand ifdef or run time condition checks here! Synchronous |
| 1007 // IPCs from browser process are banned. It is only narrowly allowed | 999 // IPCs from browser process are banned. It is only narrowly allowed |
| 1008 // for Android WebView to maintain backward compatibility. | 1000 // for Android WebView to maintain backward compatibility. |
| 1009 // See crbug.com/526842 for details. | 1001 // See crbug.com/526842 for details. |
| 1010 #if defined(OS_ANDROID) | 1002 #if defined(OS_ANDROID) |
| 1011 if (GetContentClient()->UsingSynchronousCompositing()) | 1003 if (GetContentClient()->UsingSynchronousCompositing()) { |
| 1012 channel = IPC::SyncChannel::Create(this, runner.get(), &never_signaled_); | 1004 channel_ = IPC::SyncChannel::Create( |
| 1005 this, io_task_runner.get(), &never_signaled_); | |
| 1006 } | |
| 1013 #endif // OS_ANDROID | 1007 #endif // OS_ANDROID |
| 1014 if (!channel) | 1008 if (!channel_) |
| 1015 channel.reset(new IPC::ChannelProxy(this, runner.get())); | 1009 channel_.reset(new IPC::ChannelProxy(this, io_task_runner.get())); |
| 1016 #if USE_ATTACHMENT_BROKER | 1010 #if USE_ATTACHMENT_BROKER |
| 1017 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( | 1011 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( |
| 1018 channel.get(), runner); | 1012 channel_.get(), io_task_runner); |
| 1019 #endif | 1013 #endif |
| 1020 channel->Init(std::move(channel_factory), true /* create_pipe_now */); | 1014 channel_->Init(std::move(channel_factory), true /* create_pipe_now */); |
| 1021 | 1015 |
| 1022 return channel; | 1016 // Note that Channel send is effectively paused and unpaused at various points |
| 1017 // during startup, and existing code relies on a fragile relative message | |
| 1018 // ordering resulting from some early messages being queued until process | |
| 1019 // launch while others are sent immediately. See https://goo.gl/REW75h for | |
| 1020 // details. | |
| 1021 // | |
| 1022 // We acquire a few associated interface proxies here -- before the channel is | |
| 1023 // paused -- to ensure that subsequent initialization messages on those | |
| 1024 // interfaces behave properly. Specifically, this avoids the risk of an | |
| 1025 // interface being requested while the Channel is paused, which could | |
| 1026 // effectively and undesirably block the transmission of a subsequent message | |
| 1027 // on that interface while the Channel is unpaused. | |
| 1028 // | |
| 1029 // See OnProcessLaunched() for some additional details of this somewhat | |
| 1030 // surprising behavior. | |
| 1031 channel_->GetRemoteAssociatedInterface(&remote_route_provider_); | |
| 1032 | |
| 1033 std::unique_ptr<AssociatedInterfaceHolder<mojom::Renderer>> holder = | |
| 1034 base::MakeUnique<AssociatedInterfaceHolder<mojom::Renderer>>(); | |
| 1035 channel_->GetRemoteAssociatedInterface(&holder->proxy()); | |
| 1036 SetUserData(kRendererInterfaceKeyName, holder.release()); | |
| 1037 | |
| 1038 // We start the Channel in a paused state. It will be briefly unpaused again | |
| 1039 // in Init() if applicable, before process launch is initiated. | |
| 1040 channel_->Pause(); | |
| 1023 } | 1041 } |
| 1024 | 1042 |
| 1025 void RenderProcessHostImpl::CreateMessageFilters() { | 1043 void RenderProcessHostImpl::CreateMessageFilters() { |
| 1026 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1044 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1027 AddFilter(new ResourceSchedulerFilter(GetID())); | 1045 AddFilter(new ResourceSchedulerFilter(GetID())); |
| 1028 MediaInternals* media_internals = MediaInternals::GetInstance(); | 1046 MediaInternals* media_internals = MediaInternals::GetInstance(); |
| 1029 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages | 1047 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages |
| 1030 // from guests. | 1048 // from guests. |
| 1031 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( | 1049 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( |
| 1032 new BrowserPluginMessageFilter(GetID())); | 1050 new BrowserPluginMessageFilter(GetID())); |
| (...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1942 | 1960 |
| 1943 ProcessDied(false /* already_dead */, nullptr); | 1961 ProcessDied(false /* already_dead */, nullptr); |
| 1944 return true; | 1962 return true; |
| 1945 } | 1963 } |
| 1946 | 1964 |
| 1947 bool RenderProcessHostImpl::Send(IPC::Message* msg) { | 1965 bool RenderProcessHostImpl::Send(IPC::Message* msg) { |
| 1948 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send"); | 1966 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send"); |
| 1949 | 1967 |
| 1950 std::unique_ptr<IPC::Message> message(msg); | 1968 std::unique_ptr<IPC::Message> message(msg); |
| 1951 | 1969 |
| 1970 // |channel_| is only null after Cleanup(), at which point we don't care about | |
| 1971 // delivering any messages. | |
| 1972 if (!channel_) | |
| 1973 return false; | |
| 1974 | |
| 1952 #if !defined(OS_ANDROID) | 1975 #if !defined(OS_ANDROID) |
| 1953 DCHECK(!message->is_sync()); | 1976 DCHECK(!message->is_sync()); |
| 1954 #endif | 1977 #endif |
| 1955 | 1978 |
| 1956 if (!channel_) { | |
| 1957 #if defined(OS_ANDROID) | |
| 1958 if (message->is_sync()) | |
| 1959 return false; | |
| 1960 #endif | |
| 1961 if (!is_initialized_) { | |
| 1962 queued_messages_.emplace(std::move(message)); | |
| 1963 return true; | |
| 1964 } | |
| 1965 return false; | |
| 1966 } | |
| 1967 | |
| 1968 #if defined(OS_ANDROID) | 1979 #if defined(OS_ANDROID) |
| 1969 if (child_process_launcher_.get() && child_process_launcher_->IsStarting() && | 1980 if (child_process_launcher_.get() && child_process_launcher_->IsStarting() && |
| 1970 message->is_sync()) { | 1981 message->is_sync()) { |
| 1971 return false; | 1982 return false; |
| 1972 } | 1983 } |
| 1973 #endif | 1984 #endif |
| 1974 | 1985 |
| 1975 return channel_->Send(message.release()); | 1986 return channel_->Send(message.release()); |
| 1976 } | 1987 } |
| 1977 | 1988 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2075 bool RenderProcessHostImpl::InSameStoragePartition( | 2086 bool RenderProcessHostImpl::InSameStoragePartition( |
| 2076 StoragePartition* partition) const { | 2087 StoragePartition* partition) const { |
| 2077 return storage_partition_impl_ == partition; | 2088 return storage_partition_impl_ == partition; |
| 2078 } | 2089 } |
| 2079 | 2090 |
| 2080 int RenderProcessHostImpl::GetID() const { | 2091 int RenderProcessHostImpl::GetID() const { |
| 2081 return id_; | 2092 return id_; |
| 2082 } | 2093 } |
| 2083 | 2094 |
| 2084 bool RenderProcessHostImpl::HasConnection() const { | 2095 bool RenderProcessHostImpl::HasConnection() const { |
| 2085 return channel_.get() != NULL; | 2096 return is_initialized_ && !is_dead_; |
| 2086 } | 2097 } |
| 2087 | 2098 |
| 2088 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { | 2099 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
| 2089 ignore_input_events_ = ignore_input_events; | 2100 ignore_input_events_ = ignore_input_events; |
| 2090 } | 2101 } |
| 2091 | 2102 |
| 2092 bool RenderProcessHostImpl::IgnoreInputEvents() const { | 2103 bool RenderProcessHostImpl::IgnoreInputEvents() const { |
| 2093 return ignore_input_events_; | 2104 return ignore_input_events_; |
| 2094 } | 2105 } |
| 2095 | 2106 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2137 UMA_HISTOGRAM_COUNTS("Render.Workers.MaxWorkerCountInRendererProcess", | 2148 UMA_HISTOGRAM_COUNTS("Render.Workers.MaxWorkerCountInRendererProcess", |
| 2138 max_worker_count_); | 2149 max_worker_count_); |
| 2139 } | 2150 } |
| 2140 | 2151 |
| 2141 // We cannot clean up twice; if this fails, there is an issue with our | 2152 // We cannot clean up twice; if this fails, there is an issue with our |
| 2142 // control flow. | 2153 // control flow. |
| 2143 DCHECK(!deleting_soon_); | 2154 DCHECK(!deleting_soon_); |
| 2144 | 2155 |
| 2145 DCHECK_EQ(0, pending_views_); | 2156 DCHECK_EQ(0, pending_views_); |
| 2146 | 2157 |
| 2147 // If |channel_| is still valid, the process associated with this | 2158 // If the process associated with this RenderProcessHost is still alive, |
| 2148 // RenderProcessHost is still alive. Notify all observers that the process | 2159 // 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. | 2160 // will be destroyed a bit later. Observers shouldn't rely on this process |
| 2150 // Observers shouldn't rely on this process anymore. | 2161 // anymore. |
| 2151 if (channel_.get()) { | 2162 if (!is_dead_) { |
|
ncarter (slow)
2016/10/12 23:32:42
I'm trying to reason about why we need both is_dea
Ken Rockot(use gerrit already)
2016/10/12 23:56:05
We may not need both. HasConnection() could *proba
| |
| 2152 FOR_EACH_OBSERVER( | 2163 FOR_EACH_OBSERVER( |
| 2153 RenderProcessHostObserver, observers_, | 2164 RenderProcessHostObserver, observers_, |
| 2154 RenderProcessExited(this, base::TERMINATION_STATUS_NORMAL_TERMINATION, | 2165 RenderProcessExited(this, base::TERMINATION_STATUS_NORMAL_TERMINATION, |
| 2155 0)); | 2166 0)); |
| 2156 } | 2167 } |
| 2157 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2168 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
| 2158 RenderProcessHostDestroyed(this)); | 2169 RenderProcessHostDestroyed(this)); |
| 2159 NotificationService::current()->Notify( | 2170 NotificationService::current()->Notify( |
| 2160 NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 2171 NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 2161 Source<RenderProcessHost>(this), NotificationService::NoDetails()); | 2172 Source<RenderProcessHost>(this), NotificationService::NoDetails()); |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2671 // FrameHostMsg_RenderProcessGone with status | 2682 // FrameHostMsg_RenderProcessGone with status |
| 2672 // TERMINATION_STATUS_STILL_RUNNING, since this will break WebContentsImpl | 2683 // TERMINATION_STATUS_STILL_RUNNING, since this will break WebContentsImpl |
| 2673 // logic. | 2684 // logic. |
| 2674 status = base::TERMINATION_STATUS_PROCESS_CRASHED; | 2685 status = base::TERMINATION_STATUS_PROCESS_CRASHED; |
| 2675 } | 2686 } |
| 2676 } | 2687 } |
| 2677 | 2688 |
| 2678 RendererClosedDetails details(status, exit_code); | 2689 RendererClosedDetails details(status, exit_code); |
| 2679 | 2690 |
| 2680 child_process_launcher_.reset(); | 2691 child_process_launcher_.reset(); |
| 2681 #if USE_ATTACHMENT_BROKER | 2692 is_dead_ = true; |
| 2682 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | |
| 2683 channel_.get()); | |
| 2684 #endif | |
| 2685 channel_.reset(); | |
| 2686 queued_messages_ = MessageQueue{}; | |
| 2687 | 2693 |
| 2688 // Clear all cached associated interface proxies as well, since these are | 2694 // Clear all cached associated interface proxies as well, since these are |
| 2689 // effectively bound to the lifetime of the Channel. | 2695 // effectively bound to the lifetime of the Channel. |
| 2690 remote_route_provider_.reset(); | 2696 remote_route_provider_.reset(); |
| 2691 RemoveUserData(kRendererInterfaceKeyName); | 2697 RemoveUserData(kRendererInterfaceKeyName); |
| 2692 | 2698 |
| 2693 UpdateProcessPriority(); | 2699 UpdateProcessPriority(); |
| 2694 DCHECK(!is_process_backgrounded_); | 2700 DCHECK(!is_process_backgrounded_); |
| 2695 | 2701 |
| 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; | 2702 within_process_died_observer_ = true; |
| 2710 NotificationService::current()->Notify( | 2703 NotificationService::current()->Notify( |
| 2711 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2704 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
| 2712 Details<RendererClosedDetails>(&details)); | 2705 Details<RendererClosedDetails>(&details)); |
| 2713 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2706 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
| 2714 RenderProcessExited(this, status, exit_code)); | 2707 RenderProcessExited(this, status, exit_code)); |
| 2715 within_process_died_observer_ = false; | 2708 within_process_died_observer_ = false; |
| 2716 | 2709 |
| 2717 message_port_message_filter_ = NULL; | 2710 message_port_message_filter_ = NULL; |
| 2718 | 2711 |
| 2719 DCHECK(!channel_); | |
| 2720 RemoveUserData(kSessionStorageHolderKey); | 2712 RemoveUserData(kSessionStorageHolderKey); |
| 2721 | 2713 |
| 2722 IDMap<IPC::Listener>::iterator iter(&listeners_); | 2714 IDMap<IPC::Listener>::iterator iter(&listeners_); |
| 2723 while (!iter.IsAtEnd()) { | 2715 while (!iter.IsAtEnd()) { |
| 2724 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( | 2716 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( |
| 2725 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); | 2717 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); |
| 2726 iter.Advance(); | 2718 iter.Advance(); |
| 2727 } | 2719 } |
| 2728 | 2720 |
| 2721 // Initialize a new ChannelProxy in case this host is re-used for a new | |
| 2722 // process. This ensures that new messages can be sent on the host ASAP (even | |
| 2723 // before Init()) and they'll eventually reach the new process. | |
| 2724 InitializeChannelProxy(); | |
| 2725 | |
| 2729 // It's possible that one of the calls out to the observers might have caused | 2726 // It's possible that one of the calls out to the observers might have caused |
| 2730 // this object to be no longer needed. | 2727 // this object to be no longer needed. |
| 2731 if (delayed_cleanup_needed_) | 2728 if (delayed_cleanup_needed_) |
| 2732 Cleanup(); | 2729 Cleanup(); |
| 2733 | 2730 |
| 2734 // This object is not deleted at this point and might be reused later. | 2731 // This object is not deleted at this point and might be reused later. |
| 2735 // TODO(darin): clean this up | 2732 // TODO(darin): clean this up |
| 2736 } | 2733 } |
| 2737 | 2734 |
| 2738 size_t RenderProcessHost::GetActiveViewCount() { | 2735 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; | 3026 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
| 3030 | 3027 |
| 3031 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 3028 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias |
| 3032 // enough information here so that we can determine what the bad message was. | 3029 // enough information here so that we can determine what the bad message was. |
| 3033 base::debug::Alias(&error); | 3030 base::debug::Alias(&error); |
| 3034 bad_message::ReceivedBadMessage(render_process_id, | 3031 bad_message::ReceivedBadMessage(render_process_id, |
| 3035 bad_message::RPH_MOJO_PROCESS_ERROR); | 3032 bad_message::RPH_MOJO_PROCESS_ERROR); |
| 3036 } | 3033 } |
| 3037 | 3034 |
| 3038 } // namespace content | 3035 } // namespace content |
| OLD | NEW |