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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 162 } |
163 | 163 |
164 void CloseEndpointHandle(mojo::InterfaceId id, bool is_local) override { | 164 void CloseEndpointHandle(mojo::InterfaceId id, bool is_local) override { |
165 if (!mojo::IsValidInterfaceId(id)) | 165 if (!mojo::IsValidInterfaceId(id)) |
166 return; | 166 return; |
167 | 167 |
168 base::AutoLock locker(lock_); | 168 base::AutoLock locker(lock_); |
169 if (!is_local) { | 169 if (!is_local) { |
170 DCHECK(ContainsKey(endpoints_, id)); | 170 DCHECK(ContainsKey(endpoints_, id)); |
171 DCHECK(!mojo::IsMasterInterfaceId(id)); | 171 DCHECK(!mojo::IsMasterInterfaceId(id)); |
| 172 |
| 173 base::AutoUnlock unlocker(lock_); |
172 control_message_proxy_.NotifyEndpointClosedBeforeSent(id); | 174 control_message_proxy_.NotifyEndpointClosedBeforeSent(id); |
173 return; | 175 return; |
174 } | 176 } |
175 | 177 |
176 DCHECK(ContainsKey(endpoints_, id)); | 178 DCHECK(ContainsKey(endpoints_, id)); |
177 Endpoint* endpoint = endpoints_[id].get(); | 179 Endpoint* endpoint = endpoints_[id].get(); |
178 DCHECK(!endpoint->client()); | 180 DCHECK(!endpoint->client()); |
179 DCHECK(!endpoint->closed()); | 181 DCHECK(!endpoint->closed()); |
180 MarkClosedAndMaybeRemove(endpoint); | 182 MarkClosedAndMaybeRemove(endpoint); |
181 | 183 |
| 184 base::AutoUnlock unlocker(lock_); |
182 if (!mojo::IsMasterInterfaceId(id)) | 185 if (!mojo::IsMasterInterfaceId(id)) |
183 control_message_proxy_.NotifyPeerEndpointClosed(id); | 186 control_message_proxy_.NotifyPeerEndpointClosed(id); |
184 } | 187 } |
185 | 188 |
186 mojo::InterfaceEndpointController* AttachEndpointClient( | 189 mojo::InterfaceEndpointController* AttachEndpointClient( |
187 const mojo::ScopedInterfaceEndpointHandle& handle, | 190 const mojo::ScopedInterfaceEndpointHandle& handle, |
188 mojo::InterfaceEndpointClient* client, | 191 mojo::InterfaceEndpointClient* client, |
189 scoped_refptr<base::SingleThreadTaskRunner> runner) override { | 192 scoped_refptr<base::SingleThreadTaskRunner> runner) override { |
190 const mojo::InterfaceId id = handle.id(); | 193 const mojo::InterfaceId id = handle.id(); |
191 | 194 |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 | 738 |
736 return true; | 739 return true; |
737 } | 740 } |
738 | 741 |
739 bool OnAssociatedEndpointClosedBeforeSent(mojo::InterfaceId id) override { | 742 bool OnAssociatedEndpointClosedBeforeSent(mojo::InterfaceId id) override { |
740 DCHECK(thread_checker_.CalledOnValidThread()); | 743 DCHECK(thread_checker_.CalledOnValidThread()); |
741 | 744 |
742 if (mojo::IsMasterInterfaceId(id)) | 745 if (mojo::IsMasterInterfaceId(id)) |
743 return false; | 746 return false; |
744 | 747 |
745 base::AutoLock locker(lock_); | 748 { |
746 Endpoint* endpoint = FindOrInsertEndpoint(id, nullptr); | 749 base::AutoLock locker(lock_); |
747 DCHECK(!endpoint->closed()); | 750 Endpoint* endpoint = FindOrInsertEndpoint(id, nullptr); |
748 MarkClosedAndMaybeRemove(endpoint); | 751 DCHECK(!endpoint->closed()); |
| 752 MarkClosedAndMaybeRemove(endpoint); |
| 753 } |
| 754 |
749 control_message_proxy_.NotifyPeerEndpointClosed(id); | 755 control_message_proxy_.NotifyPeerEndpointClosed(id); |
750 return true; | 756 return true; |
751 } | 757 } |
752 | 758 |
753 // 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. |
754 base::ThreadChecker thread_checker_; | 760 base::ThreadChecker thread_checker_; |
755 | 761 |
756 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 762 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
757 | 763 |
758 scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner_; | 764 scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner_; |
759 const bool set_interface_id_namespace_bit_; | 765 const bool set_interface_id_namespace_bit_; |
760 bool paused_ = false; | 766 bool paused_ = false; |
761 std::unique_ptr<mojo::Connector> connector_; | 767 std::unique_ptr<mojo::Connector> connector_; |
762 mojo::FilterChain filters_; | 768 mojo::FilterChain filters_; |
763 mojo::PipeControlMessageHandler control_message_handler_; | 769 mojo::PipeControlMessageHandler control_message_handler_; |
764 ControlMessageProxyThunk control_message_proxy_thunk_; | 770 ControlMessageProxyThunk control_message_proxy_thunk_; |
| 771 |
| 772 // NOTE: It is unsafe to call into this object while holding |lock_|. |
765 mojo::PipeControlMessageProxy control_message_proxy_; | 773 mojo::PipeControlMessageProxy control_message_proxy_; |
766 | 774 |
767 // Outgoing messages that were sent before this controller was bound to a | 775 // Outgoing messages that were sent before this controller was bound to a |
768 // real message pipe. | 776 // real message pipe. |
769 std::vector<mojo::Message> outgoing_messages_; | 777 std::vector<mojo::Message> outgoing_messages_; |
770 | 778 |
771 // Guards the fields below for thread-safe access. | 779 // Guards the fields below for thread-safe access. |
772 base::Lock lock_; | 780 base::Lock lock_; |
773 | 781 |
774 bool encountered_error_ = false; | 782 bool encountered_error_ = false; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 Channel::Mode mode, | 850 Channel::Mode mode, |
843 Delegate* delegate, | 851 Delegate* delegate, |
844 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { | 852 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { |
845 return base::MakeUnique<MojoBootstrapImpl>( | 853 return base::MakeUnique<MojoBootstrapImpl>( |
846 std::move(handle), delegate, | 854 std::move(handle), delegate, |
847 new ChannelAssociatedGroupController(mode == Channel::MODE_SERVER, | 855 new ChannelAssociatedGroupController(mode == Channel::MODE_SERVER, |
848 ipc_task_runner)); | 856 ipc_task_runner)); |
849 } | 857 } |
850 | 858 |
851 } // namespace IPC | 859 } // namespace IPC |
OLD | NEW |