Chromium Code Reviews| Index: sync/notifier/ordered_invalidation_list.cc |
| diff --git a/sync/notifier/ordered_invalidation_list.cc b/sync/notifier/ordered_invalidation_list.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dcf60ea91a2a99db2e4071c48978bec27ad50f31 |
| --- /dev/null |
| +++ b/sync/notifier/ordered_invalidation_list.cc |
| @@ -0,0 +1,108 @@ |
| +// 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. |
| + |
| +#include "sync/notifier/ordered_invalidation_list.h" |
| + |
| +#include "base/values.h" |
| +#include "sync/notifier/invalidation_util.h" |
| + |
| +namespace syncer { |
| + |
| +bool InvalidationVersionLessThan::operator()( |
| + const Invalidation& a, |
| + const Invalidation& b) { |
| + DCHECK(a.GetObjectId() == b.GetObjectId()) |
| + << "a: " << ObjectIdToString(a.GetObjectId()) << ", " |
| + << "b: " << ObjectIdToString(a.GetObjectId()); |
| + |
| + if (a.IsUnknownVersion() && !b.IsUnknownVersion()) |
| + return true; |
| + |
| + if (!a.IsUnknownVersion() && b.IsUnknownVersion()) |
| + return false; |
| + |
| + if (a.IsUnknownVersion() && b.IsUnknownVersion()) |
| + return false; |
| + |
| + return a.GetVersion() < b.GetVersion(); |
| +} |
| + |
| +OrderedInvalidationList::OrderedInvalidationList() {} |
| + |
| +OrderedInvalidationList::~OrderedInvalidationList() {} |
| + |
| +void OrderedInvalidationList::Insert(const Invalidation& invalidation) { |
| + 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.
|
| +} |
| + |
| +void OrderedInvalidationList::InsertAll(const OrderedInvalidationList& other) { |
| + invalidations_.insert(other.begin(), other.end()); |
| +} |
| + |
| +void OrderedInvalidationList::Clear() { |
| + invalidations_.clear(); |
| +} |
| + |
| +bool OrderedInvalidationList::StartsWithUnknownVersion() const { |
| + return invalidations_.begin()->IsUnknownVersion(); |
| +} |
| + |
| +size_t OrderedInvalidationList::GetSize() const { |
| + return invalidations_.size(); |
| +} |
| + |
| +bool OrderedInvalidationList::IsEmpty() const { |
| + return invalidations_.empty(); |
| +} |
| + |
| +bool OrderedInvalidationList::operator==( |
| + const OrderedInvalidationList& other) const { |
| + return invalidations_ == other.invalidations_; |
| +} |
| + |
| +OrderedInvalidationList::const_iterator OrderedInvalidationList::begin() const { |
| + return invalidations_.begin(); |
| +} |
| + |
| +OrderedInvalidationList::const_iterator OrderedInvalidationList::end() const { |
| + return invalidations_.end(); |
| +} |
| + |
| +OrderedInvalidationList::const_reverse_iterator |
| +OrderedInvalidationList::rbegin() const { |
| + return invalidations_.rbegin(); |
| +} |
| + |
| +OrderedInvalidationList::const_reverse_iterator |
| +OrderedInvalidationList::rend() const { |
| + return invalidations_.rend(); |
| +} |
| + |
| +const Invalidation& OrderedInvalidationList::back() const { |
| + return *invalidations_.rbegin(); |
| +} |
| + |
| +scoped_ptr<base::ListValue> OrderedInvalidationList::ToValue() const { |
| + scoped_ptr<base::ListValue> value(new ListValue); |
| + for (InvalidationsSet::const_iterator it = invalidations_.begin(); |
| + it != invalidations_.end(); ++it) { |
| + value->Append(it->ToValue().release()); |
| + } |
| + return value.Pass(); |
| +} |
| + |
| +bool OrderedInvalidationList::ResetFromValue(const base::ListValue& list) { |
| + for (size_t i = 0; i < list.GetSize(); ++i) { |
| + Invalidation invalidation; |
| + const base::DictionaryValue* dict; |
| + if (!list.GetDictionary(i, &dict) || !invalidation.ResetFromValue(*dict)) { |
| + DLOG(WARNING) << "Failed to parse invalidation at index " << i; |
| + return false; |
| + } |
| + invalidations_.insert(invalidation); |
| + } |
| + return true; |
| +} |
| + |
| +} // namespace syncer |