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

Unified Diff: mojo/public/cpp/bindings/binding_set.h

Issue 2318793002: Mojo C++ bindings: support disconnect with a reason. (Closed)
Patch Set: . Created 4 years, 3 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/binding.h ('k') | mojo/public/cpp/bindings/connection_error_callback.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/binding_set.h
diff --git a/mojo/public/cpp/bindings/binding_set.h b/mojo/public/cpp/bindings/binding_set.h
index ef5834cca054152df19c1bc0b644140ef01795d5..d778f6c34780f65f613b6030aead97eaf7117698 100644
--- a/mojo/public/cpp/bindings/binding_set.h
+++ b/mojo/public/cpp/bindings/binding_set.h
@@ -5,12 +5,14 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_BINDING_SET_H_
#define MOJO_PUBLIC_CPP_BINDINGS_BINDING_SET_H_
+#include <string>
#include <utility>
#include "base/bind.h"
#include "base/callback.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h"
+#include "mojo/public/cpp/bindings/connection_error_callback.h"
#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/message.h"
@@ -58,6 +60,13 @@ class BindingSet {
void set_connection_error_handler(const base::Closure& error_handler) {
error_handler_ = error_handler;
+ error_with_reason_handler_.Reset();
+ }
+
+ void set_connection_error_with_reason_handler(
+ const ConnectionErrorWithReasonCallback& error_handler) {
+ error_with_reason_handler_ = error_handler;
+ error_handler_.Reset();
}
// Sets a callback to be invoked immediately before dispatching any message or
@@ -149,8 +158,8 @@ class BindingSet {
context_(context) {
if (binding_set->SupportsContext())
binding_.AddFilter(base::MakeUnique<DispatchFilter>(this));
- binding_.set_connection_error_handler(base::Bind(
- &Entry::OnConnectionError, base::Unretained(this)));
+ binding_.set_connection_error_with_reason_handler(
+ base::Bind(&Entry::OnConnectionError, base::Unretained(this)));
}
void FlushForTesting() { binding_.FlushForTesting(); }
@@ -178,10 +187,11 @@ class BindingSet {
binding_set_->SetDispatchContext(context_);
}
- void OnConnectionError() {
+ void OnConnectionError(uint32_t custom_reason,
+ const std::string& description) {
if (binding_set_->SupportsContext())
WillDispatch();
- binding_set_->OnConnectionError(binding_id_);
+ binding_set_->OnConnectionError(binding_id_, custom_reason, description);
}
BindingType binding_;
@@ -203,17 +213,22 @@ class BindingSet {
return dispatch_mode_ == BindingSetDispatchMode::WITH_CONTEXT;
}
- void OnConnectionError(BindingId id) {
+ void OnConnectionError(BindingId id,
+ uint32_t custom_reason,
+ const std::string& description) {
auto it = bindings_.find(id);
DCHECK(it != bindings_.end());
bindings_.erase(it);
if (!error_handler_.is_null())
error_handler_.Run();
+ else if (!error_with_reason_handler_.is_null())
+ error_with_reason_handler_.Run(custom_reason, description);
}
BindingSetDispatchMode dispatch_mode_;
base::Closure error_handler_;
+ ConnectionErrorWithReasonCallback error_with_reason_handler_;
PreDispatchCallback pre_dispatch_handler_;
BindingId next_binding_id_ = 0;
std::map<BindingId, std::unique_ptr<Entry>> bindings_;
« no previous file with comments | « mojo/public/cpp/bindings/binding.h ('k') | mojo/public/cpp/bindings/connection_error_callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698