Chromium Code Reviews| Index: sync/notifier/sync_invalidation_listener.h |
| diff --git a/sync/notifier/sync_invalidation_listener.h b/sync/notifier/sync_invalidation_listener.h |
| index d1fc079050d1deaa8cb004241aa7638525004281..27da5ba2f6f68b86124fdc232f5e2cb6b172affe 100644 |
| --- a/sync/notifier/sync_invalidation_listener.h |
| +++ b/sync/notifier/sync_invalidation_listener.h |
| @@ -8,6 +8,7 @@ |
| #ifndef SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_ |
| #define SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_ |
| +#include <map> |
| #include <string> |
| #include "base/basictypes.h" |
| @@ -16,6 +17,8 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/threading/non_thread_safe.h" |
| +#include "base/time.h" |
| +#include "base/timer.h" |
| #include "google/cacheinvalidation/include/invalidation-listener.h" |
| #include "jingle/notifier/listener/push_client_observer.h" |
| #include "sync/internal_api/public/util/weak_handle.h" |
| @@ -75,7 +78,7 @@ class SyncInvalidationListener |
| create_invalidation_client_callback, |
| const std::string& client_id, const std::string& client_info, |
| const std::string& invalidation_bootstrap_data, |
| - const InvalidationVersionMap& initial_max_invalidation_versions, |
| + const InvalidationStateMap& initial_invalidation_state_map, |
| const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, |
| Delegate* delegate); |
| @@ -84,6 +87,9 @@ class SyncInvalidationListener |
| // Update the set of object IDs that we're interested in getting |
| // notifications for. May be called at any time. |
| void UpdateRegisteredIds(const ObjectIdSet& ids); |
| + // TODO(dcheng): Add a comment. |
|
akalin
2012/10/19 13:27:16
!
dcheng
2012/10/19 19:38:11
Done.
|
| + void Acknowledge(const invalidation::ObjectId& id, |
| + const AckHandle& ack_handle); |
| // invalidation::InvalidationListener implementation. |
| virtual void Ready( |
| @@ -126,23 +132,74 @@ class SyncInvalidationListener |
| virtual void OnIncomingNotification( |
| const notifier::Notification& notification) OVERRIDE; |
| - void StopForTest(); |
| - |
| void DoRegistrationUpdate(); |
| + void StopForTest(); |
| + // Immediately triggers notifications for unacknowledged invalidations |
| + // at the beginning of the queue. |next_invalidation_time| is set to the |
| + // expiration time of the first entry in the queue, all unacknowledged |
| + // invalidations with the same expiration time are immediately triggered, |
| + // and we return true. |
| + // If there are no unacknowledged invalidations, then we do nothing and |
| + // simply return false. |
| + bool TriggerNextTimeoutForTest(base::TimeTicks* next_invalidation_time); |
| + base::TimeDelta GetCurrentDelayForTest() const { |
| + return timer_.GetCurrentDelay(); |
| + } |
| + InvalidationStateMap GetStateMapForTest() const { |
| + return invalidation_state_map_; |
| + } |
| + |
| private: |
| + struct QueueEntry { |
| + QueueEntry(const invalidation::ObjectId& id, |
| + const std::string& payload, |
| + int retry_count) |
| + : id(id), payload(payload), retry_count(retry_count) { |
| + } |
| + |
| + invalidation::ObjectId id; |
| + std::string payload; |
| + int retry_count; |
| + }; |
| + typedef std::multimap<base::TimeTicks, QueueEntry> TimerQueue; |
| + |
| void Stop(); |
| InvalidatorState GetState() const; |
| void EmitStateChange(); |
| - void EmitInvalidation(const ObjectIdInvalidationMap& invalidation_map); |
| + void PrepareInvalidation(const ObjectIdSet& ids, |
|
akalin
2012/10/19 13:27:16
I feel we want to decomp out the queue-managing lo
dcheng
2012/10/19 19:38:11
I didn't do it originally because there were alrea
|
| + const std::string& payload, |
| + invalidation::InvalidationClient* client, |
| + const invalidation::AckHandle& ack_handle); |
| + void EmitInvalidation(const ObjectIdSet& ids, |
| + const std::string& payload, |
| + invalidation::InvalidationClient* client, |
| + const invalidation::AckHandle& ack_handle, |
| + const AckHandleMap& local_ack_handles); |
| + void ResendUnacknowledgedInvalidations(); |
| + void ResendUnacknowledgedInvalidationsAt(base::TimeTicks now); |
| + |
| + // Various helpers to manage the queue of items that have pending acks. |
| + void InsertId(base::TimeTicks expiration_time, |
| + const invalidation::ObjectId& id, |
| + const std::string& payload, |
| + int retry_count); |
| + void RemoveId(const invalidation::ObjectId& id); |
| + void RemoveIds(const ObjectIdSet& ids); |
| + QueueEntry Pop(); |
| + void UpdateTimer(base::TimeTicks now); |
| + |
| + base::WeakPtrFactory<SyncInvalidationListener> weak_ptr_factory_; |
| + base::OneShotTimer<SyncInvalidationListener> timer_; |
| + TimerQueue timer_queue_; |
| // Owned by |sync_system_resources_|. |
| notifier::PushClient* const push_client_; |
| SyncSystemResources sync_system_resources_; |
| - InvalidationVersionMap max_invalidation_versions_; |
| + InvalidationStateMap invalidation_state_map_; |
| WeakHandle<InvalidationStateTracker> invalidation_state_tracker_; |
| Delegate* delegate_; |
| scoped_ptr<invalidation::InvalidationClient> invalidation_client_; |