Skip to content

Commit

Permalink
Revert 265693 "Move Mojo channel initialization closer to IPC::C..."
Browse files Browse the repository at this point in the history
This is causing runhooks failures on the iOS build bots.

> Move Mojo channel initialization closer to IPC::Channel setup
> 
> This CL introduces two new content classes:
>  - MojoApplicationHost encapsulates what's needed to host a Mojo App using Chrome IPC to bootstrap.
>  - MojoApplication represents what's needed to be a Mojo App using Chrome IPC to bootstrap.
> 
> The RenderProcess and RenderProcessHost interfaces are replaced with WebUISetup and WebUISetupClient interfaces. This way the interface is more specific to the service of setting up WebUI.
> 
> WebUISetupClient is empty and uninteresting. RenderProcessHostImpl no longer deals with WebUI setup. That is all done directly by RenderViewHostImpl by talking to the WebUISetup service.
> 
> Service names get defined in content/common/mojo/mojo_service_names.{h,cc}.
> 
> R=sky@chromium.org, tsepez@chromium.org
> 
> Review URL: https://codereview.chromium.org/236813002

TBR=darin@chromium.org

Review URL: https://codereview.chromium.org/247953005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@265705 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
brianderson@chromium.org committed Apr 23, 2014
1 parent 0cfda30 commit 2442605
Show file tree
Hide file tree
Showing 37 changed files with 363 additions and 471 deletions.
65 changes: 0 additions & 65 deletions content/browser/mojo/mojo_application_host.cc

This file was deleted.

51 changes: 0 additions & 51 deletions content/browser/mojo/mojo_application_host.h

This file was deleted.

35 changes: 10 additions & 25 deletions content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
#include "content/browser/media/media_internals.h"
#include "content/browser/message_port_message_filter.h"
#include "content/browser/mime_registry_message_filter.h"
#include "content/browser/mojo/mojo_application_host.h"
#include "content/browser/plugin_service_impl.h"
#include "content/browser/profiler_message_filter.h"
#include "content/browser/push_messaging_message_filter.h"
Expand All @@ -87,6 +86,7 @@
#include "content/browser/renderer_host/pepper/pepper_message_filter.h"
#include "content/browser/renderer_host/pepper/pepper_renderer_connection.h"
#include "content/browser/renderer_host/render_message_filter.h"
#include "content/browser/renderer_host/render_process_host_mojo_impl.h"
#include "content/browser/renderer_host/render_view_host_delegate.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/render_widget_helper.h"
Expand All @@ -112,7 +112,6 @@
#include "content/common/child_process_messages.h"
#include "content/common/content_switches_internal.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/common/mojo/mojo_messages.h"
#include "content/common/resource_messages.h"
#include "content/common/view_messages.h"
#include "content/port/browser/render_widget_host_view_frame_subscriber.h"
Expand All @@ -138,8 +137,6 @@
#include "ipc/ipc_logging.h"
#include "ipc/ipc_switches.h"
#include "media/base/media_switches.h"
#include "mojo/common/common_type_converters.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
#include "net/url_request/url_request_context_getter.h"
#include "ppapi/shared_impl/ppapi_switches.h"
#include "third_party/skia/include/core/SkBitmap.h"
Expand Down Expand Up @@ -546,10 +543,6 @@ bool RenderProcessHostImpl::Init() {
BrowserThread::GetMessageLoopProxyForThread(
BrowserThread::IO).get()));

// Setup the Mojo channel.
mojo_application_host_.reset(new MojoApplicationHost());
mojo_application_host_->Init();

// Call the embedder first so that their IPC filters have priority.
GetContentClient()->browser()->RenderProcessWillLaunch(this);

