aboutsummaryrefslogtreecommitdiff
path: root/mojo/edk/embedder/named_platform_channel_pair.h
blob: 5a83ae3b85389fe4dfe96aa032eb1e32a485bd48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// 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.

#ifndef MOJO_EDK_EMBEDDER_NAMED_PLATFORM_CHANNEL_PAIR_H_
#define MOJO_EDK_EMBEDDER_NAMED_PLATFORM_CHANNEL_PAIR_H_

#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 {
 public:
  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 named_platform_handle_utils_win.cc.
    base::string16 security_descriptor;
#endif
  };

  NamedPlatformChannelPair(const Options& options = {});
  ~NamedPlatformChannelPair();

  // 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_; }

 private:
  NamedPlatformHandle pipe_handle_;
  ScopedPlatformHandle server_handle_;

  DISALLOW_COPY_AND_ASSIGN(NamedPlatformChannelPair);
};

}  // namespace edk
}  // namespace mojo

#endif  // MOJO_EDK_EMBEDDER_NAMED_PLATFORM_CHANNEL_PAIR_H_