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

Unified Diff: mojo/public/cpp/bindings/strong_binding.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
Index: mojo/public/cpp/bindings/strong_binding.h
diff --git a/mojo/public/cpp/bindings/strong_binding.h b/mojo/public/cpp/bindings/strong_binding.h
index 235a9d68948f3c7c24472a2a9994b00670a5d56b..99d10956c6f040e2835ff9f705f713f38486a641 100644
--- a/mojo/public/cpp/bindings/strong_binding.h
+++ b/mojo/public/cpp/bindings/strong_binding.h
@@ -6,6 +6,7 @@
#define MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_
#include <memory>
+#include <string>
#include <utility>
#include "base/bind.h"
@@ -14,6 +15,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/binding.h"
+#include "mojo/public/cpp/bindings/connection_error_callback.h"
#include "mojo/public/cpp/bindings/filter_chain.h"
#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "mojo/public/cpp/bindings/interface_request.h"
@@ -59,6 +61,14 @@ class StrongBinding {
void set_connection_error_handler(const base::Closure& error_handler) {
DCHECK(binding_.is_bound());
connection_error_handler_ = error_handler;
+ connection_error_with_reason_handler_.Reset();
+ }
+
+ void set_connection_error_with_reason_handler(
+ const ConnectionErrorWithReasonCallback& error_handler) {
+ DCHECK(binding_.is_bound());
+ connection_error_with_reason_handler_ = error_handler;
+ connection_error_handler_.Reset();
}
// Forces the binding to close. This destroys the StrongBinding instance.
@@ -81,20 +91,24 @@ class StrongBinding {
: impl_(std::move(impl)),
binding_(impl_.get(), std::move(request)),
weak_factory_(this) {
- binding_.set_connection_error_handler(
+ binding_.set_connection_error_with_reason_handler(
base::Bind(&StrongBinding::OnConnectionError, base::Unretained(this)));
}
~StrongBinding() {}
- void OnConnectionError() {
+ void OnConnectionError(uint32_t custom_reason,
+ const std::string& description) {
if (!connection_error_handler_.is_null())
connection_error_handler_.Run();
+ else if (!connection_error_with_reason_handler_.is_null())
+ connection_error_with_reason_handler_.Run(custom_reason, description);
Close();
}
std::unique_ptr<Interface> impl_;
base::Closure connection_error_handler_;
+ ConnectionErrorWithReasonCallback connection_error_with_reason_handler_;
Binding<Interface> binding_;
base::WeakPtrFactory<StrongBinding> weak_factory_;
« no previous file with comments | « mojo/public/cpp/bindings/lib/router.cc ('k') | mojo/public/cpp/bindings/tests/associated_interface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698