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

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

Issue 2280483002: Add FlushForTesting to InterfacePtr and Binding. (Closed)
Patch Set: 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_INTERFACE_PTR_STATE_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> // For |std::swap()|. 10 #include <algorithm> // For |std::swap()|.
11 #include <memory> 11 #include <memory>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/callback_forward.h" 15 #include "base/callback_forward.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
19 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
20 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
21 #include "mojo/public/cpp/bindings/associated_group.h" 21 #include "mojo/public/cpp/bindings/associated_group.h"
22 #include "mojo/public/cpp/bindings/filter_chain.h" 22 #include "mojo/public/cpp/bindings/filter_chain.h"
23 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" 23 #include "mojo/public/cpp/bindings/interface_endpoint_client.h"
24 #include "mojo/public/cpp/bindings/interface_id.h" 24 #include "mojo/public/cpp/bindings/interface_id.h"
25 #include "mojo/public/cpp/bindings/interface_ptr_info.h" 25 #include "mojo/public/cpp/bindings/interface_ptr_info.h"
26 #include "mojo/public/cpp/bindings/lib/control_message_handler.h"
26 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" 27 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h"
27 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" 28 #include "mojo/public/cpp/bindings/lib/multiplex_router.h"
28 #include "mojo/public/cpp/bindings/lib/router.h" 29 #include "mojo/public/cpp/bindings/lib/router.h"
29 #include "mojo/public/cpp/bindings/message_header_validator.h" 30 #include "mojo/public/cpp/bindings/message_header_validator.h"
30 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" 31 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
31 32
32 namespace mojo { 33 namespace mojo {
33 namespace internal { 34 namespace internal {
34 35
35 template <typename Interface, bool use_multiplex_router> 36 template <typename Interface, bool use_multiplex_router>
(...skipping 21 matching lines...) Expand all
57 58
58 // This will be null if the object is not bound. 59 // This will be null if the object is not bound.
59 return proxy_; 60 return proxy_;
60 } 61 }
61 62
62 uint32_t version() const { return version_; } 63 uint32_t version() const { return version_; }
63 64
64 void QueryVersion(const base::Callback<void(uint32_t)>& callback) { 65 void QueryVersion(const base::Callback<void(uint32_t)>& callback) {
65 ConfigureProxyIfNecessary(); 66 ConfigureProxyIfNecessary();
66 67
67 // Do a static cast in case the interface contains methods with the same 68 // It is safe to capture |this| because the callback won't be run after this
68 // name. It is safe to capture |this| because the callback won't be run 69 // object goes away.
69 // after this object goes away. 70 router_->control_message_proxy()->QueryVersion(base::Bind(
70 static_cast<ControlMessageProxy*>(proxy_)->QueryVersion( 71 &InterfacePtrState::OnQueryVersion, base::Unretained(this), callback));
71 base::Bind(&InterfacePtrState::OnQueryVersion, base::Unretained(this),
72 callback));
73 } 72 }
74 73
75 void RequireVersion(uint32_t version) { 74 void RequireVersion(uint32_t version) {
76 ConfigureProxyIfNecessary(); 75 ConfigureProxyIfNecessary();
77 76
78 if (version <= version_) 77 if (version <= version_)
79 return; 78 return;
80 79
81 version_ = version; 80 version_ = version;
82 // Do a static cast in case the interface contains methods with the same 81 router_->control_message_proxy()->RequireVersion(version);
83 // name. 82 }
84 static_cast<ControlMessageProxy*>(proxy_)->RequireVersion(version); 83
84 void FlushForTesting() {
85 ConfigureProxyIfNecessary();
86
87 if (encountered_error() || !router_)
88 return;
89
90 router_->control_message_proxy()->FlushForTesting();
85 } 91 }
86 92
87 void Swap(InterfacePtrState* other) { 93 void Swap(InterfacePtrState* other) {
88 using std::swap; 94 using std::swap;
89 swap(other->proxy_, proxy_); 95 swap(other->proxy_, proxy_);
90 swap(other->router_, router_); 96 swap(other->router_, router_);
91 handle_.swap(other->handle_); 97 handle_.swap(other->handle_);
92 runner_.swap(other->runner_); 98 runner_.swap(other->runner_);
93 swap(other->version_, version_); 99 swap(other->version_, version_);
94 } 100 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 157 }
152 // The object hasn't been bound. 158 // The object hasn't been bound.
153 if (!handle_.is_valid()) 159 if (!handle_.is_valid())
154 return; 160 return;
155 161
156 FilterChain filters; 162 FilterChain filters;
157 filters.Append<MessageHeaderValidator>(Interface::Name_); 163 filters.Append<MessageHeaderValidator>(Interface::Name_);
158 filters.Append<typename Interface::ResponseValidator_>(); 164 filters.Append<typename Interface::ResponseValidator_>();
159 165
160 router_ = new Router(std::move(handle_), std::move(filters), false, 166 router_ = new Router(std::move(handle_), std::move(filters), false,
161 std::move(runner_)); 167 std::move(runner_), 0);
162 168
163 proxy_ = new Proxy(router_); 169 proxy_ = new Proxy(router_);
164 } 170 }
165 171
166 void OnQueryVersion(const base::Callback<void(uint32_t)>& callback, 172 void OnQueryVersion(const base::Callback<void(uint32_t)>& callback,
167 uint32_t version) { 173 uint32_t version) {
168 version_ = version; 174 version_ = version;
169 callback.Run(version); 175 callback.Run(version);
170 } 176 }
171 177
(...skipping 30 matching lines...) Expand all
202 208
203 // This will be null if the object is not bound. 209 // This will be null if the object is not bound.
204 return proxy_.get(); 210 return proxy_.get();
205 } 211 }
206 212
207 uint32_t version() const { return version_; } 213 uint32_t version() const { return version_; }
208 214
209 void QueryVersion(const base::Callback<void(uint32_t)>& callback) { 215 void QueryVersion(const base::Callback<void(uint32_t)>& callback) {
210 ConfigureProxyIfNecessary(); 216 ConfigureProxyIfNecessary();
211 217
212 218 // It is safe to capture |this| because the callback won't be run after this
213 // Do a static cast in case the interface contains methods with the same 219 // object goes away.
214 // name. It is safe to capture |this| because the callback won't be run 220 endpoint_client_->control_message_proxy()->QueryVersion(base::Bind(
215 // after this object goes away. 221 &InterfacePtrState::OnQueryVersion, base::Unretained(this), callback));
216 static_cast<ControlMessageProxy*>(proxy_.get())->QueryVersion(
217 base::Bind(&InterfacePtrState::OnQueryVersion, base::Unretained(this),
218 callback));
219 } 222 }
220 223
221 void RequireVersion(uint32_t version) { 224 void RequireVersion(uint32_t version) {
222 ConfigureProxyIfNecessary(); 225 ConfigureProxyIfNecessary();
223 226
224 if (version <= version_) 227 if (version <= version_)
225 return; 228 return;
226 229
227 version_ = version; 230 version_ = version;
228 // Do a static cast in case the interface contains methods with the same 231 endpoint_client_->control_message_proxy()->RequireVersion(version);
229 // name. 232 }
230 static_cast<ControlMessageProxy*>(proxy_.get())->RequireVersion(version); 233
234 void FlushForTesting() {
235 ConfigureProxyIfNecessary();
236
237 if (encountered_error() || !proxy_)
238 return;
239
240 endpoint_client_->control_message_proxy()->FlushForTesting();
231 } 241 }
232 242
233 void Swap(InterfacePtrState* other) { 243 void Swap(InterfacePtrState* other) {
234 using std::swap; 244 using std::swap;
235 swap(other->router_, router_); 245 swap(other->router_, router_);
236 swap(other->endpoint_client_, endpoint_client_); 246 swap(other->endpoint_client_, endpoint_client_);
237 swap(other->proxy_, proxy_); 247 swap(other->proxy_, proxy_);
238 handle_.swap(other->handle_); 248 handle_.swap(other->handle_);
239 runner_.swap(other->runner_); 249 runner_.swap(other->runner_);
240 swap(other->version_, version_); 250 swap(other->version_, version_);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } 317 }
308 // The object hasn't been bound. 318 // The object hasn't been bound.
309 if (!handle_.is_valid()) 319 if (!handle_.is_valid())
310 return; 320 return;
311 321
312 router_ = new MultiplexRouter(true, std::move(handle_), runner_); 322 router_ = new MultiplexRouter(true, std::move(handle_), runner_);
313 router_->SetMasterInterfaceName(Interface::Name_); 323 router_->SetMasterInterfaceName(Interface::Name_);
314 endpoint_client_.reset(new InterfaceEndpointClient( 324 endpoint_client_.reset(new InterfaceEndpointClient(
315 router_->CreateLocalEndpointHandle(kMasterInterfaceId), nullptr, 325 router_->CreateLocalEndpointHandle(kMasterInterfaceId), nullptr,
316 base::WrapUnique(new typename Interface::ResponseValidator_()), false, 326 base::WrapUnique(new typename Interface::ResponseValidator_()), false,
317 std::move(runner_))); 327 std::move(runner_), 0u));
318 proxy_.reset(new Proxy(endpoint_client_.get())); 328 proxy_.reset(new Proxy(endpoint_client_.get()));
319 proxy_->serialization_context()->group_controller = 329 proxy_->serialization_context()->group_controller =
320 endpoint_client_->group_controller(); 330 endpoint_client_->group_controller();
321 } 331 }
322 332
323 void OnQueryVersion(const base::Callback<void(uint32_t)>& callback, 333 void OnQueryVersion(const base::Callback<void(uint32_t)>& callback,
324 uint32_t version) { 334 uint32_t version) {
325 version_ = version; 335 version_ = version;
326 callback.Run(version); 336 callback.Run(version);
327 } 337 }
(...skipping 11 matching lines...) Expand all
339 349
340 uint32_t version_; 350 uint32_t version_;
341 351
342 DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); 352 DISALLOW_COPY_AND_ASSIGN(InterfacePtrState);
343 }; 353 };
344 354
345 } // namespace internal 355 } // namespace internal
346 } // namespace mojo 356 } // namespace mojo
347 357
348 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_ 358 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698