| 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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 361 } |
| 362 | 362 |
| 363 if (should_stop_sync_handle_watch_) | 363 if (should_stop_sync_handle_watch_) |
| 364 should_stop_sync_handle_watch_->data = true; | 364 should_stop_sync_handle_watch_->data = true; |
| 365 } | 365 } |
| 366 | 366 |
| 367 void Connector::HandleError(bool force_pipe_reset, bool force_async_handler) { | 367 void Connector::HandleError(bool force_pipe_reset, bool force_async_handler) { |
| 368 if (error_ || !message_pipe_.is_valid()) | 368 if (error_ || !message_pipe_.is_valid()) |
| 369 return; | 369 return; |
| 370 | 370 |
| 371 if (during_sync_handle_watcher_callback() || paused_) { |
| 372 // Enforce calling the error handler asynchronously if: |
| 373 // - currently we are in a sync handle watcher callback. We don't want the |
| 374 // error handler to reenter an ongoing sync call. |
| 375 // - the user has paused receiving messages. We need to wait until the user |
| 376 // starts receiving messages again. |
| 377 force_async_handler = true; |
| 378 } |
| 379 |
| 371 if (!force_pipe_reset && force_async_handler) | 380 if (!force_pipe_reset && force_async_handler) |
| 372 force_pipe_reset = true; | 381 force_pipe_reset = true; |
| 373 | 382 |
| 374 if (paused_) { | |
| 375 // If the user has paused receiving messages, we shouldn't call the error | |
| 376 // handler right away. We need to wait until the user starts receiving | |
| 377 // messages again. | |
| 378 force_async_handler = true; | |
| 379 } | |
| 380 | |
| 381 if (force_pipe_reset) { | 383 if (force_pipe_reset) { |
| 382 CancelWait(); | 384 CancelWait(); |
| 383 MayAutoLock locker(lock_.get()); | 385 MayAutoLock locker(lock_.get()); |
| 384 Close(std::move(message_pipe_)); | 386 Close(std::move(message_pipe_)); |
| 385 MessagePipe dummy_pipe; | 387 MessagePipe dummy_pipe; |
| 386 message_pipe_ = std::move(dummy_pipe.handle0); | 388 message_pipe_ = std::move(dummy_pipe.handle0); |
| 387 } else { | 389 } else { |
| 388 CancelWait(); | 390 CancelWait(); |
| 389 } | 391 } |
| 390 | 392 |
| 391 if (force_async_handler) { | 393 if (force_async_handler) { |
| 392 if (!paused_) | 394 if (!paused_) |
| 393 WaitToReadMore(); | 395 WaitToReadMore(); |
| 394 } else { | 396 } else { |
| 395 error_ = true; | 397 error_ = true; |
| 396 connection_error_handler_.Run(); | 398 connection_error_handler_.Run(); |
| 397 } | 399 } |
| 398 } | 400 } |
| 399 | 401 |
| 400 } // namespace internal | 402 } // namespace internal |
| 401 } // namespace mojo | 403 } // namespace mojo |
| OLD | NEW |