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_MESSAGE_PIPE_DISPATCHER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ |
6 #define MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ | 6 #define MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "mojo/edk/embedder/platform_channel_pair.h" | 9 #include "mojo/edk/embedder/platform_channel_pair.h" |
10 #include "mojo/edk/system/awakable_list.h" | 10 #include "mojo/edk/system/awakable_list.h" |
11 #include "mojo/edk/system/dispatcher.h" | 11 #include "mojo/edk/system/dispatcher.h" |
12 #include "mojo/edk/system/message_in_transit_queue.h" | 12 #include "mojo/edk/system/message_in_transit_queue.h" |
13 #include "mojo/edk/system/raw_channel.h" | 13 #include "mojo/edk/system/raw_channel.h" |
14 #include "mojo/edk/system/system_impl_export.h" | 14 #include "mojo/edk/system/system_impl_export.h" |
15 #include "mojo/public/cpp/system/macros.h" | 15 #include "mojo/public/cpp/system/macros.h" |
16 | 16 |
| 17 namespace base { |
| 18 namespace debug { |
| 19 class StackTrace; |
| 20 } |
| 21 } |
| 22 |
17 namespace mojo { | 23 namespace mojo { |
18 namespace edk { | 24 namespace edk { |
19 | 25 |
20 // This is the |Dispatcher| implementation for message pipes (created by the | 26 // This is the |Dispatcher| implementation for message pipes (created by the |
21 // Mojo primitive |MojoCreateMessagePipe()|). This class is thread-safe. | 27 // Mojo primitive |MojoCreateMessagePipe()|). This class is thread-safe. |
22 class MOJO_SYSTEM_IMPL_EXPORT MessagePipeDispatcher final | 28 class MOJO_SYSTEM_IMPL_EXPORT MessagePipeDispatcher final |
23 : public Dispatcher, public RawChannel::Delegate { | 29 : public Dispatcher, public RawChannel::Delegate { |
24 public: | 30 public: |
25 // The default options to use for |MojoCreateMessagePipe()|. (Real uses | 31 // The default options to use for |MojoCreateMessagePipe()|. (Real uses |
26 // should obtain this via |ValidateCreateOptions()| with a null |in_options|; | 32 // should obtain this via |ValidateCreateOptions()| with a null |in_options|; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // "binds" the pipe id to this object. | 140 // "binds" the pipe id to this object. |
135 void RequestNontransferableChannel(); | 141 void RequestNontransferableChannel(); |
136 | 142 |
137 // Protected by |lock()|: | 143 // Protected by |lock()|: |
138 RawChannel* channel_; | 144 RawChannel* channel_; |
139 | 145 |
140 // Queue of incoming messages that we read from RawChannel but haven't been | 146 // Queue of incoming messages that we read from RawChannel but haven't been |
141 // consumed through MojoReadMessage yet. | 147 // consumed through MojoReadMessage yet. |
142 MessageInTransitQueue message_queue_; | 148 MessageInTransitQueue message_queue_; |
143 | 149 |
144 // The following members are only used when transferable_ is false; | 150 // The following members are only used when transferable_ is true; |
145 | 151 |
146 // When sending MP, contains serialized message_queue_. | 152 // When sending MP, contains serialized message_queue_. |
147 std::vector<char> serialized_message_queue_; | 153 std::vector<char> serialized_message_queue_; |
148 std::vector<char> serialized_read_buffer_; | 154 std::vector<char> serialized_read_buffer_; |
149 std::vector<char> serialized_write_buffer_; | 155 std::vector<char> serialized_write_buffer_; |
150 // Contains FDs from (in this order): the read buffer, the write buffer, and | 156 // Contains FDs from (in this order): the read buffer, the write buffer, and |
151 // message queue. | 157 // message queue. |
152 std::vector<int> serialized_fds_; | 158 std::vector<int> serialized_fds_; |
153 size_t serialized_read_fds_length_; | 159 size_t serialized_read_fds_length_; |
154 size_t serialized_write_fds_length_; | 160 size_t serialized_write_fds_length_; |
155 size_t serialized_message_fds_length_; | 161 size_t serialized_message_fds_length_; |
156 ScopedPlatformHandle serialized_platform_handle_; | 162 ScopedPlatformHandle serialized_platform_handle_; |
157 | 163 |
158 // The following members are only used when transferable_ is true; | 164 // The following members are only used when transferable_ is false; |
159 | 165 |
160 // The unique id shared by both ends of a non-transferable message pipe. This | 166 // The unique id shared by both ends of a non-transferable message pipe. This |
161 // is held on until a read or write are done, and at that point it's used to | 167 // is held on until a read or write are done, and at that point it's used to |
162 // get a RawChannel. | 168 // get a RawChannel. |
163 uint64_t pipe_id_; | 169 uint64_t pipe_id_; |
164 enum NonTransferableState { | 170 enum NonTransferableState { |
165 WAITING_FOR_READ_OR_WRITE, | 171 WAITING_FOR_READ_OR_WRITE, |
166 CONNECT_CALLED, | 172 CONNECT_CALLED, |
167 CONNECTED, | 173 CONNECTED, |
168 WAITING_FOR_CONNECT_TO_CLOSE, | 174 WAITING_FOR_CONNECT_TO_CLOSE, |
169 CLOSED, | 175 CLOSED, |
170 SERIALISED, | 176 SERIALISED, |
171 }; | 177 }; |
172 | 178 |
173 NonTransferableState non_transferable_state_; | 179 NonTransferableState non_transferable_state_; |
174 // Messages that were written while we were waiting to get a RawChannel. | 180 // Messages that were written while we were waiting to get a RawChannel. |
175 MessageInTransitQueue non_transferable_outgoing_message_queue_; | 181 MessageInTransitQueue non_transferable_outgoing_message_queue_; |
| 182 scoped_ptr<base::debug::StackTrace> non_transferable_bound_stack_; |
176 | 183 |
177 | 184 |
178 // The following members are used for both modes of transferable_. | 185 // The following members are used for both modes of transferable_. |
179 | 186 |
180 AwakableList awakable_list_; | 187 AwakableList awakable_list_; |
181 | 188 |
182 // If DispatcherTransport is created. Must be set before lock() is called to | 189 // If DispatcherTransport is created. Must be set before lock() is called to |
183 // avoid deadlocks with RawChannel calling us. | 190 // avoid deadlocks with RawChannel calling us. |
184 base::Lock started_transport_; | 191 base::Lock started_transport_; |
185 | 192 |
186 bool serialized_; | 193 bool serialized_; |
187 bool calling_init_; | 194 bool calling_init_; |
188 bool write_error_; | 195 bool write_error_; |
189 // Whether it can be sent after read or write. | 196 // Whether it can be sent after read or write. |
190 bool transferable_; | 197 bool transferable_; |
191 | 198 |
192 MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher); | 199 MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher); |
193 }; | 200 }; |
194 | 201 |
195 } // namespace edk | 202 } // namespace edk |
196 } // namespace mojo | 203 } // namespace mojo |
197 | 204 |
198 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ | 205 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ |
OLD | NEW |