OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "sync/notifier/ordered_invalidation_list.h" | |
6 | |
7 #include "base/values.h" | |
8 #include "sync/notifier/invalidation_util.h" | |
9 | |
10 namespace syncer { | |
11 | |
12 bool InvalidationVersionLessThan::operator()( | |
13 const Invalidation& a, | |
14 const Invalidation& b) { | |
15 DCHECK(a.GetObjectId() == b.GetObjectId()) | |
16 << "a: " << ObjectIdToString(a.GetObjectId()) << ", " | |
17 << "b: " << ObjectIdToString(a.GetObjectId()); | |
18 | |
19 if (a.IsUnknownVersion() && !b.IsUnknownVersion()) | |
20 return true; | |
21 | |
22 if (!a.IsUnknownVersion() && b.IsUnknownVersion()) | |
23 return false; | |
24 | |
25 if (a.IsUnknownVersion() && b.IsUnknownVersion()) | |
26 return false; | |
27 | |
28 return a.GetVersion() < b.GetVersion(); | |
29 } | |
30 | |
31 OrderedInvalidationList::OrderedInvalidationList() {} | |
32 | |
33 OrderedInvalidationList::~OrderedInvalidationList() {} | |
34 | |
35 void OrderedInvalidationList::Insert(const Invalidation& invalidation) { | |
36 invalidations_.insert(invalidation); | |
tim (not reviewing)
2013/09/20 21:53:46
It's a bit weird that the same-ID constraint is la
rlarocque
2013/09/23 18:38:19
I was kind of surprised that this didn't need the
tim (not reviewing)
2013/09/24 21:16:54
It's just not obvious why you wouldn't use this if
rlarocque
2013/09/25 00:40:00
Renamed to SingleObjectInvalidationSet.
| |
37 } | |
38 | |
39 void OrderedInvalidationList::InsertAll(const OrderedInvalidationList& other) { | |
40 invalidations_.insert(other.begin(), other.end()); | |
41 } | |
42 | |
43 void OrderedInvalidationList::Clear() { | |
44 invalidations_.clear(); | |
45 } | |
46 | |
47 bool OrderedInvalidationList::StartsWithUnknownVersion() const { | |
48 return invalidations_.begin()->IsUnknownVersion(); | |
49 } | |
50 | |
51 size_t OrderedInvalidationList::GetSize() const { | |
52 return invalidations_.size(); | |
53 } | |
54 | |
55 bool OrderedInvalidationList::IsEmpty() const { | |
56 return invalidations_.empty(); | |
57 } | |
58 | |
59 bool OrderedInvalidationList::operator==( | |
60 const OrderedInvalidationList& other) const { | |
61 return invalidations_ == other.invalidations_; | |
62 } | |
63 | |
64 OrderedInvalidationList::const_iterator OrderedInvalidationList::begin() const { | |
65 return invalidations_.begin(); | |
66 } | |
67 | |
68 OrderedInvalidationList::const_iterator OrderedInvalidationList::end() const { | |
69 return invalidations_.end(); | |
70 } | |
71 | |
72 OrderedInvalidationList::const_reverse_iterator | |
73 OrderedInvalidationList::rbegin() const { | |
74 return invalidations_.rbegin(); | |
75 } | |
76 | |
77 OrderedInvalidationList::const_reverse_iterator | |
78 OrderedInvalidationList::rend() const { | |
79 return invalidations_.rend(); | |
80 } | |
81 | |
82 const Invalidation& OrderedInvalidationList::back() const { | |
83 return *invalidations_.rbegin(); | |
84 } | |
85 | |
86 scoped_ptr<base::ListValue> OrderedInvalidationList::ToValue() const { | |
87 scoped_ptr<base::ListValue> value(new ListValue); | |
88 for (InvalidationsSet::const_iterator it = invalidations_.begin(); | |
89 it != invalidations_.end(); ++it) { | |
90 value->Append(it->ToValue().release()); | |
91 } | |
92 return value.Pass(); | |
93 } | |
94 | |
95 bool OrderedInvalidationList::ResetFromValue(const base::ListValue& list) { | |
96 for (size_t i = 0; i < list.GetSize(); ++i) { | |
97 Invalidation invalidation; | |
98 const base::DictionaryValue* dict; | |
99 if (!list.GetDictionary(i, &dict) || !invalidation.ResetFromValue(*dict)) { | |
100 DLOG(WARNING) << "Failed to parse invalidation at index " << i; | |
101 return false; | |
102 } | |
103 invalidations_.insert(invalidation); | |
104 } | |
105 return true; | |
106 } | |
107 | |
108 } // namespace syncer | |
OLD | NEW |