Home | History | Annotate | Download | only in listener
      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 #ifndef JINGLE_NOTIFIER_LISTENER_XMPP_PUSH_CLIENT_H_
      6 #define JINGLE_NOTIFIER_LISTENER_XMPP_PUSH_CLIENT_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/compiler_specific.h"
     13 #include "base/memory/ref_counted.h"
     14 #include "base/memory/scoped_ptr.h"
     15 #include "base/memory/weak_ptr.h"
     16 #include "base/observer_list.h"
     17 #include "base/threading/thread_checker.h"
     18 #include "jingle/notifier/base/notifier_options.h"
     19 #include "jingle/notifier/communicator/login.h"
     20 #include "jingle/notifier/listener/notification_defines.h"
     21 #include "jingle/notifier/listener/push_client.h"
     22 #include "jingle/notifier/listener/push_notifications_listen_task.h"
     23 #include "jingle/notifier/listener/push_notifications_subscribe_task.h"
     24 #include "jingle/notifier/listener/send_ping_task.h"
     25 #include "talk/xmpp/xmppclientsettings.h"
     26 
     27 namespace buzz {
     28 class XmppTaskParentInterface;
     29 }  // namespace buzz
     30 
     31 namespace notifier {
     32 
     33 // This class implements a client for the XMPP google:push protocol.
     34 //
     35 // This class must be used on a single thread.
     36 class XmppPushClient :
     37       public PushClient,
     38       public Login::Delegate,
     39       public PushNotificationsListenTaskDelegate,
     40       public PushNotificationsSubscribeTaskDelegate,
     41       public SendPingTaskDelegate {
     42  public:
     43   explicit XmppPushClient(const NotifierOptions& notifier_options);
     44   virtual ~XmppPushClient();
     45 
     46   // PushClient implementation.
     47   virtual void AddObserver(PushClientObserver* observer) OVERRIDE;
     48   virtual void RemoveObserver(PushClientObserver* observer) OVERRIDE;
     49   virtual void UpdateSubscriptions(
     50       const SubscriptionList& subscriptions) OVERRIDE;
     51   virtual void UpdateCredentials(
     52       const std::string& email, const std::string& token) OVERRIDE;
     53   virtual void SendNotification(const Notification& notification) OVERRIDE;
     54   virtual void SendPing() OVERRIDE;
     55 
     56   // Login::Delegate implementation.
     57   virtual void OnConnect(
     58       base::WeakPtr<buzz::XmppTaskParentInterface> base_task) OVERRIDE;
     59   virtual void OnTransientDisconnection() OVERRIDE;
     60   virtual void OnCredentialsRejected() OVERRIDE;
     61 
     62   // PushNotificationsListenTaskDelegate implementation.
     63   virtual void OnNotificationReceived(
     64       const Notification& notification) OVERRIDE;
     65 
     66   // PushNotificationsSubscribeTaskDelegate implementation.
     67   virtual void OnSubscribed() OVERRIDE;
     68   virtual void OnSubscriptionError() OVERRIDE;
     69 
     70   // SendPingTaskDelegate implementation.
     71   virtual void OnPingResponseReceived() OVERRIDE;
     72 
     73  private:
     74   base::ThreadChecker thread_checker_;
     75   const NotifierOptions notifier_options_;
     76   ObserverList<PushClientObserver> observers_;
     77 
     78   // XMPP connection settings.
     79   SubscriptionList subscriptions_;
     80   buzz::XmppClientSettings xmpp_settings_;
     81 
     82   scoped_ptr<notifier::Login> login_;
     83 
     84   // The XMPP connection.
     85   base::WeakPtr<buzz::XmppTaskParentInterface> base_task_;
     86 
     87   std::vector<Notification> pending_notifications_to_send_;
     88 
     89   DISALLOW_COPY_AND_ASSIGN(XmppPushClient);
     90 };
     91 
     92 }  // namespace notifier
     93 
     94 #endif  // JINGLE_NOTIFIER_LISTENER_XMPP_PUSH_CLIENT_H_
     95