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

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

Issue 10413014: [Sync] Turn notifier::PushClient into an interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to head 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
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_PUSH_CLIENT_H_ 5 #ifndef JINGLE_NOTIFIER_LISTENER_PUSH_CLIENT_H_
6 #define JINGLE_NOTIFIER_LISTENER_PUSH_CLIENT_H_ 6 #define JINGLE_NOTIFIER_LISTENER_PUSH_CLIENT_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector>
10 9
11 #include "base/basictypes.h" 10 #include "base/memory/scoped_ptr.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" 11 #include "jingle/notifier/listener/notification_defines.h"
16 12
17 namespace base {
18 class MessageLoopProxy;
19 } // namespace base
20
21 namespace buzz {
22 class XmppTaskParentInterface;
23 } // namespace buzz
24
25 namespace notifier { 13 namespace notifier {
26 14
27 // This class implements a client for the XMPP google:push protocol. 15 struct NotifierOptions;
28 // 16 class PushClientObserver;
29 // This class must be used on a single thread. 17
18 // A PushClient is an interface for classes that implement a push
19 // mechanism, where a client can push notifications to and receive
20 // notifications from other clients.
30 class PushClient { 21 class PushClient {
31 public: 22 public:
32 // An Observer is sent messages whenever a notification is received 23 virtual ~PushClient();
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 24
42 // Called when a notification is received. The details of the 25 // Creates a default non-blocking PushClient implementation from the
43 // notification are in |notification|. 26 // given options.
44 virtual void OnIncomingNotification(const Notification& notification) = 0; 27 static scoped_ptr<PushClient> CreateDefault(
28 const NotifierOptions& notifier_options);
45 29
46 protected: 30 // Manage the list of observers for incoming notifications.
47 virtual ~Observer(); 31 virtual void AddObserver(PushClientObserver* observer) = 0;
48 }; 32 virtual void RemoveObserver(PushClientObserver* observer) = 0;
49 33
50 explicit PushClient(const NotifierOptions& notifier_options); 34 // Implementors are required to have this take effect only on the
51 ~PushClient(); 35 // next (re-)connection. Therefore, clients should call this before
52 36 // UpdateCredentials().
53 void AddObserver(Observer* observer); 37 virtual void UpdateSubscriptions(const SubscriptionList& subscriptions) = 0;
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 38
60 // If not connected, connects with the given credentials. If 39 // If not connected, connects with the given credentials. If
61 // already connected, the next connection attempt will use the given 40 // already connected, the next connection attempt will use the given
62 // credentials. 41 // credentials.
63 void UpdateCredentials(const std::string& email, const std::string& token); 42 virtual void UpdateCredentials(
43 const std::string& email, const std::string& token) = 0;
64 44
65 // Sends a notification. Can be called when notifications are 45 // Sends a notification (with no reliability guarantees).
66 // disabled; the notification will be sent when notifications become 46 virtual void SendNotification(const Notification& notification) = 0;
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 }; 47 };
95 48
96 } // namespace notifier 49 } // namespace notifier
97 50
98 #endif // JINGLE_NOTIFIER_LISTENER_PUSH_CLIENT_H_ 51 #endif // JINGLE_NOTIFIER_LISTENER_PUSH_CLIENT_H_
OLDNEW
« no previous file with comments | « jingle/notifier/listener/notification_defines.cc ('k') | jingle/notifier/listener/push_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698