OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "mojo/public/cpp/bindings/lib/connector.h" | 5 #include "mojo/public/cpp/bindings/lib/connector.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 CHECK(!paused_); | 224 CHECK(!paused_); |
225 | 225 |
226 bool receiver_result = false; | 226 bool receiver_result = false; |
227 | 227 |
228 // Detect if |this| was destroyed during message dispatch. Allow for the | 228 // Detect if |this| was destroyed during message dispatch. Allow for the |
229 // possibility of re-entering ReadMore() through message dispatch. | 229 // possibility of re-entering ReadMore() through message dispatch. |
230 bool was_destroyed_during_dispatch = false; | 230 bool was_destroyed_during_dispatch = false; |
231 bool* previous_destroyed_flag = destroyed_flag_; | 231 bool* previous_destroyed_flag = destroyed_flag_; |
232 destroyed_flag_ = &was_destroyed_during_dispatch; | 232 destroyed_flag_ = &was_destroyed_during_dispatch; |
233 | 233 |
234 MojoResult rv = ReadAndDispatchMessage( | 234 Message message; |
235 message_pipe_.get(), incoming_receiver_, &receiver_result); | 235 const MojoResult rv = ReadMessage(message_pipe_.get(), &message); |
236 if (read_result) | 236 *read_result = rv; |
237 *read_result = rv; | 237 |
| 238 if (rv == MOJO_RESULT_OK) { |
| 239 // Dispatching the message may spin in a nested message loop. To ensure we |
| 240 // continue dispatching messages when this happens start listening for |
| 241 // messagse now. |
| 242 if (!async_wait_id_) { |
| 243 // TODO: Need to evaluate the perf impact of this. |
| 244 WaitToReadMore(); |
| 245 } |
| 246 receiver_result = |
| 247 incoming_receiver_ && incoming_receiver_->Accept(&message); |
| 248 } |
238 | 249 |
239 if (was_destroyed_during_dispatch) { | 250 if (was_destroyed_during_dispatch) { |
240 if (previous_destroyed_flag) | 251 if (previous_destroyed_flag) |
241 *previous_destroyed_flag = true; // Propagate flag. | 252 *previous_destroyed_flag = true; // Propagate flag. |
242 return false; | 253 return false; |
243 } | 254 } |
| 255 |
244 destroyed_flag_ = previous_destroyed_flag; | 256 destroyed_flag_ = previous_destroyed_flag; |
245 | 257 |
246 if (rv == MOJO_RESULT_SHOULD_WAIT) | 258 if (rv == MOJO_RESULT_SHOULD_WAIT) |
247 return true; | 259 return true; |
248 | 260 |
249 if (rv != MOJO_RESULT_OK) { | 261 if (rv != MOJO_RESULT_OK) { |
250 HandleError(rv != MOJO_RESULT_FAILED_PRECONDITION, false); | 262 HandleError(rv != MOJO_RESULT_FAILED_PRECONDITION, false); |
251 return false; | 263 return false; |
252 } | 264 } |
253 | 265 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 if (!paused_) | 332 if (!paused_) |
321 WaitToReadMore(); | 333 WaitToReadMore(); |
322 } else { | 334 } else { |
323 error_ = true; | 335 error_ = true; |
324 connection_error_handler_.Run(); | 336 connection_error_handler_.Run(); |
325 } | 337 } |
326 } | 338 } |
327 | 339 |
328 } // namespace internal | 340 } // namespace internal |
329 } // namespace mojo | 341 } // namespace mojo |
OLD | NEW |