[email protected] | 001bbfdc | 2014-07-17 19:28:46 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
knn | 062cdbb | 2015-06-26 18:18:42 | [diff] [blame] | 5 | #ifndef COMPONENTS_INVALIDATION_PUBLIC_SINGLE_OBJECT_INVALIDATION_SET_H_ |
| 6 | #define COMPONENTS_INVALIDATION_PUBLIC_SINGLE_OBJECT_INVALIDATION_SET_H_ |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 7 | |
| 8 | #include <set> |
| 9 | |
| 10 | #include "base/memory/scoped_ptr.h" |
knn | 062cdbb | 2015-06-26 18:18:42 | [diff] [blame] | 11 | #include "components/invalidation/public/invalidation.h" |
| 12 | #include "components/invalidation/public/invalidation_export.h" |
| 13 | #include "components/invalidation/public/invalidation_util.h" |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 14 | |
| 15 | namespace base { |
| 16 | class ListValue; |
| 17 | } // namespace base |
| 18 | |
| 19 | namespace syncer { |
| 20 | |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 21 | // Holds a list of invalidations that all share the same Object ID. |
| 22 | // |
| 23 | // The list is kept sorted by version to make it easier to perform common |
| 24 | // operations, like checking for an unknown version invalidation or fetching the |
| 25 | // highest invalidation with the highest version number. |
[email protected] | 001bbfdc | 2014-07-17 19:28:46 | [diff] [blame] | 26 | class INVALIDATION_EXPORT SingleObjectInvalidationSet { |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 27 | public: |
| 28 | typedef std::set<Invalidation, InvalidationVersionLessThan> InvalidationsSet; |
| 29 | typedef InvalidationsSet::const_iterator const_iterator; |
| 30 | typedef InvalidationsSet::const_reverse_iterator const_reverse_iterator; |
| 31 | |
| 32 | SingleObjectInvalidationSet(); |
| 33 | ~SingleObjectInvalidationSet(); |
| 34 | |
| 35 | void Insert(const Invalidation& invalidation); |
| 36 | void InsertAll(const SingleObjectInvalidationSet& other); |
| 37 | void Clear(); |
[email protected] | 55d56cf | 2013-12-17 07:01:11 | [diff] [blame] | 38 | void Erase(const_iterator it); |
[email protected] | 163d063 | 2013-10-04 03:51:01 | [diff] [blame] | 39 | |
| 40 | // Returns true if this list contains an unknown version. |
| 41 | // |
| 42 | // Unknown version invalidations always end up at the start of the list, |
| 43 | // because they have the lowest possible value in the sort ordering. |
| 44 | bool StartsWithUnknownVersion() const; |
| 45 | size_t GetSize() const; |
| 46 | bool IsEmpty() const; |
| 47 | bool operator==(const SingleObjectInvalidationSet& other) const; |
| 48 | |
| 49 | const_iterator begin() const; |
| 50 | const_iterator end() const; |
| 51 | const_reverse_iterator rbegin() const; |
| 52 | const_reverse_iterator rend() const; |
| 53 | const Invalidation& back() const; |
| 54 | |
| 55 | scoped_ptr<base::ListValue> ToValue() const; |
| 56 | bool ResetFromValue(const base::ListValue& list); |
| 57 | |
| 58 | private: |
| 59 | InvalidationsSet invalidations_; |
| 60 | }; |
| 61 | |
| 62 | } // syncer |
| 63 | |
knn | 062cdbb | 2015-06-26 18:18:42 | [diff] [blame] | 64 | #endif // COMPONENTS_INVALIDATION_PUBLIC_SINGLE_OBJECT_INVALIDATION_SET_H_ |