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