15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This class handles subscribing to the new Google push notifications.
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef JINGLE_NOTIFIER_LISTENER_PUSH_NOTIFICATIONS_SUBSCRIBE_TASK_H_
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define JINGLE_NOTIFIER_LISTENER_PUSH_NOTIFICATIONS_SUBSCRIBE_TASK_H_
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/gtest_prod_util.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "jingle/notifier/listener/notification_defines.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "talk/xmpp/xmpptask.h"
171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace notifier {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PushNotificationsSubscribeTask : public buzz::XmppTask {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class Delegate {
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     virtual ~Delegate() {}
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     virtual void OnSubscribed() = 0;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     virtual void OnSubscriptionError() = 0;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PushNotificationsSubscribeTask(buzz::XmppTaskParentInterface* parent,
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 const SubscriptionList& subscriptions,
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 Delegate* delegate);
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~PushNotificationsSubscribeTask();
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Overridden from XmppTask.
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int ProcessStart() OVERRIDE;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int ProcessResponse() OVERRIDE;
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool HandleStanza(const buzz::XmlElement* stanza) OVERRIDE;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Assembles an Xmpp stanza which can be sent to subscribe to notifications.
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static buzz::XmlElement* MakeSubscriptionMessage(
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const SubscriptionList& subscriptions,
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const buzz::Jid& jid, const std::string& task_id);
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SubscriptionList subscriptions_;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Delegate* delegate_;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(PushNotificationsSubscribeTaskTest,
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           MakeSubscriptionMessage);
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(PushNotificationsSubscribeTask);
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef PushNotificationsSubscribeTask::Delegate
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PushNotificationsSubscribeTaskDelegate;
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace notifier
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // JINGLE_NOTIFIER_LISTENER_PUSH_NOTIFICATIONS_SUBSCRIBE_TASK_H_
61