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

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

Issue 2487803002: Mojo C++ Bindings: Allow callbacks to own their InterfacePtr (Closed)
Patch Set: . Created 4 years, 1 month 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 | « no previous file | mojo/public/cpp/bindings/lib/router.cc » ('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 #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
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 return filters_.Accept(message); 273 return filters_.Accept(message);
274 } 274 }
275 275
276 void InterfaceEndpointClient::NotifyError() { 276 void InterfaceEndpointClient::NotifyError() {
277 DCHECK(thread_checker_.CalledOnValidThread()); 277 DCHECK(thread_checker_.CalledOnValidThread());
278 278
279 if (encountered_error_) 279 if (encountered_error_)
280 return; 280 return;
281 encountered_error_ = true; 281 encountered_error_ = true;
282 282
283 // The callbacks may hold on to resources. There is no need to keep them any 283 // Response callbacks may hold on to resource, and there's no need to keep
284 // longer. 284 // them alive any longer. Note that it's allowed that a pending response
285 async_responders_.clear(); 285 // callback may own this endpoint, so we simply move the responders onto the
286 // stack here and let them be destroyed when the stack unwinds.
287 AsyncResponderMap responders = std::move(async_responders_);
286 288
287 control_message_proxy_.OnConnectionError(); 289 control_message_proxy_.OnConnectionError();
288 290
289 if (!error_handler_.is_null()) { 291 if (!error_handler_.is_null()) {
290 error_handler_.Run(); 292 error_handler_.Run();
291 } else if (!error_with_reason_handler_.is_null()) { 293 } else if (!error_with_reason_handler_.is_null()) {
292 // Make a copy on the stack. If we directly pass a reference to a member of 294 // Make a copy on the stack. If we directly pass a reference to a member of
293 // |control_message_handler_|, that reference will be invalidated as soon as 295 // |control_message_handler_|, that reference will be invalidated as soon as
294 // the user destroys the interface endpoint. 296 // the user destroys the interface endpoint.
295 std::string description = control_message_handler_.disconnect_description(); 297 std::string description = control_message_handler_.disconnect_description();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 observing_message_loop_destruction_ = false; 349 observing_message_loop_destruction_ = false;
348 base::MessageLoop::current()->RemoveDestructionObserver(this); 350 base::MessageLoop::current()->RemoveDestructionObserver(this);
349 } 351 }
350 352
351 void InterfaceEndpointClient::WillDestroyCurrentMessageLoop() { 353 void InterfaceEndpointClient::WillDestroyCurrentMessageLoop() {
352 StopObservingIfNecessary(); 354 StopObservingIfNecessary();
353 NotifyError(); 355 NotifyError();
354 } 356 }
355 357
356 } // namespace mojo 358 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/lib/router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698