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_ASSOCIATED_BINDING_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 // dispatch. If a filter returns |false| from Accept(), the message is not | 120 // dispatch. If a filter returns |false| from Accept(), the message is not |
121 // dispatched and the pipe is closed. Filters cannot be removed. | 121 // dispatched and the pipe is closed. Filters cannot be removed. |
122 void AddFilter(std::unique_ptr<MessageReceiver> filter) { | 122 void AddFilter(std::unique_ptr<MessageReceiver> filter) { |
123 DCHECK(endpoint_client_); | 123 DCHECK(endpoint_client_); |
124 endpoint_client_->AddFilter(std::move(filter)); | 124 endpoint_client_->AddFilter(std::move(filter)); |
125 } | 125 } |
126 | 126 |
127 // Closes the associated interface. Puts this object into a state where it can | 127 // Closes the associated interface. Puts this object into a state where it can |
128 // be rebound. | 128 // be rebound. |
129 void Close() { | 129 void Close() { |
130 DCHECK(endpoint_client_); | |
131 endpoint_client_.reset(); | 130 endpoint_client_.reset(); |
132 } | 131 } |
133 | 132 |
134 // Similar to the method above, but also specifies a disconnect reason. | 133 // Similar to the method above, but also specifies a disconnect reason. |
135 void CloseWithReason(uint32_t custom_reason, const std::string& description) { | 134 void CloseWithReason(uint32_t custom_reason, const std::string& description) { |
136 DCHECK(endpoint_client_); | 135 if (endpoint_client_) |
137 endpoint_client_->control_message_proxy()->SendDisconnectReason( | 136 endpoint_client_->CloseWithReason(custom_reason, description); |
138 custom_reason, description); | |
139 Close(); | 137 Close(); |
140 } | 138 } |
141 | 139 |
142 // Unbinds and returns the associated interface request so it can be | 140 // Unbinds and returns the associated interface request so it can be |
143 // used in another context, such as on another thread or with a different | 141 // used in another context, such as on another thread or with a different |
144 // implementation. Puts this object into a state where it can be rebound. | 142 // implementation. Puts this object into a state where it can be rebound. |
145 AssociatedInterfaceRequest<Interface> Unbind() { | 143 AssociatedInterfaceRequest<Interface> Unbind() { |
146 DCHECK(endpoint_client_); | 144 DCHECK(endpoint_client_); |
147 | 145 |
148 AssociatedInterfaceRequest<Interface> request; | 146 AssociatedInterfaceRequest<Interface> request; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 private: | 190 private: |
193 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; | 191 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; |
194 typename Interface::template Stub_<ImplRefTraits> stub_; | 192 typename Interface::template Stub_<ImplRefTraits> stub_; |
195 | 193 |
196 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding); | 194 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding); |
197 }; | 195 }; |
198 | 196 |
199 } // namespace mojo | 197 } // namespace mojo |
200 | 198 |
201 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ | 199 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ |
OLD | NEW |