| Index: content/browser/renderer_host/render_process_host_impl.cc
|
| diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
|
| index d068474919cc52c084ff3302f5df35821f7f319f..9590a48e4926923bdb977905f9e1aad75278134f 100644
|
| --- a/content/browser/renderer_host/render_process_host_impl.cc
|
| +++ b/content/browser/renderer_host/render_process_host_impl.cc
|
| @@ -85,7 +85,6 @@
|
| #include "content/browser/message_port_message_filter.h"
|
| #include "content/browser/mime_registry_impl.h"
|
| #include "content/browser/mojo/constants.h"
|
| -#include "content/browser/mojo/mojo_application_host.h"
|
| #include "content/browser/mojo/mojo_child_connection.h"
|
| #include "content/browser/notifications/notification_message_filter.h"
|
| #include "content/browser/notifications/platform_notification_context_impl.h"
|
| @@ -543,7 +542,6 @@ RenderProcessHostImpl::RenderProcessHostImpl(
|
| #endif
|
| pending_views_(0),
|
| child_token_(mojo::edk::GenerateRandomToken()),
|
| - mojo_application_host_(new MojoApplicationHost(child_token_)),
|
| visible_widgets_(0),
|
| is_process_backgrounded_(false),
|
| is_initialized_(false),
|
| @@ -602,6 +600,29 @@ RenderProcessHostImpl::RenderProcessHostImpl(
|
| IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded();
|
| #endif // defined(OS_MACOSX)
|
| #endif // USE_ATTACHMENT_BROKER
|
| +
|
| + shell::Connector* connector =
|
| + BrowserContext::GetShellConnectorFor(browser_context_);
|
| + // Some embedders may not initialize Mojo or the shell connector for a browser
|
| + // context (e.g. Android WebView)... so just fall back to the per-process
|
| + // connector.
|
| + if (!connector) {
|
| + // Additionally, some test code may not initialize the process-wide
|
| + // MojoShellConnection prior to this point. This class of test code doesn't
|
| + // care about render processes so we can initialize a dummy one.
|
| + if (!MojoShellConnection::GetForProcess()) {
|
| + shell::mojom::ShellClientRequest request =
|
| + mojo::GetProxy(&test_shell_client_);
|
| + MojoShellConnection::SetForProcess(MojoShellConnection::Create(
|
| + std::move(request)));
|
| + }
|
| + connector = MojoShellConnection::GetForProcess()->GetConnector();
|
| + }
|
| + mojo_child_connection_.reset(new MojoChildConnection(
|
| + kRendererMojoApplicationName,
|
| + base::StringPrintf("%d_%d", id_, instance_id_++),
|
| + child_token_,
|
| + connector));
|
| }
|
|
|
| // static
|
| @@ -680,19 +701,6 @@ bool RenderProcessHostImpl::Init() {
|
| if (channel_)
|
| return true;
|
|
|
| - shell::Connector* connector =
|
| - BrowserContext::GetShellConnectorFor(browser_context_);
|
| - // Some embedders may not initialize Mojo or the shell connector for a browser
|
| - // context (e.g. Android WebView)... so just fall back to the per-process
|
| - // connector.
|
| - if (!connector)
|
| - connector = MojoShellConnection::GetForProcess()->GetConnector();
|
| - mojo_child_connection_.reset(new MojoChildConnection(
|
| - kRendererMojoApplicationName,
|
| - base::StringPrintf("%d_%d", id_, instance_id_++),
|
| - child_token_,
|
| - connector));
|
| -
|
| base::CommandLine::StringType renderer_prefix;
|
| // A command prefix is something prepended to the command line of the spawned
|
| // process.
|
| @@ -741,7 +749,8 @@ bool RenderProcessHostImpl::Init() {
|
| channel_id,
|
| BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO)
|
| ->task_runner(),
|
| - mojo_channel_token_, mojo_application_host_->GetToken())));
|
| + mojo_channel_token_,
|
| + mojo_child_connection_->shell_client_token())));
|
|
|
| base::Thread::Options options;
|
| #if defined(OS_WIN) && !defined(OS_MACOSX)
|
| @@ -1025,45 +1034,44 @@ void RenderProcessHostImpl::CreateMessageFilters() {
|
|
|
| void RenderProcessHostImpl::RegisterMojoInterfaces() {
|
| #if !defined(OS_ANDROID)
|
| - mojo_application_host_->service_registry()->AddService(
|
| + GetInterfaceRegistry()->AddInterface(
|
| base::Bind(&device::BatteryMonitorImpl::Create));
|
| #endif
|
|
|
| - mojo_application_host_->service_registry()->AddService(
|
| + GetInterfaceRegistry()->AddInterface(
|
| base::Bind(&PermissionServiceContext::CreateService,
|
| base::Unretained(permission_service_context_.get())));
|
|
|
| // TODO(mcasas): finalize arguments.
|
| - mojo_application_host_->service_registry()->AddService(
|
| - base::Bind(&ImageCaptureImpl::Create));
|
| + GetInterfaceRegistry()->AddInterface(base::Bind(&ImageCaptureImpl::Create));
|
|
|
| - mojo_application_host_->service_registry()->AddService(
|
| + GetInterfaceRegistry()->AddInterface(
|
| base::Bind(&OffscreenCanvasSurfaceImpl::Create));
|
|
|
| - mojo_application_host_->service_registry()->AddService(base::Bind(
|
| + GetInterfaceRegistry()->AddInterface(base::Bind(
|
| &BackgroundSyncContext::CreateService,
|
| base::Unretained(storage_partition_impl_->GetBackgroundSyncContext())));
|
|
|
| - mojo_application_host_->service_registry()->AddService(base::Bind(
|
| + GetInterfaceRegistry()->AddInterface(base::Bind(
|
| &PlatformNotificationContextImpl::CreateService,
|
| base::Unretained(
|
| storage_partition_impl_->GetPlatformNotificationContext()), GetID()));
|
|
|
| - mojo_application_host_->service_registry()->AddService(
|
| + GetInterfaceRegistry()->AddInterface(
|
| base::Bind(&RenderProcessHostImpl::CreateStoragePartitionService,
|
| base::Unretained(this)));
|
|
|
| - mojo_application_host_->service_registry()->AddService(
|
| + GetInterfaceRegistry()->AddInterface(
|
| base::Bind(&MimeRegistryImpl::Create),
|
| BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
|
|
|
| #if defined(OS_ANDROID)
|
| ServiceRegistrarAndroid::RegisterProcessHostServices(
|
| - mojo_application_host_->service_registry_android());
|
| + mojo_child_connection_->service_registry_android());
|
| #endif
|
|
|
| - GetContentClient()->browser()->RegisterRenderProcessMojoServices(
|
| - mojo_application_host_->service_registry(), this);
|
| + GetContentClient()->browser()->ExposeInterfacesToRenderer(
|
| + GetInterfaceRegistry(), this);
|
| }
|
|
|
| void RenderProcessHostImpl::CreateStoragePartitionService(
|
| @@ -1088,9 +1096,12 @@ void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) {
|
| Send(new ViewMsg_TimezoneChange(zone_id));
|
| }
|
|
|
| -ServiceRegistry* RenderProcessHostImpl::GetServiceRegistry() {
|
| - DCHECK(mojo_application_host_);
|
| - return mojo_application_host_->service_registry();
|
| +shell::InterfaceRegistry* RenderProcessHostImpl::GetInterfaceRegistry() {
|
| + return GetChildConnection()->GetInterfaceRegistry();
|
| +}
|
| +
|
| +shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() {
|
| + return GetChildConnection()->GetRemoteInterfaces();
|
| }
|
|
|
| shell::Connection* RenderProcessHostImpl::GetChildConnection() {
|
| @@ -1331,7 +1342,7 @@ void RenderProcessHostImpl::AppendRendererCommandLine(
|
| mojo_channel_token_);
|
| }
|
| command_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken,
|
| - mojo_application_host_->GetToken());
|
| + mojo_child_connection_->shell_client_token());
|
| }
|
|
|
| void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
|
| @@ -1913,14 +1924,6 @@ void RenderProcessHostImpl::Cleanup() {
|
|
|
| RemoveUserData(kSessionStorageHolderKey);
|
|
|
| - // On shutdown, |this| may not be deleted because the deleter is posted to
|
| - // the current MessageLoop, but MessageLoop deletes all its pending
|
| - // callbacks on shutdown. Since the deleter takes |this| as a raw pointer,
|
| - // deleting the callback doesn't delete |this| resulting in a memory leak.
|
| - // Valgrind complains, so delete |mojo_application_host_| explicitly here to
|
| - // stop valgrind from complaining.
|
| - mojo_application_host_.reset();
|
| -
|
| // Remove ourself from the list of renderer processes so that we can't be
|
| // reused in between now and when the Delete task runs.
|
| UnregisterHost(GetID());
|
| @@ -2417,7 +2420,15 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead,
|
| // navigate or perform other actions that require a connection. Ensure that
|
| // there is one before calling them.
|
| child_token_ = mojo::edk::GenerateRandomToken();
|
| - mojo_application_host_.reset(new MojoApplicationHost(child_token_));
|
| + shell::Connector* connector =
|
| + BrowserContext::GetShellConnectorFor(browser_context_);
|
| + if (!connector)
|
| + connector = MojoShellConnection::GetForProcess()->GetConnector();
|
| + mojo_child_connection_.reset(new MojoChildConnection(
|
| + kRendererMojoApplicationName,
|
| + base::StringPrintf("%d_%d", id_, instance_id_++),
|
| + child_token_,
|
| + connector));
|
|
|
| within_process_died_observer_ = true;
|
| NotificationService::current()->Notify(
|
|
|