blob: 5a83ae3b85389fe4dfe96aa032eb1e32a485bd48 [file] [log] [blame]
// Copyright 2016 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 <string>
#include "base/macros.h"
#include "base/strings/string16.h"
#include "build/build_config.h"
#include "mojo/edk/embedder/named_platform_handle.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/edk/system/system_impl_export.h"
namespace base {
class CommandLine;
namespace mojo {
namespace edk {
// This is used to create a named bidirectional pipe to connect new child
// processes. The resulting server handle should be passed to the EDK, and the
// child end passed as a pipe name on the command line to the child process. The
// child process can then retrieve the pipe name from the command line and
// resolve it into a client handle.
class MOJO_SYSTEM_IMPL_EXPORT NamedPlatformChannelPair {
struct Options {
#if defined(OS_WIN)
// If non-empty, a security descriptor to use when creating the pipe. If
// empty, a default security descriptor will be used. See
// kDefaultSecurityDescriptor in
base::string16 security_descriptor;
NamedPlatformChannelPair(const Options& options = {});
// Note: It is NOT acceptable to use this handle as a generic pipe channel. It
// MUST be passed to PendingProcessConnection::Connect() only.
ScopedPlatformHandle PassServerHandle();
// To be called in the child process, after the parent process called
// |PrepareToPassClientHandleToChildProcess()| and launched the child (using
// the provided data), to create a client handle connected to the server
// handle (in the parent process).
static ScopedPlatformHandle PassClientHandleFromParentProcess(
const base::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
// |*handle_passing_info| as needed.
// Note: For Windows, this method only works on Vista and later.
void PrepareToPassClientHandleToChildProcess(
base::CommandLine* command_line) const;
const NamedPlatformHandle& handle() const { return pipe_handle_; }
NamedPlatformHandle pipe_handle_;
ScopedPlatformHandle server_handle_;
} // namespace edk
} // namespace mojo