Index: remoting/protocol/jingle_session.cc |
diff --git a/remoting/protocol/jingle_session.cc b/remoting/protocol/jingle_session.cc |
index bfab845debed86b9f7b98c032acd653953f14679..9bbe09ad1a1e46f0ef21524dae28826ed66a565e 100644 |
--- a/remoting/protocol/jingle_session.cc |
+++ b/remoting/protocol/jingle_session.cc |
@@ -130,7 +130,7 @@ void JingleSession::InitializeIncomingConnection( |
session_id_ = initiate_message.sid; |
candidate_config_ = initiate_message.description->config()->Clone(); |
- SetState(CONNECTING); |
+ SetState(ACCEPTING); |
} |
void JingleSession::AcceptIncomingConnection( |
@@ -147,7 +147,15 @@ void JingleSession::AcceptIncomingConnection( |
} |
DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE); |
- authenticator_->ProcessMessage(first_auth_message); |
+ // |this| outlives authenticator_, so using Unretained is safe here. |
+ authenticator_->ProcessMessage( |
+ base::Bind(&JingleSession::ContinueAcceptIncomingConnection, |
+ base::Unretained(this)), |
+ first_auth_message); |
+} |
+ |
+void JingleSession::ContinueAcceptIncomingConnection() { |
+ DCHECK_NE(authenticator_->state(), Authenticator::PROCESSING_MESSAGE); |
if (authenticator_->state() == Authenticator::REJECTED) { |
CloseInternal(AuthRejectionReasonToErrorCode( |
authenticator_->rejection_reason())); |
@@ -435,9 +443,6 @@ void JingleSession::OnAccept(const JingleMessage& message, |
return; |
} |
- DCHECK(authenticator_->state() == Authenticator::WAITING_MESSAGE); |
- authenticator_->ProcessMessage(auth_message); |
- |
if (!InitializeConfigFromDescription(message.description.get())) { |
CloseInternal(INCOMPATIBLE_PROTOCOL); |
return; |
@@ -448,12 +453,11 @@ void JingleSession::OnAccept(const JingleMessage& message, |
SetState(CONNECTED); |
- // Process authentication. |
- if (authenticator_->state() == Authenticator::ACCEPTED) { |
- SetState(AUTHENTICATED); |
- } else { |
- ProcessAuthenticationStep(); |
- } |
+ DCHECK(authenticator_->state() == Authenticator::WAITING_MESSAGE); |
+ authenticator_->ProcessMessage( |
+ base::Bind(&JingleSession::ProcessAuthenticationStep, |
+ base::Unretained(this)), |
+ auth_message); |
} |
void JingleSession::OnSessionInfo(const JingleMessage& message, |
@@ -475,8 +479,10 @@ void JingleSession::OnSessionInfo(const JingleMessage& message, |
reply_callback.Run(JingleMessageReply::NONE); |
- authenticator_->ProcessMessage(message.info.get()); |
- ProcessAuthenticationStep(); |
+ authenticator_->ProcessMessage( |
+ base::Bind(&JingleSession::ProcessAuthenticationStep, |
+ base::Unretained(this)), |
+ message.info.get()); |
} |
void JingleSession::ProcessTransportInfo(const JingleMessage& message) { |
@@ -494,7 +500,8 @@ void JingleSession::ProcessTransportInfo(const JingleMessage& message) { |
void JingleSession::OnTerminate(const JingleMessage& message, |
const ReplyCallback& reply_callback) { |
- if (state_ != CONNECTING && state_ != CONNECTED && state_ != AUTHENTICATED) { |
+ if (state_ != CONNECTING && state_ != ACCEPTING && state_ != CONNECTED && |
+ state_ != AUTHENTICATED) { |
LOG(WARNING) << "Received unexpected session-terminate message."; |
reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); |
return; |
@@ -550,7 +557,9 @@ bool JingleSession::InitializeConfigFromDescription( |
} |
void JingleSession::ProcessAuthenticationStep() { |
+ DCHECK(CalledOnValidThread()); |
DCHECK_EQ(state_, CONNECTED); |
+ DCHECK_NE(authenticator_->state(), Authenticator::PROCESSING_MESSAGE); |
if (authenticator_->state() == Authenticator::MESSAGE_READY) { |
JingleMessage message(peer_jid_, JingleMessage::SESSION_INFO, session_id_); |
@@ -571,7 +580,8 @@ void JingleSession::ProcessAuthenticationStep() { |
void JingleSession::CloseInternal(ErrorCode error) { |
DCHECK(CalledOnValidThread()); |
- if (state_ == CONNECTING || state_ == CONNECTED || state_ == AUTHENTICATED) { |
+ if (state_ == CONNECTING || state_ == ACCEPTING || state_ == CONNECTED || |
+ state_ == AUTHENTICATED) { |
// Send session-terminate message with the appropriate error code. |
JingleMessage::Reason reason; |
switch (error) { |