Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Side by Side Diff: mojo/public/cpp/bindings/lib/binding_state.h

Issue 2276043002: Support custom message filtering on Mojo binding objects (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 12 #include "base/callback.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.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/filter_chain.h"
19 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" 20 #include "mojo/public/cpp/bindings/interface_endpoint_client.h"
20 #include "mojo/public/cpp/bindings/interface_id.h" 21 #include "mojo/public/cpp/bindings/interface_id.h"
21 #include "mojo/public/cpp/bindings/interface_ptr.h" 22 #include "mojo/public/cpp/bindings/interface_ptr.h"
22 #include "mojo/public/cpp/bindings/interface_ptr_info.h" 23 #include "mojo/public/cpp/bindings/interface_ptr_info.h"
23 #include "mojo/public/cpp/bindings/interface_request.h" 24 #include "mojo/public/cpp/bindings/interface_request.h"
24 #include "mojo/public/cpp/bindings/lib/filter_chain.h"
25 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" 25 #include "mojo/public/cpp/bindings/lib/multiplex_router.h"
26 #include "mojo/public/cpp/bindings/lib/router.h" 26 #include "mojo/public/cpp/bindings/lib/router.h"
27 #include "mojo/public/cpp/bindings/message_header_validator.h" 27 #include "mojo/public/cpp/bindings/message_header_validator.h"
28 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" 28 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
29 #include "mojo/public/cpp/system/core.h" 29 #include "mojo/public/cpp/system/core.h"
30 30
31 namespace mojo { 31 namespace mojo {
32 namespace internal { 32 namespace internal {
33 33
34 // Base class used for templated binding primitives which bind a pipe 34 // Base class used for templated binding primitives which bind a pipe
35 // exclusively to a single interface. 35 // exclusively to a single interface.
36 class SimpleBindingState { 36 class SimpleBindingState {
37 public: 37 public:
38 SimpleBindingState(); 38 SimpleBindingState();
39 ~SimpleBindingState(); 39 ~SimpleBindingState();
40 40
41 void AddFilter(std::unique_ptr<MessageReceiver> filter);
42
41 bool HasAssociatedInterfaces() const { return false; } 43 bool HasAssociatedInterfaces() const { return false; }
42 44
43 void PauseIncomingMethodCallProcessing(); 45 void PauseIncomingMethodCallProcessing();
44 void ResumeIncomingMethodCallProcessing(); 46 void ResumeIncomingMethodCallProcessing();
45 47
46 bool WaitForIncomingMethodCall( 48 bool WaitForIncomingMethodCall(
47 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE); 49 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE);
48 50
49 void Close(); 51 void Close();
50 52
(...skipping 10 matching lines...) Expand all
61 } 63 }
62 64
63 AssociatedGroup* associated_group() { return nullptr; } 65 AssociatedGroup* associated_group() { return nullptr; }
64 66
65 void EnableTestingMode(); 67 void EnableTestingMode();
66 68
67 protected: 69 protected:
68 void BindInternal(ScopedMessagePipeHandle handle, 70 void BindInternal(ScopedMessagePipeHandle handle,
69 scoped_refptr<base::SingleThreadTaskRunner> runner, 71 scoped_refptr<base::SingleThreadTaskRunner> runner,
70 const char* interface_name, 72 const char* interface_name,
71 MessageFilter* request_validator, 73 std::unique_ptr<MessageReceiver> request_validator,
72 bool has_sync_methods, 74 bool has_sync_methods,
73 MessageReceiverWithResponderStatus* stub); 75 MessageReceiverWithResponderStatus* stub);
74 76
75 void DestroyRouter(); 77 void DestroyRouter();
76 78
77 internal::Router* router_ = nullptr; 79 internal::Router* router_ = nullptr;
78 base::Closure connection_error_handler_; 80 base::Closure connection_error_handler_;
79 81
80 private: 82 private:
81 void RunConnectionErrorHandler(); 83 void RunConnectionErrorHandler();
(...skipping 11 matching lines...) Expand all
93 public: 95 public:
94 explicit BindingState(Interface* impl) : impl_(impl) { 96 explicit BindingState(Interface* impl) : impl_(impl) {
95 stub_.set_sink(impl_); 97 stub_.set_sink(impl_);
96 } 98 }
97 99
98 ~BindingState() { Close(); } 100 ~BindingState() { Close(); }
99 101
100 void Bind(ScopedMessagePipeHandle handle, 102 void Bind(ScopedMessagePipeHandle handle,
101 scoped_refptr<base::SingleThreadTaskRunner> runner) { 103 scoped_refptr<base::SingleThreadTaskRunner> runner) {
102 DCHECK(!router_); 104 DCHECK(!router_);
103 SimpleBindingState::BindInternal(std::move(handle), runner, 105 SimpleBindingState::BindInternal(
104 Interface::Name_, new 106 std::move(handle), runner, Interface::Name_,
105 typename Interface::RequestValidator_(), 107 base::MakeUnique<typename Interface::RequestValidator_>(),
106 Interface::HasSyncMethods_, &stub_); 108 Interface::HasSyncMethods_, &stub_);
107 } 109 }
108 110
109 InterfaceRequest<Interface> Unbind() { 111 InterfaceRequest<Interface> Unbind() {
110 InterfaceRequest<Interface> request = 112 InterfaceRequest<Interface> request =
111 MakeRequest<Interface>(router_->PassMessagePipe()); 113 MakeRequest<Interface>(router_->PassMessagePipe());
112 DestroyRouter(); 114 DestroyRouter();
113 return std::move(request); 115 return std::move(request);
114 } 116 }
115 117
116 Interface* impl() { return impl_; } 118 Interface* impl() { return impl_; }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 AssociatedGroup* associated_group() { 156 AssociatedGroup* associated_group() {
155 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; 157 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr;
156 } 158 }
157 159
158 void EnableTestingMode(); 160 void EnableTestingMode();
159 161
160 protected: 162 protected:
161 void BindInternal(ScopedMessagePipeHandle handle, 163 void BindInternal(ScopedMessagePipeHandle handle,
162 scoped_refptr<base::SingleThreadTaskRunner> runner, 164 scoped_refptr<base::SingleThreadTaskRunner> runner,
163 const char* interface_name, 165 const char* interface_name,
164 std::unique_ptr<MessageFilter> request_validator, 166 std::unique_ptr<MessageReceiver> request_validator,
165 bool has_sync_methods, 167 bool has_sync_methods,
166 MessageReceiverWithResponderStatus* stub); 168 MessageReceiverWithResponderStatus* stub);
167 169
168 scoped_refptr<internal::MultiplexRouter> router_; 170 scoped_refptr<internal::MultiplexRouter> router_;
169 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; 171 std::unique_ptr<InterfaceEndpointClient> endpoint_client_;
170 base::Closure connection_error_handler_; 172 base::Closure connection_error_handler_;
171 173
172 private: 174 private:
173 void RunConnectionErrorHandler(); 175 void RunConnectionErrorHandler();
174 }; 176 };
175 177
176 // Uses a multiplexing router. If |Interface| has methods to pass associated 178 // Uses a multiplexing router. If |Interface| has methods to pass associated
177 // interface pointers or requests, this specialization should be used. 179 // interface pointers or requests, this specialization should be used.
178 template <typename Interface> 180 template <typename Interface>
179 class BindingState<Interface, true> : public MultiplexedBindingState { 181 class BindingState<Interface, true> : public MultiplexedBindingState {
180 public: 182 public:
181 explicit BindingState(Interface* impl) : impl_(impl) { 183 explicit BindingState(Interface* impl) : impl_(impl) {
182 stub_.set_sink(impl_); 184 stub_.set_sink(impl_);
183 } 185 }
184 186
185 ~BindingState() { Close(); } 187 ~BindingState() { Close(); }
186 188
187 void Bind(ScopedMessagePipeHandle handle, 189 void Bind(ScopedMessagePipeHandle handle,
188 scoped_refptr<base::SingleThreadTaskRunner> runner) { 190 scoped_refptr<base::SingleThreadTaskRunner> runner) {
189 MultiplexedBindingState::BindInternal( 191 MultiplexedBindingState::BindInternal(
190 std::move(handle), runner, Interface::Name_, 192 std::move(handle), runner, Interface::Name_,
191 base::WrapUnique(new typename Interface::RequestValidator_()), 193 base::MakeUnique<typename Interface::RequestValidator_>(),
192 Interface::HasSyncMethods_, &stub_); 194 Interface::HasSyncMethods_, &stub_);
193 stub_.serialization_context()->group_controller = router_; 195 stub_.serialization_context()->group_controller = router_;
194 } 196 }
195 197
196 InterfaceRequest<Interface> Unbind() { 198 InterfaceRequest<Interface> Unbind() {
197 endpoint_client_.reset(); 199 endpoint_client_.reset();
198 InterfaceRequest<Interface> request = 200 InterfaceRequest<Interface> request =
199 MakeRequest<Interface>(router_->PassMessagePipe()); 201 MakeRequest<Interface>(router_->PassMessagePipe());
200 router_ = nullptr; 202 router_ = nullptr;
201 connection_error_handler_.Reset(); 203 connection_error_handler_.Reset();
202 return request; 204 return request;
203 } 205 }
204 206
205 Interface* impl() { return impl_; } 207 Interface* impl() { return impl_; }
206 208
207 private: 209 private:
208 typename Interface::Stub_ stub_; 210 typename Interface::Stub_ stub_;
209 Interface* impl_; 211 Interface* impl_;
210 212
211 DISALLOW_COPY_AND_ASSIGN(BindingState); 213 DISALLOW_COPY_AND_ASSIGN(BindingState);
212 }; 214 };
213 215
214 } // namesapce internal 216 } // namesapce internal
215 } // namespace mojo 217 } // namespace mojo
216 218
217 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ 219 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/interface_endpoint_client.h ('k') | mojo/public/cpp/bindings/lib/binding_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698