1 // Copyright 2012 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 // Various utilities for dealing with invalidation data types. 6 7 #ifndef SYNC_NOTIFIER_INVALIDATION_UTIL_H_ 8 #define SYNC_NOTIFIER_INVALIDATION_UTIL_H_ 9 10 #include <iosfwd> 11 #include <set> 12 #include <string> 13 14 #include "base/memory/scoped_ptr.h" 15 #include "sync/base/sync_export.h" 16 #include "sync/internal_api/public/base/model_type.h" 17 18 namespace base { 19 class DictionaryValue; 20 } // namespace 21 22 namespace invalidation { 23 24 class Invalidation; 25 class ObjectId; 26 27 // Gmock print helper 28 SYNC_EXPORT_PRIVATE void PrintTo(const invalidation::ObjectId& id, 29 std::ostream* os); 30 31 } // namespace invalidation 32 33 namespace syncer { 34 35 class Invalidation; 36 37 struct SYNC_EXPORT ObjectIdLessThan { 38 bool operator()(const invalidation::ObjectId& lhs, 39 const invalidation::ObjectId& rhs) const; 40 }; 41 42 struct InvalidationVersionLessThan { 43 bool operator()(const syncer::Invalidation& a, 44 const syncer::Invalidation& b) const; 45 }; 46 47 typedef std::set<invalidation::ObjectId, ObjectIdLessThan> ObjectIdSet; 48 49 SYNC_EXPORT bool RealModelTypeToObjectId(ModelType model_type, 50 invalidation::ObjectId* object_id); 51 52 bool ObjectIdToRealModelType(const invalidation::ObjectId& object_id, 53 ModelType* model_type); 54 55 // Caller owns the returned DictionaryValue. 56 scoped_ptr<base::DictionaryValue> ObjectIdToValue( 57 const invalidation::ObjectId& object_id); 58 59 bool ObjectIdFromValue(const base::DictionaryValue& value, 60 invalidation::ObjectId* out); 61 62 SYNC_EXPORT_PRIVATE std::string ObjectIdToString( 63 const invalidation::ObjectId& object_id); 64 65 SYNC_EXPORT_PRIVATE ObjectIdSet ModelTypeSetToObjectIdSet(ModelTypeSet models); 66 ModelTypeSet ObjectIdSetToModelTypeSet(const ObjectIdSet& ids); 67 68 std::string InvalidationToString( 69 const invalidation::Invalidation& invalidation); 70 71 } // namespace syncer 72 73 #endif // SYNC_NOTIFIER_INVALIDATION_UTIL_H_ 74