OLD | NEW |
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/edk/system/master_connection_manager.h" | 5 #include "mojo/edk/system/master_connection_manager.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
9 #include "base/location.h" | 11 #include "base/location.h" |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
12 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
13 #include "mojo/edk/embedder/master_process_delegate.h" | 15 #include "mojo/edk/embedder/master_process_delegate.h" |
14 #include "mojo/edk/embedder/platform_channel_pair.h" | 16 #include "mojo/edk/embedder/platform_channel_pair.h" |
15 #include "mojo/edk/embedder/platform_handle.h" | 17 #include "mojo/edk/embedder/platform_handle.h" |
16 #include "mojo/edk/embedder/platform_handle_vector.h" | 18 #include "mojo/edk/embedder/platform_handle_vector.h" |
17 #include "mojo/edk/system/connection_manager_messages.h" | 19 #include "mojo/edk/system/connection_manager_messages.h" |
18 #include "mojo/edk/system/message_in_transit.h" | 20 #include "mojo/edk/system/message_in_transit.h" |
19 #include "mojo/edk/system/raw_channel.h" | 21 #include "mojo/edk/system/raw_channel.h" |
20 #include "mojo/edk/system/transport_data.h" | 22 #include "mojo/edk/system/transport_data.h" |
| 23 #include "mojo/edk/util/make_unique.h" |
21 #include "mojo/public/cpp/system/macros.h" | 24 #include "mojo/public/cpp/system/macros.h" |
22 | 25 |
23 namespace mojo { | 26 namespace mojo { |
24 namespace system { | 27 namespace system { |
25 | 28 |
26 namespace { | 29 namespace { |
27 | 30 |
28 const ProcessIdentifier kFirstSlaveProcessIdentifier = 2; | 31 const ProcessIdentifier kFirstSlaveProcessIdentifier = 2; |
29 | 32 |
30 static_assert(kMasterProcessIdentifier != kInvalidProcessIdentifier, | 33 static_assert(kMasterProcessIdentifier != kInvalidProcessIdentifier, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 ConnectionManagerResultToMessageInTransitSubtype(result), num_bytes, | 189 ConnectionManagerResultToMessageInTransitSubtype(result), num_bytes, |
187 bytes)); | 190 bytes)); |
188 | 191 |
189 if (result == Result::SUCCESS_CONNECT_NEW_CONNECTION) { | 192 if (result == Result::SUCCESS_CONNECT_NEW_CONNECTION) { |
190 DCHECK_EQ(message_view.subtype(), | 193 DCHECK_EQ(message_view.subtype(), |
191 MessageInTransit::Subtype::CONNECTION_MANAGER_CONNECT); | 194 MessageInTransit::Subtype::CONNECTION_MANAGER_CONNECT); |
192 DCHECK(platform_handle.is_valid()); | 195 DCHECK(platform_handle.is_valid()); |
193 embedder::ScopedPlatformHandleVectorPtr platform_handles( | 196 embedder::ScopedPlatformHandleVectorPtr platform_handles( |
194 new embedder::PlatformHandleVector()); | 197 new embedder::PlatformHandleVector()); |
195 platform_handles->push_back(platform_handle.release()); | 198 platform_handles->push_back(platform_handle.release()); |
196 response->SetTransportData(make_scoped_ptr( | 199 response->SetTransportData(util::MakeUnique<TransportData>( |
197 new TransportData(platform_handles.Pass(), | 200 platform_handles.Pass(), |
198 raw_channel_->GetSerializedPlatformHandleSize()))); | 201 raw_channel_->GetSerializedPlatformHandleSize())); |
199 } else { | 202 } else { |
200 DCHECK(!platform_handle.is_valid()); | 203 DCHECK(!platform_handle.is_valid()); |
201 } | 204 } |
202 | 205 |
203 if (!raw_channel_->WriteMessage(response.Pass())) { | 206 if (!raw_channel_->WriteMessage(response.Pass())) { |
204 LOG(ERROR) << "WriteMessage failed"; | 207 LOG(ERROR) << "WriteMessage failed"; |
205 FatalError(); // WARNING: This destroys us. | 208 FatalError(); // WARNING: This destroys us. |
206 return; | 209 return; |
207 } | 210 } |
208 } | 211 } |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 << ": first Connect() from process identifier " | 550 << ": first Connect() from process identifier " |
548 << process_identifier; | 551 << process_identifier; |
549 *peer_process_identifier = peer; | 552 *peer_process_identifier = peer; |
550 *is_first = true; | 553 *is_first = true; |
551 return ConnectImplHelperNoLock(process_identifier, peer, platform_handle); | 554 return ConnectImplHelperNoLock(process_identifier, peer, platform_handle); |
552 } | 555 } |
553 | 556 |
554 // The remaining cases all result in |it| being removed from | 557 // The remaining cases all result in |it| being removed from |
555 // |pending_connects_| and deleting |info|. | 558 // |pending_connects_| and deleting |info|. |
556 pending_connects_.erase(it); | 559 pending_connects_.erase(it); |
557 scoped_ptr<PendingConnectInfo> info_deleter(info); | 560 std::unique_ptr<PendingConnectInfo> info_deleter(info); |
558 | 561 |
559 // |remaining_connectee| should be the same as |process_identifier|. | 562 // |remaining_connectee| should be the same as |process_identifier|. |
560 ProcessIdentifier remaining_connectee; | 563 ProcessIdentifier remaining_connectee; |
561 if (info->state == PendingConnectInfo::State::AWAITING_CONNECT_FROM_FIRST) { | 564 if (info->state == PendingConnectInfo::State::AWAITING_CONNECT_FROM_FIRST) { |
562 remaining_connectee = info->first; | 565 remaining_connectee = info->first; |
563 peer = info->second; | 566 peer = info->second; |
564 } else if (info->state == | 567 } else if (info->state == |
565 PendingConnectInfo::State::AWAITING_CONNECT_FROM_SECOND) { | 568 PendingConnectInfo::State::AWAITING_CONNECT_FROM_SECOND) { |
566 remaining_connectee = info->second; | 569 remaining_connectee = info->second; |
567 peer = info->first; | 570 peer = info->first; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 | 668 |
666 void MasterConnectionManager::AddSlaveOnPrivateThread( | 669 void MasterConnectionManager::AddSlaveOnPrivateThread( |
667 embedder::SlaveInfo slave_info, | 670 embedder::SlaveInfo slave_info, |
668 embedder::ScopedPlatformHandle platform_handle, | 671 embedder::ScopedPlatformHandle platform_handle, |
669 ProcessIdentifier slave_process_identifier, | 672 ProcessIdentifier slave_process_identifier, |
670 base::WaitableEvent* event) { | 673 base::WaitableEvent* event) { |
671 DCHECK(platform_handle.is_valid()); | 674 DCHECK(platform_handle.is_valid()); |
672 DCHECK(event); | 675 DCHECK(event); |
673 AssertOnPrivateThread(); | 676 AssertOnPrivateThread(); |
674 | 677 |
675 scoped_ptr<Helper> helper(new Helper(this, slave_process_identifier, | 678 std::unique_ptr<Helper> helper(new Helper( |
676 slave_info, platform_handle.Pass())); | 679 this, slave_process_identifier, slave_info, platform_handle.Pass())); |
677 helper->Init(); | 680 helper->Init(); |
678 | 681 |
679 DCHECK(helpers_.find(slave_process_identifier) == helpers_.end()); | 682 DCHECK(helpers_.find(slave_process_identifier) == helpers_.end()); |
680 helpers_[slave_process_identifier] = helper.release(); | 683 helpers_[slave_process_identifier] = helper.release(); |
681 | 684 |
682 DVLOG(1) << "Added slave process identifier " << slave_process_identifier; | 685 DVLOG(1) << "Added slave process identifier " << slave_process_identifier; |
683 event->Signal(); | 686 event->Signal(); |
684 } | 687 } |
685 | 688 |
686 void MasterConnectionManager::OnError(ProcessIdentifier process_identifier) { | 689 void MasterConnectionManager::OnError(ProcessIdentifier process_identifier) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 } | 736 } |
734 | 737 |
735 void MasterConnectionManager::AssertOnPrivateThread() const { | 738 void MasterConnectionManager::AssertOnPrivateThread() const { |
736 // This should only be called after |Init()| and before |Shutdown()|. | 739 // This should only be called after |Init()| and before |Shutdown()|. |
737 DCHECK(private_thread_.message_loop()); | 740 DCHECK(private_thread_.message_loop()); |
738 DCHECK_EQ(base::MessageLoop::current(), private_thread_.message_loop()); | 741 DCHECK_EQ(base::MessageLoop::current(), private_thread_.message_loop()); |
739 } | 742 } |
740 | 743 |
741 } // namespace system | 744 } // namespace system |
742 } // namespace mojo | 745 } // namespace mojo |
OLD | NEW |