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

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

Issue 2494483003: Mojo Bindings: Fix lock-order inversion in associated controllers (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
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/lib/multiplex_router.h" 5 #include "mojo/public/cpp/bindings/lib/multiplex_router.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 if (!IsValidInterfaceId(id)) 395 if (!IsValidInterfaceId(id))
396 return; 396 return;
397 397
398 MayAutoLock locker(lock_.get()); 398 MayAutoLock locker(lock_.get());
399 399
400 if (!is_local) { 400 if (!is_local) {
401 DCHECK(base::ContainsKey(endpoints_, id)); 401 DCHECK(base::ContainsKey(endpoints_, id));
402 DCHECK(!IsMasterInterfaceId(id)); 402 DCHECK(!IsMasterInterfaceId(id));
403 403
404 // We will receive a NotifyPeerEndpointClosed message from the other side. 404 // We will receive a NotifyPeerEndpointClosed message from the other side.
405 MayAutoUnlock unlocker(lock_.get());
405 control_message_proxy_.NotifyEndpointClosedBeforeSent(id); 406 control_message_proxy_.NotifyEndpointClosedBeforeSent(id);
406 407
407 return; 408 return;
408 } 409 }
409 410
410 DCHECK(base::ContainsKey(endpoints_, id)); 411 DCHECK(base::ContainsKey(endpoints_, id));
411 InterfaceEndpoint* endpoint = endpoints_[id].get(); 412 InterfaceEndpoint* endpoint = endpoints_[id].get();
412 DCHECK(!endpoint->client()); 413 DCHECK(!endpoint->client());
413 DCHECK(!endpoint->closed()); 414 DCHECK(!endpoint->closed());
414 UpdateEndpointStateMayRemove(endpoint, ENDPOINT_CLOSED); 415 UpdateEndpointStateMayRemove(endpoint, ENDPOINT_CLOSED);
415 416
416 if (!IsMasterInterfaceId(id)) 417 if (!IsMasterInterfaceId(id)) {
418 MayAutoUnlock unlocker(lock_.get());
417 control_message_proxy_.NotifyPeerEndpointClosed(id); 419 control_message_proxy_.NotifyPeerEndpointClosed(id);
420 }
418 421
419 ProcessTasks(NO_DIRECT_CLIENT_CALLS, nullptr); 422 ProcessTasks(NO_DIRECT_CLIENT_CALLS, nullptr);
420 } 423 }
421 424
422 InterfaceEndpointController* MultiplexRouter::AttachEndpointClient( 425 InterfaceEndpointController* MultiplexRouter::AttachEndpointClient(
423 const ScopedInterfaceEndpointHandle& handle, 426 const ScopedInterfaceEndpointHandle& handle,
424 InterfaceEndpointClient* client, 427 InterfaceEndpointClient* client,
425 scoped_refptr<base::SingleThreadTaskRunner> runner) { 428 scoped_refptr<base::SingleThreadTaskRunner> runner) {
426 const InterfaceId id = handle.id(); 429 const InterfaceId id = handle.id();
427 430
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 bool MultiplexRouter::OnAssociatedEndpointClosedBeforeSent(InterfaceId id) { 592 bool MultiplexRouter::OnAssociatedEndpointClosedBeforeSent(InterfaceId id) {
590 AssertLockAcquired(); 593 AssertLockAcquired();
591 594
592 if (IsMasterInterfaceId(id)) 595 if (IsMasterInterfaceId(id))
593 return false; 596 return false;
594 597
595 InterfaceEndpoint* endpoint = FindOrInsertEndpoint(id, nullptr); 598 InterfaceEndpoint* endpoint = FindOrInsertEndpoint(id, nullptr);
596 DCHECK(!endpoint->closed()); 599 DCHECK(!endpoint->closed());
597 UpdateEndpointStateMayRemove(endpoint, ENDPOINT_CLOSED); 600 UpdateEndpointStateMayRemove(endpoint, ENDPOINT_CLOSED);
598 601
602 MayAutoUnlock unlocker(lock_.get());
599 control_message_proxy_.NotifyPeerEndpointClosed(id); 603 control_message_proxy_.NotifyPeerEndpointClosed(id);
600 604
601 return true; 605 return true;
602 } 606 }
603 607
604 void MultiplexRouter::OnPipeConnectionError() { 608 void MultiplexRouter::OnPipeConnectionError() {
605 DCHECK(thread_checker_.CalledOnValidThread()); 609 DCHECK(thread_checker_.CalledOnValidThread());
606 610
607 scoped_refptr<MultiplexRouter> protector(this); 611 scoped_refptr<MultiplexRouter> protector(this);
608 MayAutoLock locker(lock_.get()); 612 MayAutoLock locker(lock_.get());
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 UpdateEndpointStateMayRemove(endpoint, ENDPOINT_CLOSED); 778 UpdateEndpointStateMayRemove(endpoint, ENDPOINT_CLOSED);
775 779
776 // It is also possible that this newly-inserted endpoint is the master 780 // It is also possible that this newly-inserted endpoint is the master
777 // endpoint. When the master InterfacePtr/Binding goes away, the message 781 // endpoint. When the master InterfacePtr/Binding goes away, the message
778 // pipe is closed and we explicitly trigger a pipe connection error. The 782 // pipe is closed and we explicitly trigger a pipe connection error. The
779 // error updates all the endpoints, including the master endpoint, with 783 // error updates all the endpoints, including the master endpoint, with
780 // PEER_ENDPOINT_CLOSED and removes the master endpoint from the 784 // PEER_ENDPOINT_CLOSED and removes the master endpoint from the
781 // registration. We continue to process remaining tasks in the queue, as 785 // registration. We continue to process remaining tasks in the queue, as
782 // long as there are refs keeping the router alive. If there are remaining 786 // long as there are refs keeping the router alive. If there are remaining
783 // messages for the master endpoint, we will get here. 787 // messages for the master endpoint, we will get here.
788 MayAutoUnlock unlocker(lock_.get());
784 if (!IsMasterInterfaceId(id)) 789 if (!IsMasterInterfaceId(id))
785 control_message_proxy_.NotifyPeerEndpointClosed(id); 790 control_message_proxy_.NotifyPeerEndpointClosed(id);
786 return true; 791 return true;
787 } 792 }
788 793
789 if (endpoint->closed()) 794 if (endpoint->closed())
790 return true; 795 return true;
791 796
792 if (!endpoint->client()) { 797 if (!endpoint->client()) {
793 // We need to wait until a client is attached in order to dispatch further 798 // We need to wait until a client is attached in order to dispatch further
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 904
900 void MultiplexRouter::AssertLockAcquired() { 905 void MultiplexRouter::AssertLockAcquired() {
901 #if DCHECK_IS_ON() 906 #if DCHECK_IS_ON()
902 if (lock_) 907 if (lock_)
903 lock_->AssertAcquired(); 908 lock_->AssertAcquired();
904 #endif 909 #endif
905 } 910 }
906 911
907 } // namespace internal 912 } // namespace internal
908 } // namespace mojo 913 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/multiplex_router.h ('k') | mojo/public/cpp/bindings/lib/pipe_control_message_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698