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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « jingle/notifier/listener/notification_defines.cc ('k') | jingle/notifier/listener/push_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: jingle/notifier/listener/push_client.h
===================================================================
--- jingle/notifier/listener/push_client.h (revision 138220)
+++ jingle/notifier/listener/push_client.h (working copy)
@@ -6,44 +6,91 @@
#define JINGLE_NOTIFIER_LISTENER_PUSH_CLIENT_H_
#include <string>
+#include <vector>
-#include "base/memory/scoped_ptr.h"
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "jingle/notifier/base/notifier_options.h"
#include "jingle/notifier/listener/notification_defines.h"
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
+namespace buzz {
+class XmppTaskParentInterface;
+} // namespace buzz
+
namespace notifier {
-struct NotifierOptions;
-class PushClientObserver;
-
-// A PushClient is an interface for classes that implement a push
-// mechanism, where a client can push notifications to and receive
-// notifications from other clients.
+// This class implements a client for the XMPP google:push protocol.
+//
+// This class must be used on a single thread.
class PushClient {
public:
- virtual ~PushClient();
+ // An Observer is sent messages whenever a notification is received
+ // or when the state of the push client changes.
+ class Observer {
+ public:
+ // Called when the state of the push client changes. If
+ // |notifications_enabled| is true, that means notifications can
+ // be sent and received freely. If it is false, that means no
+ // notifications can be sent or received.
+ virtual void OnNotificationStateChange(bool notifications_enabled) = 0;
- // Creates a default non-blocking PushClient implementation from the
- // given options.
- static scoped_ptr<PushClient> CreateDefault(
- const NotifierOptions& notifier_options);
+ // Called when a notification is received. The details of the
+ // notification are in |notification|.
+ virtual void OnIncomingNotification(const Notification& notification) = 0;
- // Manage the list of observers for incoming notifications.
- virtual void AddObserver(PushClientObserver* observer) = 0;
- virtual void RemoveObserver(PushClientObserver* observer) = 0;
+ protected:
+ virtual ~Observer();
+ };
- // Implementors are required to have this take effect only on the
- // next (re-)connection. Therefore, clients should call this before
- // UpdateCredentials().
- virtual void UpdateSubscriptions(const SubscriptionList& subscriptions) = 0;
+ explicit PushClient(const NotifierOptions& notifier_options);
+ ~PushClient();
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ // Takes effect only on the next (re-)connection. Therefore, you
+ // probably want to call this before UpdateCredentials().
+ void UpdateSubscriptions(const SubscriptionList& subscriptions);
+
// If not connected, connects with the given credentials. If
// already connected, the next connection attempt will use the given
// credentials.
- virtual void UpdateCredentials(
- const std::string& email, const std::string& token) = 0;
+ void UpdateCredentials(const std::string& email, const std::string& token);
- // Sends a notification (with no reliability guarantees).
- virtual void SendNotification(const Notification& notification) = 0;
+ // Sends a notification. Can be called when notifications are
+ // disabled; the notification will be sent when notifications become
+ // enabled.
+ void SendNotification(const Notification& notification);
+
+ void SimulateOnNotificationReceivedForTest(
+ const Notification& notification);
+
+ void SimulateConnectAndSubscribeForTest(
+ base::WeakPtr<buzz::XmppTaskParentInterface> base_task);
+
+ void SimulateDisconnectForTest();
+
+ void SimulateSubscriptionErrorForTest();
+
+ // Any notifications sent after this is called will be reflected,
+ // i.e. will be treated as an incoming notification also.
+ void ReflectSentNotificationsForTest();
+
+ private:
+ class Core;
+
+ // The real guts of PushClient, which allows this class to not be
+ // refcounted.
+ const scoped_refptr<Core> core_;
+ const scoped_refptr<base::MessageLoopProxy> parent_message_loop_proxy_;
+ const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
+
+ DISALLOW_COPY_AND_ASSIGN(PushClient);
};
} // namespace notifier
« 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