Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / invalidation / impl / unacked_invalidation_set.h
blob62ab0b2efc408f9491bb9c58039b76789536b776
1 // Copyright 2014 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 COMPONENTS_INVALIDATION_IMPL_UNACKED_INVALIDATION_SET_H_
6 #define COMPONENTS_INVALIDATION_IMPL_UNACKED_INVALIDATION_SET_H_
8 #include <set>
10 #include "base/memory/weak_ptr.h"
11 #include "base/single_thread_task_runner.h"
12 #include "components/invalidation/public/invalidation.h"
13 #include "components/invalidation/public/invalidation_export.h"
14 #include "components/invalidation/public/invalidation_util.h"
16 namespace base {
17 class DictionaryValue;
18 } // namespace base
20 namespace syncer {
22 namespace test_util {
23 class UnackedInvalidationSetEqMatcher;
24 } // test_util
26 class SingleObjectInvalidationSet;
27 class ObjectIdInvalidationMap;
28 class AckHandle;
30 // Manages the set of invalidations that are awaiting local acknowledgement for
31 // a particular ObjectId. This set of invalidations will be persisted across
32 // restarts, though this class is not directly responsible for that.
33 class INVALIDATION_EXPORT UnackedInvalidationSet {
34 public:
35 static const size_t kMaxBufferedInvalidations;
37 UnackedInvalidationSet(invalidation::ObjectId id);
38 UnackedInvalidationSet(const UnackedInvalidationSet& other);
39 ~UnackedInvalidationSet();
41 // Returns the ObjectID of the invalidations this class is tracking.
42 const invalidation::ObjectId& object_id() const;
44 // Adds a new invalidation to the set awaiting acknowledgement.
45 void Add(const Invalidation& invalidation);
47 // Adds many new invalidations to the set awaiting acknowledgement.
48 void AddSet(const SingleObjectInvalidationSet& invalidations);
50 // Exports the set of invalidations awaiting acknowledgement as an
51 // ObjectIdInvalidationMap. Each of these invalidations will be associated
52 // with the given |ack_handler|.
54 // The contents of the UnackedInvalidationSet are not directly modified by
55 // this procedure, but the AckHandles stored in those exported invalidations
56 // are likely to end up back here in calls to Acknowledge() or Drop().
57 void ExportInvalidations(
58 base::WeakPtr<AckHandler> ack_handler,
59 scoped_refptr<base::SingleThreadTaskRunner> ack_handler_task_runner,
60 ObjectIdInvalidationMap* out) const;
62 // Removes all stored invalidations from this object.
63 void Clear();
65 // Indicates that a handler has registered to handle these invalidations.
67 // Registrations with the invalidations server persist across restarts, but
68 // registrations from InvalidationHandlers to the InvalidationService are not.
69 // In the time immediately after a restart, it's possible that the server
70 // will send us invalidations, and we won't have a handler to send them to.
72 // The SetIsRegistered() call indicates that this period has come to an end.
73 // There is now a handler that can receive these invalidations. Once this
74 // function has been called, the kMaxBufferedInvalidations limit will be
75 // ignored. It is assumed that the handler will manage its own buffer size.
76 void SetHandlerIsRegistered();
78 // Indicates that the handler has now unregistered itself.
80 // This causes the object to resume enforcement of the
81 // kMaxBufferedInvalidations limit.
82 void SetHandlerIsUnregistered();
84 // Given an AckHandle belonging to one of the contained invalidations, finds
85 // the invalidation and drops it from the list. It is considered to be
86 // acknowledged, so there is no need to continue maintaining its state.
87 void Acknowledge(const AckHandle& handle);
89 // Given an AckHandle belonging to one of the contained invalidations, finds
90 // the invalidation, drops it from the list, and adds additional state to
91 // indicate that this invalidation has been lost without being acted on.
92 void Drop(const AckHandle& handle);
94 scoped_ptr<base::DictionaryValue> ToValue() const;
95 bool ResetFromValue(const base::DictionaryValue& value);
97 private:
98 // Allow this test helper to have access to our internals.
99 friend class test_util::UnackedInvalidationSetEqMatcher;
101 typedef std::set<Invalidation, InvalidationVersionLessThan> InvalidationsSet;
103 bool ResetListFromValue(const base::ListValue& value);
105 // Limits the list size to the given maximum. This function will correctly
106 // update this class' internal data to indicate if invalidations have been
107 // dropped.
108 void Truncate(size_t max_size);
110 bool registered_;
111 invalidation::ObjectId object_id_;
112 InvalidationsSet invalidations_;
115 typedef std::map<invalidation::ObjectId,
116 UnackedInvalidationSet,
117 ObjectIdLessThan> UnackedInvalidationsMap;
119 } // namespace syncer
121 #endif // COMPONENTS_INVALIDATION_IMPL_UNACKED_INVALIDATION_SET_H_