summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrockot <rockot@chromium.org>2016-02-09 18:36:07 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-10 02:36:56 +0000
commit90fc3e55390be04a2a8bcb52ffd7fdd1dc1c0ae0 (patch)
tree2fbe7f870113ebb1ea92ddaadd900b468a2317fb
parent88db4f266a41b92dcbfae1914ccea693dcb7b255 (diff)
downloadchromium_src-90fc3e55390be04a2a8bcb52ffd7fdd1dc1c0ae0.zip
chromium_src-90fc3e55390be04a2a8bcb52ffd7fdd1dc1c0ae0.tar.gz
chromium_src-90fc3e55390be04a2a8bcb52ffd7fdd1dc1c0ae0.tar.bz2
[mojo-edk] Eliminate asynchronous Create*MessagePipe APIs
These are no longer necessary and the synchronous APIs are much cleaner. All call sites update and async versions deleted. BUG=584764 Review URL: https://codereview.chromium.org/1672353002 Cr-Commit-Position: refs/heads/master@{#374580}
-rw-r--r--components/arc/arc_bridge_bootstrap.cc31
-rw-r--r--content/browser/mojo/mojo_application_host.cc21
-rw-r--r--content/browser/mojo/mojo_application_host.h5
-rw-r--r--content/browser/mojo/mojo_shell_client_host.cc78
-rw-r--r--content/browser/mojo/mojo_shell_client_host.h6
-rw-r--r--content/browser/renderer_host/render_process_host_impl.cc2
-rw-r--r--content/child/child_thread_impl.cc7
-rw-r--r--content/child/mojo/mojo_application.cc11
-rw-r--r--content/child/mojo/mojo_application.h4
-rw-r--r--content/common/mojo/channel_init.cc12
-rw-r--r--content/common/mojo/channel_init.h9
-rw-r--r--mojo/edk/embedder/embedder.cc19
-rw-r--r--mojo/edk/embedder/embedder.h41
-rw-r--r--mojo/edk/system/node_channel.h2
-rw-r--r--mojo/edk/test/mojo_test_base.cc15
-rw-r--r--mojo/edk/test/mojo_test_base.h51
-rw-r--r--mojo/edk/test/multiprocess_test_helper.cc49
-rw-r--r--mojo/edk/test/multiprocess_test_helper.h11
-rw-r--r--mojo/shell/application_manager_apptest_driver.cc53
19 files changed, 102 insertions, 325 deletions
diff --git a/components/arc/arc_bridge_bootstrap.cc b/components/arc/arc_bridge_bootstrap.cc
index 1e826b3..1b0edda 100644
--- a/components/arc/arc_bridge_bootstrap.cc
+++ b/components/arc/arc_bridge_bootstrap.cc
@@ -32,13 +32,6 @@ namespace arc {
namespace {
-static void CallMessagePipeCallbackOnThread(
- const base::Callback<void(mojo::ScopedMessagePipeHandle)>& callback,
- scoped_refptr<base::TaskRunner> task_runner,
- mojo::ScopedMessagePipeHandle pipe) {
- task_runner->PostTask(FROM_HERE, base::Bind(callback, base::Passed(&pipe)));
-}
-
// We do not know the PID of ARC, since Chrome does not create it directly.
// Since Mojo in POSIX does not use the child PID except as an unique
// identifier for the routing table, rather than doing a lot of plumbing in the
@@ -65,8 +58,6 @@ class ArcBridgeBootstrapImpl : public ArcBridgeBootstrap {
// StartArcInstance() -> OnInstanceStarted() ->
// STARTED
// AcceptInstanceConnection() -> OnInstanceConnected() ->
- // CONNECTED
- // CreateMessagePipe() -> OnMessagePipeCreated() ->
// READY
//
// When Stop() is called from any state, either because an operation
@@ -95,9 +86,6 @@ class ArcBridgeBootstrapImpl : public ArcBridgeBootstrap {
// The instance has started. Waiting for it to connect to the IPC bridge.
STARTED,
- // The instance has begun the connection handshake.
- CONNECTED,
-
// The instance is fully connected.
READY,
@@ -122,7 +110,6 @@ class ArcBridgeBootstrapImpl : public ArcBridgeBootstrap {
// connected socket's file descriptor.
static base::ScopedFD AcceptInstanceConnection(base::ScopedFD socket_fd);
void OnInstanceConnected(base::ScopedFD fd);
- void OnMessagePipeCreated(mojo::ScopedMessagePipeHandle server_pipe);
void SetState(State state);
@@ -278,22 +265,8 @@ void ArcBridgeBootstrapImpl::OnInstanceConnected(base::ScopedFD fd) {
LOG(ERROR) << "Invalid handle";
return;
}
- SetState(State::CONNECTED);
- mojo::edk::CreateMessagePipe(
- mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle(fd.release())),
- base::Bind(&CallMessagePipeCallbackOnThread,
- base::Bind(&ArcBridgeBootstrapImpl::OnMessagePipeCreated,
- weak_factory_.GetWeakPtr()),
- base::ThreadTaskRunnerHandle::Get()));
-}
-
-void ArcBridgeBootstrapImpl::OnMessagePipeCreated(
- mojo::ScopedMessagePipeHandle server_pipe) {
- DCHECK(thread_checker_.CalledOnValidThread());
- if (state_ != State::CONNECTED) {
- VLOG(1) << "Stop() called when ARC is not running";
- return;
- }
+ mojo::ScopedMessagePipeHandle server_pipe = mojo::edk::CreateMessagePipe(
+ mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle(fd.release())));
if (!server_pipe.is_valid()) {
LOG(ERROR) << "Invalid pipe";
return;
diff --git a/content/browser/mojo/mojo_application_host.cc b/content/browser/mojo/mojo_application_host.cc
index 1f568ef..0376302 100644
--- a/content/browser/mojo/mojo_application_host.cc
+++ b/content/browser/mojo/mojo_application_host.cc
@@ -49,8 +49,7 @@ class ApplicationSetupImpl : public ApplicationSetup {
} // namespace
-MojoApplicationHost::MojoApplicationHost()
- : did_activate_(false), weak_factory_(this) {
+MojoApplicationHost::MojoApplicationHost() : did_activate_(false) {
#if defined(OS_ANDROID)
service_registry_android_.reset(
new ServiceRegistryAndroid(&service_registry_));
@@ -76,13 +75,12 @@ bool MojoApplicationHost::Init() {
// Forward this to the client once we know its process handle.
client_handle_ = channel_pair.PassClientHandle();
-
- channel_init_.Init(
+ mojo::ScopedMessagePipeHandle pipe = channel_init_.Init(
PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()),
- io_task_runner,
- base::Bind(&MojoApplicationHost::OnMessagePipeCreated,
- weak_factory_.GetWeakPtr()));
-
+ io_task_runner);
+ application_setup_.reset(new ApplicationSetupImpl(
+ &service_registry_,
+ mojo::MakeRequest<ApplicationSetup>(std::move(pipe))));
return true;
}
@@ -106,12 +104,5 @@ void MojoApplicationHost::OverrideIOTaskRunnerForTest(
io_task_runner_override_ = io_task_runner;
}
-void MojoApplicationHost::OnMessagePipeCreated(
- mojo::ScopedMessagePipeHandle pipe) {
- DCHECK(pipe.is_valid());
- application_setup_.reset(new ApplicationSetupImpl(
- &service_registry_,
- mojo::MakeRequest<ApplicationSetup>(std::move(pipe))));
-}
} // namespace content
diff --git a/content/browser/mojo/mojo_application_host.h b/content/browser/mojo/mojo_application_host.h
index 82dcb64..1b6c523 100644
--- a/content/browser/mojo/mojo_application_host.h
+++ b/content/browser/mojo/mojo_application_host.h
@@ -7,7 +7,6 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
#include "base/process/process_handle.h"
#include "build/build_config.h"
#include "content/common/application_setup.mojom.h"
@@ -56,8 +55,6 @@ class CONTENT_EXPORT MojoApplicationHost {
scoped_refptr<base::TaskRunner> io_task_runner);
private:
- void OnMessagePipeCreated(mojo::ScopedMessagePipeHandle pipe);
-
ChannelInit channel_init_;
mojo::embedder::ScopedPlatformHandle client_handle_;
@@ -72,8 +69,6 @@ class CONTENT_EXPORT MojoApplicationHost {
scoped_ptr<ServiceRegistryAndroid> service_registry_android_;
#endif
- base::WeakPtrFactory<MojoApplicationHost> weak_factory_;
-
DISALLOW_COPY_AND_ASSIGN(MojoApplicationHost);
};
diff --git a/content/browser/mojo/mojo_shell_client_host.cc b/content/browser/mojo/mojo_shell_client_host.cc
index f8b67db..2d3b208 100644
--- a/content/browser/mojo/mojo_shell_client_host.cc
+++ b/content/browser/mojo/mojo_shell_client_host.cc
@@ -110,14 +110,28 @@ class PIDSender : public RenderProcessHostObserver {
} // namespace
-void ConnectChildToShell(
- int child_process_id,
- base::WeakPtr<RenderProcessHost> render_process_host,
- mojo::InterfaceRequest<mojo::shell::mojom::PIDReceiver> request,
- mojo::ScopedMessagePipeHandle pipe) {
- if (!render_process_host)
+void RegisterChildWithExternalShell(int child_process_id,
+ RenderProcessHost* render_process_host) {
+ // Some process types get created before the main message loop.
+ if (!MojoShellConnection::Get())
return;
+ // Create the channel to be shared with the target process.
+ mojo::edk::HandlePassingInformation handle_passing_info;
+ mojo::edk::PlatformChannelPair platform_channel_pair;
+
+ // Give one end to the shell so that it can create an instance.
+ mojo::edk::ScopedPlatformHandle parent_pipe =
+ platform_channel_pair.PassServerHandle();
+
+ // Send the other end to the child via Chrome IPC.
+ base::PlatformFile client_file = PlatformFileFromScopedPlatformHandle(
+ platform_channel_pair.PassClientHandle());
+ SetMojoPlatformFile(render_process_host, client_file);
+
+ mojo::ScopedMessagePipeHandle request_pipe =
+ mojo::edk::CreateMessagePipe(std::move(parent_pipe));
+
mojo::shell::mojom::ApplicationManagerPtr application_manager;
MojoShellConnection::Get()->GetShell()->ConnectToService(
"mojo:shell", &application_manager);
@@ -132,60 +146,20 @@ void ConnectChildToShell(
std::string url =
base::StringPrintf("exe:chrome_renderer%d", child_process_id);
+ mojo::shell::mojom::PIDReceiverPtr pid_receiver;
+ mojo::InterfaceRequest<mojo::shell::mojom::PIDReceiver> request =
+ GetProxy(&pid_receiver);
+ new PIDSender(render_process_host, std::move(pid_receiver));
application_manager->CreateInstanceForHandle(
- mojo::ScopedHandle(mojo::Handle(pipe.release().value())),
+ mojo::ScopedHandle(mojo::Handle(request_pipe.release().value())),
url,
CreateCapabilityFilterForRenderer(),
std::move(request));
// Store the URL on the RPH so client code can access it later via
// GetMojoApplicationInstanceURL().
- SetMojoApplicationInstanceURL(render_process_host.get(), url);
-}
-
-void OnChildMessagePipeCreated(
- int child_process_id,
- base::WeakPtr<RenderProcessHost> render_process_host,
- scoped_refptr<base::TaskRunner> task_runner,
- mojo::InterfaceRequest<mojo::shell::mojom::PIDReceiver> request,
- mojo::ScopedMessagePipeHandle pipe) {
- task_runner->PostTask(FROM_HERE,
- base::Bind(&ConnectChildToShell, child_process_id,
- render_process_host, base::Passed(&request),
- base::Passed(&pipe)));
-}
-
-void RegisterChildWithExternalShell(
- int child_process_id,
- base::WeakPtr<RenderProcessHost> render_process_host) {
- // Some process types get created before the main message loop.
- if (!MojoShellConnection::Get())
- return;
-
- // Create the channel to be shared with the target process.
- mojo::edk::HandlePassingInformation handle_passing_info;
- mojo::edk::PlatformChannelPair platform_channel_pair;
-
- // Give one end to the shell so that it can create an instance.
- mojo::edk::ScopedPlatformHandle parent_pipe =
- platform_channel_pair.PassServerHandle();
-
- mojo::shell::mojom::PIDReceiverPtr pid_receiver;
- mojo::InterfaceRequest<mojo::shell::mojom::PIDReceiver> request =
- GetProxy(&pid_receiver);
- new PIDSender(render_process_host.get(), std::move(pid_receiver));
-
- // Send the other end to the child via Chrome IPC.
- base::PlatformFile client_file = PlatformFileFromScopedPlatformHandle(
- platform_channel_pair.PassClientHandle());
- SetMojoPlatformFile(render_process_host.get(), client_file);
-
- mojo::edk::CreateMessagePipe(
- std::move(parent_pipe),
- base::Bind(&OnChildMessagePipeCreated, child_process_id,
- render_process_host, base::ThreadTaskRunnerHandle::Get(),
- base::Passed(&request)));
+ SetMojoApplicationInstanceURL(render_process_host, url);
}
std::string GetMojoApplicationInstanceURL(
diff --git a/content/browser/mojo/mojo_shell_client_host.h b/content/browser/mojo/mojo_shell_client_host.h
index a022dd7..25539a3 100644
--- a/content/browser/mojo/mojo_shell_client_host.h
+++ b/content/browser/mojo/mojo_shell_client_host.h
@@ -7,7 +7,6 @@
#include <string>
-#include "base/memory/weak_ptr.h"
#include "base/process/process_handle.h"
#include "mojo/shell/public/interfaces/shell.mojom.h"
#include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h"
@@ -20,9 +19,8 @@ class RenderProcessHost;
// child. The server handle of this channel is shared with the external shell
// via Mojo IPC. |child_process_id| is used to uniquify the child in the
// external shell's instance map.
-void RegisterChildWithExternalShell(
- int child_process_id,
- base::WeakPtr<RenderProcessHost> render_process_host);
+void RegisterChildWithExternalShell(int child_process_id,
+ RenderProcessHost* render_process_host);
// Returns the URL associated with an instance corresponding to the renderer
// process in the external shell. This URL can be passed to
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index 8ba3993..29073e0 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -628,7 +628,7 @@ RenderProcessHostImpl::RenderProcessHostImpl(
#endif // USE_ATTACHMENT_BROKER
#if defined(MOJO_SHELL_CLIENT)
- RegisterChildWithExternalShell(id_, weak_factory_.GetWeakPtr());
+ RegisterChildWithExternalShell(id_, this);
#endif
}
diff --git a/content/child/child_thread_impl.cc b/content/child/child_thread_impl.cc
index 5378463..7e815ba 100644
--- a/content/child/child_thread_impl.cc
+++ b/content/child/child_thread_impl.cc
@@ -688,10 +688,9 @@ void ChildThreadImpl::OnBindExternalMojoShellHandle(
#elif defined(OS_WIN)
base::PlatformFile handle = file;
#endif
- mojo_shell_channel_init_.Init(
- handle, GetIOTaskRunner(),
- base::Bind(&MojoShellConnectionImpl::BindToMessagePipe,
- base::Unretained(MojoShellConnectionImpl::Get())));
+ mojo::ScopedMessagePipeHandle pipe =
+ mojo_shell_channel_init_.Init(handle, GetIOTaskRunner());
+ MojoShellConnectionImpl::Get()->BindToMessagePipe(std::move(pipe));
#endif // defined(MOJO_SHELL_CLIENT)
}
diff --git a/content/child/mojo/mojo_application.cc b/content/child/mojo/mojo_application.cc
index fd0260d..d49d9da 100644
--- a/content/child/mojo/mojo_application.cc
+++ b/content/child/mojo/mojo_application.cc
@@ -18,8 +18,7 @@ namespace content {
MojoApplication::MojoApplication(
scoped_refptr<base::SequencedTaskRunner> io_task_runner)
- : io_task_runner_(io_task_runner),
- weak_factory_(this) {
+ : io_task_runner_(io_task_runner) {
DCHECK(io_task_runner_);
}
@@ -43,12 +42,8 @@ void MojoApplication::OnActivate(
base::PlatformFile handle = file;
#endif
- channel_init_.Init(handle, io_task_runner_,
- base::Bind(&MojoApplication::OnMessagePipeCreated,
- weak_factory_.GetWeakPtr()));
-}
-
-void MojoApplication::OnMessagePipeCreated(mojo::ScopedMessagePipeHandle pipe) {
+ mojo::ScopedMessagePipeHandle pipe =
+ channel_init_.Init(handle, io_task_runner_);
DCHECK(pipe.is_valid());
ApplicationSetupPtr application_setup;
diff --git a/content/child/mojo/mojo_application.h b/content/child/mojo/mojo_application.h
index 20c98c9..5303a30 100644
--- a/content/child/mojo/mojo_application.h
+++ b/content/child/mojo/mojo_application.h
@@ -6,7 +6,6 @@
#define CONTENT_CHILD_MOJO_MOJO_APPLICATION_H_
#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
#include "content/common/mojo/channel_init.h"
#include "content/common/mojo/service_registry_impl.h"
#include "ipc/ipc_platform_file.h"
@@ -38,12 +37,9 @@ class MojoApplication {
private:
void OnActivate(const IPC::PlatformFileForTransit& file);
- void OnMessagePipeCreated(mojo::ScopedMessagePipeHandle pipe);
-
scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
ChannelInit channel_init_;
ServiceRegistryImpl service_registry_;
- base::WeakPtrFactory<MojoApplication> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(MojoApplication);
};
diff --git a/content/common/mojo/channel_init.cc b/content/common/mojo/channel_init.cc
index 3b7fe21..503dc81 100644
--- a/content/common/mojo/channel_init.cc
+++ b/content/common/mojo/channel_init.cc
@@ -27,24 +27,22 @@ ChannelInit::~ChannelInit() {
base::Bind(&base::DoNothing), nullptr);
}
-void ChannelInit::Init(
+mojo::ScopedMessagePipeHandle ChannelInit::Init(
base::PlatformFile file,
- scoped_refptr<base::TaskRunner> io_thread_task_runner,
- const base::Callback<void(mojo::ScopedMessagePipeHandle)>& callback) {
+ scoped_refptr<base::TaskRunner> io_thread_task_runner) {
scoped_ptr<IPC::ScopedIPCSupport> ipc_support(
new IPC::ScopedIPCSupport(io_thread_task_runner));
if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) {
ipc_support_ = std::move(ipc_support);
- callback.Run(mojo::edk::CreateMessagePipe(
- mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle(file))));
+ return mojo::edk::CreateMessagePipe(
+ mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle(file)));
} else {
- mojo::ScopedMessagePipeHandle message_pipe = mojo::embedder::CreateChannel(
+ return mojo::embedder::CreateChannel(
mojo::embedder::ScopedPlatformHandle(
mojo::embedder::PlatformHandle(file)),
base::Bind(&ChannelInit::OnCreatedChannel, weak_factory_.GetWeakPtr(),
base::Passed(&ipc_support)),
base::ThreadTaskRunnerHandle::Get());
- callback.Run(std::move(message_pipe));
}
}
diff --git a/content/common/mojo/channel_init.h b/content/common/mojo/channel_init.h
index 34d0c95..bebac06 100644
--- a/content/common/mojo/channel_init.h
+++ b/content/common/mojo/channel_init.h
@@ -5,7 +5,6 @@
#ifndef CONTENT_COMMON_MOJO_CHANNEL_INIT_H_
#define CONTENT_COMMON_MOJO_CHANNEL_INIT_H_
-#include "base/callback.h"
#include "base/files/file.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
@@ -28,12 +27,10 @@ class CONTENT_EXPORT ChannelInit {
ChannelInit();
~ChannelInit();
- // Initializes the channel. This takes ownership of |file|. Calls |callback|
- // on the calling thread once the pipe is created.
- void Init(
+ // Initializes the channel. This takes ownership of |file|.
+ mojo::ScopedMessagePipeHandle Init(
base::PlatformFile file,
- scoped_refptr<base::TaskRunner> io_thread_task_runner,
- const base::Callback<void(mojo::ScopedMessagePipeHandle)>& callback);
+ scoped_refptr<base::TaskRunner> io_thread_task_runner);
// Notifies the channel that we (hence it) will soon be destroyed.
void WillDestroySoon();
diff --git a/mojo/edk/embedder/embedder.cc b/mojo/edk/embedder/embedder.cc
index 926ee18..696424e 100644
--- a/mojo/edk/embedder/embedder.cc
+++ b/mojo/edk/embedder/embedder.cc
@@ -111,35 +111,16 @@ ScopedMessagePipeHandle CreateMessagePipe(
return internal::g_core->CreateMessagePipe(std::move(platform_handle));
}
-void CreateMessagePipe(
- ScopedPlatformHandle platform_handle,
- const base::Callback<void(ScopedMessagePipeHandle)>& callback) {
- DCHECK(internal::g_core);
- callback.Run(CreateMessagePipe(std::move(platform_handle)));
-}
-
ScopedMessagePipeHandle CreateParentMessagePipe(const std::string& token) {
DCHECK(internal::g_core);
return internal::g_core->CreateParentMessagePipe(token);
}
-void CreateParentMessagePipe(
- const std::string& token,
- const base::Callback<void(ScopedMessagePipeHandle)>& callback) {
- callback.Run(CreateParentMessagePipe(token));
-}
-
ScopedMessagePipeHandle CreateChildMessagePipe(const std::string& token) {
DCHECK(internal::g_core);
return internal::g_core->CreateChildMessagePipe(token);
}
-void CreateChildMessagePipe(
- const std::string& token,
- const base::Callback<void(ScopedMessagePipeHandle)>& callback) {
- callback.Run(CreateChildMessagePipe(token));
-}
-
std::string GenerateRandomToken() {
char random_bytes[16];
crypto::RandBytes(random_bytes, 16);
diff --git a/mojo/edk/embedder/embedder.h b/mojo/edk/embedder/embedder.h
index 49b64c4..81d098f 100644
--- a/mojo/edk/embedder/embedder.h
+++ b/mojo/edk/embedder/embedder.h
@@ -127,59 +127,18 @@ MOJO_SYSTEM_IMPL_EXPORT void ShutdownIPCSupport();
MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle
CreateMessagePipe(ScopedPlatformHandle platform_handle);
-// Creates a message pipe over an arbitrary platform channel. In order for this
-// to work properly each end of the channel must be passed to this function: one
-// end in a parent process and one end in a child process. In a child process,
-// either PreInitializeChildProcess() or SetParentPipe() must have been been
-// called at least once already.
-//
-// |callback| must be safe to call from any thread.
-//
-// DEPRECATED: Please don't use this. Use the synchronous version above. This
-// is now merely an inconvenient wrapper for that.
-MOJO_SYSTEM_IMPL_EXPORT void
-CreateMessagePipe(
- ScopedPlatformHandle platform_handle,
- const base::Callback<void(ScopedMessagePipeHandle)>& callback);
-
// Creates a message pipe from a token. A child embedder must also have this
// token and call CreateChildMessagePipe() with it in order for the pipe to get
// connected.
MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle
CreateParentMessagePipe(const std::string& token);
-// Creates a message pipe from a token. A child embedder must also have this
-// token and call CreateChildMessagePipe() with it in order for the pipe to get
-// connected.
-//
-// |callback| must be safe to call from any thread.
-//
-// DEPRECATED: Please don't use this. Use the synchronous version above. This
-// is now merely an inconvenient wrapper for that.
-MOJO_SYSTEM_IMPL_EXPORT void
-CreateParentMessagePipe(
- const std::string& token,
- const base::Callback<void(ScopedMessagePipeHandle)>& callback);
-
// Creates a message pipe from a token in a child process. The parent must also
// have this token and call CreateParentMessagePipe() with it in order for the
// pipe to get connected.
MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle
CreateChildMessagePipe(const std::string& token);
-// Creates a message pipe from a token in a child process. The parent must also
-// have this token and call CreateParentMessagePipe() with it in order for the
-// pipe to get connected.
-//
-// |callback| must be safe to call from any thread.
-//
-// DEPRECATED: Please don't use this. Use the synchronous version above. This
-// is now merely an inconvenient wrapper for that.
-MOJO_SYSTEM_IMPL_EXPORT void
-CreateChildMessagePipe(
- const std::string& token,
- const base::Callback<void(ScopedMessagePipeHandle)>& callback);
-
// Generates a random ASCII token string for use with CreateParentMessagePipe()
// and CreateChildMessagePipe() above. The generated token is suitably random so
// as to not have to worry about collisions with other generated tokens.
diff --git a/mojo/edk/system/node_channel.h b/mojo/edk/system/node_channel.h
index 2bc86bd..e08dc47 100644
--- a/mojo/edk/system/node_channel.h
+++ b/mojo/edk/system/node_channel.h
@@ -99,7 +99,7 @@ class NodeChannel : public base::RefCountedThreadSafe<NodeChannel>,
ScopedPlatformHandle broker_channel);
void PortsMessage(Channel::MessagePtr message);
void RequestPortMerge(const ports::PortName& connector_port_name,
- const std::string& token);
+ const std::string& token);
void RequestIntroduction(const ports::NodeName& name);
void Introduce(const ports::NodeName& name,
ScopedPlatformHandle channel_handle);
diff --git a/mojo/edk/test/mojo_test_base.cc b/mojo/edk/test/mojo_test_base.cc
index a1017bc..028f5d0 100644
--- a/mojo/edk/test/mojo_test_base.cc
+++ b/mojo/edk/test/mojo_test_base.cc
@@ -22,19 +22,16 @@ MojoTestBase::MojoTestBase() {
MojoTestBase::~MojoTestBase() {}
MojoTestBase::ClientController& MojoTestBase::StartClient(
- const std::string& client_name,
- const HandlerCallback& callback) {
+ const std::string& client_name) {
clients_.push_back(
- make_scoped_ptr(new ClientController(client_name, this, callback)));
+ make_scoped_ptr(new ClientController(client_name, this)));
return *clients_.back();
}
-MojoTestBase::ClientController::ClientController(
- const std::string& client_name,
- MojoTestBase* test,
- const HandlerCallback& callback)
- : test_(test) {
- helper_.StartChild(client_name, callback);
+MojoTestBase::ClientController::ClientController(const std::string& client_name,
+ MojoTestBase* test)
+ : test_(test),
+ pipe_(helper_.StartChild(client_name)) {
}
MojoTestBase::ClientController::~ClientController() {
diff --git a/mojo/edk/test/mojo_test_base.h b/mojo/edk/test/mojo_test_base.h
index 98ee597..c158fb0 100644
--- a/mojo/edk/test/mojo_test_base.h
+++ b/mojo/edk/test/mojo_test_base.h
@@ -38,11 +38,11 @@ class MojoTestBase : public testing::Test {
class ClientController {
public:
- ClientController(const std::string& client_name,
- MojoTestBase* test,
- const HandlerCallback& callback);
+ ClientController(const std::string& client_name, MojoTestBase* test);
~ClientController();
+ MojoHandle pipe() const { return pipe_.get().value(); }
+
int WaitForShutdown();
private:
@@ -50,49 +50,20 @@ class MojoTestBase : public testing::Test {
MojoTestBase* test_;
MultiprocessTestHelper helper_;
+ ScopedMessagePipeHandle pipe_;
bool was_shutdown_ = false;
DISALLOW_COPY_AND_ASSIGN(ClientController);
};
- ClientController& StartClient(
- const std::string& client_name,
- const HandlerCallback& callback);
-
- static void RunHandlerOnMainThread(
- std::function<void(MojoHandle, int*, const base::Closure&)> handler,
- int* expected_exit_code,
- const base::Closure& quit_closure,
- ScopedMessagePipeHandle pipe) {
- handler(pipe.get().value(), expected_exit_code, quit_closure);
- }
-
- static void RunHandler(
- std::function<void(MojoHandle, int*, const base::Closure&)> handler,
- int* expected_exit_code,
- const base::Closure& quit_closure,
- scoped_refptr<base::TaskRunner> task_runner,
- ScopedMessagePipeHandle pipe) {
- task_runner->PostTask(
- FROM_HERE,
- base::Bind(&RunHandlerOnMainThread, handler,
- base::Unretained(expected_exit_code), quit_closure,
- base::Passed(&pipe)));
- }
+ ClientController& StartClient(const std::string& client_name);
template <typename HandlerFunc>
void StartClientWithHandler(const std::string& client_name,
HandlerFunc handler) {
- base::MessageLoop::ScopedNestableTaskAllower nesting(&message_loop_);
- base::RunLoop run_loop;
- int expected_exit_code;
- ClientController& c =
- StartClient(client_name,
- base::Bind(&RunHandler, handler,
- base::Unretained(&expected_exit_code),
- run_loop.QuitClosure(),
- base::ThreadTaskRunnerHandle::Get()));
- run_loop.Run();
+ int expected_exit_code = 0;
+ ClientController& c = StartClient(client_name);
+ handler(c.pipe(), &expected_exit_code);
EXPECT_EQ(expected_exit_code, c.WaitForShutdown());
}
@@ -173,22 +144,18 @@ class MojoTestBase : public testing::Test {
#define RUN_CHILD_ON_PIPE(client_name, pipe_name) \
StartClientWithHandler( \
#client_name, \
- [&](MojoHandle pipe_name, \
- int *expected_exit_code, \
- const base::Closure& quit_closure) { {
+ [&](MojoHandle pipe_name, int *expected_exit_code) { {
// Waits for the client to terminate and expects a return code of zero.
#define END_CHILD() \
} \
*expected_exit_code = 0; \
- quit_closure.Run(); \
});
// Wait for the client to terminate with a specific return code.
#define END_CHILD_AND_EXPECT_EXIT_CODE(code) \
} \
*expected_exit_code = code; \
- quit_closure.Run(); \
});
// Use this to declare the child process's "main()" function for tests using
diff --git a/mojo/edk/test/multiprocess_test_helper.cc b/mojo/edk/test/multiprocess_test_helper.cc
index a4ebd50..efc4e6b 100644
--- a/mojo/edk/test/multiprocess_test_helper.cc
+++ b/mojo/edk/test/multiprocess_test_helper.cc
@@ -37,35 +37,11 @@ namespace {
const char kMojoPrimordialPipeToken[] = "mojo-primordial-pipe-token";
-void RunHandlerOnMainThread(std::function<int(MojoHandle)> handler,
- int* exit_code,
- const base::Closure& quit_closure,
- ScopedMessagePipeHandle pipe) {
- *exit_code = handler(pipe.get().value());
- quit_closure.Run();
-}
-
-void RunHandler(std::function<int(MojoHandle)> handler,
- int* exit_code,
- const base::Closure& quit_closure,
- scoped_refptr<base::TaskRunner> task_runner,
- ScopedMessagePipeHandle pipe) {
- task_runner->PostTask(
- FROM_HERE,
- base::Bind(&RunHandlerOnMainThread, handler, base::Unretained(exit_code),
- quit_closure, base::Passed(&pipe)));
-}
-
int RunClientFunction(std::function<int(MojoHandle)> handler) {
- base::RunLoop run_loop;
- int exit_code = 0;
CHECK(!MultiprocessTestHelper::primordial_pipe_token.empty());
- CreateChildMessagePipe(
- MultiprocessTestHelper::primordial_pipe_token,
- base::Bind(&RunHandler, handler, base::Unretained(&exit_code),
- run_loop.QuitClosure(), base::ThreadTaskRunnerHandle::Get()));
- run_loop.Run();
- return exit_code;
+ ScopedMessagePipeHandle pipe = CreateChildMessagePipe(
+ MultiprocessTestHelper::primordial_pipe_token);
+ return handler(pipe.get().value());
}
} // namespace
@@ -76,17 +52,16 @@ MultiprocessTestHelper::~MultiprocessTestHelper() {
CHECK(!test_child_.IsValid());
}
-void MultiprocessTestHelper::StartChild(const std::string& test_child_name,
- const HandlerCallback& callback) {
- StartChildWithExtraSwitch(
- test_child_name, std::string(), std::string(), callback);
+ScopedMessagePipeHandle MultiprocessTestHelper::StartChild(
+ const std::string& test_child_name) {
+ return StartChildWithExtraSwitch(
+ test_child_name, std::string(), std::string());
}
-void MultiprocessTestHelper::StartChildWithExtraSwitch(
+ScopedMessagePipeHandle MultiprocessTestHelper::StartChildWithExtraSwitch(
const std::string& test_child_name,
const std::string& switch_string,
- const std::string& switch_value,
- const HandlerCallback& callback) {
+ const std::string& switch_value) {
CHECK(!test_child_name.empty());
CHECK(!test_child_.IsValid());
@@ -139,14 +114,16 @@ void MultiprocessTestHelper::StartChildWithExtraSwitch(
#error "Not supported yet."
#endif
+ ScopedMessagePipeHandle pipe = CreateParentMessagePipe(pipe_token);
+
test_child_ =
base::SpawnMultiProcessTestChild(test_child_main, command_line, options);
channel.ChildProcessLaunched();
ChildProcessLaunched(test_child_.Handle(), channel.PassServerHandle());
- CreateParentMessagePipe(pipe_token, callback);
-
CHECK(test_child_.IsValid());
+
+ return pipe;
}
int MultiprocessTestHelper::WaitForChildShutdown() {
diff --git a/mojo/edk/test/multiprocess_test_helper.h b/mojo/edk/test/multiprocess_test_helper.h
index 3b4c32a..86cefbb 100644
--- a/mojo/edk/test/multiprocess_test_helper.h
+++ b/mojo/edk/test/multiprocess_test_helper.h
@@ -32,16 +32,15 @@ class MultiprocessTestHelper {
// Start a child process and run the "main" function "named" |test_child_name|
// declared using |MOJO_MULTIPROCESS_TEST_CHILD_MAIN()| or
// |MOJO_MULTIPROCESS_TEST_CHILD_TEST()| (below).
- void StartChild(const std::string& test_child_name,
- const HandlerCallback& callback);
+ ScopedMessagePipeHandle StartChild(const std::string& test_child_name);
// Like |StartChild()|, but appends an extra switch (with ASCII value) to the
// command line. (The switch must not already be present in the default
// command line.)
- void StartChildWithExtraSwitch(const std::string& test_child_name,
- const std::string& switch_string,
- const std::string& switch_value,
- const HandlerCallback& callback);
+ ScopedMessagePipeHandle StartChildWithExtraSwitch(
+ const std::string& test_child_name,
+ const std::string& switch_string,
+ const std::string& switch_value);
// Wait for the child process to terminate.
// Returns the exit code of the child process. Note that, though it's declared
diff --git a/mojo/shell/application_manager_apptest_driver.cc b/mojo/shell/application_manager_apptest_driver.cc
index 557fc08..5c755a1 100644
--- a/mojo/shell/application_manager_apptest_driver.cc
+++ b/mojo/shell/application_manager_apptest_driver.cc
@@ -90,12 +90,23 @@ class TargetApplicationDelegate : public mojo::ShellClient,
primordial_pipe_token);
// Allocate the pipe locally.
- mojo::edk::CreateParentMessagePipe(
- primordial_pipe_token,
- base::Bind(&TargetApplicationDelegate::OnMessagePipeCreated,
- weak_factory_.GetWeakPtr(),
- base::ThreadTaskRunnerHandle::Get(),
- base::Passed(&request)));
+ mojo::ScopedMessagePipeHandle pipe =
+ mojo::edk::CreateParentMessagePipe(primordial_pipe_token);
+
+ mojo::shell::mojom::CapabilityFilterPtr filter(
+ mojo::shell::mojom::CapabilityFilter::New());
+ mojo::Array<mojo::String> test_interfaces;
+ test_interfaces.push_back(
+ mojo::shell::test::mojom::CreateInstanceForHandleTest::Name_);
+ filter->filter.insert("mojo:mojo_shell_apptests",
+ std::move(test_interfaces));
+
+ mojo::shell::mojom::ApplicationManagerPtr application_manager;
+ shell_->ConnectToService("mojo:shell", &application_manager);
+ application_manager->CreateInstanceForHandle(
+ mojo::ScopedHandle(mojo::Handle(pipe.release().value())),
+ "exe:application_manager_apptest_target", std::move(filter),
+ std::move(request));
base::LaunchOptions options;
#if defined(OS_WIN)
@@ -127,36 +138,6 @@ class TargetApplicationDelegate : public mojo::ShellClient,
shell_->Quit();
}
- static void OnMessagePipeCreated(
- base::WeakPtr<TargetApplicationDelegate> weak_self,
- scoped_refptr<base::TaskRunner> task_runner,
- mojo::InterfaceRequest<mojo::shell::mojom::PIDReceiver> request,
- mojo::ScopedMessagePipeHandle pipe) {
- task_runner->PostTask(
- FROM_HERE,
- base::Bind(&TargetApplicationDelegate::OnMessagePipeCreatedOnMainThread,
- weak_self, base::Passed(&request), base::Passed(&pipe)));
- }
-
- void OnMessagePipeCreatedOnMainThread(
- mojo::InterfaceRequest<mojo::shell::mojom::PIDReceiver> request,
- mojo::ScopedMessagePipeHandle pipe) {
- mojo::shell::mojom::CapabilityFilterPtr filter(
- mojo::shell::mojom::CapabilityFilter::New());
- mojo::Array<mojo::String> test_interfaces;
- test_interfaces.push_back(
- mojo::shell::test::mojom::CreateInstanceForHandleTest::Name_);
- filter->filter.insert("mojo:mojo_shell_apptests",
- std::move(test_interfaces));
-
- mojo::shell::mojom::ApplicationManagerPtr application_manager;
- shell_->ConnectToService("mojo:shell", &application_manager);
- application_manager->CreateInstanceForHandle(
- mojo::ScopedHandle(mojo::Handle(pipe.release().value())),
- "exe:application_manager_apptest_target", std::move(filter),
- std::move(request));
- }
-
mojo::Shell* shell_;
base::Process target_;
mojo::WeakBindingSet<Driver> bindings_;