| OLD | NEW |
| 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 // An invalidator that uses p2p invalidations based on XMPP push | 5 // An invalidator that uses p2p invalidations based on XMPP push |
| 6 // notifications. Used only for sync integration tests. | 6 // notifications. Used only for sync integration tests. |
| 7 | 7 |
| 8 #ifndef SYNC_NOTIFIER_P2P_INVALIDATOR_H_ | 8 #ifndef SYNC_NOTIFIER_P2P_INVALIDATOR_H_ |
| 9 #define SYNC_NOTIFIER_P2P_INVALIDATOR_H_ | 9 #define SYNC_NOTIFIER_P2P_INVALIDATOR_H_ |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 // Helper notification data class that can be serialized to and | 50 // Helper notification data class that can be serialized to and |
| 51 // deserialized from a string. | 51 // deserialized from a string. |
| 52 class P2PNotificationData { | 52 class P2PNotificationData { |
| 53 public: | 53 public: |
| 54 // Initializes with an empty sender ID, target set to NOTIFY_SELF, | 54 // Initializes with an empty sender ID, target set to NOTIFY_SELF, |
| 55 // and empty changed types. | 55 // and empty changed types. |
| 56 P2PNotificationData(); | 56 P2PNotificationData(); |
| 57 P2PNotificationData(const std::string& sender_id, | 57 P2PNotificationData(const std::string& sender_id, |
| 58 P2PNotificationTarget target, | 58 P2PNotificationTarget target, |
| 59 const ObjectIdStateMap& id_state_map, | 59 const ObjectIdInvalidationMap& invalidation_map, |
| 60 IncomingInvalidationSource source); | 60 IncomingInvalidationSource source); |
| 61 | 61 |
| 62 ~P2PNotificationData(); | 62 ~P2PNotificationData(); |
| 63 | 63 |
| 64 // Returns true if the given ID is targeted by this notification. | 64 // Returns true if the given ID is targeted by this notification. |
| 65 bool IsTargeted(const std::string& id) const; | 65 bool IsTargeted(const std::string& id) const; |
| 66 | 66 |
| 67 const ObjectIdStateMap& GetIdStateMap() const; | 67 const ObjectIdInvalidationMap& GetIdInvalidationMap() const; |
| 68 | 68 |
| 69 IncomingInvalidationSource GetSource() const; | 69 IncomingInvalidationSource GetSource() const; |
| 70 | 70 |
| 71 bool Equals(const P2PNotificationData& other) const; | 71 bool Equals(const P2PNotificationData& other) const; |
| 72 | 72 |
| 73 std::string ToString() const; | 73 std::string ToString() const; |
| 74 | 74 |
| 75 // Returns whether parsing |str| was successful. If parsing was | 75 // Returns whether parsing |str| was successful. If parsing was |
| 76 // unsuccessful, the state of the notification is undefined. | 76 // unsuccessful, the state of the notification is undefined. |
| 77 bool ResetFromString(const std::string& str); | 77 bool ResetFromString(const std::string& str); |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 // The unique ID of the client that sent the notification. | 80 // The unique ID of the client that sent the notification. |
| 81 std::string sender_id_; | 81 std::string sender_id_; |
| 82 // The intendent recipient(s) of the notification. | 82 // The intendent recipient(s) of the notification. |
| 83 P2PNotificationTarget target_; | 83 P2PNotificationTarget target_; |
| 84 // The state map for the notification. | 84 // The invalidation map for the notification. |
| 85 ObjectIdStateMap id_state_map_; | 85 ObjectIdInvalidationMap invalidation_map_; |
| 86 // The source of the invalidation. | 86 // The source of the invalidation. |
| 87 IncomingInvalidationSource source_; | 87 IncomingInvalidationSource source_; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 class P2PInvalidator : public Invalidator, | 90 class P2PInvalidator : public Invalidator, |
| 91 public notifier::PushClientObserver { | 91 public notifier::PushClientObserver { |
| 92 public: | 92 public: |
| 93 // The |send_notification_target| parameter was added to allow us to send | 93 // The |send_notification_target| parameter was added to allow us to send |
| 94 // self-notifications in some cases, but not others. The value should be | 94 // self-notifications in some cases, but not others. The value should be |
| 95 // either NOTIFY_ALL to send notifications to all clients, or NOTIFY_OTHERS | 95 // either NOTIFY_ALL to send notifications to all clients, or NOTIFY_OTHERS |
| 96 // to send notifications to all clients except for the one that triggered the | 96 // to send notifications to all clients except for the one that triggered the |
| 97 // notification. See crbug.com/97780. | 97 // notification. See crbug.com/97780. |
| 98 P2PInvalidator(scoped_ptr<notifier::PushClient> push_client, | 98 P2PInvalidator(scoped_ptr<notifier::PushClient> push_client, |
| 99 P2PNotificationTarget send_notification_target); | 99 P2PNotificationTarget send_notification_target); |
| 100 | 100 |
| 101 virtual ~P2PInvalidator(); | 101 virtual ~P2PInvalidator(); |
| 102 | 102 |
| 103 // Invalidator implementation. | 103 // Invalidator implementation. |
| 104 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; | 104 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; |
| 105 virtual void UpdateRegisteredIds(InvalidationHandler* handler, | 105 virtual void UpdateRegisteredIds(InvalidationHandler* handler, |
| 106 const ObjectIdSet& ids) OVERRIDE; | 106 const ObjectIdSet& ids) OVERRIDE; |
| 107 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; | 107 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; |
| 108 virtual InvalidatorState GetInvalidatorState() const OVERRIDE; | 108 virtual InvalidatorState GetInvalidatorState() const OVERRIDE; |
| 109 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; | 109 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; |
| 110 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; | 110 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; |
| 111 virtual void UpdateCredentials( | 111 virtual void UpdateCredentials( |
| 112 const std::string& email, const std::string& token) OVERRIDE; | 112 const std::string& email, const std::string& token) OVERRIDE; |
| 113 virtual void SendInvalidation(const ObjectIdStateMap& id_state_map) OVERRIDE; | 113 virtual void SendInvalidation( |
| 114 const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
| 114 | 115 |
| 115 // PushClientObserver implementation. | 116 // PushClientObserver implementation. |
| 116 virtual void OnNotificationsEnabled() OVERRIDE; | 117 virtual void OnNotificationsEnabled() OVERRIDE; |
| 117 virtual void OnNotificationsDisabled( | 118 virtual void OnNotificationsDisabled( |
| 118 notifier::NotificationsDisabledReason reason) OVERRIDE; | 119 notifier::NotificationsDisabledReason reason) OVERRIDE; |
| 119 virtual void OnIncomingNotification( | 120 virtual void OnIncomingNotification( |
| 120 const notifier::Notification& notification) OVERRIDE; | 121 const notifier::Notification& notification) OVERRIDE; |
| 121 | 122 |
| 122 void SendNotificationDataForTest( | 123 void SendNotificationDataForTest( |
| 123 const P2PNotificationData& notification_data); | 124 const P2PNotificationData& notification_data); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 138 bool notifications_enabled_; | 139 bool notifications_enabled_; |
| 139 // Which set of clients should be sent notifications. | 140 // Which set of clients should be sent notifications. |
| 140 P2PNotificationTarget send_notification_target_; | 141 P2PNotificationTarget send_notification_target_; |
| 141 | 142 |
| 142 DISALLOW_COPY_AND_ASSIGN(P2PInvalidator); | 143 DISALLOW_COPY_AND_ASSIGN(P2PInvalidator); |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 } // namespace syncer | 146 } // namespace syncer |
| 146 | 147 |
| 147 #endif // SYNC_NOTIFIER_P2P_INVALIDATOR_H_ | 148 #endif // SYNC_NOTIFIER_P2P_INVALIDATOR_H_ |
| OLD | NEW |