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/scoped_interface_endpoint_handle.h" | 22 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
23 | 23 |
24 namespace mojo { | 24 namespace mojo { |
25 | 25 |
| 26 class MessageReceiver; |
| 27 |
26 // Represents the implementation side of an associated interface. It is similar | 28 // Represents the implementation side of an associated interface. It is similar |
27 // to Binding, except that it doesn't own a message pipe handle. | 29 // to Binding, except that it doesn't own a message pipe handle. |
28 // | 30 // |
29 // When you bind this class to a request, optionally you can specify a | 31 // When you bind this class to a request, optionally you can specify a |
30 // base::SingleThreadTaskRunner. This task runner must belong to the same | 32 // base::SingleThreadTaskRunner. This task runner must belong to the same |
31 // thread. It will be used to dispatch incoming method calls and connection | 33 // thread. It will be used to dispatch incoming method calls and connection |
32 // error notification. It is useful when you attach multiple task runners to a | 34 // error notification. It is useful when you attach multiple task runners to a |
33 // single thread for the purposes of task scheduling. Please note that incoming | 35 // single thread for the purposes of task scheduling. Please note that incoming |
34 // synchrounous method calls may not be run from this task runner, when they | 36 // synchrounous method calls may not be run from this task runner, when they |
35 // reenter outgoing synchrounous calls on the same thread. | 37 // reenter outgoing synchrounous calls on the same thread. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 base::WrapUnique(new typename Interface::RequestValidator_()), | 105 base::WrapUnique(new typename Interface::RequestValidator_()), |
104 Interface::HasSyncMethods_, std::move(runner))); | 106 Interface::HasSyncMethods_, std::move(runner))); |
105 endpoint_client_->set_connection_error_handler( | 107 endpoint_client_->set_connection_error_handler( |
106 base::Bind(&AssociatedBinding::RunConnectionErrorHandler, | 108 base::Bind(&AssociatedBinding::RunConnectionErrorHandler, |
107 base::Unretained(this))); | 109 base::Unretained(this))); |
108 | 110 |
109 stub_.serialization_context()->group_controller = | 111 stub_.serialization_context()->group_controller = |
110 endpoint_client_->group_controller(); | 112 endpoint_client_->group_controller(); |
111 } | 113 } |
112 | 114 |
| 115 // 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 // dispatched and the pipe is closed. Filters cannot be removed. |
| 118 void AddFilter(std::unique_ptr<MessageReceiver> filter) { |
| 119 DCHECK(endpoint_client_); |
| 120 endpoint_client_->AddFilter(std::move(filter)); |
| 121 } |
| 122 |
113 // Closes the associated interface. Puts this object into a state where it can | 123 // Closes the associated interface. Puts this object into a state where it can |
114 // be rebound. | 124 // be rebound. |
115 void Close() { | 125 void Close() { |
116 DCHECK(endpoint_client_); | 126 DCHECK(endpoint_client_); |
117 endpoint_client_.reset(); | 127 endpoint_client_.reset(); |
118 connection_error_handler_.Reset(); | 128 connection_error_handler_.Reset(); |
119 } | 129 } |
120 | 130 |
121 // Unbinds and returns the associated interface request so it can be | 131 // Unbinds and returns the associated interface request so it can be |
122 // used in another context, such as on another thread or with a different | 132 // used in another context, such as on another thread or with a different |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 typename Interface::Stub_ stub_; | 176 typename Interface::Stub_ stub_; |
167 Interface* impl_; | 177 Interface* impl_; |
168 base::Closure connection_error_handler_; | 178 base::Closure connection_error_handler_; |
169 | 179 |
170 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding); | 180 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding); |
171 }; | 181 }; |
172 | 182 |
173 } // namespace mojo | 183 } // namespace mojo |
174 | 184 |
175 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ | 185 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ |
OLD | NEW |