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

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

Issue 1174073002: C++ bindings: support using a callback as connection error handler. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 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 | « no previous file | mojo/public/cpp/bindings/interface_ptr.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/binding.h
diff --git a/mojo/public/cpp/bindings/binding.h b/mojo/public/cpp/bindings/binding.h
index 8dbcbd45411c964409e53aa0c12b11ad6fbc3e4a..29708e0df25d89235a0b65466f838ed21d9adba9 100644
--- a/mojo/public/cpp/bindings/binding.h
+++ b/mojo/public/cpp/bindings/binding.h
@@ -6,6 +6,7 @@
#define MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
#include "mojo/public/c/environment/async_waiter.h"
+#include "mojo/public/cpp/bindings/callback.h"
#include "mojo/public/cpp/bindings/error_handler.h"
#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "mojo/public/cpp/bindings/interface_ptr_info.h"
@@ -57,7 +58,7 @@ namespace mojo {
// types of threads callers may need to provide different waiter
// implementations.
template <typename Interface>
-class Binding : public ErrorHandler {
+class Binding {
public:
// Constructs an incomplete binding that will use the implementation |impl|.
// The binding may be completed with a subsequent call to the |Bind| method.
@@ -100,7 +101,7 @@ class Binding : public ErrorHandler {
// Tears down the binding, closing the message pipe and leaving the interface
// implementation unbound.
- ~Binding() override {
+ ~Binding() {
if (internal_router_) {
Close();
}
@@ -120,7 +121,8 @@ class Binding : public ErrorHandler {
internal_router_ =
new internal::Router(handle.Pass(), filters.Pass(), waiter);
internal_router_->set_incoming_receiver(&stub_);
- internal_router_->set_error_handler(this);
+ internal_router_->set_connection_error_handler(
+ [this]() { connection_error_handler_.Run(); });
qsr 2015/06/11 09:37:53 I'm missing something. Why do you need to do this,
yzshen1 2015/06/11 16:51:45 The current code matches the previous behavior: *
}
// Completes a binding that was constructed with only an interface
@@ -181,14 +183,17 @@ class Binding : public ErrorHandler {
// Sets an error handler that will be called if a connection error occurs on
// the bound message pipe.
- void set_error_handler(ErrorHandler* error_handler) {
- error_handler_ = error_handler;
+ void set_connection_error_handler(const Closure& error_handler) {
+ connection_error_handler_ = error_handler;
}
- // Implements the |Binding|'s response to a connection error.
- void OnConnectionError() override {
- if (error_handler_)
- error_handler_->OnConnectionError();
+ // Similar to the method above but uses the ErrorHandler interface instead of
+ // a callback.
+ // NOTE: Deprecated. Please use the method above.
+ // TODO(yzshen): Remove this method once all callsites are converted.
+ void set_error_handler(ErrorHandler* error_handler) {
+ set_connection_error_handler(
+ [error_handler]() { error_handler->OnConnectionError(); });
}
// Returns the interface implementation that was previously specified. Caller
@@ -213,7 +218,7 @@ class Binding : public ErrorHandler {
private:
void DestroyRouter() {
- internal_router_->set_error_handler(nullptr);
+ internal_router_->set_connection_error_handler(Closure());
delete internal_router_;
internal_router_ = nullptr;
}
@@ -221,7 +226,7 @@ class Binding : public ErrorHandler {
internal::Router* internal_router_ = nullptr;
typename Interface::Stub_ stub_;
Interface* impl_;
- ErrorHandler* error_handler_ = nullptr;
+ Closure connection_error_handler_;
MOJO_DISALLOW_COPY_AND_ASSIGN(Binding);
};
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/interface_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698