summaryrefslogtreecommitdiffstats
path: root/chromium/sync/notifier/dropped_invalidation_tracker.h
blob: 877187ed0bcf36080281d356288a96a3e965e586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SYNC_NOTIFIER_DROPPED_INVALIDATION_TRACKER_H_
#define SYNC_NOTIFIER_DROPPED_INVALIDATION_TRACKER_H_

#include "google/cacheinvalidation/include/types.h"
#include "sync/base/sync_export.h"
#include "sync/internal_api/public/base/ack_handle.h"
#include "sync/internal_api/public/util/weak_handle.h"
#include "sync/notifier/ack_handler.h"

namespace syncer {

class Invalidation;

// Helps InvalidationHandlers keep track of dropped invalidations for a given
// ObjectId.
//
// The intent of this class is to hide some of the implementation details around
// how the invalidations system manages dropping and drop recovery.  Any
// invalidation handler that intends to buffer and occasionally drop
// invalidations should keep one instance of it per registered ObjectId.
//
// When an invalidation handler wishes to drop an invalidation, it must provide
// an instance of this class to that Invalidation's Drop() method.  In order to
// indicate recovery from a drop, the handler can call this class'
// RecordRecoveryFromDropEvent().
class SYNC_EXPORT DroppedInvalidationTracker {
 public:
  explicit DroppedInvalidationTracker(const invalidation::ObjectId& id);
  ~DroppedInvalidationTracker();

  const invalidation::ObjectId& object_id() const;

  // Called by Invalidation::Drop() to keep track of a drop event.
  //
  // Takes ownership of the internals belonging to a soon to be discarded
  // dropped invalidation.  See also the comment for this class'
  // |drop_ack_handler_| member.
  void RecordDropEvent(WeakHandle<AckHandler> handler, AckHandle handle);

  // Returns true if we're still recovering from a drop event.
  bool IsRecoveringFromDropEvent() const;

  // Called by the InvalidationHandler when it recovers from the drop event.
  void RecordRecoveryFromDropEvent();

 private:
  invalidation::ObjectId id_;
  AckHandle drop_ack_handle_;

  // A WeakHandle to the enitity responsible for persisting invalidation
  // acknowledgement state on disk.  We can get away with using a WeakHandle
  // because we don't care if our drop recovery message doesn't gets delivered
  // in some shutdown cases.  If that happens, we'll have to process the
  // invalidation state again on the next restart.  It would be a waste of time
  // and resources, but otherwise not particularly harmful.
  WeakHandle<AckHandler> drop_ack_handler_;

  DISALLOW_COPY_AND_ASSIGN(DroppedInvalidationTracker);
};

}  // namespace syncer

#endif  // SYNC_NOTIFIER_DROPPED_INVALIDATION_TRACKER_H_