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_PLATFORM_CHANNEL_PAIR_H_ | |
6 #define MOJO_SYSTEM_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 "mojo/system/scoped_platform_handle.h" | |
12 #include "mojo/system/system_impl_export.h" | |
13 | |
14 class CommandLine; | |
15 | |
16 namespace mojo { | |
17 namespace embedder { | |
18 | |
19 // This is used to create a pair of |PlatformHandle|s that are connected by a | |
20 // suitable (platform-specific) bidirectional "pipe" (e.g., socket on POSIX, | |
21 // named pipe on Windows). The resulting handles can then be used in the same | |
22 // process (e.g., in tests) or between processes. (The "server" handle is the | |
23 // one that will be used in the process that created the pair, whereas the | |
24 // "client" handle is the one that will be used in a different process.) | |
25 // | |
26 // This class provides facilities for passing the client handle to a child | |
27 // process. The parent should call |PrepareToPassClientHandlelToChildProcess()| | |
28 // to get the data needed to do this, spawn the child using that data, and then | |
29 // call |ChildProcessLaunched()|. Note that on Windows this facility (will) only | |
30 // work on Vista and later (TODO(vtl)). | |
31 // | |
32 // Note: |PlatformChannelPair()|, |PassClientHandleFromParentProcess()|, | |
33 // |PrepareToPassClientHandleToChildProcess()|, and |ChildProcessLaunched()| | |
34 // have platform-specific implementations. | |
35 class MOJO_SYSTEM_IMPL_EXPORT PlatformChannelPair { | |
36 public: | |
37 PlatformChannelPair(); | |
38 ~PlatformChannelPair(); | |
39 | |
40 ScopedPlatformHandle PassServerHandle(); | |
41 | |
42 // For in-process use (e.g., in tests). | |
43 ScopedPlatformHandle PassClientHandle(); | |
44 | |
45 // To be called in the child process, after the parent process called | |
46 // |PrepareToPassClientHandleToChildProcess()| and launched the child (using | |
47 // the provided data), to create a client handle connected to the server | |
48 // handle (in the parent process). | |
49 static ScopedPlatformHandle PassClientHandleFromParentProcess( | |
50 const CommandLine& command_line); | |
51 | |
52 // Prepares to pass the client channel to a new child process, to be launched | |
53 // using |LaunchProcess()| (from base/launch.h). Modifies |*command_line| and | |
54 // |*file_handle_mapping| as needed. (|file_handle_mapping| may be null on | |
55 // platforms that don't need it, like Windows.) | |
56 void PrepareToPassClientHandleToChildProcess( | |
57 CommandLine* command_line, | |
58 base::FileHandleMappingVector* file_handle_mapping) const; | |
59 // To be called once the child process has been successfully launched, to do | |
60 // any cleanup necessary. | |
61 void ChildProcessLaunched(); | |
62 | |
63 private: | |
64 ScopedPlatformHandle server_handle_; | |
65 ScopedPlatformHandle client_handle_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(PlatformChannelPair); | |
68 }; | |
69 | |
70 } // namespace embedder | |
71 } // namespace mojo | |
72 | |
73 #endif // MOJO_SYSTEM_PLATFORM_CHANNEL_PAIR_H_ | |
OLD | NEW |