Index: chrome/browser/sync/notifier/p2p_notifier.h |
diff --git a/chrome/browser/sync/notifier/p2p_notifier.h b/chrome/browser/sync/notifier/p2p_notifier.h |
index 0aa415da55a59226995d060e5733a7b3a049ccea..c478f0e7ea6e03e3a76c313b2fc74640f9a02bc5 100644 |
--- a/chrome/browser/sync/notifier/p2p_notifier.h |
+++ b/chrome/browser/sync/notifier/p2p_notifier.h |
@@ -23,17 +23,66 @@ class MessageLoopProxy; |
} |
-namespace notifier { |
-struct NotifierOptions; |
-} // namespace |
- |
namespace sync_notifier { |
+// The intended recipient(s) of a P2P notification. |
+enum P2PNotificationTarget { |
+ NOTIFY_SELF, |
+ FIRST_NOTIFICATION_TARGET = NOTIFY_SELF, |
+ NOTIFY_OTHERS, |
+ NOTIFY_ALL, |
+ LAST_NOTIFICATION_TARGET = NOTIFY_ALL |
+}; |
+ |
+std::string P2PNotificationTargetToString( |
+ P2PNotificationTarget target); |
+ |
+// If |target_str| can't be parsed, assumes NOTIFY_SELF. |
+P2PNotificationTarget P2PNotificationTargetFromString( |
+ const std::string& target_str); |
+ |
+// Helper notification data class that can be serialized to and |
+// deserialized from a string. |
+class P2PNotificationData { |
+ public: |
+ // Initializes with an empty sender ID, target set to NOTIFY_SELF, |
+ // and empty changed types. |
+ P2PNotificationData(); |
+ P2PNotificationData(const std::string& sender_id, |
+ P2PNotificationTarget target, |
+ const syncable::ModelTypeSet& changed_types); |
+ |
+ ~P2PNotificationData(); |
+ |
+ // Returns true if the given ID is targeted by this notification. |
+ bool IsTargeted(const std::string& id) const; |
+ |
+ const syncable::ModelTypeSet& GetChangedTypes() const; |
+ |
+ bool Equals(const P2PNotificationData& other) const; |
+ |
+ std::string ToString() const; |
+ |
+ // Returns whether parsing |str| was successful. If parsing was |
+ // unsuccessful, the state of the notification is undefined. |
+ bool FromString(const std::string& str); |
Nicolas Zea
2011/08/26 21:19:14
Since this overwrites the current data, how about
akalin
2011/08/26 22:42:27
Done.
|
+ |
+ private: |
+ // The unique ID of the client that sent the notification. |
+ std::string sender_id_; |
+ // The intendent recipient(s) of the notification. |
+ P2PNotificationTarget target_; |
+ // The types the notification is for. |
+ syncable::ModelTypeSet changed_types_; |
+}; |
+ |
class P2PNotifier |
: public SyncNotifier, |
public notifier::TalkMediator::Delegate { |
public: |
- explicit P2PNotifier(const notifier::NotifierOptions& notifier_options); |
+ // Takes ownership of |talk_mediator|, but it is guaranteed that |
+ // |talk_mediator| is destroyed only when this object is destroyed. |
+ explicit P2PNotifier(notifier::TalkMediator* talk_mediator); |
virtual ~P2PNotifier(); |
@@ -45,8 +94,9 @@ class P2PNotifier |
virtual void UpdateCredentials( |
const std::string& email, const std::string& token) OVERRIDE; |
virtual void UpdateEnabledTypes( |
- const syncable::ModelTypeSet& types) OVERRIDE; |
- virtual void SendNotification() OVERRIDE; |
+ const syncable::ModelTypeSet& enabled_types) OVERRIDE; |
+ virtual void SendNotification( |
+ const syncable::ModelTypeSet& changed_types) OVERRIDE; |
// TalkMediator::Delegate implementation. |
virtual void OnNotificationStateChange(bool notifications_enabled); |
@@ -54,15 +104,19 @@ class P2PNotifier |
const notifier::Notification& notification); |
virtual void OnOutgoingNotification(); |
+ // For testing. |
+ void SendNotificationDataForTest( |
+ const P2PNotificationData& notification_data); |
+ |
private: |
- // Call OnIncomingNotification() on observers if we have a non-empty |
- // set of enabled types. |
- void MaybeEmitNotification(); |
+ void SendNotificationData(const P2PNotificationData& notification_data); |
ObserverList<SyncNotifierObserver> observer_list_; |
// The actual notification listener. |
scoped_ptr<notifier::TalkMediator> talk_mediator_; |
+ // Our unique ID. |
+ std::string unique_id_; |
// Whether we called Login() on |talk_mediator_| yet. |
bool logged_in_; |
// Whether |talk_mediator_| has notified us that notifications are |