1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 // 5 // This class listens for notifications from the Google Push notifications 6 // service, and signals when they arrive. It checks all incoming stanzas to 7 // see if they look like notifications, and filters out those which are not 8 // valid. 9 // 10 // The task is deleted automatically by the buzz::XmppClient. This occurs in the 11 // destructor of TaskRunner, which is a superclass of buzz::XmppClient. 12 13 #ifndef JINGLE_NOTIFIER_PUSH_NOTIFICATIONS_LISTENER_LISTEN_TASK_H_ 14 #define JINGLE_NOTIFIER_PUSH_NOTIFICATIONS_LISTENER_LISTEN_TASK_H_ 15 16 #include "base/compiler_specific.h" 17 #include "talk/xmpp/xmpptask.h" 18 19 namespace buzz { 20 class XmlElement; 21 } 22 23 namespace notifier { 24 25 struct Notification; 26 27 class PushNotificationsListenTask : public buzz::XmppTask { 28 public: 29 class Delegate { 30 public: 31 virtual void OnNotificationReceived(const Notification& notification) = 0; 32 33 protected: 34 virtual ~Delegate(); 35 }; 36 37 PushNotificationsListenTask(buzz::XmppTaskParentInterface* parent, 38 Delegate* delegate); 39 virtual ~PushNotificationsListenTask(); 40 41 // Overriden from buzz::XmppTask. 42 virtual int ProcessStart() OVERRIDE; 43 virtual int ProcessResponse() OVERRIDE; 44 virtual bool HandleStanza(const buzz::XmlElement* stanza) OVERRIDE; 45 46 private: 47 bool IsValidNotification(const buzz::XmlElement* stanza); 48 49 Delegate* delegate_; 50 51 DISALLOW_COPY_AND_ASSIGN(PushNotificationsListenTask); 52 }; 53 54 typedef PushNotificationsListenTask::Delegate 55 PushNotificationsListenTaskDelegate; 56 57 } // namespace notifier 58 59 #endif // JINGLE_NOTIFIER_PUSH_NOTIFICATIONS_LISTENER_LISTEN_TASK_H_ 60