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 notifications 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 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
19 #include "jingle/notifier/listener/push_client_observer.h" | 19 #include "jingle/notifier/listener/push_client_observer.h" |
20 #include "sync/internal_api/public/base/model_type.h" | 20 #include "sync/internal_api/public/base/model_type.h" |
21 #include "sync/notifier/invalidator.h" | 21 #include "sync/notifier/invalidator.h" |
22 #include "sync/notifier/invalidator_registrar.h" | 22 #include "sync/notifier/invalidator_registrar.h" |
23 #include "sync/notifier/notifications_disabled_reason.h" | 23 #include "sync/notifier/invalidator_state.h" |
24 | 24 |
25 namespace notifier { | 25 namespace notifier { |
26 class PushClient; | 26 class PushClient; |
27 } // namespace notifier | 27 } // namespace notifier |
28 | 28 |
29 namespace syncer { | 29 namespace syncer { |
30 | 30 |
31 // The channel to use for sync notifications. | 31 // The channel to use for sync notifications. |
32 extern const char kSyncP2PNotificationChannel[]; | 32 extern const char kSyncP2PNotificationChannel[]; |
33 | 33 |
(...skipping 16 matching lines...) Expand all Loading... |
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 ObjectIdStateMap& id_state_map, |
60 IncomingNotificationSource 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 ObjectIdStateMap& GetIdStateMap() const; |
68 | 68 |
69 IncomingNotificationSource 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 state map for the notification. |
85 ObjectIdStateMap id_state_map_; | 85 ObjectIdStateMap id_state_map_; |
86 // The source of the notification. | 86 // The source of the invalidation. |
87 IncomingNotificationSource 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 void SetUniqueId(const std::string& unique_id) OVERRIDE; | 109 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; |
109 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; | 110 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; |
110 virtual void UpdateCredentials( | 111 virtual void UpdateCredentials( |
111 const std::string& email, const std::string& token) OVERRIDE; | 112 const std::string& email, const std::string& token) OVERRIDE; |
112 virtual void SendNotification(const ObjectIdStateMap& id_state_map) OVERRIDE; | 113 virtual void SendInvalidation(const ObjectIdStateMap& id_state_map) OVERRIDE; |
113 | 114 |
114 // PushClientObserver implementation. | 115 // PushClientObserver implementation. |
115 virtual void OnNotificationsEnabled() OVERRIDE; | 116 virtual void OnNotificationsEnabled() OVERRIDE; |
116 virtual void OnNotificationsDisabled( | 117 virtual void OnNotificationsDisabled( |
117 notifier::NotificationsDisabledReason reason) OVERRIDE; | 118 notifier::NotificationsDisabledReason reason) OVERRIDE; |
118 virtual void OnIncomingNotification( | 119 virtual void OnIncomingNotification( |
119 const notifier::Notification& notification) OVERRIDE; | 120 const notifier::Notification& notification) OVERRIDE; |
120 | 121 |
121 void SendNotificationDataForTest( | 122 void SendNotificationDataForTest( |
122 const P2PNotificationData& notification_data); | 123 const P2PNotificationData& notification_data); |
(...skipping 14 matching lines...) Expand all Loading... |
137 bool notifications_enabled_; | 138 bool notifications_enabled_; |
138 // Which set of clients should be sent notifications. | 139 // Which set of clients should be sent notifications. |
139 P2PNotificationTarget send_notification_target_; | 140 P2PNotificationTarget send_notification_target_; |
140 | 141 |
141 DISALLOW_COPY_AND_ASSIGN(P2PInvalidator); | 142 DISALLOW_COPY_AND_ASSIGN(P2PInvalidator); |
142 }; | 143 }; |
143 | 144 |
144 } // namespace syncer | 145 } // namespace syncer |
145 | 146 |
146 #endif // SYNC_NOTIFIER_P2P_INVALIDATOR_H_ | 147 #endif // SYNC_NOTIFIER_P2P_INVALIDATOR_H_ |
OLD | NEW |