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

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

Issue 1970693002: Use mojo for Chrome Loading, Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" 70 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
71 #include "content/browser/gpu/compositor_util.h" 71 #include "content/browser/gpu/compositor_util.h"
72 #include "content/browser/gpu/gpu_data_manager_impl.h" 72 #include "content/browser/gpu/gpu_data_manager_impl.h"
73 #include "content/browser/gpu/gpu_process_host.h" 73 #include "content/browser/gpu/gpu_process_host.h"
74 #include "content/browser/gpu/shader_disk_cache.h" 74 #include "content/browser/gpu/shader_disk_cache.h"
75 #include "content/browser/histogram_message_filter.h" 75 #include "content/browser/histogram_message_filter.h"
76 #include "content/browser/indexed_db/indexed_db_context_impl.h" 76 #include "content/browser/indexed_db/indexed_db_context_impl.h"
77 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" 77 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
78 #include "content/browser/loader/resource_message_filter.h" 78 #include "content/browser/loader/resource_message_filter.h"
79 #include "content/browser/loader/resource_scheduler_filter.h" 79 #include "content/browser/loader/resource_scheduler_filter.h"
80 #include "content/browser/loader/url_loader_factory_holder.h"
80 #include "content/browser/media/capture/audio_mirroring_manager.h" 81 #include "content/browser/media/capture/audio_mirroring_manager.h"
81 #include "content/browser/media/capture/image_capture_impl.h" 82 #include "content/browser/media/capture/image_capture_impl.h"
82 #include "content/browser/media/media_internals.h" 83 #include "content/browser/media/media_internals.h"
83 #include "content/browser/media/midi_host.h" 84 #include "content/browser/media/midi_host.h"
84 #include "content/browser/memory/memory_message_filter.h" 85 #include "content/browser/memory/memory_message_filter.h"
85 #include "content/browser/message_port_message_filter.h" 86 #include "content/browser/message_port_message_filter.h"
86 #include "content/browser/mime_registry_impl.h" 87 #include "content/browser/mime_registry_impl.h"
87 #include "content/browser/mojo/constants.h" 88 #include "content/browser/mojo/constants.h"
88 #include "content/browser/mojo/mojo_child_connection.h" 89 #include "content/browser/mojo/mojo_child_connection.h"
89 #include "content/browser/notifications/notification_message_filter.h" 90 #include "content/browser/notifications/notification_message_filter.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 #include "content/common/child_process_host_impl.h" 126 #include "content/common/child_process_host_impl.h"
126 #include "content/common/child_process_messages.h" 127 #include "content/common/child_process_messages.h"
127 #include "content/common/content_switches_internal.h" 128 #include "content/common/content_switches_internal.h"
128 #include "content/common/frame_messages.h" 129 #include "content/common/frame_messages.h"
129 #include "content/common/gpu_host_messages.h" 130 #include "content/common/gpu_host_messages.h"
130 #include "content/common/in_process_child_thread_params.h" 131 #include "content/common/in_process_child_thread_params.h"
131 #include "content/common/mojo/mojo_shell_connection_impl.h" 132 #include "content/common/mojo/mojo_shell_connection_impl.h"
132 #include "content/common/render_process_messages.h" 133 #include "content/common/render_process_messages.h"
133 #include "content/common/resource_messages.h" 134 #include "content/common/resource_messages.h"
134 #include "content/common/site_isolation_policy.h" 135 #include "content/common/site_isolation_policy.h"
136 #include "content/common/url_loader_factory.mojom.h"
135 #include "content/common/view_messages.h" 137 #include "content/common/view_messages.h"
136 #include "content/public/browser/browser_context.h" 138 #include "content/public/browser/browser_context.h"
137 #include "content/public/browser/browser_thread.h" 139 #include "content/public/browser/browser_thread.h"
138 #include "content/public/browser/content_browser_client.h" 140 #include "content/public/browser/content_browser_client.h"
139 #include "content/public/browser/notification_service.h" 141 #include "content/public/browser/notification_service.h"
140 #include "content/public/browser/notification_types.h" 142 #include "content/public/browser/notification_types.h"
141 #include "content/public/browser/owned_interface.h" 143 #include "content/public/browser/owned_interface.h"
142 #include "content/public/browser/render_process_host_factory.h" 144 #include "content/public/browser/render_process_host_factory.h"
143 #include "content/public/browser/render_process_host_observer.h" 145 #include "content/public/browser/render_process_host_observer.h"
144 #include "content/public/browser/render_widget_host.h" 146 #include "content/public/browser/render_widget_host.h"
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 << "in-process."; 664 << "in-process.";
663 } 665 }
664 } 666 }
665 667
666 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( 668 void RenderProcessHostImpl::RegisterRendererMainThreadFactory(
667 RendererMainThreadFactoryFunction create) { 669 RendererMainThreadFactoryFunction create) {
668 g_renderer_main_thread_factory = create; 670 g_renderer_main_thread_factory = create;
669 } 671 }
670 672
671 RenderProcessHostImpl::~RenderProcessHostImpl() { 673 RenderProcessHostImpl::~RenderProcessHostImpl() {
674 DCHECK_CURRENTLY_ON(BrowserThread::UI);
672 #ifndef NDEBUG 675 #ifndef NDEBUG
673 DCHECK(is_self_deleted_) 676 DCHECK(is_self_deleted_)
674 << "RenderProcessHostImpl is destroyed by something other than itself"; 677 << "RenderProcessHostImpl is destroyed by something other than itself";
675 #endif 678 #endif
676 679
677 // Make sure to clean up the in-process renderer before the channel, otherwise 680 // Make sure to clean up the in-process renderer before the channel, otherwise
678 // it may still run and have its IPCs fail, causing asserts. 681 // it may still run and have its IPCs fail, causing asserts.
679 in_process_renderer_.reset(); 682 in_process_renderer_.reset();
680 683
681 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); 684 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID());
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 GetStoragePartition()->GetMediaURLRequestContext()); 907 GetStoragePartition()->GetMediaURLRequestContext());
905 908
906 ResourceMessageFilter::GetContextsCallback get_contexts_callback( 909 ResourceMessageFilter::GetContextsCallback get_contexts_callback(
907 base::Bind(&GetContexts, browser_context->GetResourceContext(), 910 base::Bind(&GetContexts, browser_context->GetResourceContext(),
908 request_context, media_request_context)); 911 request_context, media_request_context));
909 912
910 // Several filters need the Blob storage context, so fetch it in advance. 913 // Several filters need the Blob storage context, so fetch it in advance.
911 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = 914 scoped_refptr<ChromeBlobStorageContext> blob_storage_context =
912 ChromeBlobStorageContext::GetFor(browser_context); 915 ChromeBlobStorageContext::GetFor(browser_context);
913 916
914 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( 917 resource_message_filter_ = new ResourceMessageFilter(
915 GetID(), PROCESS_TYPE_RENDERER, 918 GetID(), PROCESS_TYPE_RENDERER,
916 storage_partition_impl_->GetAppCacheService(), 919 storage_partition_impl_->GetAppCacheService(), blob_storage_context.get(),
917 blob_storage_context.get(),
918 storage_partition_impl_->GetFileSystemContext(), 920 storage_partition_impl_->GetFileSystemContext(),
919 storage_partition_impl_->GetServiceWorkerContext(), 921 storage_partition_impl_->GetServiceWorkerContext(),
920 storage_partition_impl_->GetHostZoomLevelContext(), 922 storage_partition_impl_->GetHostZoomLevelContext(),
921 get_contexts_callback); 923 get_contexts_callback);
922 924
923 AddFilter(resource_message_filter); 925 AddFilter(resource_message_filter_.get());
926
924 MediaStreamManager* media_stream_manager = 927 MediaStreamManager* media_stream_manager =
925 BrowserMainLoop::GetInstance()->media_stream_manager(); 928 BrowserMainLoop::GetInstance()->media_stream_manager();
926 // The AudioInputRendererHost and AudioRendererHost needs to be available for 929 // The AudioInputRendererHost and AudioRendererHost needs to be available for
927 // lookup, so it's stashed in a member variable. 930 // lookup, so it's stashed in a member variable.
928 audio_input_renderer_host_ = new AudioInputRendererHost( 931 audio_input_renderer_host_ = new AudioInputRendererHost(
929 GetID(), base::GetProcId(GetHandle()), audio_manager, 932 GetID(), base::GetProcId(GetHandle()), audio_manager,
930 media_stream_manager, AudioMirroringManager::GetInstance(), 933 media_stream_manager, AudioMirroringManager::GetInstance(),
931 BrowserMainLoop::GetInstance()->user_input_monitor()); 934 BrowserMainLoop::GetInstance()->user_input_monitor());
932 AddFilter(audio_input_renderer_host_.get()); 935 AddFilter(audio_input_renderer_host_.get());
933 audio_renderer_host_ = new AudioRendererHost( 936 audio_renderer_host_ = new AudioRendererHost(
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 if (memory_coordinator::IsEnabled()) { 1120 if (memory_coordinator::IsEnabled()) {
1118 GetInterfaceRegistry()->AddInterface( 1121 GetInterfaceRegistry()->AddInterface(
1119 base::Bind(&CreateMemoryCoordinatorHandle, GetID())); 1122 base::Bind(&CreateMemoryCoordinatorHandle, GetID()));
1120 } 1123 }
1121 1124
1122 #if defined(OS_ANDROID) 1125 #if defined(OS_ANDROID)
1123 ServiceRegistrarAndroid::RegisterProcessHostServices( 1126 ServiceRegistrarAndroid::RegisterProcessHostServices(
1124 mojo_child_connection_->service_registry_android()); 1127 mojo_child_connection_->service_registry_android());
1125 #endif 1128 #endif
1126 1129
1130 GetInterfaceRegistry()->AddInterface(base::Bind(
1131 &RenderProcessHostImpl::CreateURLLoaderFactory, base::Unretained(this)));
1132
1127 GetContentClient()->browser()->ExposeInterfacesToRenderer( 1133 GetContentClient()->browser()->ExposeInterfacesToRenderer(
1128 GetInterfaceRegistry(), this); 1134 GetInterfaceRegistry(), this);
1129 } 1135 }
1130 1136
1131 void RenderProcessHostImpl::CreateStoragePartitionService( 1137 void RenderProcessHostImpl::CreateStoragePartitionService(
1132 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { 1138 mojo::InterfaceRequest<mojom::StoragePartitionService> request) {
1133 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! 1139 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW!
1134 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1140 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1135 switches::kMojoLocalStorage)) { 1141 switches::kMojoLocalStorage)) {
1136 storage_partition_impl_->Bind(std::move(request)); 1142 storage_partition_impl_->Bind(std::move(request));
1137 } 1143 }
1138 } 1144 }
1139 1145
1146 void RenderProcessHostImpl::CreateURLLoaderFactory(
1147 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) {
1148 url_loader_factory_holder_.reset(
1149 new URLLoaderFactoryHolder(resource_message_filter_, std::move(request)));
1150 }
1151
1140 int RenderProcessHostImpl::GetNextRoutingID() { 1152 int RenderProcessHostImpl::GetNextRoutingID() {
1141 return widget_helper_->GetNextRoutingID(); 1153 return widget_helper_->GetNextRoutingID();
1142 } 1154 }
1143 1155
1144 void RenderProcessHostImpl::ResumeDeferredNavigation( 1156 void RenderProcessHostImpl::ResumeDeferredNavigation(
1145 const GlobalRequestID& request_id) { 1157 const GlobalRequestID& request_id) {
1146 widget_helper_->ResumeDeferredNavigation(request_id); 1158 widget_helper_->ResumeDeferredNavigation(request_id);
1147 } 1159 }
1148 1160
1149 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { 1161 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) {
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 1889
1878 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { 1890 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) {
1879 ignore_input_events_ = ignore_input_events; 1891 ignore_input_events_ = ignore_input_events;
1880 } 1892 }
1881 1893
1882 bool RenderProcessHostImpl::IgnoreInputEvents() const { 1894 bool RenderProcessHostImpl::IgnoreInputEvents() const {
1883 return ignore_input_events_; 1895 return ignore_input_events_;
1884 } 1896 }
1885 1897
1886 void RenderProcessHostImpl::Cleanup() { 1898 void RenderProcessHostImpl::Cleanup() {
1899 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1887 // Keep the one renderer thread around forever in single process mode. 1900 // Keep the one renderer thread around forever in single process mode.
1888 if (run_renderer_in_process()) 1901 if (run_renderer_in_process())
1889 return; 1902 return;
1890 1903
1891 // If within_process_died_observer_ is true, one of our observers performed an 1904 // If within_process_died_observer_ is true, one of our observers performed an
1892 // action that caused us to die (e.g. http://crbug.com/339504). Therefore, 1905 // action that caused us to die (e.g. http://crbug.com/339504). Therefore,
1893 // delay the destruction until all of the observer callbacks have been made, 1906 // delay the destruction until all of the observer callbacks have been made,
1894 // and guarantee that the RenderProcessHostDestroyed observer callback is 1907 // and guarantee that the RenderProcessHostDestroyed observer callback is
1895 // always the last callback fired. 1908 // always the last callback fired.
1896 if (within_process_died_observer_) { 1909 if (within_process_died_observer_) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 1973
1961 // It's important not to wait for the DeleteTask to delete the channel 1974 // It's important not to wait for the DeleteTask to delete the channel
1962 // proxy. Kill it off now. That way, in case the profile is going away, the 1975 // proxy. Kill it off now. That way, in case the profile is going away, the
1963 // rest of the objects attached to this RenderProcessHost start going 1976 // rest of the objects attached to this RenderProcessHost start going
1964 // away first, since deleting the channel proxy will post a 1977 // away first, since deleting the channel proxy will post a
1965 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. 1978 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread.
1966 channel_.reset(); 1979 channel_.reset();
1967 1980
1968 // The following members should be cleared in ProcessDied() as well! 1981 // The following members should be cleared in ProcessDied() as well!
1969 message_port_message_filter_ = NULL; 1982 message_port_message_filter_ = NULL;
1983 url_loader_factory_holder_ = nullptr;
1970 1984
1971 RemoveUserData(kSessionStorageHolderKey); 1985 RemoveUserData(kSessionStorageHolderKey);
1972 1986
1973 // Remove ourself from the list of renderer processes so that we can't be 1987 // Remove ourself from the list of renderer processes so that we can't be
1974 // reused in between now and when the Delete task runs. 1988 // reused in between now and when the Delete task runs.
1975 UnregisterHost(GetID()); 1989 UnregisterHost(GetID());
1976 } 1990 }
1977 } 1991 }
1978 1992
1979 void RenderProcessHostImpl::AddPendingView() { 1993 void RenderProcessHostImpl::AddPendingView() {
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
2469 2483
2470 within_process_died_observer_ = true; 2484 within_process_died_observer_ = true;
2471 NotificationService::current()->Notify( 2485 NotificationService::current()->Notify(
2472 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), 2486 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this),
2473 Details<RendererClosedDetails>(&details)); 2487 Details<RendererClosedDetails>(&details));
2474 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, 2488 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_,
2475 RenderProcessExited(this, status, exit_code)); 2489 RenderProcessExited(this, status, exit_code));
2476 within_process_died_observer_ = false; 2490 within_process_died_observer_ = false;
2477 2491
2478 message_port_message_filter_ = NULL; 2492 message_port_message_filter_ = NULL;
2493 url_loader_factory_holder_ = nullptr;
2479 RemoveUserData(kSessionStorageHolderKey); 2494 RemoveUserData(kSessionStorageHolderKey);
2480 2495
2481 IDMap<IPC::Listener>::iterator iter(&listeners_); 2496 IDMap<IPC::Listener>::iterator iter(&listeners_);
2482 while (!iter.IsAtEnd()) { 2497 while (!iter.IsAtEnd()) {
2483 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( 2498 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone(
2484 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); 2499 iter.GetCurrentKey(), static_cast<int>(status), exit_code));
2485 iter.Advance(); 2500 iter.Advance();
2486 } 2501 }
2487 2502
2488 // It's possible that one of the calls out to the observers might have caused 2503 // It's possible that one of the calls out to the observers might have caused
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
2793 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; 2808 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error;
2794 2809
2795 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias 2810 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias
2796 // enough information here so that we can determine what the bad message was. 2811 // enough information here so that we can determine what the bad message was.
2797 base::debug::Alias(&error); 2812 base::debug::Alias(&error);
2798 bad_message::ReceivedBadMessage(process.get(), 2813 bad_message::ReceivedBadMessage(process.get(),
2799 bad_message::RPH_MOJO_PROCESS_ERROR); 2814 bad_message::RPH_MOJO_PROCESS_ERROR);
2800 } 2815 }
2801 2816
2802 } // namespace content 2817 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698