Expand Down Expand Up @@ -1904,7 +1897,7 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead) {

ClearTransportDIBCache();

mojo_application_host_.reset();
render_process_host_mojo_.reset();

// It's possible that one of the calls out to the observers might have caused
// this object to be no longer needed.
Expand Down Expand Up @@ -2039,14 +2032,6 @@ void RenderProcessHostImpl::OnProcessLaunched() {
Source<RenderProcessHost>(this),
NotificationService::NoDetails());

// TODO(darin): This is blocked on security review. Un-commenting this will
// allow Mojo calls from all renderers.
#if 0
// Let the Mojo system get setup on the child process side before any other
// IPCs arrive. This way those may safely generate Mojo-related RPCs.
mojo_application_host_->Activate(this, GetHandle());
#endif

while (!queued_messages_.empty()) {
Send(queued_messages_.front());
queued_messages_.pop();
Expand All @@ -2056,6 +2041,9 @@ void RenderProcessHostImpl::OnProcessLaunched() {
if (WebRTCInternals::GetInstance()->aec_dump_enabled())
EnableAecDump(WebRTCInternals::GetInstance()->aec_dump_file_path());
#endif

if (render_process_host_mojo_.get())
render_process_host_mojo_->OnProcessLaunched();
}

scoped_refptr<AudioRendererHost>
Expand Down Expand Up @@ -2129,15 +2117,12 @@ void RenderProcessHostImpl::DecrementWorkerRefCount() {
Cleanup();
}

void RenderProcessHostImpl::ConnectTo(
const base::StringPiece& service_name,
void RenderProcessHostImpl::SetWebUIHandle(
int32 view_routing_id,
mojo::ScopedMessagePipeHandle handle) {
if (!mojo_application_host_->did_activate())
mojo_application_host_->Activate(this, GetHandle());

mojo::AllocationScope scope;
mojo_application_host_->shell_client()->AcceptConnection(service_name,
handle.Pass());
if (!render_process_host_mojo_)
render_process_host_mojo_.reset(new RenderProcessHostMojoImpl(this));
render_process_host_mojo_->SetWebUIHandle(view_routing_id, handle.Pass());
}

} // namespace content
15 changes: 5 additions & 10 deletions content/browser/renderer_host/render_process_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
#include "content/public/browser/render_process_host.h"
#include "ipc/ipc_channel_proxy.h"
#include "ipc/ipc_platform_file.h"
#include "mojo/embedder/scoped_platform_handle.h"
#include "mojo/public/cpp/bindings/remote_ptr.h"
#include "mojo/public/interfaces/shell/shell.mojom.h"
#include "mojo/public/cpp/system/core.h"
#include "ui/surface/transport_dib.h"

struct ViewHostMsg_CompositorSurfaceBuffersSwapped_Params;
Expand All @@ -43,7 +41,6 @@ class BrowserDemuxerAndroid;
class GeolocationDispatcherHost;
class GpuMessageFilter;
class MessagePortMessageFilter;
class MojoApplicationHost;
class PeerConnectionTrackerHost;
class RendererMainThread;
class RenderProcessHostMojoImpl;
Expand Down Expand Up @@ -243,10 +240,8 @@ class CONTENT_EXPORT RenderProcessHostImpl
void IncrementWorkerRefCount();
void DecrementWorkerRefCount();

// Establish a connection to a renderer-provided service. See
// content/common/mojo/mojo_service_names.h for a list of services.
void ConnectTo(const base::StringPiece& service_name,
mojo::ScopedMessagePipeHandle handle);
void SetWebUIHandle(int32 view_routing_id,
mojo::ScopedMessagePipeHandle handle);

protected:
// A proxy for our IPC::Channel that lives on the IO thread (see
Expand Down Expand Up @@ -311,8 +306,6 @@ class CONTENT_EXPORT RenderProcessHostImpl
void SendDisableAecDumpToRenderer();
#endif

scoped_ptr<MojoApplicationHost> mojo_application_host_;

// The registered IPC listener objects. When this list is empty, we should
// delete ourselves.
IDMap<IPC::Listener> listeners_;
Expand Down Expand Up @@ -438,6 +431,8 @@ class CONTENT_EXPORT RenderProcessHostImpl
// Records the time when the process starts surviving for workers for UMA.
base::TimeTicks survive_for_worker_start_time_;

scoped_ptr<RenderProcessHostMojoImpl> render_process_host_mojo_;

base::WeakPtrFactory<RenderProcessHostImpl> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl);
Expand Down
93 changes: 93 additions & 0 deletions content/browser/renderer_host/render_process_host_mojo_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/renderer_host/render_process_host_mojo_impl.h"

#include "base/platform_file.h"
#include "content/common/mojo/mojo_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "mojo/common/mojo_channel_init.h"
#include "mojo/embedder/platform_channel_pair.h"

namespace content {

namespace {

base::PlatformFile PlatformFileFromScopedPlatformHandle(
mojo::embedder::ScopedPlatformHandle handle) {
#if defined(OS_POSIX)
return handle.release().fd;
#elif defined(OS_WIN)
return handle.release().handle;
#endif
}

} // namespace

struct RenderProcessHostMojoImpl::PendingHandle {
PendingHandle() : view_routing_id(0) {}

int32 view_routing_id;
mojo::ScopedMessagePipeHandle handle;
};

RenderProcessHostMojoImpl::RenderProcessHostMojoImpl(RenderProcessHost* host)
: host_(host) {
}

RenderProcessHostMojoImpl::~RenderProcessHostMojoImpl() {
}

void RenderProcessHostMojoImpl::SetWebUIHandle(
int32 view_routing_id,
mojo::ScopedMessagePipeHandle handle) {
base::ProcessHandle process = host_->GetHandle();
if (process != base::kNullProcessHandle) {
CreateMojoChannel(process); // Does nothing if already connected.
if (!render_process_mojo_.is_null()) {
render_process_mojo_->SetWebUIHandle(view_routing_id, handle.Pass());
return;
}
}

// Remember the request, we'll attempt to reconnect once the child process is
// launched.
pending_handle_.reset(new PendingHandle);
pending_handle_->view_routing_id = view_routing_id;
pending_handle_->handle = handle.Pass();
}

void RenderProcessHostMojoImpl::OnProcessLaunched() {
if (pending_handle_) {
scoped_ptr<PendingHandle> handle(pending_handle_.Pass());
SetWebUIHandle(handle->view_routing_id, handle->handle.Pass());
}
}


void RenderProcessHostMojoImpl::CreateMojoChannel(
base::ProcessHandle process_handle) {
if (mojo_channel_init_.get())
return;

mojo::embedder::PlatformChannelPair channel_pair;
mojo_channel_init_.reset(new mojo::common::MojoChannelInit);
mojo_channel_init_->Init(
PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
if (!mojo_channel_init_->is_handle_valid())
return;
base::PlatformFile client_file =
PlatformFileFromScopedPlatformHandle(channel_pair.PassClientHandle());
host_->Send(new MojoMsg_ChannelCreated(
IPC::GetFileHandleForProcess(client_file, process_handle,
true)));
ScopedRenderProcessMojoHandle render_process_handle(
RenderProcessMojoHandle(
mojo_channel_init_->bootstrap_message_pipe().release().value()));
render_process_mojo_.reset(render_process_handle.Pass(), this);
}

} // namespace content
Loading

0 comments on commit 2442605

Please sign in to comment.