summaryrefslogtreecommitdiffstats
path: root/mojo/common
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-10 20:03:16 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-10 20:03:16 +0000
commit37df32bd517577ac6ad20c6d76b236265caeacaf (patch)
treeb200bd548d6d0c02f357e1e583c377f833d3230b /mojo/common
parent84c06f09f036cf76ba2af19ce3b79bb0fa34c517 (diff)
downloadchromium_src-37df32bd517577ac6ad20c6d76b236265caeacaf.zip
chromium_src-37df32bd517577ac6ad20c6d76b236265caeacaf.tar.gz
chromium_src-37df32bd517577ac6ad20c6d76b236265caeacaf.tar.bz2
Mojo: Refactor PlatformChannel stuff.
- Remove PlatformServerChannel/PlatformClientChannel. - Add PlatformChannelPair (move stuff formerly in PlatformServerChannel into this). It became apparent that my previous plan to make this work on Windows wasn't work nicely. On the one hand, on Vista+, we can basically make things work like POSIX (created the channels in the parent and connect them, and send a channel to a child). On the other, on XP, to be secure you need to do more work (the channels aren't connected or authenticated initially), so you'd need much more machinery (to wait for connection, to authenticate, etc.). So I'll go for a different mechanism to make things work on XP. The assumption from the Mojo embedder API will be that it's given a channel handle that's already been connected, authenticated, etc. (which will be taken care of by other means). This will add flexibility in other ways as well (e.g., make Mojo IPC more happily coexist with Chrome IPC -- you should be able to pass a handle over Chrome IPC to set up Mojo IPC). Still to do: Move PlatformChannelPair into its own files. R=darin@chromium.org Review URL: https://codereview.chromium.org/134373005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244223 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/common')
-rw-r--r--mojo/common/test/multiprocess_test_base.cc29
-rw-r--r--mojo/common/test/multiprocess_test_base.h6
-rw-r--r--mojo/common/test/multiprocess_test_base_unittest.cc24
3 files changed, 31 insertions, 28 deletions
diff --git a/mojo/common/test/multiprocess_test_base.cc b/mojo/common/test/multiprocess_test_base.cc
index e637e69..0d3d4ab 100644
--- a/mojo/common/test/multiprocess_test_base.cc
+++ b/mojo/common/test/multiprocess_test_base.cc
@@ -29,21 +29,22 @@ void MultiprocessTestBase::SetUp() {
// TODO(vtl): Not implemented on Windows yet.
#if defined(OS_POSIX)
- platform_server_channel =
- system::PlatformServerChannel::Create("TestChannel");
+ platform_channel_pair_.reset(new system::PlatformChannelPair());
+ server_platform_channel = platform_channel_pair_->CreateServerChannel();
#endif
}
void MultiprocessTestBase::TearDown() {
CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
- platform_server_channel.reset();
+ server_platform_channel.reset();
+ platform_channel_pair_.reset();
MultiProcessTest::TearDown();
}
void MultiprocessTestBase::StartChild(const std::string& test_child_name) {
- CHECK(platform_server_channel.get());
+ CHECK(platform_channel_pair_.get());
CHECK(!test_child_name.empty());
CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
@@ -52,8 +53,8 @@ void MultiprocessTestBase::StartChild(const std::string& test_child_name) {
#if defined(OS_POSIX)
CommandLine unused(CommandLine::NO_PROGRAM);
base::FileHandleMappingVector fds_to_map;
- platform_server_channel->GetDataNeededToPassClientChannelToChildProcess(
- &unused, &fds_to_map);
+ platform_channel_pair_->PrepareToPassClientChannelToChildProcess(&unused,
+ &fds_to_map);
test_child_handle_ = SpawnChild(test_child_main, fds_to_map, false);
#elif defined(OS_WIN)
test_child_handle_ = SpawnChild(test_child_main, false);
@@ -62,7 +63,7 @@ void MultiprocessTestBase::StartChild(const std::string& test_child_name) {
#endif
// TODO(vtl): Not implemented on Windows yet.
#if defined(OS_POSIX)
- platform_server_channel->ChildProcessLaunched();
+ platform_channel_pair_->ChildProcessLaunched();
#endif
CHECK_NE(test_child_handle_, base::kNullProcessHandle);
@@ -82,14 +83,14 @@ int MultiprocessTestBase::WaitForChildShutdown() {
CommandLine MultiprocessTestBase::MakeCmdLine(const std::string& procname,
bool debug_on_start) {
- CHECK(platform_server_channel.get());
+ CHECK(platform_channel_pair_.get());
CommandLine command_line =
base::MultiProcessTest::MakeCmdLine(procname, debug_on_start);
// TODO(vtl): Not implemented on Windows yet.
#if defined(OS_POSIX)
base::FileHandleMappingVector unused;
- platform_server_channel->GetDataNeededToPassClientChannelToChildProcess(
+ platform_channel_pair_->PrepareToPassClientChannelToChildProcess(
&command_line, &unused);
#endif
return command_line;
@@ -100,16 +101,16 @@ void MultiprocessTestBase::ChildSetup() {
CHECK(CommandLine::InitializedForCurrentProcess());
// TODO(vtl): Not implemented on Windows yet.
#if defined(OS_POSIX)
- platform_client_channel =
- system::PlatformClientChannel::CreateFromParentProcess(
+ client_platform_channel =
+ system::PlatformChannelPair::CreateClientChannelFromParentProcess(
*CommandLine::ForCurrentProcess());
- CHECK(platform_client_channel.get());
+ CHECK(client_platform_channel.get());
#endif
}
// static
-scoped_ptr<system::PlatformClientChannel>
- MultiprocessTestBase::platform_client_channel;
+scoped_ptr<system::PlatformChannel>
+ MultiprocessTestBase::client_platform_channel;
} // namespace test
} // namespace mojo
diff --git a/mojo/common/test/multiprocess_test_base.h b/mojo/common/test/multiprocess_test_base.h
index c983df2..9729191 100644
--- a/mojo/common/test/multiprocess_test_base.h
+++ b/mojo/common/test/multiprocess_test_base.h
@@ -40,15 +40,17 @@ class MultiprocessTestBase : public base::MultiProcessTest {
static void ChildSetup();
// For use in the main process:
- scoped_ptr<system::PlatformServerChannel> platform_server_channel;
+ scoped_ptr<system::PlatformChannel> server_platform_channel;
// For use (and only valid) in the child process:
- static scoped_ptr<system::PlatformClientChannel> platform_client_channel;
+ static scoped_ptr<system::PlatformChannel> client_platform_channel;
private:
virtual CommandLine MakeCmdLine(const std::string& procname,
bool debug_on_start) OVERRIDE;
+ scoped_ptr<system::PlatformChannelPair> platform_channel_pair_;
+
// Valid after |StartChild()| and before |WaitForChildShutdown()|.
base::ProcessHandle test_child_handle_;
diff --git a/mojo/common/test/multiprocess_test_base_unittest.cc b/mojo/common/test/multiprocess_test_base_unittest.cc
index 9b315e4..614d7b7 100644
--- a/mojo/common/test/multiprocess_test_base_unittest.cc
+++ b/mojo/common/test/multiprocess_test_base_unittest.cc
@@ -24,8 +24,8 @@ class MultiprocessTestBaseTest : public test::MultiprocessTestBase {
TEST_F(MultiprocessTestBaseTest, RunChild) {
// TODO(vtl): Not implemented on Windows yet.
#if defined(OS_POSIX)
- EXPECT_TRUE(platform_server_channel.get());
- EXPECT_TRUE(platform_server_channel->is_valid());
+ EXPECT_TRUE(server_platform_channel.get());
+ EXPECT_TRUE(server_platform_channel->is_valid());
#endif
StartChild("RunChild");
EXPECT_EQ(123, WaitForChildShutdown());
@@ -34,8 +34,8 @@ TEST_F(MultiprocessTestBaseTest, RunChild) {
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(RunChild) {
// TODO(vtl): Not implemented on Windows yet.
#if defined(OS_POSIX)
- CHECK(MultiprocessTestBaseTest::platform_client_channel.get());
- CHECK(MultiprocessTestBaseTest::platform_client_channel->is_valid());
+ CHECK(MultiprocessTestBaseTest::client_platform_channel.get());
+ CHECK(MultiprocessTestBaseTest::client_platform_channel->is_valid());
#endif
return 123;
}
@@ -50,14 +50,14 @@ TEST_F(MultiprocessTestBaseTest, TestChildMainNotFound) {
#if defined(OS_POSIX)
TEST_F(MultiprocessTestBaseTest, PassedChannelPosix) {
- EXPECT_TRUE(platform_server_channel.get());
- EXPECT_TRUE(platform_server_channel->is_valid());
+ EXPECT_TRUE(server_platform_channel.get());
+ EXPECT_TRUE(server_platform_channel->is_valid());
StartChild("PassedChannelPosix");
// Take ownership of the FD.
mojo::system::PlatformChannelHandle channel =
- platform_server_channel->PassHandle();
- platform_server_channel.reset();
+ server_platform_channel->PassHandle();
+ server_platform_channel.reset();
int fd = channel.fd;
// The FD should be non-blocking. Check this.
@@ -81,13 +81,13 @@ TEST_F(MultiprocessTestBaseTest, PassedChannelPosix) {
}
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PassedChannelPosix) {
- CHECK(MultiprocessTestBaseTest::platform_client_channel.get());
- CHECK(MultiprocessTestBaseTest::platform_client_channel->is_valid());
+ CHECK(MultiprocessTestBaseTest::client_platform_channel.get());
+ CHECK(MultiprocessTestBaseTest::client_platform_channel->is_valid());
// Take ownership of the FD.
mojo::system::PlatformChannelHandle channel =
- MultiprocessTestBaseTest::platform_client_channel->PassHandle();
- MultiprocessTestBaseTest::platform_client_channel.reset();
+ MultiprocessTestBaseTest::client_platform_channel->PassHandle();
+ MultiprocessTestBaseTest::client_platform_channel.reset();
int fd = channel.fd;
// The FD should still be non-blocking. Check this.