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/slave_connection_manager.h" | 5 #include "mojo/edk/system/slave_connection_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "mojo/edk/system/connection_manager_messages.h" | 12 #include "mojo/edk/system/connection_manager_messages.h" |
13 #include "mojo/edk/system/message_in_transit.h" | 13 #include "mojo/edk/system/message_in_transit.h" |
| 14 #include "mojo/edk/util/make_unique.h" |
14 | 15 |
15 namespace mojo { | 16 namespace mojo { |
16 namespace system { | 17 namespace system { |
17 | 18 |
18 // SlaveConnectionManager ------------------------------------------------------ | 19 // SlaveConnectionManager ------------------------------------------------------ |
19 | 20 |
20 SlaveConnectionManager::SlaveConnectionManager( | 21 SlaveConnectionManager::SlaveConnectionManager( |
21 embedder::PlatformSupport* platform_support) | 22 embedder::PlatformSupport* platform_support) |
22 : ConnectionManager(platform_support), | 23 : ConnectionManager(platform_support), |
23 slave_process_delegate_(), | 24 slave_process_delegate_(), |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 Result* result) { | 154 Result* result) { |
154 DCHECK(result); | 155 DCHECK(result); |
155 AssertOnPrivateThread(); | 156 AssertOnPrivateThread(); |
156 // This should only posted (from another thread, to |private_thread_|) with | 157 // This should only posted (from another thread, to |private_thread_|) with |
157 // the lock held (until this thread triggers |event_|). | 158 // the lock held (until this thread triggers |event_|). |
158 DCHECK(!mutex_.TryLock()); | 159 DCHECK(!mutex_.TryLock()); |
159 DCHECK_EQ(awaiting_ack_type_, NOT_AWAITING_ACK); | 160 DCHECK_EQ(awaiting_ack_type_, NOT_AWAITING_ACK); |
160 | 161 |
161 DVLOG(1) << "Sending AllowConnect: connection ID " | 162 DVLOG(1) << "Sending AllowConnect: connection ID " |
162 << connection_id.ToString(); | 163 << connection_id.ToString(); |
163 if (!raw_channel_->WriteMessage(make_scoped_ptr(new MessageInTransit( | 164 if (!raw_channel_->WriteMessage(util::MakeUnique<MessageInTransit>( |
164 MessageInTransit::Type::CONNECTION_MANAGER, | 165 MessageInTransit::Type::CONNECTION_MANAGER, |
165 MessageInTransit::Subtype::CONNECTION_MANAGER_ALLOW_CONNECT, | 166 MessageInTransit::Subtype::CONNECTION_MANAGER_ALLOW_CONNECT, |
166 sizeof(connection_id), &connection_id)))) { | 167 sizeof(connection_id), &connection_id))) { |
167 // Don't tear things down; possibly we'll still read some messages. | 168 // Don't tear things down; possibly we'll still read some messages. |
168 *result = Result::FAILURE; | 169 *result = Result::FAILURE; |
169 event_.Signal(); | 170 event_.Signal(); |
170 return; | 171 return; |
171 } | 172 } |
172 awaiting_ack_type_ = AWAITING_ACCEPT_CONNECT_ACK; | 173 awaiting_ack_type_ = AWAITING_ACCEPT_CONNECT_ACK; |
173 ack_result_ = result; | 174 ack_result_ = result; |
174 } | 175 } |
175 | 176 |
176 void SlaveConnectionManager::CancelConnectOnPrivateThread( | 177 void SlaveConnectionManager::CancelConnectOnPrivateThread( |
177 const ConnectionIdentifier& connection_id, | 178 const ConnectionIdentifier& connection_id, |
178 Result* result) { | 179 Result* result) { |
179 DCHECK(result); | 180 DCHECK(result); |
180 AssertOnPrivateThread(); | 181 AssertOnPrivateThread(); |
181 // This should only posted (from another thread, to |private_thread_|) with | 182 // This should only posted (from another thread, to |private_thread_|) with |
182 // the lock held (until this thread triggers |event_|). | 183 // the lock held (until this thread triggers |event_|). |
183 DCHECK(!mutex_.TryLock()); | 184 DCHECK(!mutex_.TryLock()); |
184 DCHECK_EQ(awaiting_ack_type_, NOT_AWAITING_ACK); | 185 DCHECK_EQ(awaiting_ack_type_, NOT_AWAITING_ACK); |
185 | 186 |
186 DVLOG(1) << "Sending CancelConnect: connection ID " | 187 DVLOG(1) << "Sending CancelConnect: connection ID " |
187 << connection_id.ToString(); | 188 << connection_id.ToString(); |
188 if (!raw_channel_->WriteMessage(make_scoped_ptr(new MessageInTransit( | 189 if (!raw_channel_->WriteMessage(util::MakeUnique<MessageInTransit>( |
189 MessageInTransit::Type::CONNECTION_MANAGER, | 190 MessageInTransit::Type::CONNECTION_MANAGER, |
190 MessageInTransit::Subtype::CONNECTION_MANAGER_CANCEL_CONNECT, | 191 MessageInTransit::Subtype::CONNECTION_MANAGER_CANCEL_CONNECT, |
191 sizeof(connection_id), &connection_id)))) { | 192 sizeof(connection_id), &connection_id))) { |
192 // Don't tear things down; possibly we'll still read some messages. | 193 // Don't tear things down; possibly we'll still read some messages. |
193 *result = Result::FAILURE; | 194 *result = Result::FAILURE; |
194 event_.Signal(); | 195 event_.Signal(); |
195 return; | 196 return; |
196 } | 197 } |
197 awaiting_ack_type_ = AWAITING_CANCEL_CONNECT_ACK; | 198 awaiting_ack_type_ = AWAITING_CANCEL_CONNECT_ACK; |
198 ack_result_ = result; | 199 ack_result_ = result; |
199 } | 200 } |
200 | 201 |
201 void SlaveConnectionManager::ConnectOnPrivateThread( | 202 void SlaveConnectionManager::ConnectOnPrivateThread( |
202 const ConnectionIdentifier& connection_id, | 203 const ConnectionIdentifier& connection_id, |
203 Result* result, | 204 Result* result, |
204 ProcessIdentifier* peer_process_identifier, | 205 ProcessIdentifier* peer_process_identifier, |
205 bool* is_first, | 206 bool* is_first, |
206 embedder::ScopedPlatformHandle* platform_handle) { | 207 embedder::ScopedPlatformHandle* platform_handle) { |
207 DCHECK(result); | 208 DCHECK(result); |
208 AssertOnPrivateThread(); | 209 AssertOnPrivateThread(); |
209 // This should only posted (from another thread, to |private_thread_|) with | 210 // This should only posted (from another thread, to |private_thread_|) with |
210 // the lock held (until this thread triggers |event_|). | 211 // the lock held (until this thread triggers |event_|). |
211 DCHECK(!mutex_.TryLock()); | 212 DCHECK(!mutex_.TryLock()); |
212 DCHECK_EQ(awaiting_ack_type_, NOT_AWAITING_ACK); | 213 DCHECK_EQ(awaiting_ack_type_, NOT_AWAITING_ACK); |
213 | 214 |
214 DVLOG(1) << "Sending Connect: connection ID " << connection_id.ToString(); | 215 DVLOG(1) << "Sending Connect: connection ID " << connection_id.ToString(); |
215 if (!raw_channel_->WriteMessage(make_scoped_ptr(new MessageInTransit( | 216 if (!raw_channel_->WriteMessage(util::MakeUnique<MessageInTransit>( |
216 MessageInTransit::Type::CONNECTION_MANAGER, | 217 MessageInTransit::Type::CONNECTION_MANAGER, |
217 MessageInTransit::Subtype::CONNECTION_MANAGER_CONNECT, | 218 MessageInTransit::Subtype::CONNECTION_MANAGER_CONNECT, |
218 sizeof(connection_id), &connection_id)))) { | 219 sizeof(connection_id), &connection_id))) { |
219 // Don't tear things down; possibly we'll still read some messages. | 220 // Don't tear things down; possibly we'll still read some messages. |
220 *result = Result::FAILURE; | 221 *result = Result::FAILURE; |
221 platform_handle->reset(); | 222 platform_handle->reset(); |
222 event_.Signal(); | 223 event_.Signal(); |
223 return; | 224 return; |
224 } | 225 } |
225 awaiting_ack_type_ = AWAITING_CONNECT_ACK; | 226 awaiting_ack_type_ = AWAITING_CONNECT_ACK; |
226 ack_result_ = result; | 227 ack_result_ = result; |
227 ack_peer_process_identifier_ = peer_process_identifier; | 228 ack_peer_process_identifier_ = peer_process_identifier; |
228 ack_is_first_ = is_first; | 229 ack_is_first_ = is_first; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 } | 336 } |
336 | 337 |
337 void SlaveConnectionManager::AssertOnPrivateThread() const { | 338 void SlaveConnectionManager::AssertOnPrivateThread() const { |
338 // This should only be called after |Init()| and before |Shutdown()|. | 339 // This should only be called after |Init()| and before |Shutdown()|. |
339 DCHECK(private_thread_.message_loop()); | 340 DCHECK(private_thread_.message_loop()); |
340 DCHECK_EQ(base::MessageLoop::current(), private_thread_.message_loop()); | 341 DCHECK_EQ(base::MessageLoop::current(), private_thread_.message_loop()); |
341 } | 342 } |
342 | 343 |
343 } // namespace system | 344 } // namespace system |
344 } // namespace mojo | 345 } // namespace mojo |
OLD | NEW |