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

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

Issue 2157143002: Move interface registration to OnConnect in RPH (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 #include "content/public/browser/owned_interface.h" 141 #include "content/public/browser/owned_interface.h"
142 #include "content/public/browser/render_process_host_factory.h" 142 #include "content/public/browser/render_process_host_factory.h"
143 #include "content/public/browser/render_process_host_observer.h" 143 #include "content/public/browser/render_process_host_observer.h"
144 #include "content/public/browser/render_widget_host.h" 144 #include "content/public/browser/render_widget_host.h"
145 #include "content/public/browser/render_widget_host_iterator.h" 145 #include "content/public/browser/render_widget_host_iterator.h"
146 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" 146 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
147 #include "content/public/browser/resource_context.h" 147 #include "content/public/browser/resource_context.h"
148 #include "content/public/browser/user_metrics.h" 148 #include "content/public/browser/user_metrics.h"
149 #include "content/public/browser/worker_service.h" 149 #include "content/public/browser/worker_service.h"
150 #include "content/public/common/child_process_host.h" 150 #include "content/public/common/child_process_host.h"
151 #include "content/public/common/connection_filter.h"
151 #include "content/public/common/content_constants.h" 152 #include "content/public/common/content_constants.h"
152 #include "content/public/common/content_features.h" 153 #include "content/public/common/content_features.h"
153 #include "content/public/common/content_switches.h" 154 #include "content/public/common/content_switches.h"
154 #include "content/public/common/mojo_channel_switches.h" 155 #include "content/public/common/mojo_channel_switches.h"
155 #include "content/public/common/process_type.h" 156 #include "content/public/common/process_type.h"
156 #include "content/public/common/resource_type.h" 157 #include "content/public/common/resource_type.h"
157 #include "content/public/common/result_codes.h" 158 #include "content/public/common/result_codes.h"
158 #include "content/public/common/sandboxed_process_launcher_delegate.h" 159 #include "content/public/common/sandboxed_process_launcher_delegate.h"
159 #include "content/public/common/url_constants.h" 160 #include "content/public/common/url_constants.h"
160 #include "device/battery/battery_monitor_impl.h" 161 #include "device/battery/battery_monitor_impl.h"
161 #include "gpu/GLES2/gl2extchromium.h" 162 #include "gpu/GLES2/gl2extchromium.h"
162 #include "gpu/command_buffer/client/gpu_switches.h" 163 #include "gpu/command_buffer/client/gpu_switches.h"
163 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 164 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
164 #include "gpu/command_buffer/service/gpu_switches.h" 165 #include "gpu/command_buffer/service/gpu_switches.h"
165 #include "ipc/attachment_broker.h" 166 #include "ipc/attachment_broker.h"
166 #include "ipc/attachment_broker_privileged.h" 167 #include "ipc/attachment_broker_privileged.h"
167 #include "ipc/ipc_channel.h" 168 #include "ipc/ipc_channel.h"
168 #include "ipc/ipc_channel_mojo.h" 169 #include "ipc/ipc_channel_mojo.h"
169 #include "ipc/ipc_logging.h" 170 #include "ipc/ipc_logging.h"
170 #include "ipc/ipc_switches.h" 171 #include "ipc/ipc_switches.h"
171 #include "media/base/media_switches.h" 172 #include "media/base/media_switches.h"
172 #include "mojo/edk/embedder/embedder.h" 173 #include "mojo/edk/embedder/embedder.h"
173 #include "net/url_request/url_request_context_getter.h" 174 #include "net/url_request/url_request_context_getter.h"
174 #include "ppapi/shared_impl/ppapi_switches.h" 175 #include "ppapi/shared_impl/ppapi_switches.h"
176 #include "services/shell/public/cpp/connection.h"
175 #include "services/shell/public/cpp/interface_provider.h" 177 #include "services/shell/public/cpp/interface_provider.h"
176 #include "services/shell/public/cpp/interface_registry.h" 178 #include "services/shell/public/cpp/interface_registry.h"
177 #include "services/shell/runner/common/switches.h" 179 #include "services/shell/runner/common/switches.h"
178 #include "storage/browser/fileapi/sandbox_file_system_backend.h" 180 #include "storage/browser/fileapi/sandbox_file_system_backend.h"
179 #include "third_party/skia/include/core/SkBitmap.h" 181 #include "third_party/skia/include/core/SkBitmap.h"
180 #include "ui/base/ui_base_switches.h" 182 #include "ui/base/ui_base_switches.h"
181 #include "ui/display/display_switches.h" 183 #include "ui/display/display_switches.h"
182 #include "ui/events/event_switches.h" 184 #include "ui/events/event_switches.h"
183 #include "ui/gfx/switches.h" 185 #include "ui/gfx/switches.h"
184 #include "ui/gl/gl_switches.h" 186 #include "ui/gl/gl_switches.h"
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 std::string UintVectorToString(const std::vector<unsigned>& vector) { 449 std::string UintVectorToString(const std::vector<unsigned>& vector) {
448 std::string str; 450 std::string str;
449 for (auto it : vector) { 451 for (auto it : vector) {
450 if (!str.empty()) 452 if (!str.empty())
451 str += ","; 453 str += ",";
452 str += base::UintToString(it); 454 str += base::UintToString(it);
453 } 455 }
454 return str; 456 return str;
455 } 457 }
456 458
457 void CreateMemoryCoordinatorHandle(
458 int render_process_id,
459 memory_coordinator::mojom::MemoryCoordinatorHandleRequest request) {
460 BrowserMainLoop::GetInstance()->memory_coordinator()->CreateHandle(
461 render_process_id, std::move(request));
462 }
463
464 } // namespace 459 } // namespace
465 460
466 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; 461 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL;
467 462
468 base::MessageLoop* g_in_process_thread; 463 base::MessageLoop* g_in_process_thread;
469 464
470 base::MessageLoop* 465 base::MessageLoop*
471 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { 466 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() {
472 return g_in_process_thread; 467 return g_in_process_thread;
473 } 468 }
474 469
475 // Stores the maximum number of renderer processes the content module can 470 // Stores the maximum number of renderer processes the content module can
476 // create. 471 // create.
477 static size_t g_max_renderer_count_override = 0; 472 static size_t g_max_renderer_count_override = 0;
478 473
474 class RenderProcessHostImpl::ConnectionFilterImpl : public ConnectionFilter {
475 public:
476 explicit ConnectionFilterImpl(
477 base::WeakPtr<RenderProcessHostImpl> render_process_host)
478 : render_process_host_(render_process_host) {}
479 ~ConnectionFilterImpl() override {}
480
481 private:
482 // ConnectionFilter implementation:
483 bool OnConnect(shell::Connection* connection,
484 shell::Connector* connector) override {
485 shell::InterfaceRegistry* reg = connection->GetInterfaceRegistry();
486
487 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner =
488 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI);
489 #if !defined(OS_ANDROID)
490 reg->AddInterface(base::Bind(&device::BatteryMonitorImpl::Create),
491 ui_task_runner);
492 #endif
493 reg->AddInterface(base::Bind(&ConnectionFilterImpl::BindPermissionService,
494 base::Unretained(this)),
495 ui_task_runner);
496 reg->AddInterface(base::Bind(&ImageCaptureImpl::Create), ui_task_runner);
497 reg->AddInterface(base::Bind(&OffscreenCanvasSurfaceImpl::Create),
498 ui_task_runner);
499 reg->AddInterface(
500 base::Bind(&ConnectionFilterImpl::BindBackgroundSyncService,
501 base::Unretained(this)),
502 ui_task_runner);
503 reg->AddInterface(
504 base::Bind(&ConnectionFilterImpl::BindNotificationService,
505 base::Unretained(this)),
506 ui_task_runner);
507 reg->AddInterface(
508 base::Bind(&ConnectionFilterImpl::BindStoragePartitionService,
509 base::Unretained(this)),
510 ui_task_runner);
511 reg->AddInterface(
512 base::Bind(&ConnectionFilterImpl::BindBroadcastChannelProvider,
513 base::Unretained(this)),
514 ui_task_runner);
515 if (memory_coordinator::IsEnabled()) {
516 reg->AddInterface(
517 base::Bind(&ConnectionFilterImpl::BindMemoryCoordinatorHandle,
518 base::Unretained(this)),
519 ui_task_runner);
520 }
521
522 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner =
523 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE);
524 reg->AddInterface(base::Bind(&MimeRegistryImpl::Create), file_task_runner);
525 #if defined(USE_MINIKIN_HYPHENATION)
526 reg->AddInterface(base::Bind(&hyphenation::HyphenationImpl::Create),
527 file_task_runner);
528 #endif
529
530 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner =
531 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
532 reg->AddInterface(base::Bind(&DeviceLightHost::Create), io_task_runner);
533 reg->AddInterface(base::Bind(&DeviceMotionHost::Create), io_task_runner);
534 reg->AddInterface(base::Bind(&DeviceOrientationHost::Create),
535 io_task_runner);
536 reg->AddInterface(base::Bind(&DeviceOrientationAbsoluteHost::Create),
537 io_task_runner);
538
539 GetContentClient()->browser()->ExposeInterfacesToRenderer(connection);
540 return true;
541 }
542
543 void BindPermissionService(blink::mojom::PermissionServiceRequest request) {
544 if (!render_process_host_)
545 return;
546 PermissionServiceContext* permission_service_context =
547 render_process_host_->permission_service_context_.get();
548 permission_service_context->CreateService(std::move(request));
549 }
550
551 void BindBackgroundSyncService(
552 blink::mojom::BackgroundSyncServiceRequest request) {
553 if (!render_process_host_)
554 return;
555 render_process_host_->storage_partition_impl_->GetBackgroundSyncContext()->
556 CreateService(std::move(request));
557 }
558
559 void BindNotificationService(
560 blink::mojom::NotificationServiceRequest request) {
561 if (!render_process_host_)
562 return;
563 render_process_host_->storage_partition_impl_->
564 GetPlatformNotificationContext()->CreateService(
565 render_process_host_->GetID(), std::move(request));
566 }
567
568 void BindStoragePartitionService(
569 mojom::StoragePartitionServiceRequest request) {
570 if (!render_process_host_)
571 return;
572 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW!
573 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
574 switches::kMojoLocalStorage)) {
575 render_process_host_->storage_partition_impl_->Bind(std::move(request));
576 }
577 }
578
579 void BindBroadcastChannelProvider(
580 blink::mojom::BroadcastChannelProviderRequest request) {
581 if (!render_process_host_)
582 return;
583 render_process_host_->storage_partition_impl_->
584 GetBroadcastChannelProvider()->Connect(std::move(request));
585 }
586
587 void BindMemoryCoordinatorHandle(
588 memory_coordinator::mojom::MemoryCoordinatorHandleRequest request) {
589 if (!render_process_host_)
590 return;
591 BrowserMainLoop::GetInstance()->memory_coordinator()->CreateHandle(
592 render_process_host_->GetID(), std::move(request));
593 }
594
595 base::WeakPtr<RenderProcessHostImpl> render_process_host_;
596
597 DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl);
598 };
599
479 // static 600 // static
480 size_t RenderProcessHost::GetMaxRendererProcessCount() { 601 size_t RenderProcessHost::GetMaxRendererProcessCount() {
481 if (g_max_renderer_count_override) 602 if (g_max_renderer_count_override)
482 return g_max_renderer_count_override; 603 return g_max_renderer_count_override;
483 604
484 #if defined(OS_ANDROID) 605 #if defined(OS_ANDROID)
485 // On Android we don't maintain a limit of renderer process hosts - we are 606 // On Android we don't maintain a limit of renderer process hosts - we are
486 // happy with keeping a lot of these, as long as the number of live renderer 607 // happy with keeping a lot of these, as long as the number of live renderer
487 // processes remains reasonable, and on Android the OS takes care of that. 608 // processes remains reasonable, and on Android the OS takes care of that.
488 return std::numeric_limits<size_t>::max(); 609 return std::numeric_limits<size_t>::max();
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 878
758 #if defined(OS_ANDROID) 879 #if defined(OS_ANDROID)
759 // Initialize the java audio manager so that media session tests will pass. 880 // Initialize the java audio manager so that media session tests will pass.
760 // See internal b/29872494. 881 // See internal b/29872494.
761 static_cast<media::AudioManagerAndroid*>(media::AudioManager::Get())-> 882 static_cast<media::AudioManagerAndroid*>(media::AudioManager::Get())->
762 InitializeIfNeeded(); 883 InitializeIfNeeded();
763 #endif // defined(OS_ANDROID) 884 #endif // defined(OS_ANDROID)
764 885
765 CreateMessageFilters(); 886 CreateMessageFilters();
766 RegisterMojoInterfaces(); 887 RegisterMojoInterfaces();
888 MojoShellConnection* connection =
889 BrowserContext::GetMojoShellConnectionFor(browser_context_);
890 BrowserThread::PostTask(BrowserThread::IO,
891 FROM_HERE,
892 base::Bind(&MojoShellConnection::AddConnectionFilter,
893 base::Unretained(connection),
894 base::Passed(base::WrapUnique(
895 new ConnectionFilterImpl(weak_factory_.GetWeakPtr())))));
767 896
768 if (run_renderer_in_process()) { 897 if (run_renderer_in_process()) {
769 DCHECK(g_renderer_main_thread_factory); 898 DCHECK(g_renderer_main_thread_factory);
770 // Crank up a thread and run the initialization there. With the way that 899 // Crank up a thread and run the initialization there. With the way that
771 // messages flow between the browser and renderer, this thread is required 900 // messages flow between the browser and renderer, this thread is required
772 // to prevent a deadlock in single-process mode. Since the primordial 901 // to prevent a deadlock in single-process mode. Since the primordial
773 // thread in the renderer process runs the WebKit code and can sometimes 902 // thread in the renderer process runs the WebKit code and can sometimes
774 // make blocking calls to the UI thread (i.e. this thread), they need to run 903 // make blocking calls to the UI thread (i.e. this thread), they need to run
775 // on separate threads. 904 // on separate threads.
776 in_process_renderer_.reset( 905 in_process_renderer_.reset(
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 AddFilter(new HistogramMessageFilter()); 1181 AddFilter(new HistogramMessageFilter());
1053 AddFilter(new MemoryMessageFilter(this)); 1182 AddFilter(new MemoryMessageFilter(this));
1054 AddFilter(new PushMessagingMessageFilter( 1183 AddFilter(new PushMessagingMessageFilter(
1055 GetID(), storage_partition_impl_->GetServiceWorkerContext())); 1184 GetID(), storage_partition_impl_->GetServiceWorkerContext()));
1056 #if defined(OS_ANDROID) 1185 #if defined(OS_ANDROID)
1057 AddFilter(new ScreenOrientationMessageFilterAndroid()); 1186 AddFilter(new ScreenOrientationMessageFilterAndroid());
1058 #endif 1187 #endif
1059 } 1188 }
1060 1189
1061 void RenderProcessHostImpl::RegisterMojoInterfaces() { 1190 void RenderProcessHostImpl::RegisterMojoInterfaces() {
1062 #if !defined(OS_ANDROID)
1063 GetInterfaceRegistry()->AddInterface(
1064 base::Bind(&device::BatteryMonitorImpl::Create));
1065 #endif
1066
1067 GetInterfaceRegistry()->AddInterface(
1068 base::Bind(&PermissionServiceContext::CreateService,
1069 base::Unretained(permission_service_context_.get())));
1070
1071 // TODO(mcasas): finalize arguments.
1072 GetInterfaceRegistry()->AddInterface(
1073 base::Bind(&ImageCaptureImpl::Create));
1074
1075 GetInterfaceRegistry()->AddInterface(
1076 base::Bind(&OffscreenCanvasSurfaceImpl::Create));
1077
1078 GetInterfaceRegistry()->AddInterface(base::Bind(
1079 &BackgroundSyncContext::CreateService,
1080 base::Unretained(storage_partition_impl_->GetBackgroundSyncContext())));
1081
1082 GetInterfaceRegistry()->AddInterface(base::Bind(
1083 &PlatformNotificationContextImpl::CreateService,
1084 base::Unretained(
1085 storage_partition_impl_->GetPlatformNotificationContext()), GetID()));
1086
1087 GetInterfaceRegistry()->AddInterface(
1088 base::Bind(&RenderProcessHostImpl::CreateStoragePartitionService,
1089 base::Unretained(this)));
1090
1091 GetInterfaceRegistry()->AddInterface(
1092 base::Bind(&BroadcastChannelProvider::Connect,
1093 base::Unretained(
1094 storage_partition_impl_->GetBroadcastChannelProvider())));
1095
1096 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner =
1097 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE);
1098 GetInterfaceRegistry()->AddInterface(
1099 base::Bind(&MimeRegistryImpl::Create), file_task_runner);
1100
1101 #if defined(USE_MINIKIN_HYPHENATION)
1102 GetInterfaceRegistry()->AddInterface(
1103 base::Bind(&hyphenation::HyphenationImpl::Create), file_task_runner);
1104 #endif
1105
1106 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner =
1107 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
1108 GetInterfaceRegistry()->AddInterface(base::Bind(&DeviceLightHost::Create),
1109 io_task_runner);
1110 GetInterfaceRegistry()->AddInterface(base::Bind(&DeviceMotionHost::Create),
1111 io_task_runner);
1112 GetInterfaceRegistry()->AddInterface(
1113 base::Bind(&DeviceOrientationHost::Create), io_task_runner);
1114 GetInterfaceRegistry()->AddInterface(
1115 base::Bind(&DeviceOrientationAbsoluteHost::Create), io_task_runner);
1116
1117 if (memory_coordinator::IsEnabled()) {
1118 GetInterfaceRegistry()->AddInterface(
1119 base::Bind(&CreateMemoryCoordinatorHandle, GetID()));
1120 }
1121
1122 #if defined(OS_ANDROID) 1191 #if defined(OS_ANDROID)
1123 ServiceRegistrarAndroid::RegisterProcessHostServices( 1192 ServiceRegistrarAndroid::RegisterProcessHostServices(
1124 mojo_child_connection_->service_registry_android()); 1193 mojo_child_connection_->service_registry_android());
1125 #endif 1194 #endif
1126
1127 GetContentClient()->browser()->ExposeInterfacesToRenderer(
1128 GetInterfaceRegistry(), this);
1129 }
1130
1131 void RenderProcessHostImpl::CreateStoragePartitionService(
1132 mojo::InterfaceRequest<mojom::StoragePartitionService> request) {
1133 // DO NOT REMOVE THIS COMMAND LINE CHECK WITHOUT SECURITY REVIEW!
1134 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1135 switches::kMojoLocalStorage)) {
1136 storage_partition_impl_->Bind(std::move(request));
1137 }
1138 } 1195 }
1139 1196
1140 int RenderProcessHostImpl::GetNextRoutingID() { 1197 int RenderProcessHostImpl::GetNextRoutingID() {
1141 return widget_helper_->GetNextRoutingID(); 1198 return widget_helper_->GetNextRoutingID();
1142 } 1199 }
1143 1200
1144 void RenderProcessHostImpl::ResumeDeferredNavigation( 1201 void RenderProcessHostImpl::ResumeDeferredNavigation(
1145 const GlobalRequestID& request_id) { 1202 const GlobalRequestID& request_id) {
1146 widget_helper_->ResumeDeferredNavigation(request_id); 1203 widget_helper_->ResumeDeferredNavigation(request_id);
1147 } 1204 }
(...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after
2793 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; 2850 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error;
2794 2851
2795 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias 2852 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias
2796 // enough information here so that we can determine what the bad message was. 2853 // enough information here so that we can determine what the bad message was.
2797 base::debug::Alias(&error); 2854 base::debug::Alias(&error);
2798 bad_message::ReceivedBadMessage(process.get(), 2855 bad_message::ReceivedBadMessage(process.get(),
2799 bad_message::RPH_MOJO_PROCESS_ERROR); 2856 bad_message::RPH_MOJO_PROCESS_ERROR);
2800 } 2857 }
2801 2858
2802 } // namespace content 2859 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.h ('k') | content/child/child_thread_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698