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

Side by Side Diff: mojo/public/cpp/bindings/binding.h

Issue 711413005: Use WeakBindingSet to manage inspector connections (Closed) Base URL: git@github.com:domokit/mojo.git@connector
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
7 7
8 #include "mojo/public/c/environment/async_waiter.h" 8 #include "mojo/public/c/environment/async_waiter.h"
9 #include "mojo/public/cpp/bindings/error_handler.h" 9 #include "mojo/public/cpp/bindings/error_handler.h"
10 #include "mojo/public/cpp/bindings/interface_ptr.h" 10 #include "mojo/public/cpp/bindings/interface_ptr.h"
(...skipping 16 matching lines...) Expand all
27 // class FooImpl : public Foo { 27 // class FooImpl : public Foo {
28 // public: 28 // public:
29 // explicit FooImpl(ScopedMessagePipeHandle handle) 29 // explicit FooImpl(ScopedMessagePipeHandle handle)
30 // : binding_(this, handle.Pass()) {} 30 // : binding_(this, handle.Pass()) {}
31 // 31 //
32 // // Foo implementation here. 32 // // Foo implementation here.
33 // 33 //
34 // private: 34 // private:
35 // Binding<Foo> binding_; 35 // Binding<Foo> binding_;
36 // }; 36 // };
37 //
38 template <typename Interface> 37 template <typename Interface>
39 class Binding : public ErrorHandler { 38 class Binding : public ErrorHandler {
40 public: 39 public:
41 using Client = typename Interface::Client; 40 using Client = typename Interface::Client;
42 41
43 explicit Binding(Interface* impl) : impl_(impl) { stub_.set_sink(impl_); } 42 explicit Binding(Interface* impl) : impl_(impl) { stub_.set_sink(impl_); }
44 43
45 Binding(Interface* impl, 44 Binding(Interface* impl,
46 ScopedMessagePipeHandle handle, 45 ScopedMessagePipeHandle handle,
47 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) 46 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter())
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 InterfaceRequest<Interface> request, 98 InterfaceRequest<Interface> request,
100 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { 99 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
101 Bind(request.PassMessagePipe(), waiter); 100 Bind(request.PassMessagePipe(), waiter);
102 } 101 }
103 102
104 bool WaitForIncomingMethodCall() { 103 bool WaitForIncomingMethodCall() {
105 MOJO_DCHECK(internal_router_); 104 MOJO_DCHECK(internal_router_);
106 return internal_router_->WaitForIncomingMessage(); 105 return internal_router_->WaitForIncomingMessage();
107 } 106 }
108 107
108 void Close() {
109 MOJO_DCHECK(internal_router_);
110 internal_router_->CloseMessagePipe();
111 }
112
109 void set_error_handler(ErrorHandler* error_handler) { 113 void set_error_handler(ErrorHandler* error_handler) {
110 error_handler_ = error_handler; 114 error_handler_ = error_handler;
111 } 115 }
112 116
113 // ErrorHandler implementation 117 // ErrorHandler implementation
114 void OnConnectionError() override { 118 void OnConnectionError() override {
115 if (error_handler_) 119 if (error_handler_)
116 error_handler_->OnConnectionError(); 120 error_handler_->OnConnectionError();
117 } 121 }
118 122
119 Interface* impl() { return impl_; } 123 Interface* impl() { return impl_; }
120 Client* client() { return proxy_; } 124 Client* client() { return proxy_; }
121 // Exposed for testing, should not generally be used. 125 // Exposed for testing, should not generally be used.
122 internal::Router* internal_router() { return internal_router_; } 126 internal::Router* internal_router() { return internal_router_; }
123 127
124 private: 128 private:
125 internal::Router* internal_router_ = nullptr; 129 internal::Router* internal_router_ = nullptr;
126 typename Client::Proxy_* proxy_ = nullptr; 130 typename Client::Proxy_* proxy_ = nullptr;
127 typename Interface::Stub_ stub_; 131 typename Interface::Stub_ stub_;
128 Interface* impl_; 132 Interface* impl_;
129 ErrorHandler* error_handler_ = nullptr; 133 ErrorHandler* error_handler_ = nullptr;
130 134
131 MOJO_DISALLOW_COPY_AND_ASSIGN(Binding); 135 MOJO_DISALLOW_COPY_AND_ASSIGN(Binding);
132 }; 136 };
133 137
134 } // namespace mojo 138 } // namespace mojo
135 139
136 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ 140 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698