OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef SYNC_NOTIFIER_OBJECT_ID_INVALIDATION_MAP_H_ | 5 #ifndef SYNC_NOTIFIER_OBJECT_ID_INVALIDATION_MAP_H_ |
6 #define SYNC_NOTIFIER_OBJECT_ID_INVALIDATION_MAP_H_ | 6 #define SYNC_NOTIFIER_OBJECT_ID_INVALIDATION_MAP_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "google/cacheinvalidation/include/types.h" | |
14 #include "sync/base/sync_export.h" | 11 #include "sync/base/sync_export.h" |
15 #include "sync/internal_api/public/base/invalidation.h" | 12 #include "sync/internal_api/public/base/invalidation.h" |
16 #include "sync/notifier/invalidation_util.h" | 13 #include "sync/notifier/invalidation_util.h" |
17 | 14 #include "sync/notifier/single_object_invalidation_set.h" |
18 namespace base { | |
19 class ListValue; | |
20 } // namespace base | |
21 | 15 |
22 namespace syncer { | 16 namespace syncer { |
23 | 17 |
24 typedef std::map<invalidation::ObjectId, | 18 // A set of notifications with some helper methods to organize them by object ID |
25 Invalidation, | 19 // and version number. |
26 ObjectIdLessThan> ObjectIdInvalidationMap; | 20 class SYNC_EXPORT ObjectIdInvalidationMap { |
| 21 public: |
| 22 // Creates an invalidation map that includes an 'unknown version' |
| 23 // invalidation for each specified ID in |ids|. |
| 24 static ObjectIdInvalidationMap InvalidateAll(const ObjectIdSet& ids); |
27 | 25 |
28 // Converts between ObjectIdInvalidationMaps and ObjectIdSets. | 26 ObjectIdInvalidationMap(); |
29 ObjectIdSet ObjectIdInvalidationMapToSet( | 27 ~ObjectIdInvalidationMap(); |
30 const ObjectIdInvalidationMap& invalidation_map); | |
31 SYNC_EXPORT ObjectIdInvalidationMap ObjectIdSetToInvalidationMap( | |
32 const ObjectIdSet& ids, int64 version, const std::string& payload); | |
33 | 28 |
34 SYNC_EXPORT bool ObjectIdInvalidationMapEquals( | 29 // Returns set of ObjectIds for which at least one invalidation is present. |
35 const ObjectIdInvalidationMap& invalidation_map1, | 30 ObjectIdSet GetObjectIds() const; |
36 const ObjectIdInvalidationMap& invalidation_map2); | |
37 | 31 |
38 scoped_ptr<base::ListValue> ObjectIdInvalidationMapToValue( | 32 // Returns true if this map contains no invalidations. |
39 const ObjectIdInvalidationMap& invalidation_map); | 33 bool Empty() const; |
40 | 34 |
41 bool ObjectIdInvalidationMapFromValue(const base::ListValue& value, | 35 // Returns true if both maps contain the same set of invalidations. |
42 ObjectIdInvalidationMap* out); | 36 bool operator==(const ObjectIdInvalidationMap& other) const; |
| 37 |
| 38 // Inserts a new invalidation into this map. |
| 39 void Insert(const Invalidation& invalidation); |
| 40 |
| 41 // Returns a new map containing the subset of invaliations from this map |
| 42 // whose IDs were in the specified |ids| set. |
| 43 ObjectIdInvalidationMap GetSubsetWithObjectIds(const ObjectIdSet& ids) const; |
| 44 |
| 45 // Returns the subset of invalidations with IDs matching |id|. |
| 46 const SingleObjectInvalidationSet& ForObject( |
| 47 invalidation::ObjectId id) const; |
| 48 |
| 49 // Returns the contents of this map in a single vector. |
| 50 void GetAllInvalidations(std::vector<syncer::Invalidation>* out) const; |
| 51 |
| 52 // Serialize this map to a value. |
| 53 scoped_ptr<base::ListValue> ToValue() const; |
| 54 |
| 55 // Deserialize the value into a map and use it to re-initialize this object. |
| 56 bool ResetFromValue(const base::ListValue& value); |
| 57 |
| 58 // Prints the contentes of this map as a human-readable string. |
| 59 std::string ToString() const; |
| 60 |
| 61 private: |
| 62 typedef std::map<invalidation::ObjectId, |
| 63 SingleObjectInvalidationSet, |
| 64 ObjectIdLessThan> IdToListMap; |
| 65 |
| 66 ObjectIdInvalidationMap(const IdToListMap& map); |
| 67 |
| 68 IdToListMap map_; |
| 69 }; |
43 | 70 |
44 } // namespace syncer | 71 } // namespace syncer |
45 | 72 |
46 #endif // SYNC_NOTIFIER_OBJECT_ID_INVALIDATION_MAP_H_ | 73 #endif // SYNC_NOTIFIER_OBJECT_ID_INVALIDATION_MAP_H_ |
OLD | NEW |