1 // Copyright (c) 2011 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 handles subscribing to the new Google push notifications. 6 7 #ifndef JINGLE_NOTIFIER_LISTENER_PUSH_NOTIFICATIONS_SUBSCRIBE_TASK_H_ 8 #define JINGLE_NOTIFIER_LISTENER_PUSH_NOTIFICATIONS_SUBSCRIBE_TASK_H_ 9 10 #include <string> 11 #include <vector> 12 13 #include "base/compiler_specific.h" 14 #include "base/gtest_prod_util.h" 15 #include "jingle/notifier/listener/notification_defines.h" 16 #include "talk/xmllite/xmlelement.h" 17 #include "talk/xmpp/xmpptask.h" 18 19 namespace notifier { 20 class PushNotificationsSubscribeTask : public buzz::XmppTask { 21 public: 22 class Delegate { 23 public: 24 virtual ~Delegate() {} 25 virtual void OnSubscribed() = 0; 26 virtual void OnSubscriptionError() = 0; 27 }; 28 29 PushNotificationsSubscribeTask(buzz::XmppTaskParentInterface* parent, 30 const SubscriptionList& subscriptions, 31 Delegate* delegate); 32 virtual ~PushNotificationsSubscribeTask(); 33 34 // Overridden from XmppTask. 35 virtual int ProcessStart() OVERRIDE; 36 virtual int ProcessResponse() OVERRIDE; 37 virtual bool HandleStanza(const buzz::XmlElement* stanza) OVERRIDE; 38 39 private: 40 // Assembles an Xmpp stanza which can be sent to subscribe to notifications. 41 static buzz::XmlElement* MakeSubscriptionMessage( 42 const SubscriptionList& subscriptions, 43 const buzz::Jid& jid, const std::string& task_id); 44 45 SubscriptionList subscriptions_; 46 Delegate* delegate_; 47 48 FRIEND_TEST_ALL_PREFIXES(PushNotificationsSubscribeTaskTest, 49 MakeSubscriptionMessage); 50 51 DISALLOW_COPY_AND_ASSIGN(PushNotificationsSubscribeTask); 52 }; 53 54 typedef PushNotificationsSubscribeTask::Delegate 55 PushNotificationsSubscribeTaskDelegate; 56 57 58 } // namespace notifier 59 60 #endif // JINGLE_NOTIFIER_LISTENER_PUSH_NOTIFICATIONS_SUBSCRIBE_TASK_H_ 61