File: unacked_invalidation_set.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (130 lines) | stat: -rw-r--r-- 5,127 bytes parent folder | download | duplicates (3)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2014 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 COMPONENTS_INVALIDATION_IMPL_UNACKED_INVALIDATION_SET_H_
#define COMPONENTS_INVALIDATION_IMPL_UNACKED_INVALIDATION_SET_H_

#include <stddef.h>

#include <memory>
#include <set>

#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "components/invalidation/public/invalidation.h"
#include "components/invalidation/public/invalidation_export.h"
#include "components/invalidation/public/invalidation_util.h"

namespace base {
class DictionaryValue;
}  // namespace base

namespace syncer {

namespace test_util {
class UnackedInvalidationSetEqMatcher;
}  // test_util

class SingleObjectInvalidationSet;
class ObjectIdInvalidationMap;
class AckHandle;
class UnackedInvalidationSet;

using UnackedInvalidationsMap =
    std::map<invalidation::ObjectId, UnackedInvalidationSet, ObjectIdLessThan>;

// Manages the set of invalidations that are awaiting local acknowledgement for
// a particular ObjectId.  This set of invalidations will be persisted across
// restarts, though this class is not directly responsible for that.
class INVALIDATION_EXPORT UnackedInvalidationSet {
 public:
  static const size_t kMaxBufferedInvalidations;

  UnackedInvalidationSet(invalidation::ObjectId id);
  UnackedInvalidationSet(const UnackedInvalidationSet& other);
  ~UnackedInvalidationSet();

  // Returns the ObjectID of the invalidations this class is tracking.
  const invalidation::ObjectId& object_id() const;

  // Adds a new invalidation to the set awaiting acknowledgement.
  void Add(const Invalidation& invalidation);

  // Adds many new invalidations to the set awaiting acknowledgement.
  void AddSet(const SingleObjectInvalidationSet& invalidations);

  // Exports the set of invalidations awaiting acknowledgement as an
  // ObjectIdInvalidationMap.  Each of these invalidations will be associated
  // with the given |ack_handler|.
  //
  // The contents of the UnackedInvalidationSet are not directly modified by
  // this procedure, but the AckHandles stored in those exported invalidations
  // are likely to end up back here in calls to Acknowledge() or Drop().
  void ExportInvalidations(
      base::WeakPtr<AckHandler> ack_handler,
      scoped_refptr<base::SingleThreadTaskRunner> ack_handler_task_runner,
      ObjectIdInvalidationMap* out) const;

  // Removes all stored invalidations from this object.
  void Clear();

  // Indicates that a handler has registered to handle these invalidations.
  //
  // Registrations with the invalidations server persist across restarts, but
  // registrations from InvalidationHandlers to the InvalidationService are not.
  // In the time immediately after a restart, it's possible that the server
  // will send us invalidations, and we won't have a handler to send them to.
  //
  // The SetIsRegistered() call indicates that this period has come to an end.
  // There is now a handler that can receive these invalidations.  Once this
  // function has been called, the kMaxBufferedInvalidations limit will be
  // ignored.  It is assumed that the handler will manage its own buffer size.
  void SetHandlerIsRegistered();

  // Indicates that the handler has now unregistered itself.
  //
  // This causes the object to resume enforcement of the
  // kMaxBufferedInvalidations limit.
  void SetHandlerIsUnregistered();

  // Given an AckHandle belonging to one of the contained invalidations, finds
  // the invalidation and drops it from the list.  It is considered to be
  // acknowledged, so there is no need to continue maintaining its state.
  void Acknowledge(const AckHandle& handle);

  // Given an AckHandle belonging to one of the contained invalidations, finds
  // the invalidation, drops it from the list, and adds additional state to
  // indicate that this invalidation has been lost without being acted on.
  void Drop(const AckHandle& handle);

  // Deserializes the given |dict| as an UnackedInvalidationSet and inserts the
  // pair into |map| using the ObjectId as the key. Returns false if the
  // deserialization fails.
  static bool DeserializeSetIntoMap(const base::DictionaryValue& dict,
                                    syncer::UnackedInvalidationsMap* map);

  std::unique_ptr<base::DictionaryValue> ToValue() const;
  bool ResetFromValue(const base::DictionaryValue& value);

 private:
  // Allow this test helper to have access to our internals.
  friend class test_util::UnackedInvalidationSetEqMatcher;

  typedef std::set<Invalidation, InvalidationVersionLessThan> InvalidationsSet;

  bool ResetListFromValue(const base::ListValue& value);

  // Limits the list size to the given maximum.  This function will correctly
  // update this class' internal data to indicate if invalidations have been
  // dropped.
  void Truncate(size_t max_size);

  bool registered_;
  invalidation::ObjectId object_id_;
  InvalidationsSet invalidations_;
};

}  // namespace syncer

#endif  // COMPONENTS_INVALIDATION_IMPL_UNACKED_INVALIDATION_SET_H_