| 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 30 matching lines...) Expand all Loading... |
| 41 : public mojo::AssociatedGroupController, | 41 : public mojo::AssociatedGroupController, |
| 42 public mojo::MessageReceiver, | 42 public mojo::MessageReceiver, |
| 43 public mojo::PipeControlMessageHandlerDelegate { | 43 public mojo::PipeControlMessageHandlerDelegate { |
| 44 public: | 44 public: |
| 45 ChannelAssociatedGroupController( | 45 ChannelAssociatedGroupController( |
| 46 bool set_interface_id_namespace_bit, | 46 bool set_interface_id_namespace_bit, |
| 47 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) | 47 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) |
| 48 : task_runner_(ipc_task_runner), | 48 : task_runner_(ipc_task_runner), |
| 49 proxy_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 49 proxy_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 50 set_interface_id_namespace_bit_(set_interface_id_namespace_bit), | 50 set_interface_id_namespace_bit_(set_interface_id_namespace_bit), |
| 51 header_validator_( | 51 filters_(this), |
| 52 "IPC::mojom::Bootstrap [master] MessageHeaderValidator", this), | |
| 53 control_message_handler_(this), | 52 control_message_handler_(this), |
| 54 control_message_proxy_thunk_(this), | 53 control_message_proxy_thunk_(this), |
| 55 control_message_proxy_(&control_message_proxy_thunk_) { | 54 control_message_proxy_(&control_message_proxy_thunk_) { |
| 56 thread_checker_.DetachFromThread(); | 55 thread_checker_.DetachFromThread(); |
| 57 control_message_handler_.SetDescription( | 56 control_message_handler_.SetDescription( |
| 58 "IPC::mojom::Bootstrap [master] PipeControlMessageHandler"); | 57 "IPC::mojom::Bootstrap [master] PipeControlMessageHandler"); |
| 58 filters_.Append<mojo::MessageHeaderValidator>( |
| 59 "IPC::mojom::Bootstrap [master] MessageHeaderValidator"); |
| 59 } | 60 } |
| 60 | 61 |
| 61 void Bind(mojo::ScopedMessagePipeHandle handle) { | 62 void Bind(mojo::ScopedMessagePipeHandle handle) { |
| 62 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
| 63 DCHECK(task_runner_->BelongsToCurrentThread()); | 64 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 64 | 65 |
| 65 connector_.reset(new mojo::Connector( | 66 connector_.reset(new mojo::Connector( |
| 66 std::move(handle), mojo::Connector::SINGLE_THREADED_SEND, | 67 std::move(handle), mojo::Connector::SINGLE_THREADED_SEND, |
| 67 task_runner_)); | 68 task_runner_)); |
| 68 connector_->set_incoming_receiver(&header_validator_); | 69 connector_->set_incoming_receiver(&filters_); |
| 69 connector_->set_connection_error_handler( | 70 connector_->set_connection_error_handler( |
| 70 base::Bind(&ChannelAssociatedGroupController::OnPipeError, | 71 base::Bind(&ChannelAssociatedGroupController::OnPipeError, |
| 71 base::Unretained(this))); | 72 base::Unretained(this))); |
| 72 | 73 |
| 73 std::vector<mojo::Message> outgoing_messages; | 74 std::vector<mojo::Message> outgoing_messages; |
| 74 std::swap(outgoing_messages, outgoing_messages_); | 75 std::swap(outgoing_messages, outgoing_messages_); |
| 75 for (auto& message : outgoing_messages) | 76 for (auto& message : outgoing_messages) |
| 76 SendMessage(&message); | 77 SendMessage(&message); |
| 77 } | 78 } |
| 78 | 79 |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 } | 746 } |
| 746 | 747 |
| 747 // Checked in places which must be run on the master endpoint's thread. | 748 // Checked in places which must be run on the master endpoint's thread. |
| 748 base::ThreadChecker thread_checker_; | 749 base::ThreadChecker thread_checker_; |
| 749 | 750 |
| 750 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 751 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 751 | 752 |
| 752 scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner_; | 753 scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner_; |
| 753 const bool set_interface_id_namespace_bit_; | 754 const bool set_interface_id_namespace_bit_; |
| 754 std::unique_ptr<mojo::Connector> connector_; | 755 std::unique_ptr<mojo::Connector> connector_; |
| 755 mojo::MessageHeaderValidator header_validator_; | 756 mojo::FilterChain filters_; |
| 756 mojo::PipeControlMessageHandler control_message_handler_; | 757 mojo::PipeControlMessageHandler control_message_handler_; |
| 757 ControlMessageProxyThunk control_message_proxy_thunk_; | 758 ControlMessageProxyThunk control_message_proxy_thunk_; |
| 758 mojo::PipeControlMessageProxy control_message_proxy_; | 759 mojo::PipeControlMessageProxy control_message_proxy_; |
| 759 | 760 |
| 760 // Outgoing messages that were sent before this controller was bound to a | 761 // Outgoing messages that were sent before this controller was bound to a |
| 761 // real message pipe. | 762 // real message pipe. |
| 762 std::vector<mojo::Message> outgoing_messages_; | 763 std::vector<mojo::Message> outgoing_messages_; |
| 763 | 764 |
| 764 // Guards the fields below for thread-safe access. | 765 // Guards the fields below for thread-safe access. |
| 765 base::Lock lock_; | 766 base::Lock lock_; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 Channel::Mode mode, | 824 Channel::Mode mode, |
| 824 Delegate* delegate, | 825 Delegate* delegate, |
| 825 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { | 826 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { |
| 826 return base::MakeUnique<MojoBootstrapImpl>( | 827 return base::MakeUnique<MojoBootstrapImpl>( |
| 827 std::move(handle), delegate, | 828 std::move(handle), delegate, |
| 828 new ChannelAssociatedGroupController(mode == Channel::MODE_SERVER, | 829 new ChannelAssociatedGroupController(mode == Channel::MODE_SERVER, |
| 829 ipc_task_runner)); | 830 ipc_task_runner)); |
| 830 } | 831 } |
| 831 | 832 |
| 832 } // namespace IPC | 833 } // namespace IPC |
| OLD | NEW |