| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/process/process.h" | 15 #include "base/process/process.h" |
| 16 #include "mojo/edk/embedder/scoped_platform_handle.h" | 16 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 17 #include "mojo/edk/system/routed_raw_channel.h" | 17 #include "mojo/edk/system/routed_raw_channel.h" |
| 18 #include "mojo/edk/system/system_impl_export.h" | 18 #include "mojo/edk/system/system_impl_export.h" |
| 19 | 19 |
| 20 namespace mojo { | 20 namespace mojo { |
| 21 namespace edk { | 21 namespace edk { |
| 22 | 22 |
| 23 // Responds to requests from ChildBroker. This is used to handle message pipe | 23 // Responds to requests from ChildBroker. This is used to handle message pipe |
| 24 // multiplexing and Windows sandbox messages. There is one object of this class | 24 // multiplexing and sandbox messages. There is one object of this class |
| 25 // per child process host object. | 25 // per child process host object. |
| 26 // This object will delete itself when it notices that the pipe is broken. | 26 // This object will delete itself when it notices that the pipe is broken. |
| 27 class MOJO_SYSTEM_IMPL_EXPORT ChildBrokerHost | 27 class MOJO_SYSTEM_IMPL_EXPORT ChildBrokerHost |
| 28 : public RawChannel::Delegate | 28 : public RawChannel::Delegate, |
| 29 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
| 30 , NON_EXPORTED_BASE(public base::MessageLoopForIO::IOHandler) { | 30 NON_EXPORTED_BASE(public base::MessageLoopForIO::IOHandler) { |
| 31 #else | 31 #else |
| 32 { | 32 public base::MessageLoopForIO::Watcher { |
| 33 #endif | 33 #endif |
| 34 public: | 34 public: |
| 35 // |child_process| is a handle to the child process. It will be duplicated by | 35 // |child_process| is a handle to the child process. It will be duplicated by |
| 36 // this object. |pipe| is a handle to the communication pipe to the child | 36 // this object. |pipe| is a handle to the communication pipe to the child |
| 37 // process, which is generated inside mojo::edk::ChildProcessLaunched. It is | 37 // process, which is generated inside mojo::edk::ChildProcessLaunched. It is |
| 38 // owned by this class. | 38 // owned by this class. |
| 39 ChildBrokerHost(base::ProcessHandle child_process, ScopedPlatformHandle pipe); | 39 ChildBrokerHost(base::ProcessHandle child_process, ScopedPlatformHandle pipe); |
| 40 | 40 |
| 41 base::ProcessId GetProcessId(); | 41 base::ProcessId GetProcessId(); |
| 42 | 42 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 68 void BeginRead(); | 68 void BeginRead(); |
| 69 | 69 |
| 70 // base::MessageLoopForIO::IOHandler implementation: | 70 // base::MessageLoopForIO::IOHandler implementation: |
| 71 void OnIOCompleted(base::MessageLoopForIO::IOContext* context, | 71 void OnIOCompleted(base::MessageLoopForIO::IOContext* context, |
| 72 DWORD bytes_transferred, | 72 DWORD bytes_transferred, |
| 73 DWORD error) override; | 73 DWORD error) override; |
| 74 | 74 |
| 75 // Helper wrappers around DuplicateHandle. | 75 // Helper wrappers around DuplicateHandle. |
| 76 HANDLE DuplicateToChild(HANDLE handle); | 76 HANDLE DuplicateToChild(HANDLE handle); |
| 77 HANDLE DuplicateFromChild(HANDLE handle); | 77 HANDLE DuplicateFromChild(HANDLE handle); |
| 78 #else |
| 79 void DoRead(); |
| 80 void DoWrite(); |
| 81 |
| 82 // base::MessageLoopForIO::Watcher implementation: |
| 83 void OnFileCanReadWithoutBlocking(int fd) override; |
| 84 void OnFileCanWriteWithoutBlocking(int fd) override; |
| 78 #endif | 85 #endif |
| 79 | 86 |
| 80 base::ProcessId process_id_; | 87 base::ProcessId process_id_; |
| 81 | 88 |
| 82 // Channel used to receive and send multiplexing related messages. | 89 // Channel used to receive and send multiplexing related messages. |
| 83 RoutedRawChannel* child_channel_; | 90 RoutedRawChannel* child_channel_; |
| 84 | 91 |
| 85 #if defined(OS_WIN) | |
| 86 // Handle to the child process, used for duplication of handles. | |
| 87 base::Process child_process_; | |
| 88 | |
| 89 // Pipe used for synchronous messages from the child. Responses are written to | 92 // Pipe used for synchronous messages from the child. Responses are written to |
| 90 // it as well. | 93 // it as well. |
| 91 ScopedPlatformHandle sync_channel_; | 94 ScopedPlatformHandle sync_channel_; |
| 92 | 95 |
| 96 #if defined(OS_WIN) |
| 97 // Handle to the child process, used for duplication of handles. |
| 98 base::Process child_process_; |
| 99 std::vector<char> write_data_; |
| 93 base::MessageLoopForIO::IOContext read_context_; | 100 base::MessageLoopForIO::IOContext read_context_; |
| 94 base::MessageLoopForIO::IOContext write_context_; | 101 base::MessageLoopForIO::IOContext write_context_; |
| 102 #else |
| 103 std::deque<PlatformHandle> write_handles_; |
| 104 base::MessageLoopForIO::FileDescriptorWatcher fd_controller_; |
| 105 #endif |
| 95 | 106 |
| 96 std::vector<char> read_data_; | 107 std::vector<char> read_data_; |
| 97 // How many bytes in read_data_ we already read. | 108 // How many bytes in read_data_ we already read. |
| 98 uint32_t num_bytes_read_; | 109 uint32_t num_bytes_read_; |
| 99 std::vector<char> write_data_; | |
| 100 #endif | |
| 101 | 110 |
| 102 DISALLOW_COPY_AND_ASSIGN(ChildBrokerHost); | 111 DISALLOW_COPY_AND_ASSIGN(ChildBrokerHost); |
| 103 }; | 112 }; |
| 104 | 113 |
| 105 } // namespace edk | 114 } // namespace edk |
| 106 } // namespace mojo | 115 } // namespace mojo |
| 107 | 116 |
| 108 #endif // MOJO_EDK_SYSTEM_CHILD_BROKER_HOST_H_ | 117 #endif // MOJO_EDK_SYSTEM_CHILD_BROKER_HOST_H_ |
| OLD | NEW |