Mojo: Move PlatformChannelPair to its own files.

(platform_channel_posix.cc gets moved to platform_channel_pair_posix.cc
entirely.)

R=darin@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244234 0039d316-1c4b-4281-b951-d872f2087c98
parent fe260f75
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "base/process/process_handle.h" #include "base/process/process_handle.h"
// TODO(vtl): Remove build_config.h include when fully implemented on Windows. // TODO(vtl): Remove build_config.h include when fully implemented on Windows.
#include "build/build_config.h" #include "build/build_config.h"
#include "mojo/system/platform_channel.h"
#include "mojo/system/platform_channel_pair.h"
namespace mojo { namespace mojo {
namespace test { namespace test {
......
...@@ -11,10 +11,15 @@ ...@@ -11,10 +11,15 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/process/process_handle.h" #include "base/process/process_handle.h"
#include "base/test/multiprocess_test.h" #include "base/test/multiprocess_test.h"
#include "mojo/system/platform_channel.h"
#include "testing/multiprocess_func_list.h" #include "testing/multiprocess_func_list.h"
namespace mojo { namespace mojo {
namespace system {
class PlatformChannel;
class PlatformChannelPair;
}
namespace test { namespace test {
class MultiprocessTestBase : public base::MultiProcessTest { class MultiprocessTestBase : public base::MultiProcessTest {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "mojo/system/platform_channel.h"
#include "mojo/system/platform_channel_handle.h" #include "mojo/system/platform_channel_handle.h"
#if defined(OS_POSIX) #if defined(OS_POSIX)
......
...@@ -112,7 +112,9 @@ ...@@ -112,7 +112,9 @@
'system/platform_channel.h', 'system/platform_channel.h',
'system/platform_channel_handle.cc', 'system/platform_channel_handle.cc',
'system/platform_channel_handle.h', 'system/platform_channel_handle.h',
'system/platform_channel_posix.cc', 'system/platform_channel_pair.cc',
'system/platform_channel_pair.h',
'system/platform_channel_pair_posix.cc',
'system/proxy_message_pipe_endpoint.cc', 'system/proxy_message_pipe_endpoint.cc',
'system/proxy_message_pipe_endpoint.h', 'system/proxy_message_pipe_endpoint.h',
'system/raw_channel.h', 'system/raw_channel.h',
......
...@@ -32,36 +32,5 @@ PlatformChannelHandle PlatformChannel::PassHandle() { ...@@ -32,36 +32,5 @@ PlatformChannelHandle PlatformChannel::PassHandle() {
PlatformChannel::PlatformChannel() { PlatformChannel::PlatformChannel() {
} }
// -----------------------------------------------------------------------------
PlatformChannelPair::~PlatformChannelPair() {
server_handle_.CloseIfNecessary();
client_handle_.CloseIfNecessary();
}
scoped_ptr<PlatformChannel> PlatformChannelPair::CreateServerChannel() {
if (!server_handle_.is_valid()) {
LOG(WARNING) << "Server handle invalid";
return scoped_ptr<PlatformChannel>();
}
scoped_ptr<PlatformChannel> rv =
PlatformChannel::CreateFromHandle(server_handle_);
server_handle_ = PlatformChannelHandle();
return rv.Pass();
}
scoped_ptr<PlatformChannel> PlatformChannelPair::CreateClientChannel() {
if (!client_handle_.is_valid()) {
LOG(WARNING) << "Client handle invalid";
return scoped_ptr<PlatformChannel>();
}
scoped_ptr<PlatformChannel> rv =
PlatformChannel::CreateFromHandle(client_handle_);
client_handle_ = PlatformChannelHandle();
return rv.Pass();
}
} // namespace system } // namespace system
} // namespace mojo } // namespace mojo
...@@ -5,14 +5,11 @@ ...@@ -5,14 +5,11 @@
#ifndef MOJO_SYSTEM_PLATFORM_CHANNEL_H_ #ifndef MOJO_SYSTEM_PLATFORM_CHANNEL_H_
#define MOJO_SYSTEM_PLATFORM_CHANNEL_H_ #define MOJO_SYSTEM_PLATFORM_CHANNEL_H_
#include "base/basictypes.h" #include "base/macros.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/process/launch.h"
#include "mojo/system/platform_channel_handle.h" #include "mojo/system/platform_channel_handle.h"
#include "mojo/system/system_impl_export.h" #include "mojo/system/system_impl_export.h"
class CommandLine;
namespace mojo { namespace mojo {
namespace system { namespace system {
...@@ -41,59 +38,6 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformChannel { ...@@ -41,59 +38,6 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformChannel {
DISALLOW_COPY_AND_ASSIGN(PlatformChannel); DISALLOW_COPY_AND_ASSIGN(PlatformChannel);
}; };
// This is used to create a pair of connected |PlatformChannel|s. The resulting
// channels can then be used in the same process (e.g., in tests) or between
// processes. (The "server" channel is the one that will be used in the process
// that created the pair, whereas the "client" channel is the one that will be
// used in a different process.)
//
// This class provides facilities for passing the client channel to a child
// process. The parent should call |PrepareToPassClientChannelToChildProcess()|
// to get the data needed to do this, spawn the child using that data, and then
// call |ChildProcessLaunched()|. Note that on Windows this facility (will) only
// work on Vista and later (TODO(vtl)).
//
// Note: |PlatformChannelPair()|, |CreateClientChannelFromParentProcess()|,
// |PrepareToPassClientChannelToChildProcess()|, and |ChildProcessLaunched()|
// have platform-specific implementations.
class MOJO_SYSTEM_IMPL_EXPORT PlatformChannelPair {
public:
PlatformChannelPair();
~PlatformChannelPair();
// This transfers ownership of the server channel to the caller. Returns null
// on failure.
scoped_ptr<PlatformChannel> CreateServerChannel();
// For in-process use (e.g., in tests). This transfers ownership of the client
// channel to the caller. Returns null on failure.
scoped_ptr<PlatformChannel> CreateClientChannel();
// To be called in the child process, after the parent process called
// |PrepareToPassClientChannelToChildProcess()| and launched the child (using
// the provided data), to create a client channel connected to the server
// channel (in the parent process). Returns null on failure.
static scoped_ptr<PlatformChannel> CreateClientChannelFromParentProcess(
const CommandLine& command_line);
// Prepares to pass the client channel to a new child process, to be launched
// using |LaunchProcess()| (from base/launch.h). Modifies |*command_line| and
// |*file_handle_mapping| as needed. (|file_handle_mapping| may be null on
// platforms that don't need it, like Windows.)
void PrepareToPassClientChannelToChildProcess(
CommandLine* command_line,
base::FileHandleMappingVector* file_handle_mapping) const;
// To be called once the child process has been successfully launched, to do
// any cleanup necessary.
void ChildProcessLaunched();
private:
PlatformChannelHandle server_handle_;
PlatformChannelHandle client_handle_;
DISALLOW_COPY_AND_ASSIGN(PlatformChannelPair);
};
} // namespace system } // namespace system
} // namespace mojo } // namespace mojo
......
// 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 "mojo/system/platform_channel_pair.h"
#include "base/logging.h"
#include "mojo/system/platform_channel.h"
namespace mojo {
namespace system {
PlatformChannelPair::~PlatformChannelPair() {
server_handle_.CloseIfNecessary();
client_handle_.CloseIfNecessary();
}
scoped_ptr<PlatformChannel> PlatformChannelPair::CreateServerChannel() {
if (!server_handle_.is_valid()) {
LOG(WARNING) << "Server handle invalid";
return scoped_ptr<PlatformChannel>();
}
scoped_ptr<PlatformChannel> rv =
PlatformChannel::CreateFromHandle(server_handle_);
server_handle_ = PlatformChannelHandle();
return rv.Pass();
}
scoped_ptr<PlatformChannel> PlatformChannelPair::CreateClientChannel() {
if (!client_handle_.is_valid()) {
LOG(WARNING) << "Client handle invalid";
return scoped_ptr<PlatformChannel>();
}
scoped_ptr<PlatformChannel> rv =
PlatformChannel::CreateFromHandle(client_handle_);
client_handle_ = PlatformChannelHandle();
return rv.Pass();
}
} // namespace system
} // namespace mojo
// 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.
#ifndef MOJO_SYSTEM_PLATFORM_CHANNEL_PAIR_H_
#define MOJO_SYSTEM_PLATFORM_CHANNEL_PAIR_H_
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/process/launch.h"
#include "mojo/system/platform_channel_handle.h"
#include "mojo/system/system_impl_export.h"
class CommandLine;
namespace mojo {
namespace system {
class PlatformChannel;
// This is used to create a pair of connected |PlatformChannel|s. The resulting
// channels can then be used in the same process (e.g., in tests) or between
// processes. (The "server" channel is the one that will be used in the process
// that created the pair, whereas the "client" channel is the one that will be
// used in a different process.)
//
// This class provides facilities for passing the client channel to a child
// process. The parent should call |PrepareToPassClientChannelToChildProcess()|
// to get the data needed to do this, spawn the child using that data, and then
// call |ChildProcessLaunched()|. Note that on Windows this facility (will) only
// work on Vista and later (TODO(vtl)).
//
// Note: |PlatformChannelPair()|, |CreateClientChannelFromParentProcess()|,
// |PrepareToPassClientChannelToChildProcess()|, and |ChildProcessLaunched()|
// have platform-specific implementations.
class MOJO_SYSTEM_IMPL_EXPORT PlatformChannelPair {
public:
PlatformChannelPair();
~PlatformChannelPair();
// This transfers ownership of the server channel to the caller. Returns null
// on failure.
scoped_ptr<PlatformChannel> CreateServerChannel();
// For in-process use (e.g., in tests). This transfers ownership of the client
// channel to the caller. Returns null on failure.
scoped_ptr<PlatformChannel> CreateClientChannel();
// To be called in the child process, after the parent process called
// |PrepareToPassClientChannelToChildProcess()| and launched the child (using
// the provided data), to create a client channel connected to the server
// channel (in the parent process). Returns null on failure.
static scoped_ptr<PlatformChannel> CreateClientChannelFromParentProcess(
const CommandLine& command_line);
// Prepares to pass the client channel to a new child process, to be launched
// using |LaunchProcess()| (from base/launch.h). Modifies |*command_line| and
// |*file_handle_mapping| as needed. (|file_handle_mapping| may be null on
// platforms that don't need it, like Windows.)
void PrepareToPassClientChannelToChildProcess(
CommandLine* command_line,
base::FileHandleMappingVector* file_handle_mapping) const;
// To be called once the child process has been successfully launched, to do
// any cleanup necessary.
void ChildProcessLaunched();
private:
PlatformChannelHandle server_handle_;
PlatformChannelHandle client_handle_;
DISALLOW_COPY_AND_ASSIGN(PlatformChannelPair);
};
} // namespace system
} // namespace mojo
#endif // MOJO_SYSTEM_PLATFORM_CHANNEL_PAIR_H_
// Copyright 2013 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "mojo/system/platform_channel.h" #include "mojo/system/platform_channel_pair.h"
#include <fcntl.h> #include <fcntl.h>
#include <sys/socket.h> #include <sys/socket.h>
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/posix/global_descriptors.h" #include "base/posix/global_descriptors.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "mojo/system/platform_channel.h"
namespace mojo { namespace mojo {
namespace system { namespace system {
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "mojo/system/message_in_transit.h" #include "mojo/system/message_in_transit.h"
#include "mojo/system/platform_channel.h" #include "mojo/system/platform_channel.h"
#include "mojo/system/platform_channel_handle.h" #include "mojo/system/platform_channel_handle.h"
#include "mojo/system/platform_channel_pair.h"
#include "mojo/system/test_utils.h" #include "mojo/system/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "mojo/system/local_message_pipe_endpoint.h" #include "mojo/system/local_message_pipe_endpoint.h"
#include "mojo/system/message_pipe.h" #include "mojo/system/message_pipe.h"
#include "mojo/system/platform_channel.h" #include "mojo/system/platform_channel.h"
#include "mojo/system/platform_channel_pair.h"
#include "mojo/system/proxy_message_pipe_endpoint.h" #include "mojo/system/proxy_message_pipe_endpoint.h"
#include "mojo/system/test_utils.h" #include "mojo/system/test_utils.h"
#include "mojo/system/waiter.h" #include "mojo/system/waiter.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment