| 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 <utility> |
| 9 |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "mojo/public/c/environment/async_waiter.h" | 14 #include "mojo/public/c/environment/async_waiter.h" |
| 13 #include "mojo/public/cpp/bindings/associated_group.h" | 15 #include "mojo/public/cpp/bindings/associated_group.h" |
| 14 #include "mojo/public/cpp/bindings/callback.h" | 16 #include "mojo/public/cpp/bindings/callback.h" |
| 15 #include "mojo/public/cpp/bindings/interface_ptr.h" | 17 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 16 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 18 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
| 17 #include "mojo/public/cpp/bindings/interface_request.h" | 19 #include "mojo/public/cpp/bindings/interface_request.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 47 if (router_) | 49 if (router_) |
| 48 Close(); | 50 Close(); |
| 49 } | 51 } |
| 50 | 52 |
| 51 void Bind(ScopedMessagePipeHandle handle, const MojoAsyncWaiter* waiter) { | 53 void Bind(ScopedMessagePipeHandle handle, const MojoAsyncWaiter* waiter) { |
| 52 DCHECK(!router_); | 54 DCHECK(!router_); |
| 53 internal::FilterChain filters; | 55 internal::FilterChain filters; |
| 54 filters.Append<internal::MessageHeaderValidator>(); | 56 filters.Append<internal::MessageHeaderValidator>(); |
| 55 filters.Append<typename Interface::RequestValidator_>(); | 57 filters.Append<typename Interface::RequestValidator_>(); |
| 56 | 58 |
| 57 router_ = new internal::Router(handle.Pass(), filters.Pass(), waiter); | 59 router_ = |
| 60 new internal::Router(std::move(handle), std::move(filters), waiter); |
| 58 router_->set_incoming_receiver(&stub_); | 61 router_->set_incoming_receiver(&stub_); |
| 59 router_->set_connection_error_handler( | 62 router_->set_connection_error_handler( |
| 60 [this]() { connection_error_handler_.Run(); }); | 63 [this]() { connection_error_handler_.Run(); }); |
| 61 } | 64 } |
| 62 | 65 |
| 63 bool HasAssociatedInterfaces() const { return false; } | 66 bool HasAssociatedInterfaces() const { return false; } |
| 64 | 67 |
| 65 void PauseIncomingMethodCallProcessing() { | 68 void PauseIncomingMethodCallProcessing() { |
| 66 DCHECK(router_); | 69 DCHECK(router_); |
| 67 router_->PauseIncomingMethodCallProcessing(); | 70 router_->PauseIncomingMethodCallProcessing(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 80 void Close() { | 83 void Close() { |
| 81 DCHECK(router_); | 84 DCHECK(router_); |
| 82 router_->CloseMessagePipe(); | 85 router_->CloseMessagePipe(); |
| 83 DestroyRouter(); | 86 DestroyRouter(); |
| 84 } | 87 } |
| 85 | 88 |
| 86 InterfaceRequest<GenericInterface> Unbind() { | 89 InterfaceRequest<GenericInterface> Unbind() { |
| 87 InterfaceRequest<GenericInterface> request = | 90 InterfaceRequest<GenericInterface> request = |
| 88 MakeRequest<GenericInterface>(router_->PassMessagePipe()); | 91 MakeRequest<GenericInterface>(router_->PassMessagePipe()); |
| 89 DestroyRouter(); | 92 DestroyRouter(); |
| 90 return request.Pass(); | 93 return std::move(request); |
| 91 } | 94 } |
| 92 | 95 |
| 93 void set_connection_error_handler(const Closure& error_handler) { | 96 void set_connection_error_handler(const Closure& error_handler) { |
| 94 DCHECK(is_bound()); | 97 DCHECK(is_bound()); |
| 95 connection_error_handler_ = error_handler; | 98 connection_error_handler_ = error_handler; |
| 96 } | 99 } |
| 97 | 100 |
| 98 Interface* impl() { return impl_; } | 101 Interface* impl() { return impl_; } |
| 99 | 102 |
| 100 bool is_bound() const { return !!router_; } | 103 bool is_bound() const { return !!router_; } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 142 } |
| 140 | 143 |
| 141 ~BindingState() { | 144 ~BindingState() { |
| 142 if (router_) | 145 if (router_) |
| 143 Close(); | 146 Close(); |
| 144 } | 147 } |
| 145 | 148 |
| 146 void Bind(ScopedMessagePipeHandle handle, const MojoAsyncWaiter* waiter) { | 149 void Bind(ScopedMessagePipeHandle handle, const MojoAsyncWaiter* waiter) { |
| 147 DCHECK(!router_); | 150 DCHECK(!router_); |
| 148 | 151 |
| 149 router_ = new internal::MultiplexRouter(false, handle.Pass(), waiter); | 152 router_ = new internal::MultiplexRouter(false, std::move(handle), waiter); |
| 150 stub_.serialization_context()->router = router_; | 153 stub_.serialization_context()->router = router_; |
| 151 | 154 |
| 152 endpoint_client_.reset(new internal::InterfaceEndpointClient( | 155 endpoint_client_.reset(new internal::InterfaceEndpointClient( |
| 153 router_->CreateLocalEndpointHandle(internal::kMasterInterfaceId), | 156 router_->CreateLocalEndpointHandle(internal::kMasterInterfaceId), |
| 154 &stub_, make_scoped_ptr(new typename Interface::RequestValidator_()))); | 157 &stub_, make_scoped_ptr(new typename Interface::RequestValidator_()))); |
| 155 | 158 |
| 156 endpoint_client_->set_connection_error_handler( | 159 endpoint_client_->set_connection_error_handler( |
| 157 [this]() { connection_error_handler_.Run(); }); | 160 [this]() { connection_error_handler_.Run(); }); |
| 158 } | 161 } |
| 159 | 162 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 Interface* impl_; | 227 Interface* impl_; |
| 225 Closure connection_error_handler_; | 228 Closure connection_error_handler_; |
| 226 | 229 |
| 227 DISALLOW_COPY_AND_ASSIGN(BindingState); | 230 DISALLOW_COPY_AND_ASSIGN(BindingState); |
| 228 }; | 231 }; |
| 229 | 232 |
| 230 } // namesapce internal | 233 } // namesapce internal |
| 231 } // namespace mojo | 234 } // namespace mojo |
| 232 | 235 |
| 233 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ | 236 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ |
| OLD | NEW |