OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 simple wrapper around invalidation::InvalidationClient that | 5 // A simple wrapper around invalidation::InvalidationClient that |
6 // handles all the startup/shutdown details and hookups. | 6 // handles all the startup/shutdown details and hookups. |
7 | 7 |
8 #ifndef SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_ | 8 #ifndef SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_ |
9 #define SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_ | 9 #define SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_ |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
19 #include "google/cacheinvalidation/include/invalidation-listener.h" | 19 #include "google/cacheinvalidation/include/invalidation-listener.h" |
20 #include "jingle/notifier/listener/push_client_observer.h" | 20 #include "jingle/notifier/listener/push_client_observer.h" |
21 #include "sync/base/sync_export.h" | 21 #include "sync/base/sync_export.h" |
22 #include "sync/internal_api/public/util/weak_handle.h" | 22 #include "sync/internal_api/public/util/weak_handle.h" |
23 #include "sync/notifier/ack_tracker.h" | |
23 #include "sync/notifier/invalidation_state_tracker.h" | 24 #include "sync/notifier/invalidation_state_tracker.h" |
24 #include "sync/notifier/invalidator_state.h" | 25 #include "sync/notifier/invalidator_state.h" |
25 #include "sync/notifier/object_id_invalidation_map.h" | 26 #include "sync/notifier/object_id_invalidation_map.h" |
26 #include "sync/notifier/state_writer.h" | 27 #include "sync/notifier/state_writer.h" |
27 #include "sync/notifier/sync_system_resources.h" | 28 #include "sync/notifier/sync_system_resources.h" |
28 | 29 |
29 namespace buzz { | 30 namespace buzz { |
30 class XmppTaskParentInterface; | 31 class XmppTaskParentInterface; |
31 } // namespace buzz | 32 } // namespace buzz |
32 | 33 |
33 namespace notifier { | 34 namespace notifier { |
34 class PushClient; | 35 class PushClient; |
35 } // namespace notifier | 36 } // namespace notifier |
36 | 37 |
37 namespace syncer { | 38 namespace syncer { |
38 | 39 |
39 class RegistrationManager; | 40 class RegistrationManager; |
40 | 41 |
41 // SyncInvalidationListener is not thread-safe and lives on the sync | 42 // SyncInvalidationListener is not thread-safe and lives on the sync |
42 // thread. | 43 // thread. |
43 class SYNC_EXPORT_PRIVATE SyncInvalidationListener | 44 class SYNC_EXPORT_PRIVATE SyncInvalidationListener |
44 : public NON_EXPORTED_BASE(invalidation::InvalidationListener), | 45 : public NON_EXPORTED_BASE(invalidation::InvalidationListener), |
45 public StateWriter, | 46 public StateWriter, |
46 public NON_EXPORTED_BASE(notifier::PushClientObserver), | 47 public NON_EXPORTED_BASE(notifier::PushClientObserver), |
47 public base::NonThreadSafe { | 48 public base::NonThreadSafe, |
49 public AckTracker::Delegate { | |
48 public: | 50 public: |
49 typedef base::Callback<invalidation::InvalidationClient*( | 51 typedef base::Callback<invalidation::InvalidationClient*( |
50 invalidation::SystemResources*, | 52 invalidation::SystemResources*, |
51 int, | 53 int, |
52 const invalidation::string&, | 54 const invalidation::string&, |
53 const invalidation::string&, | 55 const invalidation::string&, |
54 invalidation::InvalidationListener*)> CreateInvalidationClientCallback; | 56 invalidation::InvalidationListener*)> CreateInvalidationClientCallback; |
55 | 57 |
56 class SYNC_EXPORT_PRIVATE Delegate { | 58 class SYNC_EXPORT_PRIVATE Delegate { |
57 public: | 59 public: |
(...skipping 20 matching lines...) Expand all Loading... | |
78 const std::string& invalidation_bootstrap_data, | 80 const std::string& invalidation_bootstrap_data, |
79 const InvalidationStateMap& initial_invalidation_state_map, | 81 const InvalidationStateMap& initial_invalidation_state_map, |
80 const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, | 82 const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, |
81 Delegate* delegate); | 83 Delegate* delegate); |
82 | 84 |
83 void UpdateCredentials(const std::string& email, const std::string& token); | 85 void UpdateCredentials(const std::string& email, const std::string& token); |
84 | 86 |
85 // Update the set of object IDs that we're interested in getting | 87 // Update the set of object IDs that we're interested in getting |
86 // notifications for. May be called at any time. | 88 // notifications for. May be called at any time. |
87 void UpdateRegisteredIds(const ObjectIdSet& ids); | 89 void UpdateRegisteredIds(const ObjectIdSet& ids); |
90 // Acknowledge that an invalidation for |id| was handled. | |
91 void Acknowledge(const invalidation::ObjectId& id, | |
92 const AckHandle& ack_handle); | |
88 | 93 |
89 // invalidation::InvalidationListener implementation. | 94 // invalidation::InvalidationListener implementation. |
90 virtual void Ready( | 95 virtual void Ready( |
91 invalidation::InvalidationClient* client) OVERRIDE; | 96 invalidation::InvalidationClient* client) OVERRIDE; |
92 virtual void Invalidate( | 97 virtual void Invalidate( |
93 invalidation::InvalidationClient* client, | 98 invalidation::InvalidationClient* client, |
94 const invalidation::Invalidation& invalidation, | 99 const invalidation::Invalidation& invalidation, |
95 const invalidation::AckHandle& ack_handle) OVERRIDE; | 100 const invalidation::AckHandle& ack_handle) OVERRIDE; |
96 virtual void InvalidateUnknownVersion( | 101 virtual void InvalidateUnknownVersion( |
97 invalidation::InvalidationClient* client, | 102 invalidation::InvalidationClient* client, |
(...skipping 26 matching lines...) Expand all Loading... | |
124 virtual void OnNotificationsEnabled() OVERRIDE; | 129 virtual void OnNotificationsEnabled() OVERRIDE; |
125 virtual void OnNotificationsDisabled( | 130 virtual void OnNotificationsDisabled( |
126 notifier::NotificationsDisabledReason reason) OVERRIDE; | 131 notifier::NotificationsDisabledReason reason) OVERRIDE; |
127 virtual void OnIncomingNotification( | 132 virtual void OnIncomingNotification( |
128 const notifier::Notification& notification) OVERRIDE; | 133 const notifier::Notification& notification) OVERRIDE; |
129 | 134 |
130 void DoRegistrationUpdate(); | 135 void DoRegistrationUpdate(); |
131 | 136 |
132 void StopForTest(); | 137 void StopForTest(); |
133 InvalidationStateMap GetStateMapForTest() const; | 138 InvalidationStateMap GetStateMapForTest() const; |
139 AckTracker* GetAckTrackerForTest(); | |
134 | 140 |
135 private: | 141 private: |
136 void Stop(); | 142 void Stop(); |
137 | 143 |
138 InvalidatorState GetState() const; | 144 InvalidatorState GetState() const; |
139 | 145 |
140 void EmitStateChange(); | 146 void EmitStateChange(); |
141 | 147 |
142 void EmitInvalidation(const ObjectIdInvalidationMap& invalidation_map); | 148 void PrepareInvalidation(const ObjectIdSet& ids, |
149 const std::string& payload, | |
150 invalidation::InvalidationClient* client, | |
151 const invalidation::AckHandle& ack_handle); | |
152 void EmitInvalidation(const ObjectIdSet& ids, | |
153 const std::string& payload, | |
154 invalidation::InvalidationClient* client, | |
155 const invalidation::AckHandle& ack_handle, | |
156 const AckHandleMap& local_ack_handles); | |
157 // AckTracker::Delegate implementation. | |
akalin
2013/02/15 22:32:12
newline before
dcheng
2013/02/22 02:51:30
Done.
| |
158 virtual void OnTimeout(const ObjectIdSet& ids) OVERRIDE; | |
159 | |
160 base::WeakPtrFactory<SyncInvalidationListener> weak_ptr_factory_; | |
161 AckTracker ack_tracker_; | |
143 | 162 |
144 // Owned by |sync_system_resources_|. | 163 // Owned by |sync_system_resources_|. |
145 notifier::PushClient* const push_client_; | 164 notifier::PushClient* const push_client_; |
146 SyncSystemResources sync_system_resources_; | 165 SyncSystemResources sync_system_resources_; |
147 InvalidationStateMap invalidation_state_map_; | 166 InvalidationStateMap invalidation_state_map_; |
148 WeakHandle<InvalidationStateTracker> invalidation_state_tracker_; | 167 WeakHandle<InvalidationStateTracker> invalidation_state_tracker_; |
149 Delegate* delegate_; | 168 Delegate* delegate_; |
150 scoped_ptr<invalidation::InvalidationClient> invalidation_client_; | 169 scoped_ptr<invalidation::InvalidationClient> invalidation_client_; |
151 scoped_ptr<RegistrationManager> registration_manager_; | 170 scoped_ptr<RegistrationManager> registration_manager_; |
152 // Stored to pass to |registration_manager_| on start. | 171 // Stored to pass to |registration_manager_| on start. |
153 ObjectIdSet registered_ids_; | 172 ObjectIdSet registered_ids_; |
154 | 173 |
155 // The states of the ticl and the push client. | 174 // The states of the ticl and the push client. |
156 InvalidatorState ticl_state_; | 175 InvalidatorState ticl_state_; |
157 InvalidatorState push_client_state_; | 176 InvalidatorState push_client_state_; |
158 | 177 |
159 DISALLOW_COPY_AND_ASSIGN(SyncInvalidationListener); | 178 DISALLOW_COPY_AND_ASSIGN(SyncInvalidationListener); |
160 }; | 179 }; |
161 | 180 |
162 } // namespace syncer | 181 } // namespace syncer |
163 | 182 |
164 #endif // SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_ | 183 #endif // SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_ |
OLD | NEW |