Skip to content

Commit

Permalink
Change IPC::ChannelMojo to use associated interfaces.
Browse files Browse the repository at this point in the history
BUG=579813

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

Cr-Commit-Position: refs/heads/master@{#379669}
  • Loading branch information
sammc authored and Commit bot committed Mar 7, 2016
1 parent 407d245 commit e4d0abd
Show file tree
Hide file tree
Showing 33 changed files with 488 additions and 1,239 deletions.
6 changes: 4 additions & 2 deletions content/browser/child_process_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,12 @@ void LaunchOnLauncherThread(const NotifyCallback& callback,
DCHECK(mojo_fd.is_valid());

#if defined(OS_ANDROID)
files_to_register->Share(kPrimaryIPCChannel, ipcfd.get());
if (ipcfd.get() != -1)
files_to_register->Share(kPrimaryIPCChannel, ipcfd.get());
files_to_register->Share(kMojoIPCChannel, mojo_fd.get());
#else
files_to_register->Transfer(kPrimaryIPCChannel, std::move(ipcfd));
if (ipcfd.get() != -1)
files_to_register->Transfer(kPrimaryIPCChannel, std::move(ipcfd));
files_to_register->Transfer(kMojoIPCChannel, std::move(mojo_fd));
#endif
#endif
Expand Down
18 changes: 11 additions & 7 deletions content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -814,12 +814,11 @@ scoped_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy(
const std::string& channel_id) {
scoped_refptr<base::SingleThreadTaskRunner> runner =
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
scoped_refptr<base::SequencedTaskRunner> mojo_task_runner =
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO)
->task_runner();
if (ShouldUseMojoChannel()) {
VLOG(1) << "Mojo Channel is enabled on host";

mojo_channel_token_ = mojo::edk::GenerateRandomToken();

// Do NOT expand ifdef or run time condition checks here! Synchronous
// IPCs from browser process are banned. It is only narrowly allowed
// for Android WebView to maintain backward compatibility.
Expand All @@ -828,14 +827,14 @@ scoped_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy(
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kIPCSyncCompositing)) {
return IPC::SyncChannel::Create(
IPC::ChannelMojo::CreateServerFactory(mojo_task_runner, channel_id),
this, runner.get(), true, &never_signaled_);
IPC::ChannelMojo::CreateServerFactory(mojo_channel_token_), this,
runner.get(), true, &never_signaled_);
}
#endif // OS_ANDROID

return IPC::ChannelProxy::Create(
IPC::ChannelMojo::CreateServerFactory(mojo_task_runner, channel_id),
this, runner.get());
IPC::ChannelMojo::CreateServerFactory(mojo_channel_token_), this,
runner.get());
}

// Do NOT expand ifdef or run time condition checks here! See comment above.
Expand Down Expand Up @@ -1375,6 +1374,11 @@ void RenderProcessHostImpl::AppendRendererCommandLine(
#endif

AppendCompositorCommandLineFlags(command_line);

if (!mojo_channel_token_.empty()) {
command_line->AppendSwitchASCII(switches::kMojoChannelToken,
mojo_channel_token_);
}
}

void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
Expand Down
2 changes: 2 additions & 0 deletions content/browser/renderer_host/render_process_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ class CONTENT_EXPORT RenderProcessHostImpl
base::WaitableEvent never_signaled_;
#endif

std::string mojo_channel_token_;

base::WeakPtrFactory<RenderProcessHostImpl> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl);
Expand Down
8 changes: 5 additions & 3 deletions content/child/child_thread_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "content/common/in_process_child_thread_params.h"
#include "content/common/mojo/mojo_shell_connection_impl.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/mojo_channel_switches.h"
#include "ipc/attachment_broker.h"
#include "ipc/attachment_broker_unprivileged.h"
#include "ipc/ipc_logging.h"
Expand All @@ -62,6 +63,7 @@
#include "ipc/ipc_sync_channel.h"
#include "ipc/ipc_sync_message_filter.h"
#include "ipc/mojo/ipc_channel_mojo.h"
#include "ipc/mojo/scoped_ipc_support.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/platform_channel_pair.h"

Expand Down Expand Up @@ -360,10 +362,10 @@ void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) {
bool create_pipe_now = true;
if (use_mojo_channel) {
VLOG(1) << "Mojo is enabled on child";
scoped_refptr<base::SequencedTaskRunner> io_task_runner = GetIOTaskRunner();
DCHECK(io_task_runner);
channel_->Init(
IPC::ChannelMojo::CreateClientFactory(io_task_runner, channel_name_),
IPC::ChannelMojo::CreateClientFactory(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kMojoChannelToken)),
create_pipe_now);
return;
}
Expand Down
5 changes: 4 additions & 1 deletion content/public/common/mojo_channel_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ namespace switches {
const char kEnableRendererMojoChannel[] =
"enable-renderer-mojo-channel";

// Disale ChannelMojo usage regardless of the platform or the process type.
// Disable ChannelMojo usage regardless of the platform or the process type.
const char kDisableMojoChannel[] = "disable-mojo-channel";

// The token to use to construct the message pipe on which to layer ChannelMojo.
const char kMojoChannelToken[] = "mojo-channel-token";

} // namespace switches

