OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_PAIR_H_ | 5 #ifndef MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_PAIR_H_ |
6 #define MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_PAIR_H_ | 6 #define MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_PAIR_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
8 #include "base/process/launch.h" | 10 #include "base/process/launch.h" |
9 #include "mojo/edk/embedder/scoped_platform_handle.h" | 11 #include "mojo/edk/embedder/scoped_platform_handle.h" |
10 #include "mojo/public/cpp/system/macros.h" | 12 #include "mojo/public/cpp/system/macros.h" |
11 | 13 |
12 namespace base { | |
13 class CommandLine; | |
14 } | |
15 | |
16 namespace mojo { | 14 namespace mojo { |
17 namespace embedder { | 15 namespace embedder { |
18 | 16 |
19 // It would be nice to refactor base/process/launch.h to have a more platform- | 17 // It would be nice to refactor base/process/launch.h to have a more platform- |
20 // independent way of representing handles that are passed to child processes. | 18 // independent way of representing handles that are passed to child processes. |
21 using HandlePassingInformation = base::FileHandleMappingVector; | 19 using HandlePassingInformation = base::FileHandleMappingVector; |
22 | 20 |
23 // This is used to create a pair of |PlatformHandle|s that are connected by a | 21 // This is used to create a pair of |PlatformHandle|s that are connected by a |
24 // suitable (platform-specific) bidirectional "pipe" (e.g., Unix domain socket). | 22 // suitable (platform-specific) bidirectional "pipe" (e.g., Unix domain socket). |
25 // The resulting handles can then be used in the same process (e.g., in tests) | 23 // The resulting handles can then be used in the same process (e.g., in tests) |
(...skipping 20 matching lines...) Expand all Loading... |
46 ~PlatformChannelPair(); | 44 ~PlatformChannelPair(); |
47 | 45 |
48 ScopedPlatformHandle PassServerHandle(); | 46 ScopedPlatformHandle PassServerHandle(); |
49 | 47 |
50 // For in-process use (e.g., in tests or to pass over another channel). | 48 // For in-process use (e.g., in tests or to pass over another channel). |
51 ScopedPlatformHandle PassClientHandle(); | 49 ScopedPlatformHandle PassClientHandle(); |
52 | 50 |
53 // To be called in the child process, after the parent process called | 51 // To be called in the child process, after the parent process called |
54 // |PrepareToPassClientHandleToChildProcess()| and launched the child (using | 52 // |PrepareToPassClientHandleToChildProcess()| and launched the child (using |
55 // the provided data), to create a client handle connected to the server | 53 // the provided data), to create a client handle connected to the server |
56 // handle (in the parent process). | 54 // handle (in the parent process). |string_from_parent| should be the string |
| 55 // that was produced (in the parent process) by |
| 56 // |PrepareToPassClientHandleToChildProcess()|. |
57 static ScopedPlatformHandle PassClientHandleFromParentProcess( | 57 static ScopedPlatformHandle PassClientHandleFromParentProcess( |
58 const base::CommandLine& command_line); | 58 const std::string& string_from_parent); |
59 | 59 |
60 // Prepares to pass the client channel to a new child process, to be launched | 60 // Prepares to pass the client channel to a new child process, to be launched |
61 // using |LaunchProcess()| (from base/launch.h). Modifies |*command_line| and | 61 // using |LaunchProcess()| (from base/launch.h). |*string_for_child| will be |
62 // |*handle_passing_info| as needed. | 62 // set to a string that should be passed to the child process and which should |
| 63 // be given (in the child ) to |PassClientHandleFromParentProcess()|. Also |
| 64 // modifies |*handle_passing_info| as needed. |
63 void PrepareToPassClientHandleToChildProcess( | 65 void PrepareToPassClientHandleToChildProcess( |
64 base::CommandLine* command_line, | 66 std::string* string_for_child, |
65 HandlePassingInformation* handle_passing_info) const; | 67 HandlePassingInformation* handle_passing_info) const; |
66 | 68 |
67 // To be called once the child process has been successfully launched, to do | 69 // To be called once the child process has been successfully launched, to do |
68 // any cleanup necessary. | 70 // any cleanup necessary. |
69 void ChildProcessLaunched(); | 71 void ChildProcessLaunched(); |
70 | 72 |
71 private: | 73 private: |
72 static const char kMojoPlatformChannelHandleSwitch[]; | 74 static const char kMojoPlatformChannelHandleSwitch[]; |
73 | 75 |
74 ScopedPlatformHandle server_handle_; | 76 ScopedPlatformHandle server_handle_; |
75 ScopedPlatformHandle client_handle_; | 77 ScopedPlatformHandle client_handle_; |
76 | 78 |
77 MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformChannelPair); | 79 MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformChannelPair); |
78 }; | 80 }; |
79 | 81 |
80 } // namespace embedder | 82 } // namespace embedder |
81 } // namespace mojo | 83 } // namespace mojo |
82 | 84 |
83 #endif // MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_PAIR_H_ | 85 #endif // MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_PAIR_H_ |
OLD | NEW |