| OLD | NEW |
| 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 "ipc/ipc_mojo_bootstrap.h" | 5 #include "ipc/ipc_mojo_bootstrap.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 bool Accept(mojo::Message* message) override { | 595 bool Accept(mojo::Message* message) override { |
| 596 DCHECK(thread_checker_.CalledOnValidThread()); | 596 DCHECK(thread_checker_.CalledOnValidThread()); |
| 597 | 597 |
| 598 if (mojo::PipeControlMessageHandler::IsPipeControlMessage(message)) | 598 if (mojo::PipeControlMessageHandler::IsPipeControlMessage(message)) |
| 599 return control_message_handler_.Accept(message); | 599 return control_message_handler_.Accept(message); |
| 600 | 600 |
| 601 mojo::InterfaceId id = message->interface_id(); | 601 mojo::InterfaceId id = message->interface_id(); |
| 602 DCHECK(mojo::IsValidInterfaceId(id)); | 602 DCHECK(mojo::IsValidInterfaceId(id)); |
| 603 | 603 |
| 604 base::AutoLock locker(lock_); | 604 base::AutoLock locker(lock_); |
| 605 Endpoint* endpoint = | 605 Endpoint* endpoint = GetEndpointForDispatch(id, true /* create */); |
| 606 GetEndpointForDispatch(id, false /* close_on_insert */); | |
| 607 mojo::InterfaceEndpointClient* client = | 606 mojo::InterfaceEndpointClient* client = |
| 608 endpoint ? endpoint->client() : nullptr; | 607 endpoint ? endpoint->client() : nullptr; |
| 609 if (!client || !endpoint->task_runner()->BelongsToCurrentThread()) { | 608 if (!client || !endpoint->task_runner()->BelongsToCurrentThread()) { |
| 610 // No client has been bound yet or the client runs tasks on another | 609 // No client has been bound yet or the client runs tasks on another |
| 611 // thread. We assume the other thread must always be the one on which | 610 // thread. We assume the other thread must always be the one on which |
| 612 // |proxy_task_runner_| runs tasks, since that's the only valid scenario. | 611 // |proxy_task_runner_| runs tasks, since that's the only valid scenario. |
| 613 // | 612 // |
| 614 // If the client is not yet bound, it must be bound by the time this task | 613 // If the client is not yet bound, it must be bound by the time this task |
| 615 // runs or else it's programmer error. | 614 // runs or else it's programmer error. |
| 616 DCHECK(proxy_task_runner_); | 615 DCHECK(proxy_task_runner_); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 645 return client->HandleIncomingMessage(message); | 644 return client->HandleIncomingMessage(message); |
| 646 } | 645 } |
| 647 | 646 |
| 648 void AcceptOnProxyThread(mojo::Message message) { | 647 void AcceptOnProxyThread(mojo::Message message) { |
| 649 DCHECK(proxy_task_runner_->BelongsToCurrentThread()); | 648 DCHECK(proxy_task_runner_->BelongsToCurrentThread()); |
| 650 | 649 |
| 651 mojo::InterfaceId id = message.interface_id(); | 650 mojo::InterfaceId id = message.interface_id(); |
| 652 DCHECK(mojo::IsValidInterfaceId(id) && !mojo::IsMasterInterfaceId(id)); | 651 DCHECK(mojo::IsValidInterfaceId(id) && !mojo::IsMasterInterfaceId(id)); |
| 653 | 652 |
| 654 base::AutoLock locker(lock_); | 653 base::AutoLock locker(lock_); |
| 655 Endpoint* endpoint = GetEndpointForDispatch(id, true /* close_on_insert */); | 654 Endpoint* endpoint = GetEndpointForDispatch(id, false /* create */); |
| 656 if (!endpoint) | 655 if (!endpoint) |
| 657 return; | 656 return; |
| 658 | 657 |
| 659 mojo::InterfaceEndpointClient* client = endpoint->client(); | 658 mojo::InterfaceEndpointClient* client = endpoint->client(); |
| 660 if (!client) | 659 if (!client) |
| 661 return; | 660 return; |
| 662 | 661 |
| 663 DCHECK(endpoint->task_runner()->BelongsToCurrentThread()); | 662 DCHECK(endpoint->task_runner()->BelongsToCurrentThread()); |
| 664 | 663 |
| 665 // Sync messages should never make their way to this method. | 664 // Sync messages should never make their way to this method. |
| 666 DCHECK(!message.has_flag(mojo::Message::kFlagIsSync)); | 665 DCHECK(!message.has_flag(mojo::Message::kFlagIsSync)); |
| 667 | 666 |
| 668 bool result = false; | 667 bool result = false; |
| 669 { | 668 { |
| 670 base::AutoUnlock unlocker(lock_); | 669 base::AutoUnlock unlocker(lock_); |
| 671 result = client->HandleIncomingMessage(&message); | 670 result = client->HandleIncomingMessage(&message); |
| 672 } | 671 } |
| 673 | 672 |
| 674 if (!result) | 673 if (!result) |
| 675 RaiseError(); | 674 RaiseError(); |
| 676 } | 675 } |
| 677 | 676 |
| 678 void AcceptSyncMessage(mojo::InterfaceId interface_id, uint32_t message_id) { | 677 void AcceptSyncMessage(mojo::InterfaceId interface_id, uint32_t message_id) { |
| 679 DCHECK(proxy_task_runner_->BelongsToCurrentThread()); | 678 DCHECK(proxy_task_runner_->BelongsToCurrentThread()); |
| 680 | 679 |
| 681 base::AutoLock locker(lock_); | 680 base::AutoLock locker(lock_); |
| 682 Endpoint* endpoint = | 681 Endpoint* endpoint = |
| 683 GetEndpointForDispatch(interface_id, true /* close_on_insert */); | 682 GetEndpointForDispatch(interface_id, false /* create */); |
| 684 if (!endpoint) | 683 if (!endpoint) |
| 685 return; | 684 return; |
| 686 | 685 |
| 687 DCHECK(endpoint->task_runner()->BelongsToCurrentThread()); | 686 DCHECK(endpoint->task_runner()->BelongsToCurrentThread()); |
| 688 mojo::Message message = endpoint->PopSyncMessage(message_id); | 687 mojo::Message message = endpoint->PopSyncMessage(message_id); |
| 689 | 688 |
| 690 // The message must have already been dequeued by the endpoint waking up | 689 // The message must have already been dequeued by the endpoint waking up |
| 691 // from a sync wait. Nothing to do. | 690 // from a sync wait. Nothing to do. |
| 692 if (message.IsNull()) | 691 if (message.IsNull()) |
| 693 return; | 692 return; |
| 694 | 693 |
| 695 mojo::InterfaceEndpointClient* client = endpoint->client(); | 694 mojo::InterfaceEndpointClient* client = endpoint->client(); |
| 696 if (!client) | 695 if (!client) |
| 697 return; | 696 return; |
| 698 | 697 |
| 699 bool result = false; | 698 bool result = false; |
| 700 { | 699 { |
| 701 base::AutoUnlock unlocker(lock_); | 700 base::AutoUnlock unlocker(lock_); |
| 702 result = client->HandleIncomingMessage(&message); | 701 result = client->HandleIncomingMessage(&message); |
| 703 } | 702 } |
| 704 | 703 |
| 705 if (!result) | 704 if (!result) |
| 706 RaiseError(); | 705 RaiseError(); |
| 707 } | 706 } |
| 708 | 707 |
| 709 Endpoint* GetEndpointForDispatch(mojo::InterfaceId id, bool close_on_insert) { | 708 Endpoint* GetEndpointForDispatch(mojo::InterfaceId id, bool create) { |
| 710 lock_.AssertAcquired(); | 709 lock_.AssertAcquired(); |
| 710 auto iter = endpoints_.find(id); |
| 711 if (iter != endpoints_.end()) |
| 712 return iter->second.get(); |
| 713 if (!create) |
| 714 return nullptr; |
| 711 bool inserted = false; | 715 bool inserted = false; |
| 712 Endpoint* endpoint = FindOrInsertEndpoint(id, &inserted); | 716 Endpoint* endpoint = FindOrInsertEndpoint(id, &inserted); |
| 713 if (inserted && close_on_insert) { | 717 DCHECK(inserted); |
| 714 MarkClosedAndMaybeRemove(endpoint); | |
| 715 if (!mojo::IsMasterInterfaceId(id)) | |
| 716 control_message_proxy_.NotifyPeerEndpointClosed(id); | |
| 717 return nullptr; | |
| 718 } | |
| 719 | |
| 720 if (endpoint->closed()) | |
| 721 return nullptr; | |
| 722 | |
| 723 return endpoint; | 718 return endpoint; |
| 724 } | 719 } |
| 725 | 720 |
| 726 // mojo::PipeControlMessageHandlerDelegate: | 721 // mojo::PipeControlMessageHandlerDelegate: |
| 727 bool OnPeerAssociatedEndpointClosed(mojo::InterfaceId id) override { | 722 bool OnPeerAssociatedEndpointClosed(mojo::InterfaceId id) override { |
| 728 DCHECK(thread_checker_.CalledOnValidThread()); | 723 DCHECK(thread_checker_.CalledOnValidThread()); |
| 729 | 724 |
| 730 if (mojo::IsMasterInterfaceId(id)) | 725 if (mojo::IsMasterInterfaceId(id)) |
| 731 return false; | 726 return false; |
| 732 | 727 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 Channel::Mode mode, | 843 Channel::Mode mode, |
| 849 Delegate* delegate, | 844 Delegate* delegate, |
| 850 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { | 845 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { |
| 851 return base::MakeUnique<MojoBootstrapImpl>( | 846 return base::MakeUnique<MojoBootstrapImpl>( |
| 852 std::move(handle), delegate, | 847 std::move(handle), delegate, |
| 853 new ChannelAssociatedGroupController(mode == Channel::MODE_SERVER, | 848 new ChannelAssociatedGroupController(mode == Channel::MODE_SERVER, |
| 854 ipc_task_runner)); | 849 ipc_task_runner)); |
| 855 } | 850 } |
| 856 | 851 |
| 857 } // namespace IPC | 852 } // namespace IPC |
| OLD | NEW |