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

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, 7 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_impl.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_message_filter.h" 87 #include "content/browser/mime_registry_message_filter.h"
87 #include "content/browser/mojo/constants.h" 88 #include "content/browser/mojo/constants.h"
88 #include "content/browser/mojo/mojo_application_host.h" 89 #include "content/browser/mojo/mojo_application_host.h"
89 #include "content/browser/mojo/mojo_child_connection.h" 90 #include "content/browser/mojo/mojo_child_connection.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 #include "content/common/child_process_host_impl.h" 125 #include "content/common/child_process_host_impl.h"
125 #include "content/common/child_process_messages.h" 126 #include "content/common/child_process_messages.h"
126 #include "content/common/content_switches_internal.h" 127 #include "content/common/content_switches_internal.h"
127 #include "content/common/frame_messages.h" 128 #include "content/common/frame_messages.h"
128 #include "content/common/gpu_host_messages.h" 129 #include "content/common/gpu_host_messages.h"
129 #include "content/common/in_process_child_thread_params.h" 130 #include "content/common/in_process_child_thread_params.h"
130 #include "content/common/mojo/mojo_shell_connection_impl.h" 131 #include "content/common/mojo/mojo_shell_connection_impl.h"
131 #include "content/common/render_process_messages.h" 132 #include "content/common/render_process_messages.h"
132 #include "content/common/resource_messages.h" 133 #include "content/common/resource_messages.h"
133 #include "content/common/site_isolation_policy.h" 134 #include "content/common/site_isolation_policy.h"
135 #include "content/common/url_loader_factory.mojom.h"
134 #include "content/common/view_messages.h" 136 #include "content/common/view_messages.h"
135 #include "content/public/browser/browser_context.h" 137 #include "content/public/browser/browser_context.h"
136 #include "content/public/browser/browser_thread.h" 138 #include "content/public/browser/browser_thread.h"
137 #include "content/public/browser/content_browser_client.h" 139 #include "content/public/browser/content_browser_client.h"
138 #include "content/public/browser/notification_service.h" 140 #include "content/public/browser/notification_service.h"
139 #include "content/public/browser/notification_types.h" 141 #include "content/public/browser/notification_types.h"
140 #include "content/public/browser/render_process_host_factory.h" 142 #include "content/public/browser/render_process_host_factory.h"
141 #include "content/public/browser/render_process_host_observer.h" 143 #include "content/public/browser/render_process_host_observer.h"
142 #include "content/public/browser/render_widget_host.h" 144 #include "content/public/browser/render_widget_host.h"
143 #include "content/public/browser/render_widget_host_iterator.h" 145 #include "content/public/browser/render_widget_host_iterator.h"
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 << "in-process."; 622 << "in-process.";
621 } 623 }
622 } 624 }
623 625
624 void RenderProcessHostImpl::RegisterRendererMainThreadFactory( 626 void RenderProcessHostImpl::RegisterRendererMainThreadFactory(
625 RendererMainThreadFactoryFunction create) { 627 RendererMainThreadFactoryFunction create) {
626 g_renderer_main_thread_factory = create; 628 g_renderer_main_thread_factory = create;
627 } 629 }
628 630
629 RenderProcessHostImpl::~RenderProcessHostImpl() { 631 RenderProcessHostImpl::~RenderProcessHostImpl() {
632 DCHECK_CURRENTLY_ON(BrowserThread::UI);
630 #ifndef NDEBUG 633 #ifndef NDEBUG
631 DCHECK(is_self_deleted_) 634 DCHECK(is_self_deleted_)
632 << "RenderProcessHostImpl is destroyed by something other than itself"; 635 << "RenderProcessHostImpl is destroyed by something other than itself";
633 #endif 636 #endif
634 637
635 // Make sure to clean up the in-process renderer before the channel, otherwise 638 // Make sure to clean up the in-process renderer before the channel, otherwise
636 // it may still run and have its IPCs fail, causing asserts. 639 // it may still run and have its IPCs fail, causing asserts.
637 in_process_renderer_.reset(); 640 in_process_renderer_.reset();
638 641
639 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); 642 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID());
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 GetStoragePartition()->GetMediaURLRequestContext()); 852 GetStoragePartition()->GetMediaURLRequestContext());
850 853
851 ResourceMessageFilter::GetContextsCallback get_contexts_callback( 854 ResourceMessageFilter::GetContextsCallback get_contexts_callback(
852 base::Bind(&GetContexts, browser_context->GetResourceContext(), 855 base::Bind(&GetContexts, browser_context->GetResourceContext(),
853 request_context, media_request_context)); 856 request_context, media_request_context));
854 857
855 // Several filters need the Blob storage context, so fetch it in advance. 858 // Several filters need the Blob storage context, so fetch it in advance.
856 scoped_refptr<ChromeBlobStorageContext> blob_storage_context = 859 scoped_refptr<ChromeBlobStorageContext> blob_storage_context =
857 ChromeBlobStorageContext::GetFor(browser_context); 860 ChromeBlobStorageContext::GetFor(browser_context);
858 861
859 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( 862 resource_message_filter_ = new ResourceMessageFilter(
860 GetID(), PROCESS_TYPE_RENDERER, 863 GetID(), PROCESS_TYPE_RENDERER,
861 storage_partition_impl_->GetAppCacheService(), 864 storage_partition_impl_->GetAppCacheService(), blob_storage_context.get(),
862 blob_storage_context.get(),
863 storage_partition_impl_->GetFileSystemContext(), 865 storage_partition_impl_->GetFileSystemContext(),
864 storage_partition_impl_->GetServiceWorkerContext(), 866 storage_partition_impl_->GetServiceWorkerContext(),
865 storage_partition_impl_->GetHostZoomLevelContext(), 867 storage_partition_impl_->GetHostZoomLevelContext(),
866 get_contexts_callback); 868 get_contexts_callback);
867 869
868 AddFilter(resource_message_filter); 870 AddFilter(resource_message_filter_.get());
871
869 MediaStreamManager* media_stream_manager = 872 MediaStreamManager* media_stream_manager =
870 BrowserMainLoop::GetInstance()->media_stream_manager(); 873 BrowserMainLoop::GetInstance()->media_stream_manager();
871 // The AudioInputRendererHost and AudioRendererHost needs to be available for 874 // The AudioInputRendererHost and AudioRendererHost needs to be available for
872 // lookup, so it's stashed in a member variable. 875 // lookup, so it's stashed in a member variable.
873 audio_input_renderer_host_ = new AudioInputRendererHost( 876 audio_input_renderer_host_ = new AudioInputRendererHost(
874 GetID(), base::GetProcId(GetHandle()), audio_manager, 877 GetID(), base::GetProcId(GetHandle()), audio_manager,
875 media_stream_manager, AudioMirroringManager::GetInstance(), 878 media_stream_manager, AudioMirroringManager::GetInstance(),
876 BrowserMainLoop::GetInstance()->user_input_monitor()); 879 BrowserMainLoop::GetInstance()->user_input_monitor());
877 AddFilter(audio_input_renderer_host_.get()); 880 AddFilter(audio_input_renderer_host_.get());
878 audio_renderer_host_ = new AudioRendererHost( 881 audio_renderer_host_ = new AudioRendererHost(
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 1044
1042 mojo_application_host_->service_registry()->AddService( 1045 mojo_application_host_->service_registry()->AddService(
1043 base::Bind(&RenderProcessHostImpl::CreateStoragePartitionService, 1046 base::Bind(&RenderProcessHostImpl::CreateStoragePartitionService,
1044 base::Unretained(this))); 1047 base::Unretained(this)));
1045 1048
1046 #if defined(OS_ANDROID) 1049 #if defined(OS_ANDROID)
1047 ServiceRegistrarAndroid::RegisterProcessHostServices( 1050 ServiceRegistrarAndroid::RegisterProcessHostServices(
1048 mojo_application_host_->service_registry_android()); 1051 mojo_application_host_->service_registry_android());
1049 #endif 1052 #endif
1050 1053
1054 mojo_application_host_->service_registry()->AddService(base::Bind(
1055 &RenderProcessHostImpl::CreateURLLoaderFactory, base::Unretained(this)));
1056
1051 GetContentClient()->browser()->RegisterRenderProcessMojoServices( 1057 GetContentClient()->browser()->RegisterRenderProcessMojoServices(
1052 mojo_application_host_->service_registry()); 1058 mojo_application_host_->service_registry());
1053 } 1059 }
1054 1060
1055 void RenderProcessHostImpl::CreateStoragePartitionService( 1061 void RenderProcessHostImpl::CreateStoragePartitionService(
1056 mojo::InterfaceRequest<mojom::StoragePartitionService> request) { 1062 mojo::InterfaceRequest<mojom::StoragePartitionService> request) {
1057 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW! 1063 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW!
1058 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1064 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1059 switches::kMojoLocalStorage)) { 1065 switches::kMojoLocalStorage)) {
1060 storage_partition_impl_->Bind(std::move(request)); 1066 storage_partition_impl_->Bind(std::move(request));
1061 } 1067 }
1062 } 1068 }
1063 1069
1070 void RenderProcessHostImpl::CreateURLLoaderFactory(
1071 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) {
1072 url_loader_factory_.reset(
1073 new URLLoaderFactoryImpl(resource_message_filter_, std::move(request)));
1074 }
1075
1064 int RenderProcessHostImpl::GetNextRoutingID() { 1076 int RenderProcessHostImpl::GetNextRoutingID() {
1065 return widget_helper_->GetNextRoutingID(); 1077 return widget_helper_->GetNextRoutingID();
1066 } 1078 }
1067 1079
1068 void RenderProcessHostImpl::ResumeDeferredNavigation( 1080 void RenderProcessHostImpl::ResumeDeferredNavigation(
1069 const GlobalRequestID& request_id) { 1081 const GlobalRequestID& request_id) {
1070 widget_helper_->ResumeDeferredNavigation(request_id); 1082 widget_helper_->ResumeDeferredNavigation(request_id);
1071 } 1083 }
1072 1084
1073 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { 1085 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) {
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 1810
1799 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { 1811 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) {
1800 ignore_input_events_ = ignore_input_events; 1812 ignore_input_events_ = ignore_input_events;
1801 } 1813 }
1802 1814
1803 bool RenderProcessHostImpl::IgnoreInputEvents() const { 1815 bool RenderProcessHostImpl::IgnoreInputEvents() const {
1804 return ignore_input_events_; 1816 return ignore_input_events_;
1805 } 1817 }
1806 1818
1807 void RenderProcessHostImpl::Cleanup() { 1819 void RenderProcessHostImpl::Cleanup() {
1820 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1808 // If within_process_died_observer_ is true, one of our observers performed an 1821 // If within_process_died_observer_ is true, one of our observers performed an
1809 // action that caused us to die (e.g. http://crbug.com/339504). Therefore, 1822 // action that caused us to die (e.g. http://crbug.com/339504). Therefore,
1810 // delay the destruction until all of the observer callbacks have been made, 1823 // delay the destruction until all of the observer callbacks have been made,
1811 // and guarantee that the RenderProcessHostDestroyed observer callback is 1824 // and guarantee that the RenderProcessHostDestroyed observer callback is
1812 // always the last callback fired. 1825 // always the last callback fired.
1813 if (within_process_died_observer_) { 1826 if (within_process_died_observer_) {
1814 delayed_cleanup_needed_ = true; 1827 delayed_cleanup_needed_ = true;
1815 return; 1828 return;
1816 } 1829 }
1817 delayed_cleanup_needed_ = false; 1830 delayed_cleanup_needed_ = false;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 1890
1878 // It's important not to wait for the DeleteTask to delete the channel 1891 // It's important not to wait for the DeleteTask to delete the channel
1879 // proxy. Kill it off now. That way, in case the profile is going away, the 1892 // proxy. Kill it off now. That way, in case the profile is going away, the
1880 // rest of the objects attached to this RenderProcessHost start going 1893 // rest of the objects attached to this RenderProcessHost start going
1881 // away first, since deleting the channel proxy will post a 1894 // away first, since deleting the channel proxy will post a
1882 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. 1895 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread.
1883 channel_.reset(); 1896 channel_.reset();
1884 1897
1885 // The following members should be cleared in ProcessDied() as well! 1898 // The following members should be cleared in ProcessDied() as well!
1886 message_port_message_filter_ = NULL; 1899 message_port_message_filter_ = NULL;
1900 url_loader_factory_ = nullptr;
1887 1901
1888 RemoveUserData(kSessionStorageHolderKey); 1902 RemoveUserData(kSessionStorageHolderKey);
1889 1903
1890 // On shutdown, |this| may not be deleted because the deleter is posted to 1904 // On shutdown, |this| may not be deleted because the deleter is posted to
1891 // the current MessageLoop, but MessageLoop deletes all its pending 1905 // the current MessageLoop, but MessageLoop deletes all its pending
1892 // callbacks on shutdown. Since the deleter takes |this| as a raw pointer, 1906 // callbacks on shutdown. Since the deleter takes |this| as a raw pointer,
1893 // deleting the callback doesn't delete |this| resulting in a memory leak. 1907 // deleting the callback doesn't delete |this| resulting in a memory leak.
1894 // Valgrind complains, so delete |mojo_application_host_| explicitly here to 1908 // Valgrind complains, so delete |mojo_application_host_| explicitly here to
1895 // stop valgrind from complaining. 1909 // stop valgrind from complaining.
1896 mojo_application_host_.reset(); 1910 mojo_application_host_.reset();
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
2394 2408
2395 within_process_died_observer_ = true; 2409 within_process_died_observer_ = true;
2396 NotificationService::current()->Notify( 2410 NotificationService::current()->Notify(
2397 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), 2411 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this),
2398 Details<RendererClosedDetails>(&details)); 2412 Details<RendererClosedDetails>(&details));
2399 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, 2413 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_,
2400 RenderProcessExited(this, status, exit_code)); 2414 RenderProcessExited(this, status, exit_code));
2401 within_process_died_observer_ = false; 2415 within_process_died_observer_ = false;
2402 2416
2403 message_port_message_filter_ = NULL; 2417 message_port_message_filter_ = NULL;
2418 url_loader_factory_ = nullptr;
2404 RemoveUserData(kSessionStorageHolderKey); 2419 RemoveUserData(kSessionStorageHolderKey);
2405 2420
2406 IDMap<IPC::Listener>::iterator iter(&listeners_); 2421 IDMap<IPC::Listener>::iterator iter(&listeners_);
2407 while (!iter.IsAtEnd()) { 2422 while (!iter.IsAtEnd()) {
2408 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( 2423 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone(
2409 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); 2424 iter.GetCurrentKey(), static_cast<int>(status), exit_code));
2410 iter.Advance(); 2425 iter.Advance();
2411 } 2426 }
2412 2427
2413 // It's possible that one of the calls out to the observers might have caused 2428 // It's possible that one of the calls out to the observers might have caused
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
2765 2780
2766 // Skip widgets in other processes. 2781 // Skip widgets in other processes.
2767 if (rvh->GetProcess()->GetID() != GetID()) 2782 if (rvh->GetProcess()->GetID() != GetID())
2768 continue; 2783 continue;
2769 2784
2770 rvh->OnWebkitPreferencesChanged(); 2785 rvh->OnWebkitPreferencesChanged();
2771 } 2786 }
2772 } 2787 }
2773 2788
2774 } // namespace content 2789 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698