summaryrefslogtreecommitdiff
path: root/chromium/jingle/notifier/listener/xmpp_push_client.h
blob: 08a1811706d62a36a05882bb0a2bde8cec196957 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef JINGLE_NOTIFIER_LISTENER_XMPP_PUSH_CLIENT_H_
#define JINGLE_NOTIFIER_LISTENER_XMPP_PUSH_CLIENT_H_

#include <string>
#include <vector>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/threading/thread_checker.h"
#include "jingle/notifier/base/notifier_options.h"
#include "jingle/notifier/communicator/login.h"
#include "jingle/notifier/listener/notification_defines.h"
#include "jingle/notifier/listener/push_client.h"
#include "jingle/notifier/listener/push_notifications_listen_task.h"
#include "jingle/notifier/listener/push_notifications_subscribe_task.h"
#include "jingle/notifier/listener/send_ping_task.h"
#include "talk/xmpp/xmppclientsettings.h"

namespace buzz {
class XmppTaskParentInterface;
}  // namespace buzz

namespace notifier {

// This class implements a client for the XMPP google:push protocol.
//
// This class must be used on a single thread.
class XmppPushClient :
      public PushClient,
      public Login::Delegate,
      public PushNotificationsListenTaskDelegate,
      public PushNotificationsSubscribeTaskDelegate,
      public SendPingTaskDelegate {
 public:
  explicit XmppPushClient(const NotifierOptions& notifier_options);
  virtual ~XmppPushClient();

  // PushClient implementation.
  virtual void AddObserver(PushClientObserver* observer) OVERRIDE;
  virtual void RemoveObserver(PushClientObserver* observer) OVERRIDE;
  virtual void UpdateSubscriptions(
      const SubscriptionList& subscriptions) OVERRIDE;
  virtual void UpdateCredentials(
      const std::string& email, const std::string& token) OVERRIDE;
  virtual void SendNotification(const Notification& notification) OVERRIDE;
  virtual void SendPing() OVERRIDE;

  // Login::Delegate implementation.
  virtual void OnConnect(
      base::WeakPtr<buzz::XmppTaskParentInterface> base_task) OVERRIDE;
  virtual void OnTransientDisconnection() OVERRIDE;
  virtual void OnCredentialsRejected() OVERRIDE;

  // PushNotificationsListenTaskDelegate implementation.
  virtual void OnNotificationReceived(
      const Notification& notification) OVERRIDE;

  // PushNotificationsSubscribeTaskDelegate implementation.
  virtual void OnSubscribed() OVERRIDE;
  virtual void OnSubscriptionError() OVERRIDE;

  // SendPingTaskDelegate implementation.
  virtual void OnPingResponseReceived() OVERRIDE;

 private:
  base::ThreadChecker thread_checker_;
  const NotifierOptions notifier_options_;
  ObserverList<PushClientObserver> observers_;

  // XMPP connection settings.
  SubscriptionList subscriptions_;
  buzz::XmppClientSettings xmpp_settings_;

  scoped_ptr<notifier::Login> login_;

  // The XMPP connection.
  base::WeakPtr<buzz::XmppTaskParentInterface> base_task_;

  std::vector<Notification> pending_notifications_to_send_;

  DISALLOW_COPY_AND_ASSIGN(XmppPushClient);
};

}  // namespace notifier

#endif  // JINGLE_NOTIFIER_LISTENER_XMPP_PUSH_CLIENT_H_