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_DROPPED_INVALIDATION_TRACKER_H_
6 #define SYNC_NOTIFIER_DROPPED_INVALIDATION_TRACKER_H_
8 #include "google/cacheinvalidation/include/types.h"
9 #include "sync/base/sync_export.h"
10 #include "sync/internal_api/public/base/ack_handle.h"
11 #include "sync/internal_api/public/util/weak_handle.h"
12 #include "sync/notifier/ack_handler.h"
18 // Helps InvalidationHandlers keep track of dropped invalidations for a given
21 // The intent of this class is to hide some of the implementation details around
22 // how the invalidations system manages dropping and drop recovery. Any
23 // invalidation handler that intends to buffer and occasionally drop
24 // invalidations should keep one instance of it per registered ObjectId.
26 // When an invalidation handler wishes to drop an invalidation, it must provide
27 // an instance of this class to that Invalidation's Drop() method. In order to
28 // indicate recovery from a drop, the handler can call this class'
29 // RecordRecoveryFromDropEvent().
31 // Copy and assign are allowed for this class so we can use it in STL
33 class SYNC_EXPORT DroppedInvalidationTracker
{
35 explicit DroppedInvalidationTracker(const invalidation::ObjectId
& id
);
36 ~DroppedInvalidationTracker();
38 const invalidation::ObjectId
& object_id() const;
40 // Called by Invalidation::Drop() to keep track of a drop event.
42 // Takes ownership of the internals belonging to a soon to be discarded
43 // dropped invalidation. See also the comment for this class'
44 // |drop_ack_handler_| member.
45 void RecordDropEvent(WeakHandle
<AckHandler
> handler
, AckHandle handle
);
47 // Returns true if we're still recovering from a drop event.
48 bool IsRecoveringFromDropEvent() const;
50 // Called by the InvalidationHandler when it recovers from the drop event.
51 void RecordRecoveryFromDropEvent();
54 invalidation::ObjectId id_
;
55 AckHandle drop_ack_handle_
;
57 // This flag is set to true when we have dropped an invalidation and have not
58 // yet recovered from this drop event. Note that this may not always coincide
59 // with drop_ack_handler_ being initialized because a null AckHandler could be
60 // passed in to RecordDropEvent().
61 bool recovering_from_drop_
;
63 // A WeakHandle to the enitity responsible for persisting invalidation
64 // acknowledgement state on disk. We can get away with using a WeakHandle
65 // because we don't care if our drop recovery message doesn't gets delivered
66 // in some shutdown cases. If that happens, we'll have to process the
67 // invalidation state again on the next restart. It would be a waste of time
68 // and resources, but otherwise not particularly harmful.
69 WeakHandle
<AckHandler
> drop_ack_handler_
;
74 #endif // SYNC_NOTIFIER_DROPPED_INVALIDATION_TRACKER_H_