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

Side by Side Diff: mojo/public/cpp/bindings/lib/binding_state.h

Issue 1524693002: [mojo] Add GenericInterface_ to interface class variants (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bindings-2-typemaps
Patch Set: merge Created 5 years 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_LIB_BINDING_STATE_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 19 matching lines...) Expand all
30 template <typename Interface, bool use_multiplex_router> 30 template <typename Interface, bool use_multiplex_router>
31 class BindingState; 31 class BindingState;
32 32
33 // Uses a single-threaded, dedicated router. If |Interface| doesn't have any 33 // Uses a single-threaded, dedicated router. If |Interface| doesn't have any
34 // methods to pass associated interface pointers or requests, there won't be 34 // methods to pass associated interface pointers or requests, there won't be
35 // multiple interfaces running on the underlying message pipe. In that case, we 35 // multiple interfaces running on the underlying message pipe. In that case, we
36 // can use this specialization to reduce cost. 36 // can use this specialization to reduce cost.
37 template <typename Interface> 37 template <typename Interface>
38 class BindingState<Interface, false> { 38 class BindingState<Interface, false> {
39 public: 39 public:
40 using GenericInterface = typename Interface::GenericInterface;
41
40 explicit BindingState(Interface* impl) : impl_(impl) { 42 explicit BindingState(Interface* impl) : impl_(impl) {
41 stub_.set_sink(impl_); 43 stub_.set_sink(impl_);
42 } 44 }
43 45
44 ~BindingState() { 46 ~BindingState() {
45 if (router_) 47 if (router_)
46 Close(); 48 Close();
47 } 49 }
48 50
49 void Bind(ScopedMessagePipeHandle handle, const MojoAsyncWaiter* waiter) { 51 void Bind(ScopedMessagePipeHandle handle, const MojoAsyncWaiter* waiter) {
(...skipping 24 matching lines...) Expand all
74 DCHECK(router_); 76 DCHECK(router_);
75 return router_->WaitForIncomingMessage(deadline); 77 return router_->WaitForIncomingMessage(deadline);
76 } 78 }
77 79
78 void Close() { 80 void Close() {
79 DCHECK(router_); 81 DCHECK(router_);
80 router_->CloseMessagePipe(); 82 router_->CloseMessagePipe();
81 DestroyRouter(); 83 DestroyRouter();
82 } 84 }
83 85
84 InterfaceRequest<Interface> Unbind() { 86 InterfaceRequest<GenericInterface> Unbind() {
85 InterfaceRequest<Interface> request = 87 InterfaceRequest<GenericInterface> request =
86 MakeRequest<Interface>(router_->PassMessagePipe()); 88 MakeRequest<GenericInterface>(router_->PassMessagePipe());
87 DestroyRouter(); 89 DestroyRouter();
88 return request.Pass(); 90 return request.Pass();
89 } 91 }
90 92
91 void set_connection_error_handler(const Closure& error_handler) { 93 void set_connection_error_handler(const Closure& error_handler) {
92 connection_error_handler_ = error_handler; 94 connection_error_handler_ = error_handler;
93 } 95 }
94 96
95 Interface* impl() { return impl_; } 97 Interface* impl() { return impl_; }
96 98
(...skipping 24 matching lines...) Expand all
121 Closure connection_error_handler_; 123 Closure connection_error_handler_;
122 124
123 DISALLOW_COPY_AND_ASSIGN(BindingState); 125 DISALLOW_COPY_AND_ASSIGN(BindingState);
124 }; 126 };
125 127
126 // Uses a multiplexing router. If |Interface| has methods to pass associated 128 // Uses a multiplexing router. If |Interface| has methods to pass associated
127 // interface pointers or requests, this specialization should be used. 129 // interface pointers or requests, this specialization should be used.
128 template <typename Interface> 130 template <typename Interface>
129 class BindingState<Interface, true> { 131 class BindingState<Interface, true> {
130 public: 132 public:
133 using GenericInterface = typename Interface::GenericInterface;
134
131 explicit BindingState(Interface* impl) : impl_(impl) { 135 explicit BindingState(Interface* impl) : impl_(impl) {
132 stub_.set_sink(impl_); 136 stub_.set_sink(impl_);
133 } 137 }
134 138
135 ~BindingState() { 139 ~BindingState() {
136 if (router_) 140 if (router_)
137 Close(); 141 Close();
138 } 142 }
139 143
140 void Bind(ScopedMessagePipeHandle handle, const MojoAsyncWaiter* waiter) { 144 void Bind(ScopedMessagePipeHandle handle, const MojoAsyncWaiter* waiter) {
(...skipping 29 matching lines...) Expand all
170 return router_->WaitForIncomingMessage(deadline); 174 return router_->WaitForIncomingMessage(deadline);
171 } 175 }
172 176
173 void Close() { 177 void Close() {
174 DCHECK(router_); 178 DCHECK(router_);
175 endpoint_client_.reset(); 179 endpoint_client_.reset();
176 router_->CloseMessagePipe(); 180 router_->CloseMessagePipe();
177 router_ = nullptr; 181 router_ = nullptr;
178 } 182 }
179 183
180 InterfaceRequest<Interface> Unbind() { 184 InterfaceRequest<GenericInterface> Unbind() {
181 endpoint_client_.reset(); 185 endpoint_client_.reset();
182 InterfaceRequest<Interface> request = 186 InterfaceRequest<GenericInterface> request =
183 MakeRequest<Interface>(router_->PassMessagePipe()); 187 MakeRequest<GenericInterface>(router_->PassMessagePipe());
184 router_ = nullptr; 188 router_ = nullptr;
185 return request.Pass(); 189 return request.Pass();
186 } 190 }
187 191
188 void set_connection_error_handler(const Closure& error_handler) { 192 void set_connection_error_handler(const Closure& error_handler) {
189 connection_error_handler_ = error_handler; 193 connection_error_handler_ = error_handler;
190 } 194 }
191 195
192 Interface* impl() { return impl_; } 196 Interface* impl() { return impl_; }
193 197
(...skipping 21 matching lines...) Expand all
215 Interface* impl_; 219 Interface* impl_;
216 Closure connection_error_handler_; 220 Closure connection_error_handler_;
217 221
218 DISALLOW_COPY_AND_ASSIGN(BindingState); 222 DISALLOW_COPY_AND_ASSIGN(BindingState);
219 }; 223 };
220 224
221 } // namesapce internal 225 } // namesapce internal
222 } // namespace mojo 226 } // namespace mojo
223 227
224 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ 228 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h ('k') | mojo/public/cpp/bindings/lib/interface_ptr_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698