Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Side by Side Diff: content/browser/renderer_host/render_process_host_impl.cc

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

Powered by Google App Engine
This is Rietveld 408576698