Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(830)

Unified Diff: remoting/protocol/negotiating_authenticator.cc

Issue 12389010: Refactor of Authenticator to allow it to ProcessMessage asynchronously and then call a callback (Closed) Base URL: http://git.chromium.org/chromium/src.git@host_key_pair
Patch Set: Rebase missed one include Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/protocol/negotiating_authenticator.h ('k') | remoting/protocol/session.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/protocol/negotiating_authenticator.cc
diff --git a/remoting/protocol/negotiating_authenticator.cc b/remoting/protocol/negotiating_authenticator.cc
index efdbb3204c29e2cafc8a8c8eb8258c9c0ec69290..a8ed3fe0338410d256bed493cc664531c8da904d 100644
--- a/remoting/protocol/negotiating_authenticator.cc
+++ b/remoting/protocol/negotiating_authenticator.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#include <sstream>
+#include "base/bind.h"
#include "base/logging.h"
#include "base/string_split.h"
#include "crypto/rsa_private_key.h"
@@ -90,7 +91,9 @@ NegotiatingAuthenticator::rejection_reason() const {
return rejection_reason_;
}
-void NegotiatingAuthenticator::ProcessMessage(const buzz::XmlElement* message) {
+void NegotiatingAuthenticator::ProcessMessage(
+ const buzz::XmlElement* message,
+ const base::Closure& resume_callback) {
DCHECK_EQ(state(), WAITING_MESSAGE);
std::string method_attr = message->Attr(kMethodAttributeQName);
@@ -112,6 +115,7 @@ void NegotiatingAuthenticator::ProcessMessage(const buzz::XmlElement* message) {
// Message contains neither method nor supported-methods attributes.
state_ = REJECTED;
rejection_reason_ = PROTOCOL_ERROR;
+ resume_callback.Run();
return;
}
@@ -136,6 +140,7 @@ void NegotiatingAuthenticator::ProcessMessage(const buzz::XmlElement* message) {
// Failed to find a common auth method.
state_ = REJECTED;
rejection_reason_ = PROTOCOL_ERROR;
+ resume_callback.Run();
return;
}
@@ -151,15 +156,27 @@ void NegotiatingAuthenticator::ProcessMessage(const buzz::XmlElement* message) {
current_method_ = method;
CreateAuthenticator(state_);
}
-
if (state_ == WAITING_MESSAGE) {
- current_authenticator_->ProcessMessage(message);
- state_ = current_authenticator_->state();
- if (state_ == REJECTED)
- rejection_reason_ = current_authenticator_->rejection_reason();
+ // |current_authenticator_| is owned, so Unretained() is safe here.
+ current_authenticator_->ProcessMessage(message, base::Bind(
+ &NegotiatingAuthenticator::UpdateState,
+ base::Unretained(this), resume_callback));
+ } else {
+ UpdateState(resume_callback);
}
}
+void NegotiatingAuthenticator::UpdateState(
+ const base::Closure& resume_callback) {
+ // After the underlying authenticator finishes processing the message, the
+ // NegotiatingAuthenticator must update its own state before running the
+ // |resume_callback| to resume the session negotiation.
+ state_ = current_authenticator_->state();
+ if (state_ == REJECTED)
+ rejection_reason_ = current_authenticator_->rejection_reason();
+ resume_callback.Run();
+}
+
scoped_ptr<buzz::XmlElement> NegotiatingAuthenticator::GetNextMessage() {
DCHECK_EQ(state(), MESSAGE_READY);
« no previous file with comments | « remoting/protocol/negotiating_authenticator.h ('k') | remoting/protocol/session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698