| 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 OrderedInvalidationList::OrderedInvalidationList() {} |
| 13 |
| 14 OrderedInvalidationList::~OrderedInvalidationList() {} |
| 15 |
| 16 void OrderedInvalidationList::Insert(const Invalidation& invalidation) { |
| 17 invalidations_.insert(invalidation); |
| 18 } |
| 19 |
| 20 void OrderedInvalidationList::InsertAll(const OrderedInvalidationList& other) { |
| 21 invalidations_.insert(other.begin(), other.end()); |
| 22 } |
| 23 |
| 24 void OrderedInvalidationList::Clear() { |
| 25 invalidations_.clear(); |
| 26 } |
| 27 |
| 28 bool OrderedInvalidationList::StartsWithUnknownVersion() const { |
| 29 return invalidations_.begin()->IsUnknownVersion(); |
| 30 } |
| 31 |
| 32 size_t OrderedInvalidationList::GetSize() const { |
| 33 return invalidations_.size(); |
| 34 } |
| 35 |
| 36 bool OrderedInvalidationList::IsEmpty() const { |
| 37 return invalidations_.empty(); |
| 38 } |
| 39 |
| 40 bool OrderedInvalidationList::operator==( |
| 41 const OrderedInvalidationList& other) const { |
| 42 return invalidations_ == other.invalidations_; |
| 43 } |
| 44 |
| 45 OrderedInvalidationList::const_iterator OrderedInvalidationList::begin() const { |
| 46 return invalidations_.begin(); |
| 47 } |
| 48 |
| 49 OrderedInvalidationList::const_iterator OrderedInvalidationList::end() const { |
| 50 return invalidations_.end(); |
| 51 } |
| 52 |
| 53 OrderedInvalidationList::const_reverse_iterator |
| 54 OrderedInvalidationList::rbegin() const { |
| 55 return invalidations_.rbegin(); |
| 56 } |
| 57 |
| 58 OrderedInvalidationList::const_reverse_iterator |
| 59 OrderedInvalidationList::rend() const { |
| 60 return invalidations_.rend(); |
| 61 } |
| 62 |
| 63 const Invalidation& OrderedInvalidationList::back() const { |
| 64 return *invalidations_.rbegin(); |
| 65 } |
| 66 |
| 67 scoped_ptr<base::ListValue> OrderedInvalidationList::ToValue() const { |
| 68 scoped_ptr<base::ListValue> value(new ListValue); |
| 69 for (InvalidationsSet::const_iterator it = invalidations_.begin(); |
| 70 it != invalidations_.end(); ++it) { |
| 71 value->Append(it->ToValue().release()); |
| 72 } |
| 73 return value.Pass(); |
| 74 } |
| 75 |
| 76 bool OrderedInvalidationList::ResetFromValue(const base::ListValue& list) { |
| 77 for (size_t i = 0; i < list.GetSize(); ++i) { |
| 78 Invalidation invalidation; |
| 79 const base::DictionaryValue* dict; |
| 80 if (!list.GetDictionary(i, &dict) || !invalidation.ResetFromValue(*dict)) { |
| 81 DLOG(WARNING) << "Failed to parse invalidation at index " << i; |
| 82 return false; |
| 83 } |
| 84 invalidations_.insert(invalidation); |
| 85 } |
| 86 return true; |
| 87 } |
| 88 |
| 89 } // namespace syncer |
| OLD | NEW |