diff options
author | jamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-14 05:08:35 +0000 |
---|---|---|
committer | jamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-14 05:08:35 +0000 |
commit | a40bc3c973cc9698902fc16edeae8c91a86b1d6f (patch) | |
tree | 42af752e62827d5bd61c4fcec994ab090831705d /remoting/protocol | |
parent | 0b3212b2bf028f043f5dbfdee4a8256ef9359639 (diff) | |
download | chromium_src-a40bc3c973cc9698902fc16edeae8c91a86b1d6f.zip chromium_src-a40bc3c973cc9698902fc16edeae8c91a86b1d6f.tar.gz chromium_src-a40bc3c973cc9698902fc16edeae8c91a86b1d6f.tar.bz2 |
Added support for an optimistic protocol message from the client.
This allows the client to avoid a round-trip to the server by preemptively sending the first message of its preferred protocol exchange. This functionality is required by the pairing authenticator, coming soon to a code review near you.
BUG=156182
Review URL: https://chromiumcodereview.appspot.com/15085018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199908 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol')
-rw-r--r-- | remoting/protocol/negotiating_client_authenticator.cc | 32 | ||||
-rw-r--r-- | remoting/protocol/negotiating_client_authenticator.h | 15 |
2 files changed, 36 insertions, 11 deletions
diff --git a/remoting/protocol/negotiating_client_authenticator.cc b/remoting/protocol/negotiating_client_authenticator.cc index 5ab0507..af5d56b 100644 --- a/remoting/protocol/negotiating_client_authenticator.cc +++ b/remoting/protocol/negotiating_client_authenticator.cc @@ -62,11 +62,13 @@ void NegotiatingClientAuthenticator::ProcessMessage( current_method_ = method; method_set_by_host_ = true; state_ = PROCESSING_MESSAGE; + // Copy the message since the authenticator may process it asynchronously. - CreateAuthenticator(WAITING_MESSAGE, base::Bind( + base::Closure callback = base::Bind( &NegotiatingAuthenticatorBase::ProcessMessageInternal, base::Unretained(this), base::Owned(new buzz::XmlElement(*message)), - resume_callback)); + resume_callback); + CreateAuthenticatorForCurrentMethod(WAITING_MESSAGE, callback); return; } ProcessMessageInternal(message, resume_callback); @@ -76,12 +78,18 @@ scoped_ptr<buzz::XmlElement> NegotiatingClientAuthenticator::GetNextMessage() { DCHECK_EQ(state(), MESSAGE_READY); // This is the first message to the host, send a list of supported methods. if (!current_method_.is_valid()) { - // We currently send just an empty message with the supported list, but, in - // the future, the client may optimistically pick a method and send its - // first message, along with the supported methods. If the host doesn't - // support that method, it is free to ignore this first message and pick a - // different method from the supported list. - scoped_ptr<buzz::XmlElement> result = CreateEmptyAuthenticatorMessage(); + // If no authentication method has been chosen, see if we can optimistically + // choose one. + scoped_ptr<buzz::XmlElement> result; + current_authenticator_ = CreatePreferredAuthenticator(); + if (current_authenticator_) { + DCHECK(current_authenticator_->state() == MESSAGE_READY); + result = GetNextMessageInternal(); + } else { + result = CreateEmptyAuthenticatorMessage(); + } + + // Include a list of supported methods. std::stringstream supported_methods(std::stringstream::out); for (std::vector<AuthenticationMethod>::iterator it = methods_.begin(); it != methods_.end(); ++it) { @@ -96,7 +104,7 @@ scoped_ptr<buzz::XmlElement> NegotiatingClientAuthenticator::GetNextMessage() { return GetNextMessageInternal(); } -void NegotiatingClientAuthenticator::CreateAuthenticator( +void NegotiatingClientAuthenticator::CreateAuthenticatorForCurrentMethod( Authenticator::State preferred_initial_state, const base::Closure& resume_callback) { DCHECK(current_method_.is_valid()); @@ -115,6 +123,12 @@ void NegotiatingClientAuthenticator::CreateAuthenticator( } } +scoped_ptr<Authenticator> +NegotiatingClientAuthenticator::CreatePreferredAuthenticator() { + NOTIMPLEMENTED(); + return scoped_ptr<Authenticator>(); +} + void NegotiatingClientAuthenticator::CreateV2AuthenticatorWithSecret( Authenticator::State initial_state, const base::Closure& resume_callback, diff --git a/remoting/protocol/negotiating_client_authenticator.h b/remoting/protocol/negotiating_client_authenticator.h index d2047fe..995cf1dd 100644 --- a/remoting/protocol/negotiating_client_authenticator.h +++ b/remoting/protocol/negotiating_client_authenticator.h @@ -45,8 +45,19 @@ class NegotiatingClientAuthenticator : public NegotiatingAuthenticatorBase { // |current_authenticator_|. Authenticators that can be started in either // state will be created in |preferred_initial_state|. // |resume_callback| is called after |current_authenticator_| is set. - void CreateAuthenticator(Authenticator::State preferred_initial_state, - const base::Closure& resume_callback); + void CreateAuthenticatorForCurrentMethod( + Authenticator::State preferred_initial_state, + const base::Closure& resume_callback); + + // If possible, create a preferred authenticator ready to send an + // initial message optimistically to the host. The host is free to + // ignore the client's preferred authenticator and initial message + // and to instead reply with an alternative method. See the comments + // in negotiating_authenticator_base.h for more details. + // + // Returns the preferred authenticator if possible, or NULL otherwise. + scoped_ptr<Authenticator> CreatePreferredAuthenticator(); + // Creates a V2Authenticator in state |initial_state| with the given // |shared_secret|, then runs |resume_callback|. |