Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: mojo/edk/system/message_pipe_dispatcher.h

Issue 1554623005: Ensure that in-flight message pipes are always closed and the other end is notified. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix dcheck of lock being acquired at destruction Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/system/message_in_transit.h ('k') | mojo/edk/system/message_pipe_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 size_t size, 86 size_t size,
87 PlatformHandleVector* platform_handles); 87 PlatformHandleVector* platform_handles);
88 88
89 private: 89 private:
90 // See MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_TRANSFERABLE's definition for an 90 // See MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_TRANSFERABLE's definition for an
91 // explanation of what is a transferable pipe. 91 // explanation of what is a transferable pipe.
92 explicit MessagePipeDispatcher(bool transferable); 92 explicit MessagePipeDispatcher(bool transferable);
93 ~MessagePipeDispatcher() override; 93 ~MessagePipeDispatcher() override;
94 94
95 void InitOnIO(); 95 void InitOnIO();
96 void CloseOnIOAndRelease();
96 void CloseOnIO(); 97 void CloseOnIO();
97 98
98 // |Dispatcher| protected methods: 99 // |Dispatcher| protected methods:
99 void CancelAllAwakablesNoLock() override; 100 void CancelAllAwakablesNoLock() override;
100 void CloseImplNoLock() override; 101 void CloseImplNoLock() override;
101 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() 102 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock()
102 override; 103 override;
103 MojoResult WriteMessageImplNoLock( 104 MojoResult WriteMessageImplNoLock(
104 const void* bytes, 105 const void* bytes,
105 uint32_t num_bytes, 106 uint32_t num_bytes,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 size_t serialized_message_fds_length_; 165 size_t serialized_message_fds_length_;
165 ScopedPlatformHandle serialized_platform_handle_; 166 ScopedPlatformHandle serialized_platform_handle_;
166 167
167 // The following members are only used when transferable_ is false; 168 // The following members are only used when transferable_ is false;
168 169
169 // The unique id shared by both ends of a non-transferable message pipe. This 170 // The unique id shared by both ends of a non-transferable message pipe. This
170 // is held on until a read or write are done, and at that point it's used to 171 // is held on until a read or write are done, and at that point it's used to
171 // get a RawChannel. 172 // get a RawChannel.
172 uint64_t pipe_id_; 173 uint64_t pipe_id_;
173 enum NonTransferableState { 174 enum NonTransferableState {
175 // The pipe_id hasn't been bound to this object yet until it's read,
176 // written, or waited on.
174 WAITING_FOR_READ_OR_WRITE, 177 WAITING_FOR_READ_OR_WRITE,
178 // This object was interacted with, so the pipe_id has been bound and we are
179 // waiting for the broker to connect both sides.
175 CONNECT_CALLED, 180 CONNECT_CALLED,
181 // We have a connection to the other end of the message pipe.
176 CONNECTED, 182 CONNECTED,
183 // This object has been closed before it's connected. To ensure that the
184 // other end receives a closed message from this end, we've initiated
185 // connecting and will close after it succeeds.
177 WAITING_FOR_CONNECT_TO_CLOSE, 186 WAITING_FOR_CONNECT_TO_CLOSE,
187 // The message pipe is closed.
178 CLOSED, 188 CLOSED,
189 // The message pipe has been transferred.
179 SERIALISED, 190 SERIALISED,
180 }; 191 };
181 192
182 NonTransferableState non_transferable_state_; 193 NonTransferableState non_transferable_state_;
183 // Messages that were written while we were waiting to get a RawChannel. 194 // Messages that were written while we were waiting to get a RawChannel.
184 MessageInTransitQueue non_transferable_outgoing_message_queue_; 195 MessageInTransitQueue non_transferable_outgoing_message_queue_;
185 scoped_ptr<base::debug::StackTrace> non_transferable_bound_stack_; 196 scoped_ptr<base::debug::StackTrace> non_transferable_bound_stack_;
186 197
187 198
188 // The following members are used for both modes of transferable_. 199 // The following members are used for both modes of transferable_.
189 200
190 AwakableList awakable_list_; 201 AwakableList awakable_list_;
191 202
192 // If DispatcherTransport is created. Must be set before lock() is called to 203 // If DispatcherTransport is created. Must be set before lock() is called to
193 // avoid deadlocks with RawChannel calling us. 204 // avoid deadlocks with RawChannel calling us.
194 base::Lock started_transport_; 205 base::Lock started_transport_;
195 206
196 bool serialized_; 207 bool serialized_;
197 bool calling_init_; 208 bool calling_init_;
198 bool write_error_; 209 bool write_error_;
199 // Whether it can be sent after read or write. 210 // Whether it can be sent after read or write.
200 bool transferable_; 211 bool transferable_;
212 // When this object is closed, it has to wait to flush any pending messages
213 // from the other side to ensure that any in-queue message pipes are closed.
214 // If this is true, we have already sent the other side the request.
215 bool close_requested_;
201 216
202 MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher); 217 MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher);
203 }; 218 };
204 219
205 } // namespace edk 220 } // namespace edk
206 } // namespace mojo 221 } // namespace mojo
207 222
208 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ 223 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/message_in_transit.h ('k') | mojo/edk/system/message_pipe_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698