1116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Copyright 2014 The Chromium Authors. All rights reserved. 24e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 34e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// found in the LICENSE file. 44e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 5116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#ifndef COMPONENTS_INVALIDATION_SINGLE_OBJECT_INVALIDATION_SET_H_ 6116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#define COMPONENTS_INVALIDATION_SINGLE_OBJECT_INVALIDATION_SET_H_ 74e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 84e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include <set> 94e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/invalidation/invalidation.h" 12116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/invalidation/invalidation_export.h" 135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/invalidation/invalidation_util.h" 144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)namespace base { 164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class ListValue; 174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} // namespace base 184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)namespace syncer { 204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Holds a list of invalidations that all share the same Object ID. 224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// 234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// The list is kept sorted by version to make it easier to perform common 244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// operations, like checking for an unknown version invalidation or fetching the 254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// highest invalidation with the highest version number. 26116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass INVALIDATION_EXPORT SingleObjectInvalidationSet { 274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) public: 284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) typedef std::set<Invalidation, InvalidationVersionLessThan> InvalidationsSet; 294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) typedef InvalidationsSet::const_iterator const_iterator; 304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) typedef InvalidationsSet::const_reverse_iterator const_reverse_iterator; 314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) SingleObjectInvalidationSet(); 334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ~SingleObjectInvalidationSet(); 344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void Insert(const Invalidation& invalidation); 364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void InsertAll(const SingleObjectInvalidationSet& other); 374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void Clear(); 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void Erase(const_iterator it); 394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Returns true if this list contains an unknown version. 414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // 424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Unknown version invalidations always end up at the start of the list, 434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // because they have the lowest possible value in the sort ordering. 444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool StartsWithUnknownVersion() const; 454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) size_t GetSize() const; 464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool IsEmpty() const; 474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool operator==(const SingleObjectInvalidationSet& other) const; 484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const_iterator begin() const; 504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const_iterator end() const; 514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const_reverse_iterator rbegin() const; 524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const_reverse_iterator rend() const; 534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const Invalidation& back() const; 544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<base::ListValue> ToValue() const; 564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool ResetFromValue(const base::ListValue& list); 574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) private: 594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) InvalidationsSet invalidations_; 604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}; 614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} // syncer 634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 64116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#endif // COMPONENTS_INVALIDATION_SINGLE_OBJECT_INVALIDATION_SET_H_ 65