| Index: remoting/protocol/validating_authenticator.cc
|
| diff --git a/remoting/protocol/validating_authenticator.cc b/remoting/protocol/validating_authenticator.cc
|
| index ee622be44d496be8e0f880fbaf371d543eb24eac..9fcb38508d34f944a678d83b29de8073137f3d13 100644
|
| --- a/remoting/protocol/validating_authenticator.cc
|
| +++ b/remoting/protocol/validating_authenticator.cc
|
| @@ -23,21 +23,24 @@ namespace protocol {
|
|
|
| ValidatingAuthenticator::ValidatingAuthenticator(
|
| const std::string& remote_jid,
|
| - const ValidationCallback& validation_callback,
|
| + const ValidationCallback& incoming_callback,
|
| + const ValidationCallback& accepted_callback,
|
| std::unique_ptr<Authenticator> current_authenticator)
|
| : remote_jid_(remote_jid),
|
| - validation_callback_(validation_callback),
|
| + incoming_callback_(incoming_callback),
|
| + accepted_callback_(accepted_callback),
|
| current_authenticator_(std::move(current_authenticator)),
|
| weak_factory_(this) {
|
| DCHECK(!remote_jid_.empty());
|
| - DCHECK(!validation_callback_.is_null());
|
| + DCHECK(incoming_callback_);
|
| + DCHECK(accepted_callback_);
|
| DCHECK(current_authenticator_);
|
| }
|
|
|
| ValidatingAuthenticator::~ValidatingAuthenticator() {}
|
|
|
| Authenticator::State ValidatingAuthenticator::state() const {
|
| - return state_;
|
| + return pending_auth_message_ ? MESSAGE_READY : state_;
|
| }
|
|
|
| bool ValidatingAuthenticator::started() const {
|
| @@ -70,15 +73,26 @@ void ValidatingAuthenticator::ProcessMessage(
|
| weak_factory_.GetWeakPtr(), resume_callback));
|
| } else {
|
| first_message_received_ = true;
|
| - validation_callback_.Run(
|
| - remote_jid_, base::Bind(&ValidatingAuthenticator::OnValidateComplete,
|
| - weak_factory_.GetWeakPtr(),
|
| - base::Owned(new buzz::XmlElement(*message)),
|
| - resume_callback));
|
| + incoming_callback_.Run(
|
| + remote_jid_,
|
| + base::Bind(
|
| + &ValidatingAuthenticator::OnValidateComplete,
|
| + weak_factory_.GetWeakPtr(),
|
| + base::Bind(&Authenticator::ProcessMessage,
|
| + base::Unretained(current_authenticator_.get()),
|
| + base::Owned(new buzz::XmlElement(*message)),
|
| + base::Bind(&ValidatingAuthenticator::UpdateState,
|
| + weak_factory_.GetWeakPtr(), resume_callback)),
|
| + resume_callback));
|
| }
|
| }
|
|
|
| std::unique_ptr<buzz::XmlElement> ValidatingAuthenticator::GetNextMessage() {
|
| + if (pending_auth_message_) {
|
| + DCHECK(state_ == ACCEPTED || state_ == WAITING_MESSAGE);
|
| + return std::move(pending_auth_message_);
|
| + }
|
| +
|
| std::unique_ptr<buzz::XmlElement> result(
|
| current_authenticator_->GetNextMessage());
|
| state_ = current_authenticator_->state();
|
| @@ -88,17 +102,14 @@ std::unique_ptr<buzz::XmlElement> ValidatingAuthenticator::GetNextMessage() {
|
| }
|
|
|
| void ValidatingAuthenticator::OnValidateComplete(
|
| - const buzz::XmlElement* message,
|
| - const base::Closure& resume_callback,
|
| + const base::Closure& success_callback,
|
| + const base::Closure& failure_callback,
|
| Result validation_result) {
|
| - // Process the original message in the success case, otherwise map
|
| - // |rejection_reason_| to a known reason, set |state_| to REJECTED and notify
|
| - // the listener of the connection error via the callback.
|
| + // Map |rejection_reason_| to a known reason, set |state_| to REJECTED and
|
| + // notify the listener of the connection error via the callback.
|
| switch (validation_result) {
|
| case Result::SUCCESS:
|
| - current_authenticator_->ProcessMessage(
|
| - message, base::Bind(&ValidatingAuthenticator::UpdateState,
|
| - weak_factory_.GetWeakPtr(), resume_callback));
|
| + success_callback.Run();
|
| return;
|
|
|
| case Result::ERROR_INVALID_CREDENTIALS:
|
| @@ -109,13 +120,17 @@ void ValidatingAuthenticator::OnValidateComplete(
|
| rejection_reason_ = Authenticator::INVALID_ACCOUNT;
|
| break;
|
|
|
| + case Result::ERROR_TOO_MANY_CONNECTIONS:
|
| + rejection_reason_ = Authenticator::TOO_MANY_CONNECTIONS;
|
| + break;
|
| +
|
| case Result::ERROR_REJECTED_BY_USER:
|
| rejection_reason_ = Authenticator::REJECTED_BY_USER;
|
| break;
|
| }
|
|
|
| state_ = Authenticator::REJECTED;
|
| - resume_callback.Run();
|
| + failure_callback.Run();
|
| }
|
|
|
| void ValidatingAuthenticator::UpdateState(
|
| @@ -126,9 +141,20 @@ void ValidatingAuthenticator::UpdateState(
|
| state_ = current_authenticator_->state();
|
| if (state_ == REJECTED) {
|
| rejection_reason_ = current_authenticator_->rejection_reason();
|
| + } else if (state_ == MESSAGE_READY) {
|
| + DCHECK(!pending_auth_message_);
|
| + pending_auth_message_ = current_authenticator_->GetNextMessage();
|
| + state_ = current_authenticator_->state();
|
| }
|
|
|
| - resume_callback.Run();
|
| + if (state_ == ACCEPTED) {
|
| + accepted_callback_.Run(
|
| + remote_jid_, base::Bind(&ValidatingAuthenticator::OnValidateComplete,
|
| + weak_factory_.GetWeakPtr(), resume_callback,
|
| + resume_callback));
|
| + } else {
|
| + resume_callback.Run();
|
| + }
|
| }
|
|
|
| } // namespace protocol
|
|
|