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