Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Side by Side Diff: jingle/notifier/listener/push_client.h

Issue 10398051: [Sync] Replace TalkMediator*/MediatorThread* with PushClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments, fix test Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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& notification);
69
70 void SimulateOnNotificationReceivedForTest(
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 // Any notifications sent after this is called will be reflected,
81 // i.e. will be treated as an incoming notification also.
82 void ReflectSentNotificationsForTest();
83
84 private:
85 class Core;
86
87 // The real guts of PushClient, which allows this class to not be
88 // refcounted.
89 const scoped_refptr<Core> core_;
90 const scoped_refptr<base::MessageLoopProxy> parent_message_loop_proxy_;
91 const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
92
93 DISALLOW_COPY_AND_ASSIGN(PushClient);
94 };
95
96 } // namespace notifier
97
98 #endif // JINGLE_NOTIFIER_LISTENER_PUSH_CLIENT_H_
OLDNEW
« no previous file with comments | « jingle/notifier/listener/mediator_thread_unittest.cc ('k') | jingle/notifier/listener/push_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698