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

Unified Diff: mojo/public/cpp/bindings/lib/interface_impl_internal.h

Issue 686883005: Provides a way to use bindings that doesn't require subclassing (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: review feedback Created 6 years, 1 month 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/interface_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/interface_impl_internal.h
diff --git a/mojo/public/cpp/bindings/lib/interface_impl_internal.h b/mojo/public/cpp/bindings/lib/interface_impl_internal.h
index 492b1822496749d6d68dea24f71fc866d5193a11..c9e3315d5fcea305eee3841c72ba18370e7e05b5 100644
--- a/mojo/public/cpp/bindings/lib/interface_impl_internal.h
+++ b/mojo/public/cpp/bindings/lib/interface_impl_internal.h
@@ -6,6 +6,7 @@
#define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
#include "mojo/public/cpp/bindings/error_handler.h"
+#include "mojo/public/cpp/bindings/interface_binding_delegate.h"
#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "mojo/public/cpp/bindings/lib/filter_chain.h"
#include "mojo/public/cpp/bindings/lib/message_header_validator.h"
@@ -14,38 +15,27 @@
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
-namespace internal {
-template <typename Interface>
-class InterfaceImplBase : public Interface {
- public:
- virtual ~InterfaceImplBase() {}
- virtual void OnConnectionEstablished() = 0;
- virtual void OnConnectionError() = 0;
-};
+class InterfaceBindingDelegate;
+
+namespace internal {
template <typename Interface>
class InterfaceImplState : public ErrorHandler {
public:
typedef typename Interface::Client Client;
- explicit InterfaceImplState(InterfaceImplBase<Interface>* instance)
- : router_(nullptr),
+ explicit InterfaceImplState(Interface* instance,
+ InterfaceBindingDelegate* delegate)
+ : delegate_(delegate),
+ router_(nullptr),
proxy_(nullptr),
- instance_bound_to_pipe_(false)
-#ifndef NDEBUG
- ,
- deleting_instance_due_to_error_(false)
-#endif
- {
+ instance_bound_to_pipe_(false) {
MOJO_DCHECK(instance);
stub_.set_sink(instance);
}
virtual ~InterfaceImplState() {
-#ifndef NDEBUG
- MOJO_DCHECK(!instance_bound_to_pipe_ || deleting_instance_due_to_error_);
-#endif
delete proxy_;
if (router_) {
router_->set_error_handler(nullptr);
@@ -80,7 +70,8 @@ class InterfaceImplState : public ErrorHandler {
instance_bound_to_pipe_ = instance_bound_to_pipe;
- instance()->OnConnectionEstablished();
+ if (delegate_)
+ delegate_->OnConnectionEstablished();
}
bool WaitForIncomingMethodCall() {
@@ -90,34 +81,18 @@ class InterfaceImplState : public ErrorHandler {
Router* router() { return router_; }
Client* client() { return proxy_; }
+ Interface* instance() { return stub_.sink(); }
- private:
- InterfaceImplBase<Interface>* instance() {
- return static_cast<InterfaceImplBase<Interface>*>(stub_.sink());
- }
+ bool instance_bound_to_pipe() const { return instance_bound_to_pipe_; }
- virtual void OnConnectionError() override {
- // If the the instance is not bound to the pipe, the instance might choose
- // to delete itself in the OnConnectionError handler, which would in turn
- // delete this. Save the error behavior before invoking the error handler
- // so we can correctly decide what to do.
- bool bound = instance_bound_to_pipe_;
- instance()->OnConnectionError();
- if (!bound)
- return;
-#ifndef NDEBUG
- deleting_instance_due_to_error_ = true;
-#endif
- delete instance();
- }
+ private:
+ virtual void OnConnectionError() override { delegate_->OnConnectionError(); }
+ InterfaceBindingDelegate* delegate_;
Router* router_;
typename Client::Proxy_* proxy_;
typename Interface::Stub_ stub_;
bool instance_bound_to_pipe_;
-#ifndef NDEBUG
- bool deleting_instance_due_to_error_;
-#endif
MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState);
};
« no previous file with comments | « mojo/public/cpp/bindings/interface_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698