| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 bool is_bound() const { return !!router_; } | 58 bool is_bound() const { return !!router_; } |
| 59 | 59 |
| 60 MessagePipeHandle handle() const { | 60 MessagePipeHandle handle() const { |
| 61 DCHECK(is_bound()); | 61 DCHECK(is_bound()); |
| 62 return router_->handle(); | 62 return router_->handle(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 AssociatedGroup* associated_group() { return nullptr; } | 65 AssociatedGroup* associated_group() { return nullptr; } |
| 66 | 66 |
| 67 void FlushForTesting(); |
| 68 |
| 67 void EnableTestingMode(); | 69 void EnableTestingMode(); |
| 68 | 70 |
| 69 protected: | 71 protected: |
| 70 void BindInternal(ScopedMessagePipeHandle handle, | 72 void BindInternal(ScopedMessagePipeHandle handle, |
| 71 scoped_refptr<base::SingleThreadTaskRunner> runner, | 73 scoped_refptr<base::SingleThreadTaskRunner> runner, |
| 72 const char* interface_name, | 74 const char* interface_name, |
| 73 std::unique_ptr<MessageReceiver> request_validator, | 75 std::unique_ptr<MessageReceiver> request_validator, |
| 74 bool has_sync_methods, | 76 bool has_sync_methods, |
| 75 MessageReceiverWithResponderStatus* stub); | 77 MessageReceiverWithResponderStatus* stub, |
| 78 uint32_t interface_version); |
| 76 | 79 |
| 77 void DestroyRouter(); | 80 void DestroyRouter(); |
| 78 | 81 |
| 79 internal::Router* router_ = nullptr; | 82 internal::Router* router_ = nullptr; |
| 80 base::Closure connection_error_handler_; | 83 base::Closure connection_error_handler_; |
| 81 | 84 |
| 82 private: | 85 private: |
| 83 void RunConnectionErrorHandler(); | 86 void RunConnectionErrorHandler(); |
| 84 }; | 87 }; |
| 85 | 88 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 98 } | 101 } |
| 99 | 102 |
| 100 ~BindingState() { Close(); } | 103 ~BindingState() { Close(); } |
| 101 | 104 |
| 102 void Bind(ScopedMessagePipeHandle handle, | 105 void Bind(ScopedMessagePipeHandle handle, |
| 103 scoped_refptr<base::SingleThreadTaskRunner> runner) { | 106 scoped_refptr<base::SingleThreadTaskRunner> runner) { |
| 104 DCHECK(!router_); | 107 DCHECK(!router_); |
| 105 SimpleBindingState::BindInternal( | 108 SimpleBindingState::BindInternal( |
| 106 std::move(handle), runner, Interface::Name_, | 109 std::move(handle), runner, Interface::Name_, |
| 107 base::MakeUnique<typename Interface::RequestValidator_>(), | 110 base::MakeUnique<typename Interface::RequestValidator_>(), |
| 108 Interface::HasSyncMethods_, &stub_); | 111 Interface::HasSyncMethods_, &stub_, Interface::Version_); |
| 109 } | 112 } |
| 110 | 113 |
| 111 InterfaceRequest<Interface> Unbind() { | 114 InterfaceRequest<Interface> Unbind() { |
| 112 InterfaceRequest<Interface> request = | 115 InterfaceRequest<Interface> request = |
| 113 MakeRequest<Interface>(router_->PassMessagePipe()); | 116 MakeRequest<Interface>(router_->PassMessagePipe()); |
| 114 DestroyRouter(); | 117 DestroyRouter(); |
| 115 return std::move(request); | 118 return std::move(request); |
| 116 } | 119 } |
| 117 | 120 |
| 118 Interface* impl() { return impl_; } | 121 Interface* impl() { return impl_; } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 155 |
| 153 MessagePipeHandle handle() const { | 156 MessagePipeHandle handle() const { |
| 154 DCHECK(is_bound()); | 157 DCHECK(is_bound()); |
| 155 return router_->handle(); | 158 return router_->handle(); |
| 156 } | 159 } |
| 157 | 160 |
| 158 AssociatedGroup* associated_group() { | 161 AssociatedGroup* associated_group() { |
| 159 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; | 162 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; |
| 160 } | 163 } |
| 161 | 164 |
| 165 void FlushForTesting(); |
| 166 |
| 162 void EnableTestingMode(); | 167 void EnableTestingMode(); |
| 163 | 168 |
| 164 protected: | 169 protected: |
| 165 void BindInternal(ScopedMessagePipeHandle handle, | 170 void BindInternal(ScopedMessagePipeHandle handle, |
| 166 scoped_refptr<base::SingleThreadTaskRunner> runner, | 171 scoped_refptr<base::SingleThreadTaskRunner> runner, |
| 167 const char* interface_name, | 172 const char* interface_name, |
| 168 std::unique_ptr<MessageReceiver> request_validator, | 173 std::unique_ptr<MessageReceiver> request_validator, |
| 169 bool has_sync_methods, | 174 bool has_sync_methods, |
| 170 MessageReceiverWithResponderStatus* stub); | 175 MessageReceiverWithResponderStatus* stub, |
| 176 uint32_t interface_version); |
| 171 | 177 |
| 172 scoped_refptr<internal::MultiplexRouter> router_; | 178 scoped_refptr<internal::MultiplexRouter> router_; |
| 173 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; | 179 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; |
| 174 base::Closure connection_error_handler_; | 180 base::Closure connection_error_handler_; |
| 175 | 181 |
| 176 private: | 182 private: |
| 177 void RunConnectionErrorHandler(); | 183 void RunConnectionErrorHandler(); |
| 178 }; | 184 }; |
| 179 | 185 |
| 180 // Uses a multiplexing router. If |Interface| has methods to pass associated | 186 // Uses a multiplexing router. If |Interface| has methods to pass associated |
| 181 // interface pointers or requests, this specialization should be used. | 187 // interface pointers or requests, this specialization should be used. |
| 182 template <typename Interface> | 188 template <typename Interface> |
| 183 class BindingState<Interface, true> : public MultiplexedBindingState { | 189 class BindingState<Interface, true> : public MultiplexedBindingState { |
| 184 public: | 190 public: |
| 185 explicit BindingState(Interface* impl) : impl_(impl) { | 191 explicit BindingState(Interface* impl) : impl_(impl) { |
| 186 stub_.set_sink(impl_); | 192 stub_.set_sink(impl_); |
| 187 } | 193 } |
| 188 | 194 |
| 189 ~BindingState() { Close(); } | 195 ~BindingState() { Close(); } |
| 190 | 196 |
| 191 void Bind(ScopedMessagePipeHandle handle, | 197 void Bind(ScopedMessagePipeHandle handle, |
| 192 scoped_refptr<base::SingleThreadTaskRunner> runner) { | 198 scoped_refptr<base::SingleThreadTaskRunner> runner) { |
| 193 MultiplexedBindingState::BindInternal( | 199 MultiplexedBindingState::BindInternal( |
| 194 std::move(handle), runner, Interface::Name_, | 200 std::move(handle), runner, Interface::Name_, |
| 195 base::MakeUnique<typename Interface::RequestValidator_>(), | 201 base::MakeUnique<typename Interface::RequestValidator_>(), |
| 196 Interface::HasSyncMethods_, &stub_); | 202 Interface::HasSyncMethods_, &stub_, Interface::Version_); |
| 197 stub_.serialization_context()->group_controller = router_; | 203 stub_.serialization_context()->group_controller = router_; |
| 198 } | 204 } |
| 199 | 205 |
| 200 InterfaceRequest<Interface> Unbind() { | 206 InterfaceRequest<Interface> Unbind() { |
| 201 endpoint_client_.reset(); | 207 endpoint_client_.reset(); |
| 202 InterfaceRequest<Interface> request = | 208 InterfaceRequest<Interface> request = |
| 203 MakeRequest<Interface>(router_->PassMessagePipe()); | 209 MakeRequest<Interface>(router_->PassMessagePipe()); |
| 204 router_ = nullptr; | 210 router_ = nullptr; |
| 205 connection_error_handler_.Reset(); | 211 connection_error_handler_.Reset(); |
| 206 return request; | 212 return request; |
| 207 } | 213 } |
| 208 | 214 |
| 209 Interface* impl() { return impl_; } | 215 Interface* impl() { return impl_; } |
| 210 | 216 |
| 211 private: | 217 private: |
| 212 typename Interface::Stub_ stub_; | 218 typename Interface::Stub_ stub_; |
| 213 Interface* impl_; | 219 Interface* impl_; |
| 214 | 220 |
| 215 DISALLOW_COPY_AND_ASSIGN(BindingState); | 221 DISALLOW_COPY_AND_ASSIGN(BindingState); |
| 216 }; | 222 }; |
| 217 | 223 |
| 218 } // namesapce internal | 224 } // namesapce internal |
| 219 } // namespace mojo | 225 } // namespace mojo |
| 220 | 226 |
| 221 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ | 227 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ |
| OLD | NEW |