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

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));
152 156
153 controller_ = handle_.group_controller()->AttachEndpointClient( 157 controller_ = handle_.group_controller()->AttachEndpointClient(
154 handle_, this, task_runner_); 158 handle_, this, task_runner_);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 DCHECK(thread_checker_.CalledOnValidThread()); 272 DCHECK(thread_checker_.CalledOnValidThread());
269 273
270 if (encountered_error_) 274 if (encountered_error_)
271 return; 275 return;
272 encountered_error_ = true; 276 encountered_error_ = true;
273 277
274 // The callbacks may hold on to resources. There is no need to keep them any 278 // The callbacks may hold on to resources. There is no need to keep them any
275 // longer. 279 // longer.
276 async_responders_.clear(); 280 async_responders_.clear();
277 281
282 control_message_proxy_.OnConnectionError();
283
278 if (!error_handler_.is_null()) 284 if (!error_handler_.is_null())
279 error_handler_.Run(); 285 error_handler_.Run();
280 } 286 }
281 287
282 bool InterfaceEndpointClient::HandleValidatedMessage(Message* message) { 288 bool InterfaceEndpointClient::HandleValidatedMessage(Message* message) {
283 DCHECK_EQ(handle_.id(), message->interface_id()); 289 DCHECK_EQ(handle_.id(), message->interface_id());
284 DCHECK(!encountered_error_); 290 DCHECK(!encountered_error_);
285 291
286 if (message->has_flag(Message::kFlagExpectsResponse)) { 292 if (message->has_flag(Message::kFlagExpectsResponse)) {
287 if (!incoming_receiver_)
288 return false;
289
290 MessageReceiverWithStatus* responder = 293 MessageReceiverWithStatus* responder =
291 new ResponderThunk(weak_ptr_factory_.GetWeakPtr(), task_runner_); 294 new ResponderThunk(weak_ptr_factory_.GetWeakPtr(), task_runner_);
292 bool ok = incoming_receiver_->AcceptWithResponder(message, responder); 295 bool ok = false;
296 if (mojo::internal::ControlMessageHandler::IsControlMessage(message)) {
297 ok = control_message_handler_.AcceptWithResponder(message, responder);
298 } else {
299 ok = incoming_receiver_->AcceptWithResponder(message, responder);
300 }
293 if (!ok) 301 if (!ok)
294 delete responder; 302 delete responder;
295 return ok; 303 return ok;
296 } else if (message->has_flag(Message::kFlagIsResponse)) { 304 } else if (message->has_flag(Message::kFlagIsResponse)) {
297 uint64_t request_id = message->request_id(); 305 uint64_t request_id = message->request_id();
298 306
299 if (message->has_flag(Message::kFlagIsSync)) { 307 if (message->has_flag(Message::kFlagIsSync)) {
300 auto it = sync_responses_.find(request_id); 308 auto it = sync_responses_.find(request_id);
301 if (it == sync_responses_.end()) 309 if (it == sync_responses_.end())
302 return false; 310 return false;
303 it->second->response = std::move(*message); 311 it->second->response = std::move(*message);
304 *it->second->response_received = true; 312 *it->second->response_received = true;
305 return true; 313 return true;
306 } 314 }
307 315
308 auto it = async_responders_.find(request_id); 316 auto it = async_responders_.find(request_id);
309 if (it == async_responders_.end()) 317 if (it == async_responders_.end())
310 return false; 318 return false;
311 std::unique_ptr<MessageReceiver> responder = std::move(it->second); 319 std::unique_ptr<MessageReceiver> responder = std::move(it->second);
312 async_responders_.erase(it); 320 async_responders_.erase(it);
313 return responder->Accept(message); 321 return responder->Accept(message);
314 } else { 322 } else {
315 if (!incoming_receiver_) 323 if (mojo::internal::ControlMessageHandler::IsControlMessage(message))
316 return false; 324 return control_message_handler_.Accept(message);
317 325
318 return incoming_receiver_->Accept(message); 326 return incoming_receiver_->Accept(message);
319 } 327 }
320 } 328 }
321 329
322 } // namespace mojo 330 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/control_message_proxy.cc ('k') | mojo/public/cpp/bindings/lib/interface_ptr_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698