Chromium Code Reviews| Index: jingle/notifier/listener/send_ping_task.cc |
| diff --git a/jingle/notifier/listener/send_ping_task.cc b/jingle/notifier/listener/send_ping_task.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..974a4565f940b0644bdb498ca484782d7e4074d4 |
| --- /dev/null |
| +++ b/jingle/notifier/listener/send_ping_task.cc |
| @@ -0,0 +1,79 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "jingle/notifier/listener/send_ping_task.h" |
| + |
| +#include <string> |
| + |
| +#include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "jingle/notifier/listener/xml_element_util.h" |
| +#include "talk/xmllite/qname.h" |
| +#include "talk/xmllite/xmlelement.h" |
| +#include "talk/xmpp/constants.h" |
| +#include "talk/xmpp/jid.h" |
| +#include "talk/xmpp/xmppclient.h" |
| + |
| +namespace notifier { |
| + |
| +SendPingTask::Delegate::~Delegate() { |
| +} |
| + |
| +SendPingTask::SendPingTask(buzz::XmppTaskParentInterface* parent, |
| + Delegate* delegate) |
| + : XmppTask(parent, buzz::XmppEngine::HL_SINGLE), delegate_(delegate) { |
| +} |
| + |
| +SendPingTask::~SendPingTask() { |
| +} |
| + |
| +int SendPingTask::ProcessStart() { |
| + ping_task_id_ = task_id(); |
| + scoped_ptr<buzz::XmlElement> stanza(MakePingStanza(ping_task_id_)); |
| + DVLOG(1) << "Sending ping stanza " << XmlElementToString(*stanza); |
| + if (SendStanza(stanza.get()) != buzz::XMPP_RETURN_OK) { |
| + LOG(WARNING) << "Could not send stanza " << XmlElementToString(*stanza); |
| + return STATE_ERROR; |
| + } |
| + return STATE_RESPONSE; |
| +} |
| + |
| +int SendPingTask::ProcessResponse() { |
| + const buzz::XmlElement* stanza = NextStanza(); |
| + if (stanza == NULL) { |
| + return STATE_BLOCKED; |
| + } |
| + |
| + DVLOG(1) << "Received stanza " << XmlElementToString(*stanza); |
| + |
| + std::string type = stanza->Attr(buzz::QN_TYPE); |
| + if (type != buzz::STR_RESULT) { |
| + LOG(WARNING) << "No type=\"result\" attribute found in stanza " |
| + << XmlElementToString(*stanza); |
| + return STATE_ERROR; |
| + } |
| + |
| + delegate_->OnPingResponseReceived(); |
| + return STATE_DONE; |
| +} |
| + |
| +bool SendPingTask::HandleStanza(const buzz::XmlElement* stanza) { |
| + // MatchResponseIq() does not match supplied Jid with to field in stanza. |
|
akalin
2012/10/25 00:10:13
the comment is a little confusing. Perhaps someth
gene
2012/10/25 00:43:26
Done.
|
| + // We should supply empty Jid for this to work. |
| + if (MatchResponseIq(stanza, buzz::Jid(buzz::STR_EMPTY), ping_task_id_)) { |
| + QueueStanza(stanza); |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +buzz::XmlElement* SendPingTask::MakePingStanza(const std::string& task_id) { |
| + buzz::XmlElement* stanza = MakeIq(buzz::STR_GET, |
| + buzz::Jid(buzz::STR_EMPTY), |
| + task_id); |
| + stanza->AddElement(new buzz::XmlElement(buzz::QN_PING)); |
| + return stanza; |
| +} |
| + |
| +} // namespace notifier |