| 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 <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 AssociatedGroup* associated_group() { | 173 AssociatedGroup* associated_group() { |
| 174 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; | 174 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; |
| 175 } | 175 } |
| 176 | 176 |
| 177 void FlushForTesting(); | 177 void FlushForTesting(); |
| 178 | 178 |
| 179 void EnableTestingMode(); | 179 void EnableTestingMode(); |
| 180 | 180 |
| 181 protected: | 181 protected: |
| 182 void BindInternal(ScopedMessagePipeHandle handle, | 182 void BindInternal(ScopedMessagePipeHandle handle, |
| 183 MultiplexRouter::Config config, | |
| 184 scoped_refptr<base::SingleThreadTaskRunner> runner, | 183 scoped_refptr<base::SingleThreadTaskRunner> runner, |
| 185 const char* interface_name, | 184 const char* interface_name, |
| 186 std::unique_ptr<MessageReceiver> request_validator, | 185 std::unique_ptr<MessageReceiver> request_validator, |
| 187 bool has_sync_methods, | 186 bool has_sync_methods, |
| 188 MessageReceiverWithResponderStatus* stub, | 187 MessageReceiverWithResponderStatus* stub, |
| 189 uint32_t interface_version); | 188 uint32_t interface_version); |
| 190 | 189 |
| 191 scoped_refptr<internal::MultiplexRouter> router_; | 190 scoped_refptr<internal::MultiplexRouter> router_; |
| 192 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; | 191 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; |
| 193 }; | 192 }; |
| 194 | 193 |
| 195 // Uses a multiplexing router. If |Interface| has methods to pass associated | 194 // Uses a multiplexing router. If |Interface| has methods to pass associated |
| 196 // interface pointers or requests, this specialization should be used. | 195 // interface pointers or requests, this specialization should be used. |
| 197 template <typename Interface> | 196 template <typename Interface> |
| 198 class BindingState<Interface, true> : public MultiplexedBindingState { | 197 class BindingState<Interface, true> : public MultiplexedBindingState { |
| 199 public: | 198 public: |
| 200 explicit BindingState(Interface* impl) : impl_(impl) { | 199 explicit BindingState(Interface* impl) : impl_(impl) { |
| 201 stub_.set_sink(impl_); | 200 stub_.set_sink(impl_); |
| 202 } | 201 } |
| 203 | 202 |
| 204 ~BindingState() { Close(); } | 203 ~BindingState() { Close(); } |
| 205 | 204 |
| 206 void Bind(ScopedMessagePipeHandle handle, | 205 void Bind(ScopedMessagePipeHandle handle, |
| 207 scoped_refptr<base::SingleThreadTaskRunner> runner) { | 206 scoped_refptr<base::SingleThreadTaskRunner> runner) { |
| 208 MultiplexedBindingState::BindInternal( | 207 MultiplexedBindingState::BindInternal( |
| 209 std::move(handle), | 208 std::move(handle), runner, Interface::Name_, |
| 210 Interface::PassesAssociatedKinds_ ? MultiplexRouter::MULTI_INTERFACE | |
| 211 : MultiplexRouter::SINGLE_INTERFACE, | |
| 212 runner, Interface::Name_, | |
| 213 base::MakeUnique<typename Interface::RequestValidator_>(), | 209 base::MakeUnique<typename Interface::RequestValidator_>(), |
| 214 Interface::HasSyncMethods_, &stub_, Interface::Version_); | 210 Interface::HasSyncMethods_, &stub_, Interface::Version_); |
| 215 stub_.serialization_context()->group_controller = router_; | 211 stub_.serialization_context()->group_controller = router_; |
| 216 } | 212 } |
| 217 | 213 |
| 218 InterfaceRequest<Interface> Unbind() { | 214 InterfaceRequest<Interface> Unbind() { |
| 219 endpoint_client_.reset(); | 215 endpoint_client_.reset(); |
| 220 InterfaceRequest<Interface> request = | 216 InterfaceRequest<Interface> request = |
| 221 MakeRequest<Interface>(router_->PassMessagePipe()); | 217 MakeRequest<Interface>(router_->PassMessagePipe()); |
| 222 router_ = nullptr; | 218 router_ = nullptr; |
| 223 return request; | 219 return request; |
| 224 } | 220 } |
| 225 | 221 |
| 226 Interface* impl() { return impl_; } | 222 Interface* impl() { return impl_; } |
| 227 | 223 |
| 228 private: | 224 private: |
| 229 typename Interface::Stub_ stub_; | 225 typename Interface::Stub_ stub_; |
| 230 Interface* impl_; | 226 Interface* impl_; |
| 231 | 227 |
| 232 DISALLOW_COPY_AND_ASSIGN(BindingState); | 228 DISALLOW_COPY_AND_ASSIGN(BindingState); |
| 233 }; | 229 }; |
| 234 | 230 |
| 235 } // namesapce internal | 231 } // namesapce internal |
| 236 } // namespace mojo | 232 } // namespace mojo |
| 237 | 233 |
| 238 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ | 234 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ |
| OLD | NEW |