Chromium Code Reviews| 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 |