Index: third_party/mojo/src/mojo/edk/system/slave_connection_manager.cc |
diff --git a/third_party/mojo/src/mojo/edk/system/slave_connection_manager.cc b/third_party/mojo/src/mojo/edk/system/slave_connection_manager.cc |
index 7d0a9987eac397e852671021a917f62fec9208b4..d59bd827b9d13736b17719019d10b4ca13e73df6 100644 |
--- a/third_party/mojo/src/mojo/edk/system/slave_connection_manager.cc |
+++ b/third_party/mojo/src/mojo/edk/system/slave_connection_manager.cc |
@@ -22,9 +22,9 @@ |
slave_process_delegate_(), |
private_thread_("SlaveConnectionManagerPrivateThread"), |
awaiting_ack_type_(NOT_AWAITING_ACK), |
- ack_result_(nullptr), |
- ack_peer_process_identifier_(nullptr), |
- ack_platform_handle_(nullptr), |
+ ack_result_(), |
+ ack_peer_process_identifier_(), |
+ ack_platform_handle_(), |
event_(false, false) { // Auto-reset, not initially signalled. |
} |
@@ -78,40 +78,38 @@ |
const ConnectionIdentifier& connection_id) { |
AssertNotOnPrivateThread(); |
- MutexLocker locker(&mutex_); |
- Result result = Result::FAILURE; |
+ base::AutoLock locker(lock_); |
+ bool result = false; |
private_thread_.message_loop()->PostTask( |
FROM_HERE, |
base::Bind(&SlaveConnectionManager::AllowConnectOnPrivateThread, |
base::Unretained(this), connection_id, &result)); |
event_.Wait(); |
- DCHECK(result == Result::FAILURE || result == Result::SUCCESS); |
- return result == Result::SUCCESS; |
+ return result; |
} |
bool SlaveConnectionManager::CancelConnect( |
const ConnectionIdentifier& connection_id) { |
AssertNotOnPrivateThread(); |
- MutexLocker locker(&mutex_); |
- Result result = Result::FAILURE; |
+ base::AutoLock locker(lock_); |
+ bool result = false; |
private_thread_.message_loop()->PostTask( |
FROM_HERE, |
base::Bind(&SlaveConnectionManager::CancelConnectOnPrivateThread, |
base::Unretained(this), connection_id, &result)); |
event_.Wait(); |
- DCHECK(result == Result::FAILURE || result == Result::SUCCESS); |
- return result == Result::SUCCESS; |
-} |
- |
-ConnectionManager::Result SlaveConnectionManager::Connect( |
+ return result; |
+} |
+ |
+bool SlaveConnectionManager::Connect( |
const ConnectionIdentifier& connection_id, |
ProcessIdentifier* peer_process_identifier, |
embedder::ScopedPlatformHandle* platform_handle) { |
AssertNotOnPrivateThread(); |
- MutexLocker locker(&mutex_); |
- Result result = Result::FAILURE; |
+ base::AutoLock locker(lock_); |
+ bool result = false; |
private_thread_.message_loop()->PostTask( |
FROM_HERE, base::Bind(&SlaveConnectionManager::ConnectOnPrivateThread, |
base::Unretained(this), connection_id, &result, |
@@ -141,12 +139,12 @@ |
void SlaveConnectionManager::AllowConnectOnPrivateThread( |
const ConnectionIdentifier& connection_id, |
- Result* result) { |
+ bool* result) { |
DCHECK(result); |
AssertOnPrivateThread(); |
// This should only posted (from another thread, to |private_thread_|) with |
// the lock held (until this thread triggers |event_|). |
- DCHECK(!mutex_.TryLock()); |
+ DCHECK(!lock_.Try()); |
DCHECK_EQ(awaiting_ack_type_, NOT_AWAITING_ACK); |
DVLOG(1) << "Sending AllowConnect: connection ID " |
@@ -156,7 +154,7 @@ |
MessageInTransit::Subtype::CONNECTION_MANAGER_ALLOW_CONNECT, |
sizeof(connection_id), &connection_id)))) { |
// Don't tear things down; possibly we'll still read some messages. |
- *result = Result::FAILURE; |
+ *result = false; |
event_.Signal(); |
return; |
} |
@@ -166,12 +164,12 @@ |
void SlaveConnectionManager::CancelConnectOnPrivateThread( |
const ConnectionIdentifier& connection_id, |
- Result* result) { |
+ bool* result) { |
DCHECK(result); |
AssertOnPrivateThread(); |
// This should only posted (from another thread, to |private_thread_|) with |
// the lock held (until this thread triggers |event_|). |
- DCHECK(!mutex_.TryLock()); |
+ DCHECK(!lock_.Try()); |
DCHECK_EQ(awaiting_ack_type_, NOT_AWAITING_ACK); |
DVLOG(1) << "Sending CancelConnect: connection ID " |
@@ -181,7 +179,7 @@ |
MessageInTransit::Subtype::CONNECTION_MANAGER_CANCEL_CONNECT, |
sizeof(connection_id), &connection_id)))) { |
// Don't tear things down; possibly we'll still read some messages. |
- *result = Result::FAILURE; |
+ *result = false; |
event_.Signal(); |
return; |
} |
@@ -191,7 +189,7 @@ |
void SlaveConnectionManager::ConnectOnPrivateThread( |
const ConnectionIdentifier& connection_id, |
- Result* result, |
+ bool* result, |
ProcessIdentifier* peer_process_identifier, |
embedder::ScopedPlatformHandle* platform_handle) { |
DCHECK(result); |
@@ -200,7 +198,7 @@ |
AssertOnPrivateThread(); |
// This should only posted (from another thread, to |private_thread_|) with |
// the lock held (until this thread triggers |event_|). |
- DCHECK(!mutex_.TryLock()); |
+ DCHECK(!lock_.Try()); |
DCHECK_EQ(awaiting_ack_type_, NOT_AWAITING_ACK); |
DVLOG(1) << "Sending Connect: connection ID " << connection_id.ToString(); |
@@ -209,7 +207,7 @@ |
MessageInTransit::Subtype::CONNECTION_MANAGER_CONNECT, |
sizeof(connection_id), &connection_id)))) { |
// Don't tear things down; possibly we'll still read some messages. |
- *result = Result::FAILURE; |
+ *result = false; |
platform_handle->reset(); |
event_.Signal(); |
return; |
@@ -225,8 +223,8 @@ |
embedder::ScopedPlatformHandleVectorPtr platform_handles) { |
AssertOnPrivateThread(); |
- // Set |*ack_result_| to failure by default. |
- *ack_result_ = Result::FAILURE; |
+ // Set |*ack_result_| to false by default. |
+ *ack_result_ = false; |
// Note: Since we should be able to trust the master, simply crash (i.e., |
// |CHECK()|-fail) if it sends us something invalid. |
@@ -242,53 +240,38 @@ |
if (message_view.subtype() == |
MessageInTransit::Subtype::CONNECTION_MANAGER_ACK_FAILURE) { |
// Failure acks never have any contents. |
- DCHECK_EQ(num_bytes, 0u); |
- DCHECK_EQ(num_platform_handles, 0u); |
- // Leave |*ack_result_| as failure. |
- } else { |
- if (awaiting_ack_type_ != AWAITING_CONNECT_ACK) { |
- // In the non-"connect" case, there's only one type of success ack, which |
- // never has any contents. |
- CHECK_EQ(message_view.subtype(), |
- MessageInTransit::Subtype::CONNECTION_MANAGER_ACK_SUCCESS); |
- DCHECK_EQ(num_bytes, 0u); |
- DCHECK_EQ(num_platform_handles, 0u); |
- *ack_result_ = Result::SUCCESS; |
+ CHECK_EQ(num_bytes, 0u); |
+ CHECK_EQ(num_platform_handles, 0u); |
+ // Leave |*ack_result_| false. |
+ } else if (message_view.subtype() == |
+ MessageInTransit::Subtype::CONNECTION_MANAGER_ACK_SUCCESS) { |
+ if (awaiting_ack_type_ == AWAITING_ACCEPT_CONNECT_ACK || |
+ awaiting_ack_type_ == AWAITING_CANCEL_CONNECT_ACK) { |
+ // Success acks for "accept/cancel connect" have no contents. |
+ CHECK_EQ(num_bytes, 0u); |
+ CHECK_EQ(num_platform_handles, 0u); |
+ *ack_result_ = true; |
DCHECK(!ack_peer_process_identifier_); |
DCHECK(!ack_platform_handle_); |
} else { |
- // Success acks for "connect" always have a |ProcessIdentifier| as data. |
+ DCHECK_EQ(awaiting_ack_type_, AWAITING_CONNECT_ACK); |
+ // Success acks for "connect" always have a |ProcessIdentifier| as data, |
+ // and *maybe* one platform handle. |
CHECK_EQ(num_bytes, sizeof(ProcessIdentifier)); |
+ CHECK_LE(num_platform_handles, 1u); |
+ *ack_result_ = true; |
*ack_peer_process_identifier_ = |
*reinterpret_cast<const ProcessIdentifier*>(message_view.bytes()); |
- |
- switch (message_view.subtype()) { |
- case MessageInTransit::Subtype:: |
- CONNECTION_MANAGER_ACK_SUCCESS_CONNECT_SAME_PROCESS: |
- DCHECK_EQ(num_platform_handles, 0u); |
- *ack_result_ = Result::SUCCESS_CONNECT_SAME_PROCESS; |
- ack_platform_handle_->reset(); |
- break; |
- case MessageInTransit::Subtype:: |
- CONNECTION_MANAGER_ACK_SUCCESS_CONNECT_NEW_CONNECTION: |
- CHECK_EQ(num_platform_handles, 1u); |
- *ack_result_ = Result::SUCCESS_CONNECT_NEW_CONNECTION; |
- ack_platform_handle_->reset(platform_handles->at(0)); |
- platform_handles->at(0) = embedder::PlatformHandle(); |
- break; |
- case MessageInTransit::Subtype:: |
- CONNECTION_MANAGER_ACK_SUCCESS_CONNECT_REUSE_CONNECTION: |
- DCHECK_EQ(num_platform_handles, 0u); |
- *ack_result_ = Result::SUCCESS_CONNECT_REUSE_CONNECTION; |
- ack_platform_handle_->reset(); |
- // TODO(vtl): FIXME -- currently, nothing should generate |
- // SUCCESS_CONNECT_REUSE_CONNECTION. |
- CHECK(false); |
- break; |
- default: |
- CHECK(false); |
+ if (num_platform_handles > 0) { |
+ ack_platform_handle_->reset(platform_handles->at(0)); |
+ platform_handles->at(0) = embedder::PlatformHandle(); |
+ } else { |
+ ack_platform_handle_->reset(); |
} |
} |
+ } else { |
+ // Bad message subtype. |
+ CHECK(false); |
} |
awaiting_ack_type_ = NOT_AWAITING_ACK; |