OLD | NEW |
---|---|
(Empty) | |
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_PUSH_CLIENT_H_ | |
6 #define JINGLE_NOTIFIER_LISTENER_PUSH_CLIENT_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "jingle/notifier/base/notifier_options.h" | |
15 #include "jingle/notifier/listener/notification_defines.h" | |
16 | |
17 namespace base { | |
18 class MessageLoopProxy; | |
19 } // namespace base | |
20 | |
21 namespace buzz { | |
22 class XmppTaskParentInterface; | |
23 } // namespace buzz | |
24 | |
25 namespace notifier { | |
26 | |
27 // This class implements a client for the XMPP google:push protocol. | |
28 // | |
29 // This class must be used on a single thread. | |
30 class PushClient { | |
31 public: | |
32 // An Observer is sent messages whenever a notification is received | |
33 // or when the state of the push client changes. | |
34 class Observer { | |
35 public: | |
36 // Called when the state of the push client changes. If | |
37 // |notifications_enabled| is true, that means notifications can | |
38 // be sent and received freely. If it is false, that means no | |
39 // notifications can be sent or received. | |
40 virtual void OnNotificationStateChange(bool notifications_enabled) = 0; | |
41 | |
42 // Called when a notification is received. The details of the | |
43 // notification are in |notification|. | |
44 virtual void OnIncomingNotification(const Notification& notification) = 0; | |
45 | |
46 protected: | |
47 virtual ~Observer(); | |
48 }; | |
49 | |
50 explicit PushClient(const NotifierOptions& notifier_options); | |
51 ~PushClient(); | |
52 | |
53 void AddObserver(Observer* observer); | |
54 void RemoveObserver(Observer* observer); | |
55 | |
56 // Takes effect only on the next (re-)connection. Therefore, you | |
57 // probably want to call this before UpdateCredentials(). | |
58 void UpdateSubscriptions(const SubscriptionList& subscriptions); | |
59 | |
60 // If not connected, connects with the given credentials. If | |
61 // already connected, the next connection attempt will use the given | |
62 // credentials. | |
63 void UpdateCredentials(const std::string& email, const std::string& token); | |
64 | |
65 // Sends a notification. Can be called when notifications are | |
66 // disabled; the notification will be sent when notifications become | |
67 // enabled. | |
68 void SendNotification(const Notification& data); | |
69 | |
70 void SimulateOnNotificationReceivedForTest( | |
rlarocque
2012/05/16 17:46:00
Is there no way to move these into a test class?
akalin
2012/05/16 17:53:16
What do you mean? I couldn't think of a better wa
rlarocque
2012/05/16 19:07:50
I see it now. Moving these functions out of this
akalin
2012/05/16 22:47:42
The logic in ::Core will be moved out into another
| |
71 const Notification& notification); | |
72 | |
73 void SimulateConnectAndSubscribeForTest( | |
74 base::WeakPtr<buzz::XmppTaskParentInterface> base_task); | |
75 | |
76 void SimulateDisconnectForTest(); | |
77 | |
78 void SimulateSubscriptionErrorForTest(); | |
79 | |
80 private: | |
81 class Core; | |
82 | |
83 // The real guts of PushClient, which allows this class to not be | |
84 // refcounted. | |
85 const scoped_refptr<Core> core_; | |
86 const scoped_refptr<base::MessageLoopProxy> parent_message_loop_proxy_; | |
87 const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(PushClient); | |
90 }; | |
91 | |
92 } // namespace notifier | |
93 | |
94 #endif // JINGLE_NOTIFIER_LISTENER_PUSH_CLIENT_H_ | |
OLD | NEW |