| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/invalidation/public/single_object_invalidation_set.h" | 5 #include "components/invalidation/public/single_object_invalidation_set.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "components/invalidation/public/invalidation_util.h" | 8 #include "components/invalidation/public/invalidation_util.h" |
| 9 | 9 |
| 10 namespace syncer { | 10 namespace syncer { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 85 } |
| 86 | 86 |
| 87 const Invalidation& SingleObjectInvalidationSet::back() const { | 87 const Invalidation& SingleObjectInvalidationSet::back() const { |
| 88 return *invalidations_.rbegin(); | 88 return *invalidations_.rbegin(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 std::unique_ptr<base::ListValue> SingleObjectInvalidationSet::ToValue() const { | 91 std::unique_ptr<base::ListValue> SingleObjectInvalidationSet::ToValue() const { |
| 92 std::unique_ptr<base::ListValue> value(new base::ListValue); | 92 std::unique_ptr<base::ListValue> value(new base::ListValue); |
| 93 for (InvalidationsSet::const_iterator it = invalidations_.begin(); | 93 for (InvalidationsSet::const_iterator it = invalidations_.begin(); |
| 94 it != invalidations_.end(); ++it) { | 94 it != invalidations_.end(); ++it) { |
| 95 value->Append(it->ToValue().release()); | 95 value->Append(it->ToValue()); |
| 96 } | 96 } |
| 97 return value; | 97 return value; |
| 98 } | 98 } |
| 99 | 99 |
| 100 bool SingleObjectInvalidationSet::ResetFromValue( | 100 bool SingleObjectInvalidationSet::ResetFromValue( |
| 101 const base::ListValue& list) { | 101 const base::ListValue& list) { |
| 102 for (size_t i = 0; i < list.GetSize(); ++i) { | 102 for (size_t i = 0; i < list.GetSize(); ++i) { |
| 103 const base::DictionaryValue* dict; | 103 const base::DictionaryValue* dict; |
| 104 if (!list.GetDictionary(i, &dict)) { | 104 if (!list.GetDictionary(i, &dict)) { |
| 105 DLOG(WARNING) << "Could not find invalidation at index " << i; | 105 DLOG(WARNING) << "Could not find invalidation at index " << i; |
| 106 return false; | 106 return false; |
| 107 } | 107 } |
| 108 std::unique_ptr<Invalidation> invalidation = | 108 std::unique_ptr<Invalidation> invalidation = |
| 109 Invalidation::InitFromValue(*dict); | 109 Invalidation::InitFromValue(*dict); |
| 110 if (!invalidation) { | 110 if (!invalidation) { |
| 111 DLOG(WARNING) << "Failed to parse invalidation at index " << i; | 111 DLOG(WARNING) << "Failed to parse invalidation at index " << i; |
| 112 return false; | 112 return false; |
| 113 } | 113 } |
| 114 invalidations_.insert(*invalidation); | 114 invalidations_.insert(*invalidation); |
| 115 } | 115 } |
| 116 return true; | 116 return true; |
| 117 } | 117 } |
| 118 | 118 |
| 119 } // namespace syncer | 119 } // namespace syncer |
| OLD | NEW |