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

Unified Diff: mojo/public/cpp/bindings/lib/router.cc

Issue 1781573004: Mojo C++ bindings: error notification behavior related to sync calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/router.h ('k') | mojo/public/cpp/bindings/tests/sync_method_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/router.cc
diff --git a/mojo/public/cpp/bindings/lib/router.cc b/mojo/public/cpp/bindings/lib/router.cc
index ddfc0cfa8b51fdc1157af9f109ba5e9db6532d95..d929e804c21c41358c7261c826b9cb831f14a175 100644
--- a/mojo/public/cpp/bindings/lib/router.cc
+++ b/mojo/public/cpp/bindings/lib/router.cc
@@ -93,11 +93,13 @@ Router::Router(ScopedMessagePipeHandle message_pipe,
next_request_id_(0),
testing_mode_(false),
pending_task_for_messages_(false),
+ encountered_error_(false),
weak_factory_(this) {
filters_.SetSink(&thunk_);
if (expects_sync_requests)
connector_.RegisterSyncHandleWatch();
connector_.set_incoming_receiver(filters_.GetHead());
+ connector_.set_connection_error_handler([this]() { OnConnectionError(); });
}
Router::~Router() {}
@@ -205,6 +207,12 @@ void Router::HandleQueuedMessages() {
}
pending_task_for_messages_ = false;
+
+ // We may have already seen a connection error from the connector, but
+ // haven't notified the user because we want to process all the queued
+ // messages first. We should do it now.
+ if (connector_.encountered_error() && !encountered_error_)
+ OnConnectionError();
}
bool Router::HandleMessageInternal(Message* message) {
@@ -250,6 +258,21 @@ bool Router::HandleMessageInternal(Message* message) {
}
}
+void Router::OnConnectionError() {
+ DCHECK(!encountered_error_);
+
+ if (!pending_messages_.empty()) {
+ // After all the pending messages are processed, we will check whether an
+ // error has been encountered and run the user's connection error handler
+ // if necessary.
+ DCHECK(pending_task_for_messages_);
+ return;
+ }
+
+ encountered_error_ = true;
+ error_handler_.Run();
+}
+
// ----------------------------------------------------------------------------
} // namespace internal
« no previous file with comments | « mojo/public/cpp/bindings/lib/router.h ('k') | mojo/public/cpp/bindings/tests/sync_method_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698