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

Side by Side Diff: mojo/public/cpp/bindings/associated_binding.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, 3 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
« no previous file with comments | « mojo/public/cpp/bindings/BUILD.gn ('k') | mojo/public/cpp/bindings/binding.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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
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
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_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/BUILD.gn ('k') | mojo/public/cpp/bindings/binding.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698