namespace content {
Expand Down
1 change: 1 addition & 0 deletions content/public/common/mojo_channel_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace switches {

extern const char kEnableRendererMojoChannel[];
extern const char kDisableMojoChannel[];
extern const char kMojoChannelToken[];

} // namespace switches

Expand Down
5 changes: 2 additions & 3 deletions content/test/render_thread_impl_browser_test_ipc_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ void RenderThreadImplBrowserIPCTestHelper::SetupMojo() {
ipc_thread_->task_runner());

channel_ = IPC::ChannelProxy::Create(
IPC::ChannelMojo::CreateServerFactory(ipc_thread_->task_runner(),
channel_id_),
dummy_listener_.get(), ipc_thread_->task_runner());
IPC::ChannelMojo::CreateServerFactory(channel_id_), dummy_listener_.get(),
ipc_thread_->task_runner());

mojo_application_host_->Init();
mojo_application_host_->Activate(channel_.get(),
Expand Down
1 change: 1 addition & 0 deletions ipc/ipc_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class IPC_EXPORT Channel : public Endpoint {
// message from client to server we need to send the PID from the global
// PID namespace.
static void SetGlobalPid(int pid);
static int GetGlobalPid();
#endif

#if defined(OS_ANDROID)
Expand Down
7 changes: 7 additions & 0 deletions ipc/ipc_channel_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ bool ChannelPosix::IsNamedServerInitialized(
void ChannelPosix::SetGlobalPid(int pid) {
global_pid_ = pid;
}
// static
int ChannelPosix::GetGlobalPid() {
return global_pid_;
}
#endif // OS_LINUX

// Called by libevent when we can read from the pipe without blocking.
Expand Down Expand Up @@ -1125,6 +1129,9 @@ bool Channel::IsNamedServerInitialized(
void Channel::SetGlobalPid(int pid) {
ChannelPosix::SetGlobalPid(pid);
}
int Channel::GetGlobalPid() {
return ChannelPosix::GetGlobalPid();
}
#endif // OS_LINUX

} // namespace IPC
1 change: 1 addition & 0 deletions ipc/ipc_channel_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class IPC_EXPORT ChannelPosix : public Channel,
static bool IsNamedServerInitialized(const std::string& channel_id);
#if defined(OS_LINUX)
static void SetGlobalPid(int pid);
static int GetGlobalPid();
#endif // OS_LINUX

private:
Expand Down
9 changes: 7 additions & 2 deletions ipc/ipc_perftest_support.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ class PerformanceChannelListener : public Listener {
scoped_ptr<base::PerfTimeLogger> perf_logger_;
};

IPCChannelPerfTestBase::IPCChannelPerfTestBase() = default;
IPCChannelPerfTestBase::~IPCChannelPerfTestBase() = default;

std::vector<PingPongTestParams>
IPCChannelPerfTestBase::GetDefaultTestParams() {
// Test several sizes. We use 12^N for message size, and limit the message
Expand Down Expand Up @@ -281,14 +284,14 @@ void IPCChannelPerfTestBase::RunTestChannelPingPong(

void IPCChannelPerfTestBase::RunTestChannelProxyPingPong(
const std::vector<PingPongTestParams>& params) {
io_thread_.reset(new base::TestIOThread(base::TestIOThread::kAutoStart));
InitWithCustomMessageLoop("PerformanceClient",
make_scoped_ptr(new base::MessageLoop()));

base::TestIOThread io_thread(base::TestIOThread::kAutoStart);

// Set up IPC channel and start client.
PerformanceChannelListener listener("ChannelProxy");
CreateChannelProxy(&listener, io_thread.task_runner());
CreateChannelProxy(&listener, io_thread_->task_runner());
listener.Init(channel_proxy());
ASSERT_TRUE(StartClient());

Expand Down Expand Up @@ -318,6 +321,8 @@ void IPCChannelPerfTestBase::RunTestChannelProxyPingPong(

EXPECT_TRUE(WaitForClientShutdown());
DestroyChannelProxy();

io_thread_.reset();
}


Expand Down
14 changes: 14 additions & 0 deletions ipc/ipc_perftest_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <vector>

#include "base/macros.h"
#include "base/test/test_io_thread.h"
#include "base/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "ipc/ipc_test_base.h"

Expand All @@ -34,12 +36,24 @@ class PingPongTestParams {

class IPCChannelPerfTestBase : public IPCTestBase {
public:
IPCChannelPerfTestBase();
~IPCChannelPerfTestBase() override;

static std::vector<PingPongTestParams> GetDefaultTestParams();

void RunTestChannelPingPong(
const std::vector<PingPongTestParams>& params_list);
void RunTestChannelProxyPingPong(
const std::vector<PingPongTestParams>& params_list);

scoped_refptr<base::TaskRunner> io_task_runner() {
if (io_thread_)
return io_thread_->task_runner();
return base::ThreadTaskRunnerHandle::Get();
}

private:
scoped_ptr<base::TestIOThread> io_thread_;
};

class PingPongTestClient {
Expand Down
9 changes: 5 additions & 4 deletions ipc/ipc_test_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class IPCTestBase : public base::MultiProcessTest {
// message loop on the main thread. As IPCTestBase creates IO message loop by
// default, such tests need to provide a custom message loop for the main
// thread.
void InitWithCustomMessageLoop(const std::string& test_client_name,
scoped_ptr<base::MessageLoop> message_loop);
virtual void InitWithCustomMessageLoop(
const std::string& test_client_name,
scoped_ptr<base::MessageLoop> message_loop);

// Creates a channel with the given listener and connects to the channel
// (returning true if successful), respectively. Use these to use a channel
Expand Down Expand Up @@ -80,7 +81,7 @@ class IPCTestBase : public base::MultiProcessTest {

// Starts the client process, returning true if successful; this should be
// done after connecting to the channel.
bool StartClient();
virtual bool StartClient();

#if defined(OS_POSIX)
// A StartClient() variant that allows caller to pass the FD of IPC pipe
Expand All @@ -91,7 +92,7 @@ class IPCTestBase : public base::MultiProcessTest {
// this does not initiate client shutdown; that must be done by the test
// (somehow). This must be called before the end of the test whenever
// StartClient() was called successfully.
bool WaitForClientShutdown();
virtual bool WaitForClientShutdown();

IPC::ChannelHandle GetTestChannelHandle();

Expand Down
26 changes: 15 additions & 11 deletions ipc/mojo/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
import("//mojo/public/tools/bindings/mojom.gni")
import("//testing/test.gni")

mojom("client_channel") {
mojom("mojom") {
sources = [
"client_channel.mojom",
"ipc.mojom",
]
}

component("mojo") {
sources = [
"async_handle_waiter.cc",
"async_handle_waiter.h",
"client_channel.mojom",
"ipc_channel_mojo.cc",
"ipc_channel_mojo.h",
"ipc_message_pipe_reader.cc",
Expand All @@ -35,7 +32,7 @@ component("mojo") {
defines = [ "IPC_MOJO_IMPLEMENTATION" ]

deps = [
":client_channel",
":mojom",
"//base",
"//base/third_party/dynamic_annotations",
"//ipc",
Expand All @@ -48,8 +45,6 @@ component("mojo") {

test("ipc_mojo_unittests") {
sources = [
"async_handle_waiter_unittest.cc",

# TODO(rockot): Re-enable these when we're ready to start using ChannelMojo
# again. They need to be updated to support multiprocess testing with the
# current Mojo EDK implementation.
Expand All @@ -59,13 +54,15 @@ test("ipc_mojo_unittests") {
]

deps = [
":mojo",
":mojom",
"//base",
"//base/test:test_support",
"//base/third_party/dynamic_annotations",
"//ipc",
"//ipc:test_support",
"//ipc/mojo",
"//mojo/edk/system",
"//mojo/edk/test:test_support",
"//mojo/environment:chromium",
"//testing/gtest",
"//url",
Expand All @@ -75,18 +72,25 @@ test("ipc_mojo_unittests") {
test("ipc_mojo_perftests") {
sources = [
"ipc_mojo_perftest.cc",
"run_all_perftests.cc",
]

deps = [
":mojo",
":mojom",
"//base",
"//base/test:test_support",
"//base/test:test_support_perf",
"//base/third_party/dynamic_annotations",
"//ipc",
"//ipc:test_support",
"//ipc/mojo",
"//mojo/edk/system",
"//mojo/edk/test:test_support",
"//mojo/edk/test:test_support_impl",
"//mojo/environment:chromium",
"//url",
]

if (is_linux && !is_component_build) {
public_configs = [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
}
}
1 change: 1 addition & 0 deletions ipc/mojo/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+mojo/edk/embedder",
"+mojo/edk/test",
"+mojo/public",
]
Loading

0 comments on commit e4d0abd

Please sign in to comment.