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