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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 bool WaitForIncomingMethodCall( | 169 bool WaitForIncomingMethodCall( |
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; |
yzshen1
2015/12/16 00:56:06
Please also make the corresponding changes here.
Anand Mistry (off Chromium)
2015/12/16 01:49:34
Done.
| |
178 } | 180 } |
179 | 181 |
180 InterfaceRequest<Interface> Unbind() { | 182 InterfaceRequest<Interface> Unbind() { |
yzshen1
2015/12/16 00:56:05
ditto.
Anand Mistry (off Chromium)
2015/12/16 01:49:34
Done.
| |
181 endpoint_client_.reset(); | 183 endpoint_client_.reset(); |
182 InterfaceRequest<Interface> request = | 184 InterfaceRequest<Interface> request = |
183 MakeRequest<Interface>(router_->PassMessagePipe()); | 185 MakeRequest<Interface>(router_->PassMessagePipe()); |
184 router_ = nullptr; | 186 router_ = nullptr; |
185 return request.Pass(); | 187 return request.Pass(); |
186 } | 188 } |
187 | 189 |
188 void set_connection_error_handler(const Closure& error_handler) { | 190 void set_connection_error_handler(const Closure& error_handler) { |
189 connection_error_handler_ = error_handler; | 191 connection_error_handler_ = error_handler; |
190 } | 192 } |
(...skipping 24 matching lines...) Expand all Loading... | |
215 Interface* impl_; | 217 Interface* impl_; |
216 Closure connection_error_handler_; | 218 Closure connection_error_handler_; |
217 | 219 |
218 DISALLOW_COPY_AND_ASSIGN(BindingState); | 220 DISALLOW_COPY_AND_ASSIGN(BindingState); |
219 }; | 221 }; |
220 | 222 |
221 } // namesapce internal | 223 } // namesapce internal |
222 } // namespace mojo | 224 } // namespace mojo |
223 | 225 |
224 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ | 226 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ |
OLD | NEW |