1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef SYNC_NOTIFIER_UNACKED_INVALIDATION_SET_H_
6 #define SYNC_NOTIFIER_UNACKED_INVALIDATION_SET_H_
10 #include "sync/base/sync_export.h"
11 #include "sync/internal_api/public/base/invalidation.h"
12 #include "sync/internal_api/public/util/weak_handle.h"
13 #include "sync/notifier/invalidation_util.h"
16 class DictionaryValue
;
21 class SingleObjectInvalidationSet
;
22 class ObjectIdInvalidationMap
;
25 // Manages the set of invalidations that are awaiting local acknowledgement for
26 // a particular ObjectId. This set of invalidations will be persisted across
27 // restarts, though this class is not directly responsible for that.
28 class SYNC_EXPORT UnackedInvalidationSet
{
30 static const size_t kMaxBufferedInvalidations
;
32 UnackedInvalidationSet(invalidation::ObjectId id
);
33 ~UnackedInvalidationSet();
35 // Returns the ObjectID of the invalidations this class is tracking.
36 const invalidation::ObjectId
& object_id() const;
38 // Adds a new invalidation to the set awaiting acknowledgement.
39 void Add(const Invalidation
& invalidation
);
41 // Adds many new invalidations to the set awaiting acknowledgement.
42 void AddSet(const SingleObjectInvalidationSet
& invalidations
);
44 // Exports the set of invalidations awaiting acknowledgement as an
45 // ObjectIdInvalidationMap. Each of these invalidations will be associated
46 // with the given |ack_handler|.
48 // The contents of the UnackedInvalidationSet are not directly modified by
49 // this procedure, but the AckHandles stored in those exported invalidations
50 // are likely to end up back here in calls to Acknowledge() or Drop().
51 void ExportInvalidations(WeakHandle
<AckHandler
> ack_handler
,
52 ObjectIdInvalidationMap
* out
) const;
54 // Removes all stored invalidations from this object.
57 // Indicates that a handler has registered to handle these invalidations.
59 // Registrations with the invalidations server persist across restarts, but
60 // registrations from InvalidationHandlers to the InvalidationService are not.
61 // In the time immediately after a restart, it's possible that the server
62 // will send us invalidations, and we won't have a handler to send them to.
64 // The SetIsRegistered() call indicates that this period has come to an end.
65 // There is now a handler that can receive these invalidations. Once this
66 // function has been called, the kMaxBufferedInvalidations limit will be
67 // ignored. It is assumed that the handler will manage its own buffer size.
68 void SetHandlerIsRegistered();
70 // Indicates that the handler has now unregistered itself.
72 // This causes the object to resume enforcement of the
73 // kMaxBufferedInvalidations limit.
74 void SetHandlerIsUnregistered();
76 // Given an AckHandle belonging to one of the contained invalidations, finds
77 // the invalidation and drops it from the list. It is considered to be
78 // acknowledged, so there is no need to continue maintaining its state.
79 void Acknowledge(const AckHandle
& handle
);
81 // Given an AckHandle belonging to one of the contained invalidations, finds
82 // the invalidation, drops it from the list, and adds additional state to
83 // indicate that this invalidation has been lost without being acted on.
84 void Drop(const AckHandle
& handle
);
86 scoped_ptr
<base::DictionaryValue
> ToValue() const;
87 bool ResetFromValue(const base::DictionaryValue
& value
);
90 // Allow this test helper to have access to our internals.
91 friend class UnackedInvalidationSetEqMatcher
;
93 typedef std::set
<Invalidation
, InvalidationVersionLessThan
> InvalidationsSet
;
95 bool ResetListFromValue(const base::ListValue
& value
);
97 // Limits the list size to the given maximum. This function will correctly
98 // update this class' internal data to indicate if invalidations have been
100 void Truncate(size_t max_size
);
103 invalidation::ObjectId object_id_
;
104 InvalidationsSet invalidations_
;
107 typedef std::map
<invalidation::ObjectId
,
108 UnackedInvalidationSet
,
109 ObjectIdLessThan
> UnackedInvalidationsMap
;
111 } // namespace syncer
113 #endif // SYNC_NOTIFIER_UNACKED_INVALIDATION_SET_H_