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

Unified Diff: jingle/notifier/listener/push_notifications_listen_task.cc

Issue 11232048: Adding XMPP ping functionality to CLoudPrint. XMPP ping and timeout is controlled thorugh Service S… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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
Index: jingle/notifier/listener/push_notifications_listen_task.cc
diff --git a/jingle/notifier/listener/push_notifications_listen_task.cc b/jingle/notifier/listener/push_notifications_listen_task.cc
index ad1da9f9debd3ec4e73566760891badffbfa9a13..2fda06eab8d788aa22fc44af2acbd5de9d4072cc 100644
--- a/jingle/notifier/listener/push_notifications_listen_task.cc
+++ b/jingle/notifier/listener/push_notifications_listen_task.cc
@@ -40,6 +40,34 @@ int PushNotificationsListenTask::ProcessResponse() {
DVLOG(1) << "Received stanza " << XmlElementToString(*stanza);
+ if (stanza->Name() == buzz::QN_MESSAGE) {
+ ProcessMessageStanza(stanza);
+ } else if (stanza->Name() == buzz::QN_IQ) {
+ ProcessPingStanza(stanza);
+ } else {
+ LOG(WARNING) << "Unknwon stanza " << XmlElementToString(*stanza);
+ }
+ return STATE_RESPONSE;
+}
+
+bool PushNotificationsListenTask::HandleStanza(const buzz::XmlElement* stanza) {
+ if (IsValidNotification(stanza)) {
+ QueueStanza(stanza);
+ return true;
Vitaly Buka (NO REVIEWS) 2012/10/22 20:52:53 Following order looks better to me if (!IsValidN
gene 2012/10/22 21:44:12 This is an original code.
+ }
+ return false;
+}
+
+bool PushNotificationsListenTask::IsValidNotification(
+ const buzz::XmlElement* stanza) {
+ // We don't do much validation here, just check if the stanza is a message
+ // or iq (ping) stanza.
+ return
+ (stanza->Name() == buzz::QN_MESSAGE) || (stanza->Name() == buzz::QN_IQ);
Vitaly Buka (NO REVIEWS) 2012/10/22 20:52:53 return only looks weird to me, how about? return
gene 2012/10/22 21:44:12 Done.
+}
+
+void PushNotificationsListenTask::ProcessMessageStanza(
+ const buzz::XmlElement* stanza) {
// The push notifications service does not need us to acknowledge receipt of
// the notification to the buzz server.
@@ -78,22 +106,20 @@ int PushNotificationsListenTask::ProcessResponse() {
LOG(WARNING) << "No push element found in stanza "
<< XmlElementToString(*stanza);
}
- return STATE_RESPONSE;
}
-bool PushNotificationsListenTask::HandleStanza(const buzz::XmlElement* stanza) {
- if (IsValidNotification(stanza)) {
- QueueStanza(stanza);
- return true;
- }
- return false;
-}
-
-bool PushNotificationsListenTask::IsValidNotification(
+void PushNotificationsListenTask::ProcessPingStanza(
const buzz::XmlElement* stanza) {
- // We don't do much validation here, just check if the stanza is a message
- // stanza.
- return (stanza->Name() == buzz::QN_MESSAGE);
+ // TODO(gene): Do we need to check if to=<jid> condition?
+ std::string type = stanza->Attr(buzz::QN_TYPE);
+ if (type == buzz::STR_RESULT) {
+ Notification notification;
+ notification.ping = true;
+ delegate_->OnNotificationReceived(notification);
+ } else {
+ LOG(WARNING) << "No type=\"result\" attribute found in stanza "
+ << XmlElementToString(*stanza);
+ }
}
} // namespace notifier

Powered by Google App Engine
This is Rietveld 408576698