1cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli// Copyright 2016 The Chromium Authors. All rights reserved.
2cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli// Use of this source code is governed by a BSD-style license that can be
3cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli// found in the LICENSE file.
4cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
5cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli#ifndef MOJO_EDK_EMBEDDER_NAMED_PLATFORM_CHANNEL_PAIR_H_
6cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli#define MOJO_EDK_EMBEDDER_NAMED_PLATFORM_CHANNEL_PAIR_H_
7cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
8cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli#include <string>
9cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
10cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli#include "base/macros.h"
11cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli#include "base/strings/string16.h"
12cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli#include "build/build_config.h"
13cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli#include "mojo/edk/embedder/named_platform_handle.h"
14cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli#include "mojo/edk/embedder/scoped_platform_handle.h"
15cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli#include "mojo/edk/system/system_impl_export.h"
16cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
17cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civellinamespace base {
18cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelliclass CommandLine;
19cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli}
20cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
21cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civellinamespace mojo {
22cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civellinamespace edk {
23cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
24cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli// This is used to create a named bidirectional pipe to connect new child
25cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli// processes. The resulting server handle should be passed to the EDK, and the
26cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli// child end passed as a pipe name on the command line to the child process. The
27cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli// child process can then retrieve the pipe name from the command line and
28cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli// resolve it into a client handle.
29cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelliclass MOJO_SYSTEM_IMPL_EXPORT NamedPlatformChannelPair {
30cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli public:
31cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  struct Options {
32cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli#if defined(OS_WIN)
33cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli    // If non-empty, a security descriptor to use when creating the pipe. If
34cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli    // empty, a default security descriptor will be used. See
35cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli    // kDefaultSecurityDescriptor in named_platform_handle_utils_win.cc.
36cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli    base::string16 security_descriptor;
37cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli#endif
38cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  };
39cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
40cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  NamedPlatformChannelPair(const Options& options = {});
41cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  ~NamedPlatformChannelPair();
42cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
43cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  // Note: It is NOT acceptable to use this handle as a generic pipe channel. It
44cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  // MUST be passed to PendingProcessConnection::Connect() only.
45cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  ScopedPlatformHandle PassServerHandle();
46cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
47cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  // To be called in the child process, after the parent process called
48cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  // |PrepareToPassClientHandleToChildProcess()| and launched the child (using
49cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  // the provided data), to create a client handle connected to the server
50cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  // handle (in the parent process).
51cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  static ScopedPlatformHandle PassClientHandleFromParentProcess(
52cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli      const base::CommandLine& command_line);
53cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
54cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  // Prepares to pass the client channel to a new child process, to be launched
55cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  // using |LaunchProcess()| (from base/launch.h). Modifies |*command_line| and
56cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  // |*handle_passing_info| as needed.
57cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  // Note: For Windows, this method only works on Vista and later.
58cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  void PrepareToPassClientHandleToChildProcess(
59cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli      base::CommandLine* command_line) const;
60cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
61cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  const NamedPlatformHandle& handle() const { return pipe_handle_; }
62cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
63cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli private:
64cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  NamedPlatformHandle pipe_handle_;
65cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  ScopedPlatformHandle server_handle_;
66cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
67cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli  DISALLOW_COPY_AND_ASSIGN(NamedPlatformChannelPair);
68cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli};
69cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
70cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli}  // namespace edk
71cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli}  // namespace mojo
72cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli
73cfc1eaa913db3974e56c87b5489bda0a2bf36d93Jay Civelli#endif  // MOJO_EDK_EMBEDDER_NAMED_PLATFORM_CHANNEL_PAIR_H_
74