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

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

Issue 2274743002: Mojo C++ bindings: clean up pending callbacks when connection error occurs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « mojo/public/cpp/bindings/lib/interface_endpoint_client.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "mojo/public/cpp/bindings/lib/router.h" 5 #include "mojo/public/cpp/bindings/lib/router.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 pending_task_for_messages_ = false; 239 pending_task_for_messages_ = false;
240 240
241 // We may have already seen a connection error from the connector, but 241 // We may have already seen a connection error from the connector, but
242 // haven't notified the user because we want to process all the queued 242 // haven't notified the user because we want to process all the queued
243 // messages first. We should do it now. 243 // messages first. We should do it now.
244 if (connector_.encountered_error() && !encountered_error_) 244 if (connector_.encountered_error() && !encountered_error_)
245 OnConnectionError(); 245 OnConnectionError();
246 } 246 }
247 247
248 bool Router::HandleMessageInternal(Message* message) { 248 bool Router::HandleMessageInternal(Message* message) {
249 DCHECK(!encountered_error_);
250
249 if (message->has_flag(Message::kFlagExpectsResponse)) { 251 if (message->has_flag(Message::kFlagExpectsResponse)) {
250 if (!incoming_receiver_) 252 if (!incoming_receiver_)
251 return false; 253 return false;
252 254
253 MessageReceiverWithStatus* responder = new ResponderThunk( 255 MessageReceiverWithStatus* responder = new ResponderThunk(
254 weak_factory_.GetWeakPtr(), connector_.task_runner()); 256 weak_factory_.GetWeakPtr(), connector_.task_runner());
255 bool ok = incoming_receiver_->AcceptWithResponder(message, responder); 257 bool ok = incoming_receiver_->AcceptWithResponder(message, responder);
256 if (!ok) 258 if (!ok)
257 delete responder; 259 delete responder;
258 return ok; 260 return ok;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 303
302 if (connector_.during_sync_handle_watcher_callback()) { 304 if (connector_.during_sync_handle_watcher_callback()) {
303 // We don't want the error handler to reenter an ongoing sync call. 305 // We don't want the error handler to reenter an ongoing sync call.
304 connector_.task_runner()->PostTask( 306 connector_.task_runner()->PostTask(
305 FROM_HERE, 307 FROM_HERE,
306 base::Bind(&Router::OnConnectionError, weak_factory_.GetWeakPtr())); 308 base::Bind(&Router::OnConnectionError, weak_factory_.GetWeakPtr()));
307 return; 309 return;
308 } 310 }
309 311
310 encountered_error_ = true; 312 encountered_error_ = true;
313
314 // The callbacks may hold on to resources. There is no need to keep them any
315 // longer.
316 async_responders_.clear();
317
311 if (!error_handler_.is_null()) 318 if (!error_handler_.is_null())
312 error_handler_.Run(); 319 error_handler_.Run();
313 } 320 }
314 321
315 // ---------------------------------------------------------------------------- 322 // ----------------------------------------------------------------------------
316 323
317 } // namespace internal 324 } // namespace internal
318 } // namespace mojo 325 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/interface_endpoint_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698