diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-25 03:51:56 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-25 03:51:56 +0000 |
commit | 740d451cf5222a5046d63029a88e58c7204c6ba2 (patch) | |
tree | 43b3a71eb8c9d23e48f31434cc3c2ef2e85ef877 /remoting/jingle_glue/iq_sender.cc | |
parent | 426199abc7929b84c80df803b828f3f9c47b4b6d (diff) | |
download | chromium_src-740d451cf5222a5046d63029a88e58c7204c6ba2.zip chromium_src-740d451cf5222a5046d63029a88e58c7204c6ba2.tar.gz chromium_src-740d451cf5222a5046d63029a88e58c7204c6ba2.tar.bz2 |
Revert 123635 - Implement timeouts for IQ requests.
Now the IqRequest class supports setting timeouts for each request, and
JingleSession uses it to disconnect if no response is receive within 10
secons from a request.
BUG=107925
Review URL: http://codereview.chromium.org/9452038
TBR=sergeyu@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9447087
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123638 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/jingle_glue/iq_sender.cc')
-rw-r--r-- | remoting/jingle_glue/iq_sender.cc | 60 |
1 files changed, 8 insertions, 52 deletions
diff --git a/remoting/jingle_glue/iq_sender.cc b/remoting/jingle_glue/iq_sender.cc index ca0b3f6..eb8f17a 100644 --- a/remoting/jingle_glue/iq_sender.cc +++ b/remoting/jingle_glue/iq_sender.cc @@ -4,10 +4,7 @@ #include "remoting/jingle_glue/iq_sender.h" -#include "base/bind.h" -#include "base/location.h" #include "base/logging.h" -#include "base/message_loop_proxy.h" #include "base/string_number_conversions.h" #include "remoting/jingle_glue/signal_strategy.h" #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" @@ -39,14 +36,13 @@ IqSender::~IqSender() { scoped_ptr<IqRequest> IqSender::SendIq(scoped_ptr<buzz::XmlElement> stanza, const ReplyCallback& callback) { - std::string addressee = stanza->Attr(buzz::QN_TO); std::string id = signal_strategy_->GetNextId(); stanza->AddAttr(buzz::QN_ID, id); if (!signal_strategy_->SendStanza(stanza.Pass())) { return scoped_ptr<IqRequest>(NULL); } DCHECK(requests_.find(id) == requests_.end()); - scoped_ptr<IqRequest> request(new IqRequest(this, callback, addressee)); + scoped_ptr<IqRequest> request(new IqRequest(this, callback)); if (!callback.is_null()) requests_[id] = request.get(); return request.Pass(); @@ -96,72 +92,32 @@ bool IqSender::OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) { return false; } - std::string from = stanza->Attr(buzz::QN_FROM); - IqRequestMap::iterator it = requests_.find(id); - - // This is a hack to workaround the issue with the WCS changing IDs - // of IQ responses sent from client to host. Whenever we receive a - // stanza with an unknown ID we try to match it with an outstanding - // request sent to the same peer. - if (it == requests_.end()) { - for (it = requests_.begin(); it != requests_.end(); ++it) { - if (it->second->addressee_ == from) { - break; - } - } - } - if (it == requests_.end()) { return false; } IqRequest* request = it->second; - - if (request->addressee_ != from) { - LOG(ERROR) << "Received IQ response from from a invalid JID. Ignoring it." - << " Message received from: " << from - << " Original JID: " << request->addressee_; - return false; - } - requests_.erase(it); - request->OnResponse(stanza); + request->OnResponse(stanza); return true; } -IqRequest::IqRequest(IqSender* sender, const IqSender::ReplyCallback& callback, - const std::string& addressee) +IqRequest::IqRequest(IqSender* sender, const IqSender::ReplyCallback& callback) : sender_(sender), - callback_(callback), - addressee_(addressee) { + callback_(callback) { } IqRequest::~IqRequest() { sender_->RemoveRequest(this); } -void IqRequest::SetTimeout(base::TimeDelta timeout) { - base::MessageLoopProxy::current()->PostDelayedTask( - FROM_HERE, base::Bind(&IqRequest::OnTimeout, AsWeakPtr()), - timeout.InMilliseconds()); -} - -void IqRequest::CallCallback(const buzz::XmlElement* stanza) { - if (!callback_.is_null()) { - IqSender::ReplyCallback callback(callback_); - callback_.Reset(); - callback.Run(this, stanza); - } -} - -void IqRequest::OnTimeout() { - CallCallback(NULL); -} - void IqRequest::OnResponse(const buzz::XmlElement* stanza) { - CallCallback(stanza); + DCHECK(!callback_.is_null()); + IqSender::ReplyCallback callback(callback_); + callback_.Reset(); + callback.Run(stanza); } } // namespace remoting |