diff options
author | ben <ben@chromium.org> | 2015-11-17 20:57:49 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-18 04:58:34 +0000 |
commit | 3edb97198bc5fbc22c5cf13286e8af80449ddfb9 (patch) | |
tree | 2728c10bc308270956b27a8b04a080d4c14ffffb /mojo | |
parent | ff14aff0758577956d4704050ef3d546a9bac624 (diff) | |
download | chromium_src-3edb97198bc5fbc22c5cf13286e8af80449ddfb9.zip chromium_src-3edb97198bc5fbc22c5cf13286e8af80449ddfb9.tar.gz chromium_src-3edb97198bc5fbc22c5cf13286e8af80449ddfb9.tar.bz2 |
Bind Application in renderer.
This involved changing how we get the client handle to the renderer. In the first iteration I was passing this on the command line but that turns out not to work with the sandbox. So instead I an approach used by the Mojo-in-Chrome MojoApplication class and pass the primordial handle via Chrome IPC.
I had to twiddle a bunch of BUILD.gn files in content to get this to work without crashing due to inconsistencies in how MOJO_SHELL_CLIENT was defined.
R=jam@chromium.org,tsepez@chromium.org
http://crbug.com/551253
Review URL: https://codereview.chromium.org/1452823003
Cr-Commit-Position: refs/heads/master@{#360293}
Diffstat (limited to 'mojo')
-rw-r--r-- | mojo/runner/child/runner_connection.cc | 51 | ||||
-rw-r--r-- | mojo/runner/child/runner_connection.h | 3 | ||||
-rw-r--r-- | mojo/runner/child/test_native_main.cc | 8 |
3 files changed, 29 insertions, 33 deletions
diff --git a/mojo/runner/child/runner_connection.cc b/mojo/runner/child/runner_connection.cc index c7758c4..ca0c7fc 100644 --- a/mojo/runner/child/runner_connection.cc +++ b/mojo/runner/child/runner_connection.cc @@ -23,6 +23,8 @@ namespace mojo { namespace runner { namespace { +void DidCreateChannel(embedder::ChannelInfo* channel_info) {} + // Blocks a thread until another thread unblocks it, at which point it unblocks // and runs a closure provided by that thread. class Blocker { @@ -89,7 +91,8 @@ class RunnerConnectionImpl : public RunnerConnection { // Returns true if a connection to the runner has been established and // |request| has been modified, false if no connection was established. - bool WaitForApplicationRequest(InterfaceRequest<Application>* request); + bool WaitForApplicationRequest(InterfaceRequest<Application>* request, + ScopedMessagePipeHandle handle); ChildControllerImpl* controller() const { return controller_.get(); } @@ -133,23 +136,15 @@ class ChildControllerImpl : public ChildController { // etc. static void Create(RunnerConnectionImpl* connection, const GotApplicationRequestCallback& callback, - embedder::ScopedPlatformHandle platform_channel, + ScopedMessagePipeHandle runner_handle, const Blocker::Unblocker& unblocker) { DCHECK(connection); - DCHECK(platform_channel.is_valid()); - DCHECK(!connection->controller()); scoped_ptr<ChildControllerImpl> impl( new ChildControllerImpl(connection, callback, unblocker)); - ScopedMessagePipeHandle host_message_pipe(embedder::CreateChannel( - platform_channel.Pass(), - base::Bind(&ChildControllerImpl::DidCreateChannel, - base::Unretained(impl.get())), - base::ThreadTaskRunnerHandle::Get())); - - impl->Bind(host_message_pipe.Pass()); + impl->Bind(runner_handle.Pass()); connection->set_controller(impl.Pass()); } @@ -191,13 +186,6 @@ class ChildControllerImpl : public ChildController { binding_.set_connection_error_handler([this]() { OnConnectionError(); }); } - // Callback for |embedder::CreateChannel()|. - void DidCreateChannel(embedder::ChannelInfo* channel_info) { - DVLOG(2) << "ChildControllerImpl::DidCreateChannel()"; - DCHECK(thread_checker_.CalledOnValidThread()); - channel_info_ = channel_info; - } - static void ReturnApplicationRequestOnMainThread( const GotApplicationRequestCallback& callback, InterfaceRequest<Application> application_request) { @@ -217,12 +205,20 @@ class ChildControllerImpl : public ChildController { }; bool RunnerConnectionImpl::WaitForApplicationRequest( - InterfaceRequest<Application>* request) { - embedder::ScopedPlatformHandle platform_channel = - embedder::PlatformChannelPair::PassClientHandleFromParentProcess( - *base::CommandLine::ForCurrentProcess()); - if (!platform_channel.is_valid()) - return false; + InterfaceRequest<Application>* request, + ScopedMessagePipeHandle handle) { + // If a valid message pipe to the runner was not provided, look for one on the + // command line. + if (!handle.is_valid()) { + embedder::ScopedPlatformHandle platform_channel = + embedder::PlatformChannelPair::PassClientHandleFromParentProcess( + *base::CommandLine::ForCurrentProcess()); + if (!platform_channel.is_valid()) + return false; + handle = embedder::CreateChannel(platform_channel.Pass(), + base::Bind(&DidCreateChannel), + base::ThreadTaskRunnerHandle::Get()); + } Blocker blocker; controller_runner_->PostTask( @@ -230,7 +226,7 @@ bool RunnerConnectionImpl::WaitForApplicationRequest( base::Bind( &ChildControllerImpl::Create, base::Unretained(this), base::Bind(&OnGotApplicationRequest, base::Unretained(request)), - base::Passed(&platform_channel), blocker.GetUnblocker())); + base::Passed(&handle), blocker.GetUnblocker())); blocker.Block(); return true; @@ -242,9 +238,10 @@ RunnerConnection::~RunnerConnection() {} // static RunnerConnection* RunnerConnection::ConnectToRunner( - InterfaceRequest<Application>* request) { + InterfaceRequest<Application>* request, + ScopedMessagePipeHandle handle) { RunnerConnectionImpl* connection = new RunnerConnectionImpl; - if (!connection->WaitForApplicationRequest(request)) { + if (!connection->WaitForApplicationRequest(request, handle.Pass())) { delete connection; return nullptr; } diff --git a/mojo/runner/child/runner_connection.h b/mojo/runner/child/runner_connection.h index 8ca8778..68202e1 100644 --- a/mojo/runner/child/runner_connection.h +++ b/mojo/runner/child/runner_connection.h @@ -24,7 +24,8 @@ class RunnerConnection { // If a connection to the runner cannot be established, |request| will not be // modified and this function will return null. static RunnerConnection* ConnectToRunner( - InterfaceRequest<Application>* request); + InterfaceRequest<Application>* request, + ScopedMessagePipeHandle handle); protected: RunnerConnection(); diff --git a/mojo/runner/child/test_native_main.cc b/mojo/runner/child/test_native_main.cc index c9bf253..a7e57b4 100644 --- a/mojo/runner/child/test_native_main.cc +++ b/mojo/runner/child/test_native_main.cc @@ -56,19 +56,17 @@ int TestNativeMain(mojo::ApplicationDelegate* application_delegate) { mojo::embedder::ProcessType::NONE, &process_delegate, io_thread.task_runner().get(), mojo::embedder::ScopedPlatformHandle()); + base::MessageLoop loop(mojo::common::MessagePumpMojo::Create()); mojo::InterfaceRequest<mojo::Application> application_request; scoped_ptr<mojo::runner::RunnerConnection> connection( - mojo::runner::RunnerConnection::ConnectToRunner(&application_request)); - - base::MessageLoop loop(mojo::common::MessagePumpMojo::Create()); + mojo::runner::RunnerConnection::ConnectToRunner( + &application_request, ScopedMessagePipeHandle())); { mojo::ApplicationImpl impl(application_delegate, application_request.Pass()); loop.Run(); } - connection.reset(); - mojo::embedder::ShutdownIPCSupport(); } |