| 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" | |
| 13 #include "base/logging.h" | 12 #include "base/logging.h" |
| 14 #include "base/macros.h" | 13 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 17 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 18 #include "mojo/public/cpp/bindings/associated_group.h" | 17 #include "mojo/public/cpp/bindings/associated_group.h" |
| 18 #include "mojo/public/cpp/bindings/callback.h" |
| 19 #include "mojo/public/cpp/bindings/interface_ptr.h" | 19 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 20 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 20 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
| 21 #include "mojo/public/cpp/bindings/interface_request.h" | 21 #include "mojo/public/cpp/bindings/interface_request.h" |
| 22 #include "mojo/public/cpp/bindings/lib/filter_chain.h" | 22 #include "mojo/public/cpp/bindings/lib/filter_chain.h" |
| 23 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h" | 23 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h" |
| 24 #include "mojo/public/cpp/bindings/lib/interface_id.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" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 DestroyRouter(); | 88 DestroyRouter(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 InterfaceRequest<Interface> Unbind() { | 91 InterfaceRequest<Interface> Unbind() { |
| 92 InterfaceRequest<Interface> request = | 92 InterfaceRequest<Interface> request = |
| 93 MakeRequest<Interface>(router_->PassMessagePipe()); | 93 MakeRequest<Interface>(router_->PassMessagePipe()); |
| 94 DestroyRouter(); | 94 DestroyRouter(); |
| 95 return std::move(request); | 95 return std::move(request); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void set_connection_error_handler(const base::Closure& error_handler) { | 98 void set_connection_error_handler(const Closure& error_handler) { |
| 99 DCHECK(is_bound()); | 99 DCHECK(is_bound()); |
| 100 connection_error_handler_ = error_handler; | 100 connection_error_handler_ = error_handler; |
| 101 } | 101 } |
| 102 | 102 |
| 103 Interface* impl() { return impl_; } | 103 Interface* impl() { return impl_; } |
| 104 | 104 |
| 105 bool is_bound() const { return !!router_; } | 105 bool is_bound() const { return !!router_; } |
| 106 | 106 |
| 107 MessagePipeHandle handle() const { | 107 MessagePipeHandle handle() const { |
| 108 DCHECK(is_bound()); | 108 DCHECK(is_bound()); |
| 109 return router_->handle(); | 109 return router_->handle(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 AssociatedGroup* associated_group() { return nullptr; } | 112 AssociatedGroup* associated_group() { return nullptr; } |
| 113 | 113 |
| 114 void EnableTestingMode() { | 114 void EnableTestingMode() { |
| 115 DCHECK(is_bound()); | 115 DCHECK(is_bound()); |
| 116 router_->EnableTestingMode(); | 116 router_->EnableTestingMode(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 private: | 119 private: |
| 120 void DestroyRouter() { | 120 void DestroyRouter() { |
| 121 router_->set_connection_error_handler(base::Closure()); | 121 router_->set_connection_error_handler(Closure()); |
| 122 delete router_; | 122 delete router_; |
| 123 router_ = nullptr; | 123 router_ = nullptr; |
| 124 connection_error_handler_.Reset(); | 124 connection_error_handler_.Reset(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void RunConnectionErrorHandler() { | 127 void RunConnectionErrorHandler() { |
| 128 if (!connection_error_handler_.is_null()) | 128 if (!connection_error_handler_.is_null()) |
| 129 connection_error_handler_.Run(); | 129 connection_error_handler_.Run(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 internal::Router* router_ = nullptr; | 132 internal::Router* router_ = nullptr; |
| 133 typename Interface::Stub_ stub_; | 133 typename Interface::Stub_ stub_; |
| 134 Interface* impl_; | 134 Interface* impl_; |
| 135 base::Closure connection_error_handler_; | 135 Closure connection_error_handler_; |
| 136 | 136 |
| 137 DISALLOW_COPY_AND_ASSIGN(BindingState); | 137 DISALLOW_COPY_AND_ASSIGN(BindingState); |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 // Uses a multiplexing router. If |Interface| has methods to pass associated | 140 // Uses a multiplexing router. If |Interface| has methods to pass associated |
| 141 // interface pointers or requests, this specialization should be used. | 141 // interface pointers or requests, this specialization should be used. |
| 142 template <typename Interface> | 142 template <typename Interface> |
| 143 class BindingState<Interface, true> { | 143 class BindingState<Interface, true> { |
| 144 public: | 144 public: |
| 145 explicit BindingState(Interface* impl) : impl_(impl) { | 145 explicit BindingState(Interface* impl) : impl_(impl) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 197 |
| 198 InterfaceRequest<Interface> Unbind() { | 198 InterfaceRequest<Interface> Unbind() { |
| 199 endpoint_client_.reset(); | 199 endpoint_client_.reset(); |
| 200 InterfaceRequest<Interface> request = | 200 InterfaceRequest<Interface> request = |
| 201 MakeRequest<Interface>(router_->PassMessagePipe()); | 201 MakeRequest<Interface>(router_->PassMessagePipe()); |
| 202 router_ = nullptr; | 202 router_ = nullptr; |
| 203 connection_error_handler_.Reset(); | 203 connection_error_handler_.Reset(); |
| 204 return request; | 204 return request; |
| 205 } | 205 } |
| 206 | 206 |
| 207 void set_connection_error_handler(const base::Closure& error_handler) { | 207 void set_connection_error_handler(const Closure& error_handler) { |
| 208 DCHECK(is_bound()); | 208 DCHECK(is_bound()); |
| 209 connection_error_handler_ = error_handler; | 209 connection_error_handler_ = error_handler; |
| 210 } | 210 } |
| 211 | 211 |
| 212 Interface* impl() { return impl_; } | 212 Interface* impl() { return impl_; } |
| 213 | 213 |
| 214 bool is_bound() const { return !!router_; } | 214 bool is_bound() const { return !!router_; } |
| 215 | 215 |
| 216 MessagePipeHandle handle() const { | 216 MessagePipeHandle handle() const { |
| 217 DCHECK(is_bound()); | 217 DCHECK(is_bound()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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<internal::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 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 |