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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 connector_.reset(new mojo::Connector( | 66 connector_.reset(new mojo::Connector( |
67 std::move(handle), mojo::Connector::SINGLE_THREADED_SEND, | 67 std::move(handle), mojo::Connector::SINGLE_THREADED_SEND, |
68 task_runner_)); | 68 task_runner_)); |
69 connector_->set_incoming_receiver(&filters_); | 69 connector_->set_incoming_receiver(&filters_); |
70 connector_->set_connection_error_handler( | 70 connector_->set_connection_error_handler( |
71 base::Bind(&ChannelAssociatedGroupController::OnPipeError, | 71 base::Bind(&ChannelAssociatedGroupController::OnPipeError, |
72 base::Unretained(this))); | 72 base::Unretained(this))); |
73 } | 73 } |
74 | 74 |
75 void Start() { | 75 void Pause() { |
76 DCHECK(!started_); | 76 DCHECK(!paused_); |
77 started_ = true; | 77 paused_ = true; |
| 78 } |
| 79 |
| 80 void Unpause() { |
| 81 DCHECK(paused_); |
| 82 paused_ = false; |
78 } | 83 } |
79 | 84 |
80 void FlushOutgoingMessages() { | 85 void FlushOutgoingMessages() { |
81 std::vector<mojo::Message> outgoing_messages; | 86 std::vector<mojo::Message> outgoing_messages; |
82 std::swap(outgoing_messages, outgoing_messages_); | 87 std::swap(outgoing_messages, outgoing_messages_); |
83 for (auto& message : outgoing_messages) | 88 for (auto& message : outgoing_messages) |
84 SendMessage(&message); | 89 SendMessage(&message); |
85 } | 90 } |
86 | 91 |
87 void CreateChannelEndpoints(mojom::ChannelAssociatedPtr* sender, | 92 void CreateChannelEndpoints(mojom::ChannelAssociatedPtr* sender, |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 DCHECK(endpoint->closed()); | 471 DCHECK(endpoint->closed()); |
467 MarkPeerClosedAndMaybeRemove(endpoint); | 472 MarkPeerClosedAndMaybeRemove(endpoint); |
468 } | 473 } |
469 | 474 |
470 DCHECK(endpoints_.empty()); | 475 DCHECK(endpoints_.empty()); |
471 } | 476 } |
472 | 477 |
473 bool SendMessage(mojo::Message* message) { | 478 bool SendMessage(mojo::Message* message) { |
474 if (task_runner_->BelongsToCurrentThread()) { | 479 if (task_runner_->BelongsToCurrentThread()) { |
475 DCHECK(thread_checker_.CalledOnValidThread()); | 480 DCHECK(thread_checker_.CalledOnValidThread()); |
476 if (!connector_ || !started_) { | 481 if (!connector_ || paused_) { |
477 // Pipe may not be bound yet or the channel may still be paused, so we | |
478 // queue the message. | |
479 outgoing_messages_.emplace_back(std::move(*message)); | 482 outgoing_messages_.emplace_back(std::move(*message)); |
480 return true; | 483 return true; |
481 } | 484 } |
482 return connector_->Accept(message); | 485 return connector_->Accept(message); |
483 } else { | 486 } else { |
484 // We always post tasks to the master endpoint thread when called from the | 487 // We always post tasks to the master endpoint thread when called from the |
485 // proxy thread in order to simulate IPC::ChannelProxy::Send behavior. | 488 // proxy thread in order to simulate IPC::ChannelProxy::Send behavior. |
486 DCHECK(proxy_task_runner_->BelongsToCurrentThread()); | 489 DCHECK(proxy_task_runner_->BelongsToCurrentThread()); |
487 task_runner_->PostTask( | 490 task_runner_->PostTask( |
488 FROM_HERE, | 491 FROM_HERE, |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 return true; | 756 return true; |
754 } | 757 } |
755 | 758 |
756 // Checked in places which must be run on the master endpoint's thread. | 759 // Checked in places which must be run on the master endpoint's thread. |
757 base::ThreadChecker thread_checker_; | 760 base::ThreadChecker thread_checker_; |
758 | 761 |
759 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 762 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
760 | 763 |
761 scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner_; | 764 scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner_; |
762 const bool set_interface_id_namespace_bit_; | 765 const bool set_interface_id_namespace_bit_; |
763 bool started_ = false; | 766 bool paused_ = false; |
764 std::unique_ptr<mojo::Connector> connector_; | 767 std::unique_ptr<mojo::Connector> connector_; |
765 mojo::FilterChain filters_; | 768 mojo::FilterChain filters_; |
766 mojo::PipeControlMessageHandler control_message_handler_; | 769 mojo::PipeControlMessageHandler control_message_handler_; |
767 ControlMessageProxyThunk control_message_proxy_thunk_; | 770 ControlMessageProxyThunk control_message_proxy_thunk_; |
768 mojo::PipeControlMessageProxy control_message_proxy_; | 771 mojo::PipeControlMessageProxy control_message_proxy_; |
769 | 772 |
770 // Outgoing messages that were sent before this controller was bound to a | 773 // Outgoing messages that were sent before this controller was bound to a |
771 // real message pipe. | 774 // real message pipe. |
772 std::vector<mojo::Message> outgoing_messages_; | 775 std::vector<mojo::Message> outgoing_messages_; |
773 | 776 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 void Connect() override { | 808 void Connect() override { |
806 controller_->Bind(std::move(handle_)); | 809 controller_->Bind(std::move(handle_)); |
807 | 810 |
808 IPC::mojom::ChannelAssociatedPtr sender; | 811 IPC::mojom::ChannelAssociatedPtr sender; |
809 IPC::mojom::ChannelAssociatedRequest receiver; | 812 IPC::mojom::ChannelAssociatedRequest receiver; |
810 controller_->CreateChannelEndpoints(&sender, &receiver); | 813 controller_->CreateChannelEndpoints(&sender, &receiver); |
811 | 814 |
812 delegate_->OnPipesAvailable(std::move(sender), std::move(receiver)); | 815 delegate_->OnPipesAvailable(std::move(sender), std::move(receiver)); |
813 } | 816 } |
814 | 817 |
815 void Start() override { | 818 void Pause() override { |
816 controller_->Start(); | 819 controller_->Pause(); |
| 820 } |
| 821 |
| 822 void Unpause() override { |
| 823 controller_->Unpause(); |
817 } | 824 } |
818 | 825 |
819 void Flush() override { | 826 void Flush() override { |
820 controller_->FlushOutgoingMessages(); | 827 controller_->FlushOutgoingMessages(); |
821 } | 828 } |
822 | 829 |
823 mojo::AssociatedGroup* GetAssociatedGroup() override { | 830 mojo::AssociatedGroup* GetAssociatedGroup() override { |
824 return associated_group_.get(); | 831 return associated_group_.get(); |
825 } | 832 } |
826 | 833 |
(...skipping 14 matching lines...) Expand all Loading... |
841 Channel::Mode mode, | 848 Channel::Mode mode, |
842 Delegate* delegate, | 849 Delegate* delegate, |
843 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { | 850 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { |
844 return base::MakeUnique<MojoBootstrapImpl>( | 851 return base::MakeUnique<MojoBootstrapImpl>( |
845 std::move(handle), delegate, | 852 std::move(handle), delegate, |
846 new ChannelAssociatedGroupController(mode == Channel::MODE_SERVER, | 853 new ChannelAssociatedGroupController(mode == Channel::MODE_SERVER, |
847 ipc_task_runner)); | 854 ipc_task_runner)); |
848 } | 855 } |
849 | 856 |
850 } // namespace IPC | 857 } // namespace IPC |
OLD | NEW |