Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: sync/notifier/sync_invalidation_listener.h

Issue 10911084: Implement Invalidator::Acknowledge (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 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 <map>
11 #include <string> 12 #include <string>
12 13
13 #include "base/basictypes.h" 14 #include "base/basictypes.h"
14 #include "base/callback_forward.h" 15 #include "base/callback_forward.h"
15 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
16 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
18 #include "base/threading/non_thread_safe.h" 19 #include "base/threading/non_thread_safe.h"
20 #include "base/time.h"
21 #include "base/timer.h"
19 #include "google/cacheinvalidation/include/invalidation-listener.h" 22 #include "google/cacheinvalidation/include/invalidation-listener.h"
20 #include "jingle/notifier/listener/push_client_observer.h" 23 #include "jingle/notifier/listener/push_client_observer.h"
21 #include "sync/internal_api/public/util/weak_handle.h" 24 #include "sync/internal_api/public/util/weak_handle.h"
22 #include "sync/notifier/invalidation_state_tracker.h" 25 #include "sync/notifier/invalidation_state_tracker.h"
23 #include "sync/notifier/invalidator_state.h" 26 #include "sync/notifier/invalidator_state.h"
24 #include "sync/notifier/object_id_state_map.h" 27 #include "sync/notifier/object_id_state_map.h"
25 #include "sync/notifier/state_writer.h" 28 #include "sync/notifier/state_writer.h"
26 #include "sync/notifier/sync_system_resources.h" 29 #include "sync/notifier/sync_system_resources.h"
27 30
28 namespace buzz { 31 namespace buzz {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // Calls Stop(). 70 // Calls Stop().
68 virtual ~SyncInvalidationListener(); 71 virtual ~SyncInvalidationListener();
69 72
70 // Does not take ownership of |delegate| or |state_writer|. 73 // Does not take ownership of |delegate| or |state_writer|.
71 // |invalidation_state_tracker| must be initialized. 74 // |invalidation_state_tracker| must be initialized.
72 void Start( 75 void Start(
73 const CreateInvalidationClientCallback& 76 const CreateInvalidationClientCallback&
74 create_invalidation_client_callback, 77 create_invalidation_client_callback,
75 const std::string& client_id, const std::string& client_info, 78 const std::string& client_id, const std::string& client_info,
76 const std::string& state, 79 const std::string& state,
77 const InvalidationVersionMap& initial_max_invalidation_versions, 80 const InvalidationStateMap& initial_invalidation_state_map,
78 const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, 81 const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker,
79 Delegate* delegate); 82 Delegate* delegate);
80 83
81 void UpdateCredentials(const std::string& email, const std::string& token); 84 void UpdateCredentials(const std::string& email, const std::string& token);
82 85
83 // Update the set of object IDs that we're interested in getting 86 // Update the set of object IDs that we're interested in getting
84 // notifications for. May be called at any time. 87 // notifications for. May be called at any time.
85 void UpdateRegisteredIds(const ObjectIdSet& ids); 88 void UpdateRegisteredIds(const ObjectIdSet& ids);
89 // TODO(dcheng): Add a comment.
90 void Acknowledge(const invalidation::ObjectId& id,
91 const AckHandle& ack_handle);
86 92
87 // invalidation::InvalidationListener implementation. 93 // invalidation::InvalidationListener implementation.
88 virtual void Ready( 94 virtual void Ready(
89 invalidation::InvalidationClient* client) OVERRIDE; 95 invalidation::InvalidationClient* client) OVERRIDE;
90 virtual void Invalidate( 96 virtual void Invalidate(
91 invalidation::InvalidationClient* client, 97 invalidation::InvalidationClient* client,
92 const invalidation::Invalidation& invalidation, 98 const invalidation::Invalidation& invalidation,
93 const invalidation::AckHandle& ack_handle) OVERRIDE; 99 const invalidation::AckHandle& ack_handle) OVERRIDE;
94 virtual void InvalidateUnknownVersion( 100 virtual void InvalidateUnknownVersion(
95 invalidation::InvalidationClient* client, 101 invalidation::InvalidationClient* client,
(...skipping 27 matching lines...) Expand all
123 virtual void OnNotificationsDisabled( 129 virtual void OnNotificationsDisabled(
124 notifier::NotificationsDisabledReason reason) OVERRIDE; 130 notifier::NotificationsDisabledReason reason) OVERRIDE;
125 virtual void OnIncomingNotification( 131 virtual void OnIncomingNotification(
126 const notifier::Notification& notification) OVERRIDE; 132 const notifier::Notification& notification) OVERRIDE;
127 133
128 void StopForTest(); 134 void StopForTest();
129 135
130 void DoRegistrationUpdate(); 136 void DoRegistrationUpdate();
131 137
132 private: 138 private:
139 struct QueueEntry {
140 QueueEntry(const invalidation::ObjectId& id,
141 const std::string& payload,
142 int retry_count)
143 : id(id), payload(payload), retry_count(retry_count) {
144 }
145
146 invalidation::ObjectId id;
147 std::string payload;
148 int retry_count;
149 };
150 typedef std::multimap<base::TimeTicks, QueueEntry> TimerQueue;
Pete Williamson 2012/09/14 18:28:22 Is a multimap the right data structure here? I wo
dcheng 2012/09/14 19:08:49 std::priority_queue doesn't allow erasing arbitrar
151
133 void Stop(); 152 void Stop();
134 153
135 InvalidatorState GetState() const; 154 InvalidatorState GetState() const;
136 155
137 void EmitStateChange(); 156 void EmitStateChange();
138 157
139 void EmitInvalidation(const ObjectIdStateMap& id_state_map); 158 void PrepareInvalidation(const ObjectIdSet& ids,
159 const std::string& payload,
160 invalidation::InvalidationClient* client,
161 const invalidation::AckHandle& ack_handle);
162 void EmitInvalidation(const ObjectIdSet& ids,
163 const std::string& payload,
164 const AckHandleMap* const local_ack_handles,
165 invalidation::InvalidationClient* client,
166 const invalidation::AckHandle& ack_handle);
167 void RemitInvalidation();
168
169 base::WeakPtrFactory<SyncInvalidationListener> weak_ptr_factory_;
170 base::OneShotTimer<SyncInvalidationListener> timer_;
171 TimerQueue timer_queue_;
140 172
141 // Owned by |sync_system_resources_|. 173 // Owned by |sync_system_resources_|.
142 notifier::PushClient* const push_client_; 174 notifier::PushClient* const push_client_;
143 SyncSystemResources sync_system_resources_; 175 SyncSystemResources sync_system_resources_;
144 InvalidationVersionMap max_invalidation_versions_; 176 InvalidationStateMap invalidation_state_map_;
145 WeakHandle<InvalidationStateTracker> invalidation_state_tracker_; 177 WeakHandle<InvalidationStateTracker> invalidation_state_tracker_;
146 Delegate* delegate_; 178 Delegate* delegate_;
147 scoped_ptr<invalidation::InvalidationClient> invalidation_client_; 179 scoped_ptr<invalidation::InvalidationClient> invalidation_client_;
148 scoped_ptr<RegistrationManager> registration_manager_; 180 scoped_ptr<RegistrationManager> registration_manager_;
149 // Stored to pass to |registration_manager_| on start. 181 // Stored to pass to |registration_manager_| on start.
150 ObjectIdSet registered_ids_; 182 ObjectIdSet registered_ids_;
151 183
152 // The states of the ticl and the push client. 184 // The states of the ticl and the push client.
153 InvalidatorState ticl_state_; 185 InvalidatorState ticl_state_;
154 InvalidatorState push_client_state_; 186 InvalidatorState push_client_state_;
155 187
156 DISALLOW_COPY_AND_ASSIGN(SyncInvalidationListener); 188 DISALLOW_COPY_AND_ASSIGN(SyncInvalidationListener);
157 }; 189 };
158 190
159 } // namespace syncer 191 } // namespace syncer
160 192
161 #endif // SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_ 193 #endif // SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698