diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-10 20:50:18 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-10 20:50:18 +0000 |
commit | 35cfded5c32c6dd14c2e0332caf9eb354416e269 (patch) | |
tree | b001d44a7b732730e78d53127787db3555e4a2d7 /mojo | |
parent | fe260f752a59e0001ed296bbb8c955abf256c1af (diff) | |
download | chromium_src-35cfded5c32c6dd14c2e0332caf9eb354416e269.zip chromium_src-35cfded5c32c6dd14c2e0332caf9eb354416e269.tar.gz chromium_src-35cfded5c32c6dd14c2e0332caf9eb354416e269.tar.bz2 |
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
Diffstat (limited to 'mojo')
-rw-r--r-- | mojo/common/test/multiprocess_test_base.cc | 2 | ||||
-rw-r--r-- | mojo/common/test/multiprocess_test_base.h | 7 | ||||
-rw-r--r-- | mojo/common/test/multiprocess_test_base_unittest.cc | 1 | ||||
-rw-r--r-- | mojo/mojo.gyp | 4 | ||||
-rw-r--r-- | mojo/system/platform_channel.cc | 31 | ||||
-rw-r--r-- | mojo/system/platform_channel.h | 58 | ||||
-rw-r--r-- | mojo/system/platform_channel_pair.cc | 43 | ||||
-rw-r--r-- | mojo/system/platform_channel_pair.h | 77 | ||||
-rw-r--r-- | mojo/system/platform_channel_pair_posix.cc (renamed from mojo/system/platform_channel_posix.cc) | 5 | ||||
-rw-r--r-- | mojo/system/raw_channel_posix_unittest.cc | 1 | ||||
-rw-r--r-- | mojo/system/remote_message_pipe_posix_unittest.cc | 1 |
11 files changed, 138 insertions, 92 deletions
diff --git a/mojo/common/test/multiprocess_test_base.cc b/mojo/common/test/multiprocess_test_base.cc index 0d3d4ab..1ff9d95 100644 --- a/mojo/common/test/multiprocess_test_base.cc +++ b/mojo/common/test/multiprocess_test_base.cc @@ -10,6 +10,8 @@ #include "base/process/process_handle.h" // TODO(vtl): Remove build_config.h include when fully implemented on Windows. #include "build/build_config.h" +#include "mojo/system/platform_channel.h" +#include "mojo/system/platform_channel_pair.h" namespace mojo { namespace test { diff --git a/mojo/common/test/multiprocess_test_base.h b/mojo/common/test/multiprocess_test_base.h index 9729191..d86c61a 100644 --- a/mojo/common/test/multiprocess_test_base.h +++ b/mojo/common/test/multiprocess_test_base.h @@ -11,10 +11,15 @@ #include "base/compiler_specific.h" #include "base/process/process_handle.h" #include "base/test/multiprocess_test.h" -#include "mojo/system/platform_channel.h" #include "testing/multiprocess_func_list.h" namespace mojo { + +namespace system { +class PlatformChannel; +class PlatformChannelPair; +} + namespace test { class MultiprocessTestBase : public base::MultiProcessTest { diff --git a/mojo/common/test/multiprocess_test_base_unittest.cc b/mojo/common/test/multiprocess_test_base_unittest.cc index 614d7b7..e2c1903 100644 --- a/mojo/common/test/multiprocess_test_base_unittest.cc +++ b/mojo/common/test/multiprocess_test_base_unittest.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "build/build_config.h" +#include "mojo/system/platform_channel.h" #include "mojo/system/platform_channel_handle.h" #if defined(OS_POSIX) diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp index a31195d..8255cf0 100644 --- a/mojo/mojo.gyp +++ b/mojo/mojo.gyp @@ -112,7 +112,9 @@ 'system/platform_channel.h', 'system/platform_channel_handle.cc', '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.h', 'system/raw_channel.h', diff --git a/mojo/system/platform_channel.cc b/mojo/system/platform_channel.cc index 9f362f6..159dece 100644 --- a/mojo/system/platform_channel.cc +++ b/mojo/system/platform_channel.cc @@ -32,36 +32,5 @@ PlatformChannelHandle PlatformChannel::PassHandle() { 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 mojo diff --git a/mojo/system/platform_channel.h b/mojo/system/platform_channel.h index 47e1e6a..9c993d5 100644 --- a/mojo/system/platform_channel.h +++ b/mojo/system/platform_channel.h @@ -5,14 +5,11 @@ #ifndef 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/process/launch.h" #include "mojo/system/platform_channel_handle.h" #include "mojo/system/system_impl_export.h" -class CommandLine; - namespace mojo { namespace system { @@ -41,59 +38,6 @@ class MOJO_SYSTEM_IMPL_EXPORT 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 mojo diff --git a/mojo/system/platform_channel_pair.cc b/mojo/system/platform_channel_pair.cc new file mode 100644 index 0000000..cdf27a4 --- /dev/null +++ b/mojo/system/platform_channel_pair.cc @@ -0,0 +1,43 @@ +// 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 diff --git a/mojo/system/platform_channel_pair.h b/mojo/system/platform_channel_pair.h new file mode 100644 index 0000000..215b96e --- /dev/null +++ b/mojo/system/platform_channel_pair.h @@ -0,0 +1,77 @@ +// 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_ diff --git a/mojo/system/platform_channel_posix.cc b/mojo/system/platform_channel_pair_posix.cc index b71428d..f0a072b 100644 --- a/mojo/system/platform_channel_posix.cc +++ b/mojo/system/platform_channel_pair_posix.cc @@ -1,8 +1,8 @@ -// 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 // found in the LICENSE file. -#include "mojo/system/platform_channel.h" +#include "mojo/system/platform_channel_pair.h" #include <fcntl.h> #include <sys/socket.h> @@ -13,6 +13,7 @@ #include "base/logging.h" #include "base/posix/global_descriptors.h" #include "base/strings/string_number_conversions.h" +#include "mojo/system/platform_channel.h" namespace mojo { namespace system { diff --git a/mojo/system/raw_channel_posix_unittest.cc b/mojo/system/raw_channel_posix_unittest.cc index b93ba9a..1564d6d 100644 --- a/mojo/system/raw_channel_posix_unittest.cc +++ b/mojo/system/raw_channel_posix_unittest.cc @@ -33,6 +33,7 @@ #include "mojo/system/message_in_transit.h" #include "mojo/system/platform_channel.h" #include "mojo/system/platform_channel_handle.h" +#include "mojo/system/platform_channel_pair.h" #include "mojo/system/test_utils.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/mojo/system/remote_message_pipe_posix_unittest.cc b/mojo/system/remote_message_pipe_posix_unittest.cc index 758f7f6..94196fe 100644 --- a/mojo/system/remote_message_pipe_posix_unittest.cc +++ b/mojo/system/remote_message_pipe_posix_unittest.cc @@ -19,6 +19,7 @@ #include "mojo/system/local_message_pipe_endpoint.h" #include "mojo/system/message_pipe.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/test_utils.h" #include "mojo/system/waiter.h" |