Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_SYSTEM_CHILD_BROKER_HOST_H_ | 5 #ifndef MOJO_EDK_SYSTEM_CHILD_BROKER_HOST_H_ |
| 6 #define MOJO_EDK_SYSTEM_CHILD_BROKER_HOST_H_ | 6 #define MOJO_EDK_SYSTEM_CHILD_BROKER_HOST_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "base/process/process_handle.h" | 13 #include "base/process/process_handle.h" |
| 13 #include "mojo/edk/embedder/scoped_platform_handle.h" | 14 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 15 #include "mojo/edk/system/raw_channel.h" | |
| 14 #include "mojo/edk/system/system_impl_export.h" | 16 #include "mojo/edk/system/system_impl_export.h" |
| 15 | 17 |
| 16 namespace mojo { | 18 namespace mojo { |
| 17 namespace edk { | 19 namespace edk { |
| 18 | 20 |
| 19 // Responds to requests from a child process to exchange handles to tokens and | 21 // Responds to requests from ChildBroker. This is used to handle message pipe |
| 20 // vice versa. There is one object of this class per child process host object. | 22 // multiplexing and Windows sandbox messages. There is one object of this class |
| 23 // per child process host object. | |
| 21 // This object will delete itself when it notices that the pipe is broken. | 24 // This object will delete itself when it notices that the pipe is broken. |
| 22 class MOJO_SYSTEM_IMPL_EXPORT ChildBrokerHost | 25 class MOJO_SYSTEM_IMPL_EXPORT ChildBrokerHost |
| 26 : public RawChannel::Delegate | |
| 23 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 24 : NON_EXPORTED_BASE(public base::MessageLoopForIO::IOHandler) { | 28 , NON_EXPORTED_BASE(public base::MessageLoopForIO::IOHandler) { |
| 25 #else | 29 #else |
| 26 { | 30 { |
| 27 #endif | 31 #endif |
| 28 public: | 32 public: |
| 29 // |child_process| is a handle to the child process. It's not owned by this | 33 // |child_process| is a handle to the child process. It's not owned by this |
| 30 // class but is guaranteed to be alive as long as the child process is | 34 // class but is guaranteed to be alive as long as the child process is |
| 31 // running. |pipe| is a handle to the communication pipe to the child process, | 35 // running. |pipe| is a handle to the communication pipe to the child process, |
| 32 // which is generated inside mojo::edk::ChildProcessLaunched. It is owned by | 36 // which is generated inside mojo::edk::ChildProcessLaunched. It is owned by |
| 33 // this class. | 37 // this class. |
| 34 ChildBrokerHost(base::ProcessHandle child_process, ScopedPlatformHandle pipe); | 38 ChildBrokerHost(base::ProcessHandle child_process, ScopedPlatformHandle pipe); |
| 35 | 39 |
| 40 base::ProcessId GetProcessId(); | |
| 41 | |
| 42 // Sends a message to the child process to connect to |process_id| via |pipe|. | |
| 43 void ConnectToProcess(base::ProcessId process_id, ScopedPlatformHandle pipe); | |
| 44 | |
| 45 // Sends a message to the child process that |pipe_id|'s other end is in | |
| 46 // |process_id|. | |
|
yzshen1
2015/12/03 23:37:50
nit: please update the comment to |peer_id|.
jam
2015/12/04 05:06:47
Done.
| |
| 47 void ConnectMessagePipe(uint64_t pipe_id, base::ProcessId peer_pid); | |
| 48 | |
| 36 private: | 49 private: |
| 50 ~ChildBrokerHost() override; | |
| 51 | |
| 52 // RawChannel::Delegate implementation: | |
| 53 void OnReadMessage( | |
| 54 const MessageInTransit::View& message_view, | |
| 55 ScopedPlatformHandleVectorPtr platform_handles) override; | |
| 56 void OnError(Error error) override; | |
| 57 | |
| 37 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
| 38 ~ChildBrokerHost() override; | |
| 39 #else | |
| 40 ~ChildBrokerHost(); | |
| 41 #endif | |
| 42 | |
| 43 void RegisterIOHandler(); | 59 void RegisterIOHandler(); |
| 44 void BeginRead(); | 60 void BeginRead(); |
| 45 | 61 |
| 46 #if defined(OS_WIN) | 62 // base::MessageLoopForIO::IOHandler implementation: |
| 47 void OnIOCompleted(base::MessageLoopForIO::IOContext* context, | 63 void OnIOCompleted(base::MessageLoopForIO::IOContext* context, |
| 48 DWORD bytes_transferred, | 64 DWORD bytes_transferred, |
| 49 DWORD error) override; | 65 DWORD error) override; |
| 50 | 66 |
| 51 // Helper wrappers around DuplicateHandle. | 67 // Helper wrappers around DuplicateHandle. |
| 52 HANDLE DuplicateToChild(HANDLE handle); | 68 HANDLE DuplicateToChild(HANDLE handle); |
| 53 HANDLE DuplicateFromChild(HANDLE handle); | 69 HANDLE DuplicateFromChild(HANDLE handle); |
| 54 #endif | 70 #endif |
| 55 | 71 |
| 56 base::ProcessHandle child_process_; | 72 base::ProcessId process_id_; |
| 57 ScopedPlatformHandle pipe_; | 73 |
| 74 // Channel used to receive and send multiplexing related messages. | |
| 75 RawChannel* child_channel_; | |
| 58 | 76 |
| 59 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
| 78 // Handle to the child process, used for duplication of handles. | |
| 79 base::ProcessHandle child_process_; | |
| 80 | |
| 81 // Pipe used for synchronous messages from the child. Responses are written to | |
| 82 // it as well. | |
| 83 ScopedPlatformHandle sync_channel_; | |
| 84 | |
| 60 base::MessageLoopForIO::IOContext read_context_; | 85 base::MessageLoopForIO::IOContext read_context_; |
| 61 base::MessageLoopForIO::IOContext write_context_; | 86 base::MessageLoopForIO::IOContext write_context_; |
| 62 #endif | |
| 63 | 87 |
| 64 std::vector<char> read_data_; | 88 std::vector<char> read_data_; |
| 65 // How many bytes in read_data_ we already read. | 89 // How many bytes in read_data_ we already read. |
| 66 uint32_t num_bytes_read_; | 90 uint32_t num_bytes_read_; |
| 67 std::vector<char> write_data_; | 91 std::vector<char> write_data_; |
| 92 #endif | |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(ChildBrokerHost); | |
| 68 }; | 95 }; |
| 69 | 96 |
| 70 } // namespace edk | 97 } // namespace edk |
| 71 } // namespace mojo | 98 } // namespace mojo |
| 72 | 99 |
| 73 #endif // MOJO_EDK_SYSTEM_CHILD_BROKER_HOST_H_ | 100 #endif // MOJO_EDK_SYSTEM_CHILD_BROKER_HOST_H_ |
| OLD | NEW |