Chromium Code Reviews| Index: remoting/jingle_glue/xmpp_signal_strategy.cc |
| diff --git a/remoting/jingle_glue/xmpp_signal_strategy.cc b/remoting/jingle_glue/xmpp_signal_strategy.cc |
| index 1aa7d9cd3c7820b0f9bbe4dfc70555313e03387a..4f40f4d5ead46063af4075fbc67f0e66ac65fd72 100644 |
| --- a/remoting/jingle_glue/xmpp_signal_strategy.cc |
| +++ b/remoting/jingle_glue/xmpp_signal_strategy.cc |
| @@ -4,7 +4,9 @@ |
| #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
| +#include "base/bind.h" |
| #include "base/logging.h" |
| +#include "base/string_util.h" |
| #include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h" |
| #include "remoting/jingle_glue/jingle_thread.h" |
| #include "remoting/jingle_glue/xmpp_socket_adapter.h" |
| @@ -20,6 +22,10 @@ const char kDefaultResourceName[] = "chromoting"; |
| // connections that are idle for more than a minute. |
| const int kKeepAliveIntervalSeconds = 50; |
| +void DisconnectXmppClient(buzz::XmppClient* client) { |
| + client->Disconnect(); |
| +} |
| + |
| } // namespace |
| namespace remoting { |
| @@ -34,11 +40,11 @@ XmppSignalStrategy::XmppSignalStrategy(JingleThread* jingle_thread, |
| auth_token_service_(auth_token_service), |
| resource_name_(kDefaultResourceName), |
| xmpp_client_(NULL), |
| - state_(DISCONNECTED) { |
| + state_(DISCONNECTED), |
| + error_(NO_ERROR) { |
| } |
| XmppSignalStrategy::~XmppSignalStrategy() { |
| - DCHECK_EQ(listeners_.size(), 0U); |
| Disconnect(); |
| } |
| @@ -89,6 +95,11 @@ SignalStrategy::State XmppSignalStrategy::GetState() const { |
| return state_; |
| } |
| +SignalStrategy::Error XmppSignalStrategy::GetError() const { |
| + DCHECK(CalledOnValidThread()); |
| + return error_; |
| +} |
| + |
| std::string XmppSignalStrategy::GetLocalJid() const { |
| DCHECK(CalledOnValidThread()); |
| return xmpp_client_->jid().Str(); |
| @@ -154,7 +165,23 @@ void XmppSignalStrategy::SetResourceName(const std::string &resource_name) { |
| void XmppSignalStrategy::OnConnectionStateChanged( |
| buzz::XmppEngine::State state) { |
| DCHECK(CalledOnValidThread()); |
| + |
| if (state == buzz::XmppEngine::STATE_OPEN) { |
| + // Verify that the JID that we've received doesn't match the |
|
simonmorris
2012/05/11 19:57:25
"doesn't match" -> "matches".
Sergey Ulanov
2012/05/11 20:48:05
Done.
|
| + // username that we have. That probably means that the OAuth token |
|
simonmorris
2012/05/11 19:57:25
"That probably means" -> "If it doesn't, then... w
Sergey Ulanov
2012/05/11 20:48:05
Done.
|
| + // was issued for a different account, so we treat is a an auth |
| + // error. |
| + if (!StartsWithASCII(GetLocalJid(), username_, false)) { |
|
simonmorris
2012/05/11 19:57:25
Other cases may be worth considering. I'll follow
|
| + LOG(ERROR) << "Received JID that is different from the expected value."; |
| + error_ = AUTHENTICATION_FAILED; |
| + xmpp_client_->SignalStateChange.disconnect(this); |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, base::Bind(&DisconnectXmppClient, xmpp_client_)); |
| + xmpp_client_ = NULL; |
| + SetState(DISCONNECTED); |
| + return; |
| + } |
| + |
| keep_alive_timer_.Start( |
| FROM_HERE, base::TimeDelta::FromSeconds(kKeepAliveIntervalSeconds), |
| this, &XmppSignalStrategy::SendKeepAlive); |
| @@ -171,6 +198,18 @@ void XmppSignalStrategy::OnConnectionStateChanged( |
| // Client is destroyed by the TaskRunner after the client is |
| // closed. Reset the pointer so we don't try to use it later. |
| xmpp_client_ = NULL; |
| + |
| + switch (error) { |
| + case buzz::XmppEngine::ERROR_UNAUTHORIZED: |
| + case buzz::XmppEngine::ERROR_AUTH: |
| + case buzz::XmppEngine::ERROR_MISSING_USERNAME: |
| + error_ = AUTHENTICATION_FAILED; |
| + break; |
| + |
| + default: |
| + error_ = NETWORK_ERROR; |
| + } |
| + |
| SetState(DISCONNECTED); |
| } |
| } |