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

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: Created 4 years, 6 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" 69 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
70 #include "content/browser/gpu/compositor_util.h" 70 #include "content/browser/gpu/compositor_util.h"
71 #include "content/browser/gpu/gpu_data_manager_impl.h" 71 #include "content/browser/gpu/gpu_data_manager_impl.h"
72 #include "content/browser/gpu/gpu_process_host.h" 72 #include "content/browser/gpu/gpu_process_host.h"
73 #include "content/browser/gpu/shader_disk_cache.h" 73 #include "content/browser/gpu/shader_disk_cache.h"
74 #include "content/browser/histogram_message_filter.h" 74 #include "content/browser/histogram_message_filter.h"
75 #include "content/browser/indexed_db/indexed_db_context_impl.h" 75 #include "content/browser/indexed_db/indexed_db_context_impl.h"
76 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" 76 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
77 #include "content/browser/loader/resource_message_filter.h" 77 #include "content/browser/loader/resource_message_filter.h"
78 #include "content/browser/loader/resource_scheduler_filter.h" 78 #include "content/browser/loader/resource_scheduler_filter.h"
79 #include "content/browser/loader/url_loader_factory_impl.h"
79 #include "content/browser/media/capture/audio_mirroring_manager.h" 80 #include "content/browser/media/capture/audio_mirroring_manager.h"
80 #include "content/browser/media/capture/image_capture_impl.h" 81 #include "content/browser/media/capture/image_capture_impl.h"
81 #include "content/browser/media/media_internals.h" 82 #include "content/browser/media/media_internals.h"
82 #include "content/browser/media/midi_host.h" 83 #include "content/browser/media/midi_host.h"
83 #include "content/browser/memory/memory_message_filter.h" 84 #include "content/browser/memory/memory_message_filter.h"
84 #include "content/browser/message_port_message_filter.h" 85 #include "content/browser/message_port_message_filter.h"
85 #include "content/browser/mime_registry_message_filter.h" 86 #include "content/browser/mime_registry_message_filter.h"
86 #include "content/browser/mojo/constants.h" 87 #include "content/browser/mojo/constants.h"
87 #include "content/browser/mojo/mojo_application_host.h" 88 #include "content/browser/mojo/mojo_application_host.h"
88 #include "content/browser/mojo/mojo_child_connection.h" 89 #include "content/browser/mojo/mojo_child_connection.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 #include "content/common/child_process_host_impl.h" 124 #include "content/common/child_process_host_impl.h"
124 #include "content/common/child_process_messages.h" 125 #include "content/common/child_process_messages.h"
125 #include "content/common/content_switches_internal.h" 126 #include "content/common/content_switches_internal.h"
126 #include "content/common/frame_messages.h" 127 #include "content/common/frame_messages.h"
127 #include "content/common/gpu_host_messages.h" 128 #include "content/common/gpu_host_messages.h"
128 #include "content/common/in_process_child_thread_params.h" 129 #include "content/common/in_process_child_thread_params.h"
129 #include "content/common/mojo/mojo_shell_connection_impl.h" 130 #include "content/common/mojo/mojo_shell_connection_impl.h"
130 #include "content/common/render_process_messages.h" 131 #include "content/common/render_process_messages.h"
131 #include "content/common/resource_messages.h" 132 #include "content/common/resource_messages.h"
132 #include "content/common/site_isolation_policy.h" 133 #include "content/common/site_isolation_policy.h"
134 #include "content/common/url_loader_factory.mojom.h"
133 #include "content/common/view_messages.h" 135 #include "content/common/view_messages.h"
134 #include "content/public/browser/browser_context.h" 136 #include "content/public/browser/browser_context.h"
135 #include "content/public/browser/browser_thread.h" 137 #include "content/public/browser/browser_thread.h"
136 #include "content/public/browser/content_browser_client.h" 138 #include "content/public/browser/content_browser_client.h"
137 #include "content/public/browser/notification_service.h" 139 #include "content/public/browser/notification_service.h"
138 #include "content/public/browser/notification_types.h" 140 #include "content/public/browser/notification_types.h"
139 #include "content/public/browser/render_process_host_factory.h" 141 #include "content/public/browser/render_process_host_factory.h"
140 #include "content/public/browser/render_process_host_observer.h" 142 #include "content/public/browser/render_process_host_observer.h"
141 #include "content/public/browser/render_widget_host.h" 143 #include "content/public/browser/render_widget_host.h"
142 #include "content/public/browser/render_widget_host_iterator.h" 144 #include "content/public/browser/render_widget_host_iterator.h"
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 << "in-process."; 642 << "in-process.";
641 } 643 }
642 } 644 }
643 645
644 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( 646 void RenderProcessHostImpl::RegisterRendererMainThreadFactory(
645 RendererMainThreadFactoryFunction create) { 647 RendererMainThreadFactoryFunction create) {
646 g_renderer_main_thread_factory = create; 648 g_renderer_main_thread_factory = create;
647 } 649 }
648 650
649 RenderProcessHostImpl::~RenderProcessHostImpl() { 651 RenderProcessHostImpl::~RenderProcessHostImpl() {
652 DCHECK_CURRENTLY_ON(BrowserThread::UI);
650 #ifndef NDEBUG 653 #ifndef NDEBUG
651 DCHECK(is_self_deleted_) 654 DCHECK(is_self_deleted_)
652 << "RenderProcessHostImpl is destroyed by something other than itself"; 655 << "RenderProcessHostImpl is destroyed by something other than itself";
653 #endif 656 #endif
654 657
655 // Make sure to clean up the in-process renderer before the channel, otherwise 658 // Make sure to clean up the in-process renderer before the channel, otherwise
656 // it may still run and have its IPCs fail, causing asserts. 659 // it may still run and have its IPCs fail, causing asserts.
657 in_process_renderer_.reset(); 660 in_process_renderer_.reset();
658 661
659 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); 662 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID());
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 GetStoragePartition()->GetMediaURLRequestContext()); 868 GetStoragePartition()->GetMediaURLRequestContext());
866 869
867 ResourceMessageFilter::GetContextsCallback get_contexts_callback( 870 ResourceMessageFilter::GetContextsCallback get_contexts_callback(
868 base::Bind(&GetContexts, browser_context->GetResourceContext(), 871 base::Bind(&GetContexts, browser_context->GetResourceContext(),
869 request_context, media_request_context)); 872 request_context, media_request_context));
870 873
871 // Several filters need the Blob storage context, so fetch it in advance. 874 // Several filters need the Blob storage context, so fetch it in advance.
872 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = 875 scoped_refptr<ChromeBlobStorageContext> blob_storage_context =
873 ChromeBlobStorageContext::GetFor(browser_context); 876 ChromeBlobStorageContext::GetFor(browser_context);
874 877
875 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( 878 resource_message_filter_ = new ResourceMessageFilter(
876 GetID(), PROCESS_TYPE_RENDERER, 879 GetID(), PROCESS_TYPE_RENDERER,
877 storage_partition_impl_->GetAppCacheService(), 880 storage_partition_impl_->GetAppCacheService(), blob_storage_context.get(),
878 blob_storage_context.get(),
879 storage_partition_impl_->GetFileSystemContext(), 881 storage_partition_impl_->GetFileSystemContext(),
880 storage_partition_impl_->GetServiceWorkerContext(), 882 storage_partition_impl_->GetServiceWorkerContext(),
881 storage_partition_impl_->GetHostZoomLevelContext(), 883 storage_partition_impl_->GetHostZoomLevelContext(),
882 get_contexts_callback); 884 get_contexts_callback);
883 885
884 AddFilter(resource_message_filter); 886 AddFilter(resource_message_filter_.get());
887
885 MediaStreamManager* media_stream_manager = 888 MediaStreamManager* media_stream_manager =
886 BrowserMainLoop::GetInstance()->media_stream_manager(); 889 BrowserMainLoop::GetInstance()->media_stream_manager();
887 // The AudioInputRendererHost and AudioRendererHost needs to be available for 890 // The AudioInputRendererHost and AudioRendererHost needs to be available for
888 // lookup, so it's stashed in a member variable. 891 // lookup, so it's stashed in a member variable.
889 audio_input_renderer_host_ = new AudioInputRendererHost( 892 audio_input_renderer_host_ = new AudioInputRendererHost(
890 GetID(), base::GetProcId(GetHandle()), audio_manager, 893 GetID(), base::GetProcId(GetHandle()), audio_manager,
891 media_stream_manager, AudioMirroringManager::GetInstance(), 894 media_stream_manager, AudioMirroringManager::GetInstance(),
892 BrowserMainLoop::GetInstance()->user_input_monitor()); 895 BrowserMainLoop::GetInstance()->user_input_monitor());
893 AddFilter(audio_input_renderer_host_.get()); 896 AddFilter(audio_input_renderer_host_.get());
894 audio_renderer_host_ = new AudioRendererHost( 897 audio_renderer_host_ = new AudioRendererHost(
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 1081
1079 mojo_application_host_->service_registry()->AddService( 1082 mojo_application_host_->service_registry()->AddService(
1080 base::Bind(&RenderProcessHostImpl::CreateStoragePartitionService, 1083 base::Bind(&RenderProcessHostImpl::CreateStoragePartitionService,
1081 base::Unretained(this))); 1084 base::Unretained(this)));
1082 1085
1083 #if defined(OS_ANDROID) 1086 #if defined(OS_ANDROID)
1084 ServiceRegistrarAndroid::RegisterProcessHostServices( 1087 ServiceRegistrarAndroid::RegisterProcessHostServices(
1085 mojo_application_host_->service_registry_android()); 1088 mojo_application_host_->service_registry_android());
1086 #endif 1089 #endif
1087 1090
1091 mojo_application_host_->service_registry()->AddService(base::Bind(
1092 &RenderProcessHostImpl::CreateURLLoaderFactory, base::Unretained(this)));
1093
1088 GetContentClient()->browser()->RegisterRenderProcessMojoServices( 1094 GetContentClient()->browser()->RegisterRenderProcessMojoServices(
1089 mojo_application_host_->service_registry()); 1095 mojo_application_host_->service_registry());
1090 } 1096 }
1091 1097
1092 void RenderProcessHostImpl::CreateStoragePartitionService( 1098 void RenderProcessHostImpl::CreateStoragePartitionService(
1093 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { 1099 mojo::InterfaceRequest<mojom::StoragePartitionService> request) {
1094 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! 1100 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW!
1095 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1101 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1096 switches::kMojoLocalStorage)) { 1102 switches::kMojoLocalStorage)) {
1097 storage_partition_impl_->Bind(std::move(request)); 1103 storage_partition_impl_->Bind(std::move(request));
1098 } 1104 }
1099 } 1105 }
1100 1106
1107 void RenderProcessHostImpl::CreateURLLoaderFactory(
1108 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) {
1109 url_loader_factory_.reset(
1110 new URLLoaderFactoryImpl(resource_message_filter_, std::move(request)));
1111 }
1112
1101 int RenderProcessHostImpl::GetNextRoutingID() { 1113 int RenderProcessHostImpl::GetNextRoutingID() {
1102 return widget_helper_->GetNextRoutingID(); 1114 return widget_helper_->GetNextRoutingID();
1103 } 1115 }
1104 1116
1105 void RenderProcessHostImpl::ResumeDeferredNavigation( 1117 void RenderProcessHostImpl::ResumeDeferredNavigation(
1106 const GlobalRequestID& request_id) { 1118 const GlobalRequestID& request_id) {
1107 widget_helper_->ResumeDeferredNavigation(request_id); 1119 widget_helper_->ResumeDeferredNavigation(request_id);
1108 } 1120 }
1109 1121
1110 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { 1122 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) {
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1803 1815
1804 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { 1816 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) {
1805 ignore_input_events_ = ignore_input_events; 1817 ignore_input_events_ = ignore_input_events;
1806 } 1818 }
1807 1819
1808 bool RenderProcessHostImpl::IgnoreInputEvents() const { 1820 bool RenderProcessHostImpl::IgnoreInputEvents() const {
1809 return ignore_input_events_; 1821 return ignore_input_events_;
1810 } 1822 }
1811 1823
1812 void RenderProcessHostImpl::Cleanup() { 1824 void RenderProcessHostImpl::Cleanup() {
1825 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1813 // Keep the one renderer thread around forever in single process mode. 1826 // Keep the one renderer thread around forever in single process mode.
1814 if (run_renderer_in_process()) 1827 if (run_renderer_in_process())
1815 return; 1828 return;
1816 1829
1817 // If within_process_died_observer_ is true, one of our observers performed an 1830 // If within_process_died_observer_ is true, one of our observers performed an
1818 // action that caused us to die (e.g. http://crbug.com/339504). Therefore, 1831 // action that caused us to die (e.g. http://crbug.com/339504). Therefore,
1819 // delay the destruction until all of the observer callbacks have been made, 1832 // delay the destruction until all of the observer callbacks have been made,
1820 // and guarantee that the RenderProcessHostDestroyed observer callback is 1833 // and guarantee that the RenderProcessHostDestroyed observer callback is
1821 // always the last callback fired. 1834 // always the last callback fired.
1822 if (within_process_died_observer_) { 1835 if (within_process_died_observer_) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1886 1899
1887 // It's important not to wait for the DeleteTask to delete the channel 1900 // It's important not to wait for the DeleteTask to delete the channel
1888 // proxy. Kill it off now. That way, in case the profile is going away, the 1901 // proxy. Kill it off now. That way, in case the profile is going away, the
1889 // rest of the objects attached to this RenderProcessHost start going 1902 // rest of the objects attached to this RenderProcessHost start going
1890 // away first, since deleting the channel proxy will post a 1903 // away first, since deleting the channel proxy will post a
1891 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. 1904 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread.
1892 channel_.reset(); 1905 channel_.reset();
1893 1906
1894 // The following members should be cleared in ProcessDied() as well! 1907 // The following members should be cleared in ProcessDied() as well!
1895 message_port_message_filter_ = NULL; 1908 message_port_message_filter_ = NULL;
1909 url_loader_factory_ = nullptr;
1896 1910
1897 RemoveUserData(kSessionStorageHolderKey); 1911 RemoveUserData(kSessionStorageHolderKey);
1898 1912
1899 // On shutdown, |this| may not be deleted because the deleter is posted to 1913 // On shutdown, |this| may not be deleted because the deleter is posted to
1900 // the current MessageLoop, but MessageLoop deletes all its pending 1914 // the current MessageLoop, but MessageLoop deletes all its pending
1901 // callbacks on shutdown. Since the deleter takes |this| as a raw pointer, 1915 // callbacks on shutdown. Since the deleter takes |this| as a raw pointer,
1902 // deleting the callback doesn't delete |this| resulting in a memory leak. 1916 // deleting the callback doesn't delete |this| resulting in a memory leak.
1903 // Valgrind complains, so delete |mojo_application_host_| explicitly here to 1917 // Valgrind complains, so delete |mojo_application_host_| explicitly here to
1904 // stop valgrind from complaining. 1918 // stop valgrind from complaining.
1905 mojo_application_host_.reset(); 1919 mojo_application_host_.reset();
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
2409 2423
2410 within_process_died_observer_ = true; 2424 within_process_died_observer_ = true;
2411 NotificationService::current()->Notify( 2425 NotificationService::current()->Notify(
2412 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), 2426 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this),
2413 Details<RendererClosedDetails>(&details)); 2427 Details<RendererClosedDetails>(&details));
2414 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, 2428 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_,
2415 RenderProcessExited(this, status, exit_code)); 2429 RenderProcessExited(this, status, exit_code));
2416 within_process_died_observer_ = false; 2430 within_process_died_observer_ = false;
2417 2431
2418 message_port_message_filter_ = NULL; 2432 message_port_message_filter_ = NULL;
2433 url_loader_factory_ = nullptr;
2419 RemoveUserData(kSessionStorageHolderKey); 2434 RemoveUserData(kSessionStorageHolderKey);
2420 2435
2421 IDMap<IPC::Listener>::iterator iter(&listeners_); 2436 IDMap<IPC::Listener>::iterator iter(&listeners_);
2422 while (!iter.IsAtEnd()) { 2437 while (!iter.IsAtEnd()) {
2423 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( 2438 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone(
2424 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); 2439 iter.GetCurrentKey(), static_cast<int>(status), exit_code));
2425 iter.Advance(); 2440 iter.Advance();
2426 } 2441 }
2427 2442
2428 // It's possible that one of the calls out to the observers might have caused 2443 // It's possible that one of the calls out to the observers might have caused
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
2781 2796
2782 // Skip widgets in other processes. 2797 // Skip widgets in other processes.
2783 if (rvh->GetProcess()->GetID() != GetID()) 2798 if (rvh->GetProcess()->GetID() != GetID())
2784 continue; 2799 continue;
2785 2800
2786 rvh->OnWebkitPreferencesChanged(); 2801 rvh->OnWebkitPreferencesChanged();
2787 } 2802 }
2788 } 2803 }
2789 2804
2790 } // namespace content 2805 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698