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 sandbox messages. There is one object of this class | 24 // multiplexing and Windows 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 public base::MessageLoopForIO::Watcher { | 32 { |
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 29 matching lines...) Expand all Loading... |
72 void BeginRead(); | 72 void BeginRead(); |
73 | 73 |
74 // base::MessageLoopForIO::IOHandler implementation: | 74 // base::MessageLoopForIO::IOHandler implementation: |
75 void OnIOCompleted(base::MessageLoopForIO::IOContext* context, | 75 void OnIOCompleted(base::MessageLoopForIO::IOContext* context, |
76 DWORD bytes_transferred, | 76 DWORD bytes_transferred, |
77 DWORD error) override; | 77 DWORD error) override; |
78 | 78 |
79 // Helper wrappers around DuplicateHandle. | 79 // Helper wrappers around DuplicateHandle. |
80 HANDLE DuplicateToChild(HANDLE handle); | 80 HANDLE DuplicateToChild(HANDLE handle); |
81 HANDLE DuplicateFromChild(HANDLE handle); | 81 HANDLE DuplicateFromChild(HANDLE handle); |
82 #else | |
83 // Reads all currently available data, and responds to any completed messages. | |
84 void TryReadAndWriteHandles(); | |
85 | |
86 // base::MessageLoopForIO::Watcher implementation: | |
87 void OnFileCanReadWithoutBlocking(int fd) override; | |
88 void OnFileCanWriteWithoutBlocking(int fd) override; | |
89 #endif | 82 #endif |
90 | 83 |
91 base::ProcessId process_id_; | 84 base::ProcessId process_id_; |
92 | 85 |
93 // Channel used to receive and send multiplexing related messages. | 86 // Channel used to receive and send multiplexing related messages. |
94 RoutedRawChannel* child_channel_; | 87 RoutedRawChannel* child_channel_; |
95 | 88 |
| 89 #if defined(OS_WIN) |
| 90 // Handle to the child process, used for duplication of handles. |
| 91 base::Process child_process_; |
| 92 |
96 // Pipe used for synchronous messages from the child. Responses are written to | 93 // Pipe used for synchronous messages from the child. Responses are written to |
97 // it as well. | 94 // it as well. |
98 ScopedPlatformHandle sync_channel_; | 95 ScopedPlatformHandle sync_channel_; |
99 | 96 |
100 #if defined(OS_WIN) | |
101 // Handle to the child process, used for duplication of handles. | |
102 base::Process child_process_; | |
103 std::vector<char> write_data_; | |
104 base::MessageLoopForIO::IOContext read_context_; | 97 base::MessageLoopForIO::IOContext read_context_; |
105 base::MessageLoopForIO::IOContext write_context_; | 98 base::MessageLoopForIO::IOContext write_context_; |
106 #else | |
107 std::deque<PlatformHandle> write_handles_; | |
108 base::MessageLoopForIO::FileDescriptorWatcher fd_controller_; | |
109 #endif | |
110 | 99 |
111 std::vector<char> read_data_; | 100 std::vector<char> read_data_; |
112 // How many bytes in read_data_ we already read. | 101 // How many bytes in read_data_ we already read. |
113 uint32_t num_bytes_read_; | 102 uint32_t num_bytes_read_; |
| 103 std::vector<char> write_data_; |
| 104 #endif |
114 | 105 |
115 DISALLOW_COPY_AND_ASSIGN(ChildBrokerHost); | 106 DISALLOW_COPY_AND_ASSIGN(ChildBrokerHost); |
116 }; | 107 }; |
117 | 108 |
118 } // namespace edk | 109 } // namespace edk |
119 } // namespace mojo | 110 } // namespace mojo |
120 | 111 |
121 #endif // MOJO_EDK_SYSTEM_CHILD_BROKER_HOST_H_ | 112 #endif // MOJO_EDK_SYSTEM_CHILD_BROKER_HOST_H_ |
OLD | NEW |