OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MOJO_SYSTEM_EMBEDDER_PLATFORM_CHANNEL_PAIR_H_ | |
6 #define MOJO_SYSTEM_EMBEDDER_PLATFORM_CHANNEL_PAIR_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/process/launch.h" | |
11 #include "build/build_config.h" | |
12 #include "mojo/system/embedder/scoped_platform_handle.h" | |
13 #include "mojo/system/system_impl_export.h" | |
14 | |
15 namespace base { | |
16 class CommandLine; | |
17 } | |
18 | |
19 namespace mojo { | |
20 namespace embedder { | |
21 | |
22 // It would be nice to refactor base/process/launch.h to have a more platform- | |
23 // independent way of representing handles that are passed to child processes. | |
24 #if defined(OS_WIN) | |
25 typedef base::HandlesToInheritVector HandlePassingInformation; | |
26 #elif defined(OS_POSIX) | |
27 typedef base::FileHandleMappingVector HandlePassingInformation; | |
28 #else | |
29 #error "Unsupported." | |
30 #endif | |
31 | |
32 // This is used to create a pair of |PlatformHandle|s that are connected by a | |
33 // suitable (platform-specific) bidirectional "pipe" (e.g., socket on POSIX, | |
34 // named pipe on Windows). The resulting handles can then be used in the same | |
35 // process (e.g., in tests) or between processes. (The "server" handle is the | |
36 // one that will be used in the process that created the pair, whereas the | |
37 // "client" handle is the one that will be used in a different process.) | |
38 // | |
39 // This class provides facilities for passing the client handle to a child | |
40 // process. The parent should call |PrepareToPassClientHandlelToChildProcess()| | |
41 // to get the data needed to do this, spawn the child using that data, and then | |
42 // call |ChildProcessLaunched()|. Note that on Windows this facility (will) only | |
43 // work on Vista and later (TODO(vtl)). | |
44 // | |
45 // Note: |PlatformChannelPair()|, |PassClientHandleFromParentProcess()| and | |
46 // |PrepareToPassClientHandleToChildProcess()| have platform-specific | |
47 // implementations. | |
48 class MOJO_SYSTEM_IMPL_EXPORT PlatformChannelPair { | |
49 public: | |
50 PlatformChannelPair(); | |
51 ~PlatformChannelPair(); | |
52 | |
53 ScopedPlatformHandle PassServerHandle(); | |
54 | |
55 // For in-process use (e.g., in tests or to pass over another channel). | |
56 ScopedPlatformHandle PassClientHandle(); | |
57 | |
58 // To be called in the child process, after the parent process called | |
59 // |PrepareToPassClientHandleToChildProcess()| and launched the child (using | |
60 // the provided data), to create a client handle connected to the server | |
61 // handle (in the parent process). | |
62 static ScopedPlatformHandle PassClientHandleFromParentProcess( | |
63 const base::CommandLine& command_line); | |
64 | |
65 // Prepares to pass the client channel to a new child process, to be launched | |
66 // using |LaunchProcess()| (from base/launch.h). Modifies |*command_line| and | |
67 // |*handle_passing_info| as needed. | |
68 // Note: For Windows, this method only works on Vista and later. | |
69 void PrepareToPassClientHandleToChildProcess( | |
70 base::CommandLine* command_line, | |
71 HandlePassingInformation* handle_passing_info) const; | |
72 | |
73 // To be called once the child process has been successfully launched, to do | |
74 // any cleanup necessary. | |
75 void ChildProcessLaunched(); | |
76 | |
77 private: | |
78 static const char kMojoPlatformChannelHandleSwitch[]; | |
79 | |
80 ScopedPlatformHandle server_handle_; | |
81 ScopedPlatformHandle client_handle_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(PlatformChannelPair); | |
84 }; | |
85 | |
86 } // namespace embedder | |
87 } // namespace mojo | |
88 | |
89 #endif // MOJO_SYSTEM_EMBEDDER_PLATFORM_CHANNEL_PAIR_H_ | |
OLD | NEW |