| 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 <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/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.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/associated_group_controller.h" | 19 #include "mojo/public/cpp/bindings/associated_group_controller.h" |
| 20 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 20 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
| 21 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" | 21 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" |
| 22 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" |
| 22 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 23 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
| 23 | 24 |
| 24 namespace mojo { | 25 namespace mojo { |
| 25 | 26 |
| 26 class MessageReceiver; | 27 class MessageReceiver; |
| 27 | 28 |
| 28 // Represents the implementation side of an associated interface. It is similar | 29 // Represents the implementation side of an associated interface. It is similar |
| 29 // to Binding, except that it doesn't own a message pipe handle. | 30 // to Binding, except that it doesn't own a message pipe handle. |
| 30 // | 31 // |
| 31 // When you bind this class to a request, optionally you can specify a | 32 // When you bind this class to a request, optionally you can specify a |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 << "other side of the message pipe."; | 97 << "other side of the message pipe."; |
| 97 | 98 |
| 98 if (!handle.is_valid() || !handle.is_local()) { | 99 if (!handle.is_valid() || !handle.is_local()) { |
| 99 endpoint_client_.reset(); | 100 endpoint_client_.reset(); |
| 100 return; | 101 return; |
| 101 } | 102 } |
| 102 | 103 |
| 103 endpoint_client_.reset(new InterfaceEndpointClient( | 104 endpoint_client_.reset(new InterfaceEndpointClient( |
| 104 std::move(handle), &stub_, | 105 std::move(handle), &stub_, |
| 105 base::WrapUnique(new typename Interface::RequestValidator_()), | 106 base::WrapUnique(new typename Interface::RequestValidator_()), |
| 106 Interface::HasSyncMethods_, std::move(runner))); | 107 Interface::HasSyncMethods_, std::move(runner), Interface::Version_)); |
| 107 endpoint_client_->set_connection_error_handler( | 108 endpoint_client_->set_connection_error_handler( |
| 108 base::Bind(&AssociatedBinding::RunConnectionErrorHandler, | 109 base::Bind(&AssociatedBinding::RunConnectionErrorHandler, |
| 109 base::Unretained(this))); | 110 base::Unretained(this))); |
| 110 | 111 |
| 111 stub_.serialization_context()->group_controller = | 112 stub_.serialization_context()->group_controller = |
| 112 endpoint_client_->group_controller(); | 113 endpoint_client_->group_controller(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 // Adds a message filter to be notified of each incoming message before | 116 // Adds a message filter to be notified of each incoming message before |
| 116 // dispatch. If a filter returns |false| from Accept(), the message is not | 117 // dispatch. If a filter returns |false| from Accept(), the message is not |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 159 |
| 159 // Indicates whether the associated binding has been completed. | 160 // Indicates whether the associated binding has been completed. |
| 160 bool is_bound() const { return !!endpoint_client_; } | 161 bool is_bound() const { return !!endpoint_client_; } |
| 161 | 162 |
| 162 // Returns the associated group that this object belongs to. Returns null if | 163 // Returns the associated group that this object belongs to. Returns null if |
| 163 // the object is not bound. | 164 // the object is not bound. |
| 164 AssociatedGroup* associated_group() { | 165 AssociatedGroup* associated_group() { |
| 165 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; | 166 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; |
| 166 } | 167 } |
| 167 | 168 |
| 169 // Sends a message on the underlying message pipe and runs the current |
| 170 // message loop until its response is received. This can be used in tests to |
| 171 // verify that no message was sent on a message pipe in response to some |
| 172 // stimulus. |
| 173 void FlushForTesting() { |
| 174 endpoint_client_->control_message_proxy()->FlushForTesting(); |
| 175 } |
| 176 |
| 168 private: | 177 private: |
| 169 void RunConnectionErrorHandler() { | 178 void RunConnectionErrorHandler() { |
| 170 if (!connection_error_handler_.is_null()) | 179 if (!connection_error_handler_.is_null()) |
| 171 connection_error_handler_.Run(); | 180 connection_error_handler_.Run(); |
| 172 } | 181 } |
| 173 | 182 |
| 174 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; | 183 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; |
| 175 | 184 |
| 176 typename Interface::Stub_ stub_; | 185 typename Interface::Stub_ stub_; |
| 177 Interface* impl_; | 186 Interface* impl_; |
| 178 base::Closure connection_error_handler_; | 187 base::Closure connection_error_handler_; |
| 179 | 188 |
| 180 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding); | 189 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding); |
| 181 }; | 190 }; |
| 182 | 191 |
| 183 } // namespace mojo | 192 } // namespace mojo |
| 184 | 193 |
| 185 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ | 194 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ |
| OLD | NEW |