| 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> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/process/launch.h" | 10 #include "base/process/launch.h" |
| 11 #include "mojo/edk/embedder/scoped_platform_handle.h" | 11 #include "mojo/edk/platform/scoped_platform_handle.h" |
| 12 #include "mojo/public/cpp/system/macros.h" | 12 #include "mojo/public/cpp/system/macros.h" |
| 13 | 13 |
| 14 namespace mojo { | 14 namespace mojo { |
| 15 namespace embedder { | 15 namespace embedder { |
| 16 | 16 |
| 17 // 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- |
| 18 // independent way of representing handles that are passed to child processes. | 18 // independent way of representing handles that are passed to child processes. |
| 19 using HandlePassingInformation = base::FileHandleMappingVector; | 19 using HandlePassingInformation = base::FileHandleMappingVector; |
| 20 | 20 |
| 21 // 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 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 36 // | 36 // |
| 37 // Note: On POSIX platforms, to write to the "pipe", use | 37 // Note: On POSIX platforms, to write to the "pipe", use |
| 38 // |PlatformChannel{Write,Writev}()| (from platform_channel_utils.h) instead of | 38 // |PlatformChannel{Write,Writev}()| (from platform_channel_utils.h) instead of |
| 39 // |write()|, |writev()|, etc. Otherwise, you have to worry about platform | 39 // |write()|, |writev()|, etc. Otherwise, you have to worry about platform |
| 40 // differences in suppressing |SIGPIPE|. | 40 // differences in suppressing |SIGPIPE|. |
| 41 class PlatformChannelPair { | 41 class PlatformChannelPair { |
| 42 public: | 42 public: |
| 43 PlatformChannelPair(); | 43 PlatformChannelPair(); |
| 44 ~PlatformChannelPair(); | 44 ~PlatformChannelPair(); |
| 45 | 45 |
| 46 ScopedPlatformHandle PassServerHandle(); | 46 platform::ScopedPlatformHandle PassServerHandle(); |
| 47 | 47 |
| 48 // 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). |
| 49 ScopedPlatformHandle PassClientHandle(); | 49 platform::ScopedPlatformHandle PassClientHandle(); |
| 50 | 50 |
| 51 // 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 |
| 52 // |PrepareToPassClientHandleToChildProcess()| and launched the child (using | 52 // |PrepareToPassClientHandleToChildProcess()| and launched the child (using |
| 53 // 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 |
| 54 // handle (in the parent process). |string_from_parent| should be the string | 54 // handle (in the parent process). |string_from_parent| should be the string |
| 55 // that was produced (in the parent process) by | 55 // that was produced (in the parent process) by |
| 56 // |PrepareToPassClientHandleToChildProcess()|. | 56 // |PrepareToPassClientHandleToChildProcess()|. |
| 57 static ScopedPlatformHandle PassClientHandleFromParentProcess( | 57 static platform::ScopedPlatformHandle PassClientHandleFromParentProcess( |
| 58 const std::string& string_from_parent); | 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). |*string_for_child| will be | 61 // using |LaunchProcess()| (from base/launch.h). |*string_for_child| will be |
| 62 // set to a string that should be passed to the child process and which should | 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 | 63 // be given (in the child ) to |PassClientHandleFromParentProcess()|. Also |
| 64 // modifies |*handle_passing_info| as needed. | 64 // modifies |*handle_passing_info| as needed. |
| 65 void PrepareToPassClientHandleToChildProcess( | 65 void PrepareToPassClientHandleToChildProcess( |
| 66 std::string* string_for_child, | 66 std::string* string_for_child, |
| 67 HandlePassingInformation* handle_passing_info) const; | 67 HandlePassingInformation* handle_passing_info) const; |
| 68 | 68 |
| 69 // 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 |
| 70 // any cleanup necessary. | 70 // any cleanup necessary. |
| 71 void ChildProcessLaunched(); | 71 void ChildProcessLaunched(); |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 static const char kMojoPlatformChannelHandleSwitch[]; | 74 static const char kMojoPlatformChannelHandleSwitch[]; |
| 75 | 75 |
| 76 ScopedPlatformHandle server_handle_; | 76 platform::ScopedPlatformHandle server_handle_; |
| 77 ScopedPlatformHandle client_handle_; | 77 platform::ScopedPlatformHandle client_handle_; |
| 78 | 78 |
| 79 MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformChannelPair); | 79 MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformChannelPair); |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 } // namespace embedder | 82 } // namespace embedder |
| 83 } // namespace mojo | 83 } // namespace mojo |
| 84 | 84 |
| 85 #endif // MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_PAIR_H_ | 85 #endif // MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_PAIR_H_ |
| OLD | NEW |