| 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 // A notifier that uses p2p notifications based on XMPP push | 5 // A notifier that uses p2p notifications 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_NOTIFIER_H_ | 8 #ifndef SYNC_NOTIFIER_P2P_NOTIFIER_H_ |
| 9 #define SYNC_NOTIFIER_P2P_NOTIFIER_H_ | 9 #define SYNC_NOTIFIER_P2P_NOTIFIER_H_ |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 // Helper notification data class that can be serialized to and | 49 // Helper notification data class that can be serialized to and |
| 50 // deserialized from a string. | 50 // deserialized from a string. |
| 51 class P2PNotificationData { | 51 class P2PNotificationData { |
| 52 public: | 52 public: |
| 53 // Initializes with an empty sender ID, target set to NOTIFY_SELF, | 53 // Initializes with an empty sender ID, target set to NOTIFY_SELF, |
| 54 // and empty changed types. | 54 // and empty changed types. |
| 55 P2PNotificationData(); | 55 P2PNotificationData(); |
| 56 P2PNotificationData(const std::string& sender_id, | 56 P2PNotificationData(const std::string& sender_id, |
| 57 P2PNotificationTarget target, | 57 P2PNotificationTarget target, |
| 58 syncer::ModelTypeSet changed_types); | 58 ModelTypeSet changed_types); |
| 59 | 59 |
| 60 ~P2PNotificationData(); | 60 ~P2PNotificationData(); |
| 61 | 61 |
| 62 // Returns true if the given ID is targeted by this notification. | 62 // Returns true if the given ID is targeted by this notification. |
| 63 bool IsTargeted(const std::string& id) const; | 63 bool IsTargeted(const std::string& id) const; |
| 64 | 64 |
| 65 syncer::ModelTypeSet GetChangedTypes() const; | 65 ModelTypeSet GetChangedTypes() const; |
| 66 | 66 |
| 67 bool Equals(const P2PNotificationData& other) const; | 67 bool Equals(const P2PNotificationData& other) const; |
| 68 | 68 |
| 69 std::string ToString() const; | 69 std::string ToString() const; |
| 70 | 70 |
| 71 // Returns whether parsing |str| was successful. If parsing was | 71 // Returns whether parsing |str| was successful. If parsing was |
| 72 // unsuccessful, the state of the notification is undefined. | 72 // unsuccessful, the state of the notification is undefined. |
| 73 bool ResetFromString(const std::string& str); | 73 bool ResetFromString(const std::string& str); |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 // The unique ID of the client that sent the notification. | 76 // The unique ID of the client that sent the notification. |
| 77 std::string sender_id_; | 77 std::string sender_id_; |
| 78 // The intendent recipient(s) of the notification. | 78 // The intendent recipient(s) of the notification. |
| 79 P2PNotificationTarget target_; | 79 P2PNotificationTarget target_; |
| 80 // The types the notification is for. | 80 // The types the notification is for. |
| 81 syncer::ModelTypeSet changed_types_; | 81 ModelTypeSet changed_types_; |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 class P2PNotifier | 84 class P2PNotifier |
| 85 : public SyncNotifier, | 85 : public SyncNotifier, |
| 86 public notifier::PushClientObserver { | 86 public notifier::PushClientObserver { |
| 87 public: | 87 public: |
| 88 // The |send_notification_target| parameter was added to allow us to send | 88 // The |send_notification_target| parameter was added to allow us to send |
| 89 // self-notifications in some cases, but not others. The value should be | 89 // self-notifications in some cases, but not others. The value should be |
| 90 // either NOTIFY_ALL to send notifications to all clients, or NOTIFY_OTHERS | 90 // either NOTIFY_ALL to send notifications to all clients, or NOTIFY_OTHERS |
| 91 // to send notifications to all clients except for the one that triggered the | 91 // to send notifications to all clients except for the one that triggered the |
| 92 // notification. See crbug.com/97780. | 92 // notification. See crbug.com/97780. |
| 93 P2PNotifier(scoped_ptr<notifier::PushClient> push_client, | 93 P2PNotifier(scoped_ptr<notifier::PushClient> push_client, |
| 94 P2PNotificationTarget send_notification_target); | 94 P2PNotificationTarget send_notification_target); |
| 95 | 95 |
| 96 virtual ~P2PNotifier(); | 96 virtual ~P2PNotifier(); |
| 97 | 97 |
| 98 // SyncNotifier implementation | 98 // SyncNotifier implementation |
| 99 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; | 99 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; |
| 100 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; | 100 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; |
| 101 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; | 101 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; |
| 102 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; | 102 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; |
| 103 virtual void UpdateCredentials( | 103 virtual void UpdateCredentials( |
| 104 const std::string& email, const std::string& token) OVERRIDE; | 104 const std::string& email, const std::string& token) OVERRIDE; |
| 105 virtual void UpdateEnabledTypes( | 105 virtual void UpdateEnabledTypes(ModelTypeSet enabled_types) OVERRIDE; |
| 106 syncer::ModelTypeSet enabled_types) OVERRIDE; | 106 virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE; |
| 107 virtual void SendNotification( | |
| 108 syncer::ModelTypeSet changed_types) OVERRIDE; | |
| 109 | 107 |
| 110 // PushClientObserver implementation. | 108 // PushClientObserver implementation. |
| 111 virtual void OnNotificationsEnabled() OVERRIDE; | 109 virtual void OnNotificationsEnabled() OVERRIDE; |
| 112 virtual void OnNotificationsDisabled( | 110 virtual void OnNotificationsDisabled( |
| 113 notifier::NotificationsDisabledReason reason) OVERRIDE; | 111 notifier::NotificationsDisabledReason reason) OVERRIDE; |
| 114 virtual void OnIncomingNotification( | 112 virtual void OnIncomingNotification( |
| 115 const notifier::Notification& notification) OVERRIDE; | 113 const notifier::Notification& notification) OVERRIDE; |
| 116 | 114 |
| 117 void SendNotificationDataForTest( | 115 void SendNotificationDataForTest( |
| 118 const P2PNotificationData& notification_data); | 116 const P2PNotificationData& notification_data); |
| 119 | 117 |
| 120 private: | 118 private: |
| 121 void SendNotificationData(const P2PNotificationData& notification_data); | 119 void SendNotificationData(const P2PNotificationData& notification_data); |
| 122 | 120 |
| 123 base::ThreadChecker thread_checker_; | 121 base::ThreadChecker thread_checker_; |
| 124 | 122 |
| 125 ObserverList<SyncNotifierObserver> observer_list_; | 123 ObserverList<SyncNotifierObserver> observer_list_; |
| 126 | 124 |
| 127 // The push client. | 125 // The push client. |
| 128 scoped_ptr<notifier::PushClient> push_client_; | 126 scoped_ptr<notifier::PushClient> push_client_; |
| 129 // Our unique ID. | 127 // Our unique ID. |
| 130 std::string unique_id_; | 128 std::string unique_id_; |
| 131 // Whether we have called UpdateCredentials() yet. | 129 // Whether we have called UpdateCredentials() yet. |
| 132 bool logged_in_; | 130 bool logged_in_; |
| 133 bool notifications_enabled_; | 131 bool notifications_enabled_; |
| 134 // Which set of clients should be sent notifications. | 132 // Which set of clients should be sent notifications. |
| 135 P2PNotificationTarget send_notification_target_; | 133 P2PNotificationTarget send_notification_target_; |
| 136 | 134 |
| 137 syncer::ModelTypeSet enabled_types_; | 135 ModelTypeSet enabled_types_; |
| 138 }; | 136 }; |
| 139 | 137 |
| 140 } // namespace syncer | 138 } // namespace syncer |
| 141 | 139 |
| 142 #endif // SYNC_NOTIFIER_P2P_NOTIFIER_H_ | 140 #endif // SYNC_NOTIFIER_P2P_NOTIFIER_H_ |
| OLD | NEW |