OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_SYNC_NOTIFIER_P2P_NOTIFIER_H_ | 8 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_P2P_NOTIFIER_H_ |
9 #define CHROME_BROWSER_SYNC_NOTIFIER_P2P_NOTIFIER_H_ | 9 #define CHROME_BROWSER_SYNC_NOTIFIER_P2P_NOTIFIER_H_ |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 // Helper notification data class that can be serialized to and | 47 // Helper notification data class that can be serialized to and |
48 // deserialized from a string. | 48 // deserialized from a string. |
49 class P2PNotificationData { | 49 class P2PNotificationData { |
50 public: | 50 public: |
51 // Initializes with an empty sender ID, target set to NOTIFY_SELF, | 51 // Initializes with an empty sender ID, target set to NOTIFY_SELF, |
52 // and empty changed types. | 52 // and empty changed types. |
53 P2PNotificationData(); | 53 P2PNotificationData(); |
54 P2PNotificationData(const std::string& sender_id, | 54 P2PNotificationData(const std::string& sender_id, |
55 P2PNotificationTarget target, | 55 P2PNotificationTarget target, |
56 syncable::ModelEnumSet changed_types); | 56 syncable::ModelTypeSet changed_types); |
57 | 57 |
58 ~P2PNotificationData(); | 58 ~P2PNotificationData(); |
59 | 59 |
60 // Returns true if the given ID is targeted by this notification. | 60 // Returns true if the given ID is targeted by this notification. |
61 bool IsTargeted(const std::string& id) const; | 61 bool IsTargeted(const std::string& id) const; |
62 | 62 |
63 syncable::ModelEnumSet GetChangedTypes() const; | 63 syncable::ModelTypeSet GetChangedTypes() const; |
64 | 64 |
65 bool Equals(const P2PNotificationData& other) const; | 65 bool Equals(const P2PNotificationData& other) const; |
66 | 66 |
67 std::string ToString() const; | 67 std::string ToString() const; |
68 | 68 |
69 // Returns whether parsing |str| was successful. If parsing was | 69 // Returns whether parsing |str| was successful. If parsing was |
70 // unsuccessful, the state of the notification is undefined. | 70 // unsuccessful, the state of the notification is undefined. |
71 bool ResetFromString(const std::string& str); | 71 bool ResetFromString(const std::string& str); |
72 | 72 |
73 private: | 73 private: |
74 // The unique ID of the client that sent the notification. | 74 // The unique ID of the client that sent the notification. |
75 std::string sender_id_; | 75 std::string sender_id_; |
76 // The intendent recipient(s) of the notification. | 76 // The intendent recipient(s) of the notification. |
77 P2PNotificationTarget target_; | 77 P2PNotificationTarget target_; |
78 // The types the notification is for. | 78 // The types the notification is for. |
79 syncable::ModelEnumSet changed_types_; | 79 syncable::ModelTypeSet changed_types_; |
80 }; | 80 }; |
81 | 81 |
82 class P2PNotifier | 82 class P2PNotifier |
83 : public SyncNotifier, | 83 : public SyncNotifier, |
84 public notifier::TalkMediator::Delegate { | 84 public notifier::TalkMediator::Delegate { |
85 public: | 85 public: |
86 // Takes ownership of |talk_mediator|, but it is guaranteed that | 86 // Takes ownership of |talk_mediator|, but it is guaranteed that |
87 // |talk_mediator| is destroyed only when this object is destroyed. | 87 // |talk_mediator| is destroyed only when this object is destroyed. |
88 // | 88 // |
89 // The |send_notification_target| parameter was added to allow us to send | 89 // The |send_notification_target| parameter was added to allow us to send |
90 // self-notifications in some cases, but not others. The value should be | 90 // self-notifications in some cases, but not others. The value should be |
91 // either NOTIFY_ALL to send notifications to all clients, or NOTIFY_OTHERS | 91 // either NOTIFY_ALL to send notifications to all clients, or NOTIFY_OTHERS |
92 // to send notificaitons to all clients except for the one that triggered the | 92 // to send notificaitons to all clients except for the one that triggered the |
93 // notification. See crbug.com/97780. | 93 // notification. See crbug.com/97780. |
94 P2PNotifier(notifier::TalkMediator* talk_mediator, | 94 P2PNotifier(notifier::TalkMediator* talk_mediator, |
95 P2PNotificationTarget send_notification_target); | 95 P2PNotificationTarget send_notification_target); |
96 | 96 |
97 virtual ~P2PNotifier(); | 97 virtual ~P2PNotifier(); |
98 | 98 |
99 // SyncNotifier implementation | 99 // SyncNotifier implementation |
100 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; | 100 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; |
101 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; | 101 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; |
102 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; | 102 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; |
103 virtual void SetState(const std::string& state) OVERRIDE; | 103 virtual void SetState(const std::string& state) OVERRIDE; |
104 virtual void UpdateCredentials( | 104 virtual void UpdateCredentials( |
105 const std::string& email, const std::string& token) OVERRIDE; | 105 const std::string& email, const std::string& token) OVERRIDE; |
106 virtual void UpdateEnabledTypes( | 106 virtual void UpdateEnabledTypes( |
107 syncable::ModelEnumSet enabled_types) OVERRIDE; | 107 syncable::ModelTypeSet enabled_types) OVERRIDE; |
108 virtual void SendNotification( | 108 virtual void SendNotification( |
109 syncable::ModelEnumSet changed_types) OVERRIDE; | 109 syncable::ModelTypeSet changed_types) OVERRIDE; |
110 | 110 |
111 // TalkMediator::Delegate implementation. | 111 // TalkMediator::Delegate implementation. |
112 virtual void OnNotificationStateChange(bool notifications_enabled) OVERRIDE; | 112 virtual void OnNotificationStateChange(bool notifications_enabled) OVERRIDE; |
113 virtual void OnIncomingNotification( | 113 virtual void OnIncomingNotification( |
114 const notifier::Notification& notification) OVERRIDE; | 114 const notifier::Notification& notification) OVERRIDE; |
115 virtual void OnOutgoingNotification() OVERRIDE; | 115 virtual void OnOutgoingNotification() OVERRIDE; |
116 | 116 |
117 // For testing. | 117 // For testing. |
118 void SendNotificationDataForTest( | 118 void SendNotificationDataForTest( |
119 const P2PNotificationData& notification_data); | 119 const P2PNotificationData& notification_data); |
120 | 120 |
121 private: | 121 private: |
122 void SendNotificationData(const P2PNotificationData& notification_data); | 122 void SendNotificationData(const P2PNotificationData& notification_data); |
123 | 123 |
124 ObserverList<SyncNotifierObserver> observer_list_; | 124 ObserverList<SyncNotifierObserver> observer_list_; |
125 | 125 |
126 // The actual notification listener. | 126 // The actual notification listener. |
127 scoped_ptr<notifier::TalkMediator> talk_mediator_; | 127 scoped_ptr<notifier::TalkMediator> talk_mediator_; |
128 // Our unique ID. | 128 // Our unique ID. |
129 std::string unique_id_; | 129 std::string unique_id_; |
130 // Whether we called Login() on |talk_mediator_| yet. | 130 // Whether we called Login() on |talk_mediator_| yet. |
131 bool logged_in_; | 131 bool logged_in_; |
132 // Whether |talk_mediator_| has notified us that notifications are | 132 // Whether |talk_mediator_| has notified us that notifications are |
133 // enabled. | 133 // enabled. |
134 bool notifications_enabled_; | 134 bool notifications_enabled_; |
135 // Which set of clients should be sent notifications. | 135 // Which set of clients should be sent notifications. |
136 P2PNotificationTarget send_notification_target_; | 136 P2PNotificationTarget send_notification_target_; |
137 | 137 |
138 syncable::ModelEnumSet enabled_types_; | 138 syncable::ModelTypeSet enabled_types_; |
139 scoped_refptr<base::MessageLoopProxy> parent_message_loop_proxy_; | 139 scoped_refptr<base::MessageLoopProxy> parent_message_loop_proxy_; |
140 }; | 140 }; |
141 | 141 |
142 } // namespace sync_notifier | 142 } // namespace sync_notifier |
143 #endif // CHROME_BROWSER_SYNC_NOTIFIER_P2P_NOTIFIER_H_ | 143 #endif // CHROME_BROWSER_SYNC_NOTIFIER_P2P_NOTIFIER_H_ |
OLD | NEW |