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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
18 #include "mojo/public/cpp/bindings/associated_group.h" | 18 #include "mojo/public/cpp/bindings/associated_group.h" |
| 19 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" |
| 20 #include "mojo/public/cpp/bindings/interface_id.h" |
19 #include "mojo/public/cpp/bindings/interface_ptr.h" | 21 #include "mojo/public/cpp/bindings/interface_ptr.h" |
20 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 22 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
21 #include "mojo/public/cpp/bindings/interface_request.h" | 23 #include "mojo/public/cpp/bindings/interface_request.h" |
22 #include "mojo/public/cpp/bindings/lib/filter_chain.h" | 24 #include "mojo/public/cpp/bindings/lib/filter_chain.h" |
23 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h" | |
24 #include "mojo/public/cpp/bindings/lib/interface_id.h" | |
25 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" | 25 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" |
26 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" | 26 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
27 #include "mojo/public/cpp/bindings/lib/router.h" | 27 #include "mojo/public/cpp/bindings/lib/router.h" |
28 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 28 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
29 #include "mojo/public/cpp/system/core.h" | 29 #include "mojo/public/cpp/system/core.h" |
30 | 30 |
31 namespace mojo { | 31 namespace mojo { |
32 namespace internal { | 32 namespace internal { |
33 | 33 |
34 template <typename Interface, bool use_multiplex_router> | 34 template <typename Interface, bool use_multiplex_router> |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 } | 147 } |
148 | 148 |
149 ~BindingState() { Close(); } | 149 ~BindingState() { Close(); } |
150 | 150 |
151 void Bind(ScopedMessagePipeHandle handle, | 151 void Bind(ScopedMessagePipeHandle handle, |
152 scoped_refptr<base::SingleThreadTaskRunner> runner) { | 152 scoped_refptr<base::SingleThreadTaskRunner> runner) { |
153 DCHECK(!router_); | 153 DCHECK(!router_); |
154 | 154 |
155 router_ = new internal::MultiplexRouter(false, std::move(handle), runner); | 155 router_ = new internal::MultiplexRouter(false, std::move(handle), runner); |
156 router_->SetMasterInterfaceName(Interface::Name_); | 156 router_->SetMasterInterfaceName(Interface::Name_); |
157 stub_.serialization_context()->router = router_; | 157 stub_.serialization_context()->group_controller = router_; |
158 | 158 |
159 endpoint_client_.reset(new internal::InterfaceEndpointClient( | 159 endpoint_client_.reset(new InterfaceEndpointClient( |
160 router_->CreateLocalEndpointHandle(internal::kMasterInterfaceId), | 160 router_->CreateLocalEndpointHandle(kMasterInterfaceId), |
161 &stub_, base::WrapUnique(new typename Interface::RequestValidator_()), | 161 &stub_, base::WrapUnique(new typename Interface::RequestValidator_()), |
162 Interface::HasSyncMethods_, std::move(runner))); | 162 Interface::HasSyncMethods_, std::move(runner))); |
163 | 163 |
164 endpoint_client_->set_connection_error_handler( | 164 endpoint_client_->set_connection_error_handler( |
165 base::Bind(&BindingState::RunConnectionErrorHandler, | 165 base::Bind(&BindingState::RunConnectionErrorHandler, |
166 base::Unretained(this))); | 166 base::Unretained(this))); |
167 } | 167 } |
168 | 168 |
169 bool HasAssociatedInterfaces() const { | 169 bool HasAssociatedInterfaces() const { |
170 return router_ ? router_->HasAssociatedEndpoints() : false; | 170 return router_ ? router_->HasAssociatedEndpoints() : false; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 router_->EnableTestingMode(); | 227 router_->EnableTestingMode(); |
228 } | 228 } |
229 | 229 |
230 private: | 230 private: |
231 void RunConnectionErrorHandler() { | 231 void RunConnectionErrorHandler() { |
232 if (!connection_error_handler_.is_null()) | 232 if (!connection_error_handler_.is_null()) |
233 connection_error_handler_.Run(); | 233 connection_error_handler_.Run(); |
234 } | 234 } |
235 | 235 |
236 scoped_refptr<internal::MultiplexRouter> router_; | 236 scoped_refptr<internal::MultiplexRouter> router_; |
237 std::unique_ptr<internal::InterfaceEndpointClient> endpoint_client_; | 237 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; |
238 | 238 |
239 typename Interface::Stub_ stub_; | 239 typename Interface::Stub_ stub_; |
240 Interface* impl_; | 240 Interface* impl_; |
241 base::Closure connection_error_handler_; | 241 base::Closure connection_error_handler_; |
242 | 242 |
243 DISALLOW_COPY_AND_ASSIGN(BindingState); | 243 DISALLOW_COPY_AND_ASSIGN(BindingState); |
244 }; | 244 }; |
245 | 245 |
246 } // namesapce internal | 246 } // namesapce internal |
247 } // namespace mojo | 247 } // namespace mojo |
248 | 248 |
249 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ | 249 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ |
OLD | NEW |