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

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

Powered by Google App Engine
This is Rietveld 408576698