| 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 <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // methods to pass associated interface pointers or requests, there won't be | 37 // methods to pass associated interface pointers or requests, there won't be |
| 38 // multiple interfaces running on the underlying message pipe. In that case, we | 38 // multiple interfaces running on the underlying message pipe. In that case, we |
| 39 // can use this specialization to reduce cost. | 39 // can use this specialization to reduce cost. |
| 40 template <typename Interface> | 40 template <typename Interface> |
| 41 class BindingState<Interface, false> { | 41 class BindingState<Interface, false> { |
| 42 public: | 42 public: |
| 43 explicit BindingState(Interface* impl) : impl_(impl) { | 43 explicit BindingState(Interface* impl) : impl_(impl) { |
| 44 stub_.set_sink(impl_); | 44 stub_.set_sink(impl_); |
| 45 } | 45 } |
| 46 | 46 |
| 47 ~BindingState() { | 47 ~BindingState() { Close(); } |
| 48 if (router_) | |
| 49 Close(); | |
| 50 } | |
| 51 | 48 |
| 52 void Bind(ScopedMessagePipeHandle handle, | 49 void Bind(ScopedMessagePipeHandle handle, |
| 53 scoped_refptr<base::SingleThreadTaskRunner> runner) { | 50 scoped_refptr<base::SingleThreadTaskRunner> runner) { |
| 54 DCHECK(!router_); | 51 DCHECK(!router_); |
| 55 internal::FilterChain filters; | 52 internal::FilterChain filters; |
| 56 filters.Append<internal::MessageHeaderValidator>(); | 53 filters.Append<internal::MessageHeaderValidator>(); |
| 57 filters.Append<typename Interface::RequestValidator_>(); | 54 filters.Append<typename Interface::RequestValidator_>(); |
| 58 | 55 |
| 59 router_ = | 56 router_ = |
| 60 new internal::Router(std::move(handle), std::move(filters), | 57 new internal::Router(std::move(handle), std::move(filters), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 75 router_->ResumeIncomingMethodCallProcessing(); | 72 router_->ResumeIncomingMethodCallProcessing(); |
| 76 } | 73 } |
| 77 | 74 |
| 78 bool WaitForIncomingMethodCall( | 75 bool WaitForIncomingMethodCall( |
| 79 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE) { | 76 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE) { |
| 80 DCHECK(router_); | 77 DCHECK(router_); |
| 81 return router_->WaitForIncomingMessage(deadline); | 78 return router_->WaitForIncomingMessage(deadline); |
| 82 } | 79 } |
| 83 | 80 |
| 84 void Close() { | 81 void Close() { |
| 85 DCHECK(router_); | 82 if (!router_) |
| 83 return; |
| 84 |
| 86 router_->CloseMessagePipe(); | 85 router_->CloseMessagePipe(); |
| 87 DestroyRouter(); | 86 DestroyRouter(); |
| 88 } | 87 } |
| 89 | 88 |
| 90 InterfaceRequest<Interface> Unbind() { | 89 InterfaceRequest<Interface> Unbind() { |
| 91 InterfaceRequest<Interface> request = | 90 InterfaceRequest<Interface> request = |
| 92 MakeRequest<Interface>(router_->PassMessagePipe()); | 91 MakeRequest<Interface>(router_->PassMessagePipe()); |
| 93 DestroyRouter(); | 92 DestroyRouter(); |
| 94 return std::move(request); | 93 return std::move(request); |
| 95 } | 94 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 132 |
| 134 // Uses a multiplexing router. If |Interface| has methods to pass associated | 133 // Uses a multiplexing router. If |Interface| has methods to pass associated |
| 135 // interface pointers or requests, this specialization should be used. | 134 // interface pointers or requests, this specialization should be used. |
| 136 template <typename Interface> | 135 template <typename Interface> |
| 137 class BindingState<Interface, true> { | 136 class BindingState<Interface, true> { |
| 138 public: | 137 public: |
| 139 explicit BindingState(Interface* impl) : impl_(impl) { | 138 explicit BindingState(Interface* impl) : impl_(impl) { |
| 140 stub_.set_sink(impl_); | 139 stub_.set_sink(impl_); |
| 141 } | 140 } |
| 142 | 141 |
| 143 ~BindingState() { | 142 ~BindingState() { Close(); } |
| 144 if (router_) | |
| 145 Close(); | |
| 146 } | |
| 147 | 143 |
| 148 void Bind(ScopedMessagePipeHandle handle, | 144 void Bind(ScopedMessagePipeHandle handle, |
| 149 scoped_refptr<base::SingleThreadTaskRunner> runner) { | 145 scoped_refptr<base::SingleThreadTaskRunner> runner) { |
| 150 DCHECK(!router_); | 146 DCHECK(!router_); |
| 151 | 147 |
| 152 router_ = new internal::MultiplexRouter(false, std::move(handle), runner); | 148 router_ = new internal::MultiplexRouter(false, std::move(handle), runner); |
| 153 stub_.serialization_context()->router = router_; | 149 stub_.serialization_context()->router = router_; |
| 154 | 150 |
| 155 endpoint_client_.reset(new internal::InterfaceEndpointClient( | 151 endpoint_client_.reset(new internal::InterfaceEndpointClient( |
| 156 router_->CreateLocalEndpointHandle(internal::kMasterInterfaceId), | 152 router_->CreateLocalEndpointHandle(internal::kMasterInterfaceId), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 174 router_->ResumeIncomingMethodCallProcessing(); | 170 router_->ResumeIncomingMethodCallProcessing(); |
| 175 } | 171 } |
| 176 | 172 |
| 177 bool WaitForIncomingMethodCall( | 173 bool WaitForIncomingMethodCall( |
| 178 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE) { | 174 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE) { |
| 179 DCHECK(router_); | 175 DCHECK(router_); |
| 180 return router_->WaitForIncomingMessage(deadline); | 176 return router_->WaitForIncomingMessage(deadline); |
| 181 } | 177 } |
| 182 | 178 |
| 183 void Close() { | 179 void Close() { |
| 184 DCHECK(router_); | 180 if (!router_) |
| 181 return; |
| 182 |
| 185 endpoint_client_.reset(); | 183 endpoint_client_.reset(); |
| 186 router_->CloseMessagePipe(); | 184 router_->CloseMessagePipe(); |
| 187 router_ = nullptr; | 185 router_ = nullptr; |
| 188 connection_error_handler_.reset(); | 186 connection_error_handler_.reset(); |
| 189 } | 187 } |
| 190 | 188 |
| 191 InterfaceRequest<Interface> Unbind() { | 189 InterfaceRequest<Interface> Unbind() { |
| 192 endpoint_client_.reset(); | 190 endpoint_client_.reset(); |
| 193 InterfaceRequest<Interface> request = | 191 InterfaceRequest<Interface> request = |
| 194 MakeRequest<Interface>(router_->PassMessagePipe()); | 192 MakeRequest<Interface>(router_->PassMessagePipe()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 Interface* impl_; | 226 Interface* impl_; |
| 229 Closure connection_error_handler_; | 227 Closure connection_error_handler_; |
| 230 | 228 |
| 231 DISALLOW_COPY_AND_ASSIGN(BindingState); | 229 DISALLOW_COPY_AND_ASSIGN(BindingState); |
| 232 }; | 230 }; |
| 233 | 231 |
| 234 } // namesapce internal | 232 } // namesapce internal |
| 235 } // namespace mojo | 233 } // namespace mojo |
| 236 | 234 |
| 237 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ | 235 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ |
| OLD | NEW |