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

Side by Side Diff: mojo/public/cpp/bindings/lib/interface_endpoint_client.cc

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 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 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" 5 #include "mojo/public/cpp/bindings/interface_endpoint_client.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/location.h" 12 #include "base/location.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/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "mojo/public/cpp/bindings/associated_group.h" 17 #include "mojo/public/cpp/bindings/associated_group.h"
18 #include "mojo/public/cpp/bindings/associated_group_controller.h" 18 #include "mojo/public/cpp/bindings/associated_group_controller.h"
19 #include "mojo/public/cpp/bindings/interface_endpoint_controller.h" 19 #include "mojo/public/cpp/bindings/interface_endpoint_controller.h"
20 #include "mojo/public/cpp/bindings/lib/validation_util.h"
20 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" 21 #include "mojo/public/cpp/bindings/sync_call_restrictions.h"
21 22
22 namespace mojo { 23 namespace mojo {
23 24
24 // ---------------------------------------------------------------------------- 25 // ----------------------------------------------------------------------------
25 26
26 namespace { 27 namespace {
27 28
28 void DCheckIfInvalid(const base::WeakPtr<InterfaceEndpointClient>& client, 29 void DCheckIfInvalid(const base::WeakPtr<InterfaceEndpointClient>& client,
29 const std::string& message) { 30 const std::string& message) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 return owner_->HandleValidatedMessage(message); 128 return owner_->HandleValidatedMessage(message);
128 } 129 }
129 130
130 // ---------------------------------------------------------------------------- 131 // ----------------------------------------------------------------------------
131 132
132 InterfaceEndpointClient::InterfaceEndpointClient( 133 InterfaceEndpointClient::InterfaceEndpointClient(
133 ScopedInterfaceEndpointHandle handle, 134 ScopedInterfaceEndpointHandle handle,
134 MessageReceiverWithResponderStatus* receiver, 135 MessageReceiverWithResponderStatus* receiver,
135 std::unique_ptr<MessageReceiver> payload_validator, 136 std::unique_ptr<MessageReceiver> payload_validator,
136 bool expect_sync_requests, 137 bool expect_sync_requests,
137 scoped_refptr<base::SingleThreadTaskRunner> runner) 138 scoped_refptr<base::SingleThreadTaskRunner> runner,
139 uint32_t interface_version)
138 : handle_(std::move(handle)), 140 : handle_(std::move(handle)),
139 incoming_receiver_(receiver), 141 incoming_receiver_(receiver),
140 thunk_(this), 142 thunk_(this),
141 filters_(&thunk_), 143 filters_(&thunk_),
142 next_request_id_(1), 144 next_request_id_(1),
143 encountered_error_(false), 145 encountered_error_(false),
144 task_runner_(std::move(runner)), 146 task_runner_(std::move(runner)),
147 control_message_proxy_(this),
148 control_message_handler_(interface_version),
145 weak_ptr_factory_(this) { 149 weak_ptr_factory_(this) {
146 DCHECK(handle_.is_valid()); 150 DCHECK(handle_.is_valid());
147 DCHECK(handle_.is_local()); 151 DCHECK(handle_.is_local());
148 152
149 // TODO(yzshen): the way to use validator (or message filter in general) 153 // TODO(yzshen): the way to use validator (or message filter in general)
150 // directly is a little awkward. 154 // directly is a little awkward.
151 filters_.Append(std::move(payload_validator)); 155 filters_.Append(std::move(payload_validator));
156 filters_.Append(base::MakeUnique<internal::ControlMessageValidator>());
yzshen1 2016/08/29 23:24:58 I took a different approach for pipe-control messa
Sam McNally 2016/08/30 03:05:51 Done.
152 157
153 controller_ = handle_.group_controller()->AttachEndpointClient( 158 controller_ = handle_.group_controller()->AttachEndpointClient(
154 handle_, this, task_runner_); 159 handle_, this, task_runner_);
155 if (expect_sync_requests) 160 if (expect_sync_requests)
156 controller_->AllowWokenUpBySyncWatchOnSameThread(); 161 controller_->AllowWokenUpBySyncWatchOnSameThread();
157 } 162 }
158 163
159 InterfaceEndpointClient::~InterfaceEndpointClient() { 164 InterfaceEndpointClient::~InterfaceEndpointClient() {
160 DCHECK(thread_checker_.CalledOnValidThread()); 165 DCHECK(thread_checker_.CalledOnValidThread());
161 166
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 DCHECK(thread_checker_.CalledOnValidThread()); 273 DCHECK(thread_checker_.CalledOnValidThread());
269 274
270 if (encountered_error_) 275 if (encountered_error_)
271 return; 276 return;
272 encountered_error_ = true; 277 encountered_error_ = true;
273 278
274 // The callbacks may hold on to resources. There is no need to keep them any 279 // The callbacks may hold on to resources. There is no need to keep them any
275 // longer. 280 // longer.
276 async_responders_.clear(); 281 async_responders_.clear();
277 282
283 control_message_proxy_.OnConnectionError();
284
278 if (!error_handler_.is_null()) 285 if (!error_handler_.is_null())
279 error_handler_.Run(); 286 error_handler_.Run();
280 } 287 }
281 288
282 bool InterfaceEndpointClient::HandleValidatedMessage(Message* message) { 289 bool InterfaceEndpointClient::HandleValidatedMessage(Message* message) {
283 DCHECK_EQ(handle_.id(), message->interface_id()); 290 DCHECK_EQ(handle_.id(), message->interface_id());
284 DCHECK(!encountered_error_); 291 DCHECK(!encountered_error_);
285 292
286 if (message->has_flag(Message::kFlagExpectsResponse)) { 293 if (message->has_flag(Message::kFlagExpectsResponse)) {
287 if (!incoming_receiver_) 294 if (!incoming_receiver_ &&
yzshen1 2016/08/29 23:24:58 nit: maybe we could remove this check and let it c
Sam McNally 2016/08/30 03:05:51 Done. This should never happen because validation
295 !mojo::internal::ControlMessageHandler::IsControlMessage(message)) {
288 return false; 296 return false;
297 }
289 298
290 MessageReceiverWithStatus* responder = 299 MessageReceiverWithStatus* responder =
291 new ResponderThunk(weak_ptr_factory_.GetWeakPtr(), task_runner_); 300 new ResponderThunk(weak_ptr_factory_.GetWeakPtr(), task_runner_);
292 bool ok = incoming_receiver_->AcceptWithResponder(message, responder); 301 bool ok = false;
302 if (mojo::internal::ControlMessageHandler::IsControlMessage(message)) {
303 ok = control_message_handler_.AcceptWithResponder(message, responder);
304 } else {
305 ok = incoming_receiver_->AcceptWithResponder(message, responder);
306 }
293 if (!ok) 307 if (!ok)
294 delete responder; 308 delete responder;
295 return ok; 309 return ok;
296 } else if (message->has_flag(Message::kFlagIsResponse)) { 310 } else if (message->has_flag(Message::kFlagIsResponse)) {
297 uint64_t request_id = message->request_id(); 311 uint64_t request_id = message->request_id();
298 312
299 if (message->has_flag(Message::kFlagIsSync)) { 313 if (message->has_flag(Message::kFlagIsSync)) {
300 auto it = sync_responses_.find(request_id); 314 auto it = sync_responses_.find(request_id);
301 if (it == sync_responses_.end()) 315 if (it == sync_responses_.end())
302 return false; 316 return false;
303 it->second->response = std::move(*message); 317 it->second->response = std::move(*message);
304 *it->second->response_received = true; 318 *it->second->response_received = true;
305 return true; 319 return true;
306 } 320 }
307 321
308 auto it = async_responders_.find(request_id); 322 auto it = async_responders_.find(request_id);
309 if (it == async_responders_.end()) 323 if (it == async_responders_.end())
310 return false; 324 return false;
311 std::unique_ptr<MessageReceiver> responder = std::move(it->second); 325 std::unique_ptr<MessageReceiver> responder = std::move(it->second);
312 async_responders_.erase(it); 326 async_responders_.erase(it);
313 return responder->Accept(message); 327 return responder->Accept(message);
314 } else { 328 } else {
329 if (mojo::internal::ControlMessageHandler::IsControlMessage(message))
330 return control_message_handler_.Accept(message);
331
315 if (!incoming_receiver_) 332 if (!incoming_receiver_)
316 return false; 333 return false;
317 334
318 return incoming_receiver_->Accept(message); 335 return incoming_receiver_->Accept(message);
319 } 336 }
320 } 337 }
321 338
322 } // namespace mojo 339 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698