OLD | NEW |
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 82 } |
83 | 83 |
84 InterfaceRequest<Interface> Unbind() { | 84 InterfaceRequest<Interface> Unbind() { |
85 InterfaceRequest<Interface> request = | 85 InterfaceRequest<Interface> request = |
86 MakeRequest<Interface>(router_->PassMessagePipe()); | 86 MakeRequest<Interface>(router_->PassMessagePipe()); |
87 DestroyRouter(); | 87 DestroyRouter(); |
88 return request.Pass(); | 88 return request.Pass(); |
89 } | 89 } |
90 | 90 |
91 void set_connection_error_handler(const Closure& error_handler) { | 91 void set_connection_error_handler(const Closure& error_handler) { |
| 92 DCHECK(is_bound()); |
92 connection_error_handler_ = error_handler; | 93 connection_error_handler_ = error_handler; |
93 } | 94 } |
94 | 95 |
95 Interface* impl() { return impl_; } | 96 Interface* impl() { return impl_; } |
96 | 97 |
97 bool is_bound() const { return !!router_; } | 98 bool is_bound() const { return !!router_; } |
98 | 99 |
99 MessagePipeHandle handle() const { | 100 MessagePipeHandle handle() const { |
100 DCHECK(is_bound()); | 101 DCHECK(is_bound()); |
101 return router_->handle(); | 102 return router_->handle(); |
102 } | 103 } |
103 | 104 |
104 AssociatedGroup* associated_group() { return nullptr; } | 105 AssociatedGroup* associated_group() { return nullptr; } |
105 | 106 |
106 void EnableTestingMode() { | 107 void EnableTestingMode() { |
107 DCHECK(is_bound()); | 108 DCHECK(is_bound()); |
108 router_->EnableTestingMode(); | 109 router_->EnableTestingMode(); |
109 } | 110 } |
110 | 111 |
111 private: | 112 private: |
112 void DestroyRouter() { | 113 void DestroyRouter() { |
113 router_->set_connection_error_handler(Closure()); | 114 router_->set_connection_error_handler(Closure()); |
114 delete router_; | 115 delete router_; |
115 router_ = nullptr; | 116 router_ = nullptr; |
| 117 connection_error_handler_.reset(); |
116 } | 118 } |
117 | 119 |
118 internal::Router* router_ = nullptr; | 120 internal::Router* router_ = nullptr; |
119 typename Interface::Stub_ stub_; | 121 typename Interface::Stub_ stub_; |
120 Interface* impl_; | 122 Interface* impl_; |
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 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE) { | 170 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE) { |
169 DCHECK(router_); | 171 DCHECK(router_); |
170 return router_->WaitForIncomingMessage(deadline); | 172 return router_->WaitForIncomingMessage(deadline); |
171 } | 173 } |
172 | 174 |
173 void Close() { | 175 void Close() { |
174 DCHECK(router_); | 176 DCHECK(router_); |
175 endpoint_client_.reset(); | 177 endpoint_client_.reset(); |
176 router_->CloseMessagePipe(); | 178 router_->CloseMessagePipe(); |
177 router_ = nullptr; | 179 router_ = nullptr; |
| 180 connection_error_handler_.reset(); |
178 } | 181 } |
179 | 182 |
180 InterfaceRequest<Interface> Unbind() { | 183 InterfaceRequest<Interface> Unbind() { |
181 endpoint_client_.reset(); | 184 endpoint_client_.reset(); |
182 InterfaceRequest<Interface> request = | 185 InterfaceRequest<Interface> request = |
183 MakeRequest<Interface>(router_->PassMessagePipe()); | 186 MakeRequest<Interface>(router_->PassMessagePipe()); |
184 router_ = nullptr; | 187 router_ = nullptr; |
| 188 connection_error_handler_.reset(); |
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) { |
| 193 DCHECK(is_bound()); |
189 connection_error_handler_ = error_handler; | 194 connection_error_handler_ = error_handler; |
190 } | 195 } |
191 | 196 |
192 Interface* impl() { return impl_; } | 197 Interface* impl() { return impl_; } |
193 | 198 |
194 bool is_bound() const { return !!router_; } | 199 bool is_bound() const { return !!router_; } |
195 | 200 |
196 MessagePipeHandle handle() const { | 201 MessagePipeHandle handle() const { |
197 DCHECK(is_bound()); | 202 DCHECK(is_bound()); |
198 return router_->handle(); | 203 return router_->handle(); |
(...skipping 16 matching lines...) Expand all Loading... |
215 Interface* impl_; | 220 Interface* impl_; |
216 Closure connection_error_handler_; | 221 Closure connection_error_handler_; |
217 | 222 |
218 DISALLOW_COPY_AND_ASSIGN(BindingState); | 223 DISALLOW_COPY_AND_ASSIGN(BindingState); |
219 }; | 224 }; |
220 | 225 |
221 } // namesapce internal | 226 } // namesapce internal |
222 } // namespace mojo | 227 } // namespace mojo |
223 | 228 |
224 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ | 229 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ |
OLD | NEW |