OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SYNCABLE_PARENT_CHILD_INDEX | 5 #ifndef SYNC_SYNCABLE_PARENT_CHILD_INDEX |
6 #define SYNC_SYNCABLE_PARENT_CHILD_INDEX | 6 #define SYNC_SYNCABLE_PARENT_CHILD_INDEX |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 // Returns all children of the entry. Returns NULL if the node has no | 54 // Returns all children of the entry. Returns NULL if the node has no |
55 // children. | 55 // children. |
56 const OrderedChildSet* GetChildren(EntryKernel* e) const; | 56 const OrderedChildSet* GetChildren(EntryKernel* e) const; |
57 | 57 |
58 // Returns all siblings of the entry. | 58 // Returns all siblings of the entry. |
59 const OrderedChildSet* GetSiblings(EntryKernel* e) const; | 59 const OrderedChildSet* GetSiblings(EntryKernel* e) const; |
60 | 60 |
61 private: | 61 private: |
62 friend class ParentChildIndexTest; | 62 friend class ParentChildIndexTest; |
| 63 |
63 typedef std::map<Id, OrderedChildSet*> ParentChildrenMap; | 64 typedef std::map<Id, OrderedChildSet*> ParentChildrenMap; |
| 65 typedef std::vector<Id> TypeRootIds; |
| 66 typedef std::vector<OrderedChildSet*> TypeRootChildSets; |
64 | 67 |
65 // Determines entry's model type. | 68 static bool ShouldUseParentId(const Id& parent_id, ModelType model_type); |
66 static ModelType GetModelType(EntryKernel* e); | |
67 | 69 |
68 // Returns parent ID for the entry which is either its PARENT_ID value | 70 // Returns OrderedChildSet that should contain the specified entry |
69 // or derived from its model type. | 71 // based on the entry's Parent ID or model type. |
70 const Id& GetParentId(EntryKernel* e) const; | 72 const OrderedChildSet* GetChildSet(EntryKernel* e) const; |
| 73 |
| 74 // Returns OrderedChildSet that contain entries of the |model_type| type. |
| 75 const OrderedChildSet* GetModelTypeChildSet(ModelType model_type) const; |
| 76 |
| 77 // Returns mutable OrderedChildSet that contain entries of the |model_type| |
| 78 // type. Create one as necessary. |
| 79 OrderedChildSet* GetOrCreateModelTypeChildSet(ModelType model_type); |
71 | 80 |
72 // Returns previously cached model type root ID for the given |model_type|. | 81 // Returns previously cached model type root ID for the given |model_type|. |
73 const Id& GetModelTypeRootId(ModelType model_type) const; | 82 const Id& GetModelTypeRootId(ModelType model_type) const; |
74 | 83 |
75 // A map of parent IDs to children. | 84 // A map of parent IDs to children. |
76 // Parents with no children are not included in this map. | 85 // Parents with no children are not included in this map. |
77 ParentChildrenMap parent_children_map_; | 86 ParentChildrenMap parent_children_map_; |
78 | 87 |
79 // This array tracks model type roots IDs. | 88 // This array tracks model type roots IDs. |
80 Id model_type_root_ids_[MODEL_TYPE_COUNT]; | 89 TypeRootIds model_type_root_ids_; |
| 90 |
| 91 // This array contains pre-defined child sets for |
| 92 // non-hierarchical types (types with flat hierarchy) that support entries |
| 93 // with implicit parent. |
| 94 TypeRootChildSets type_root_child_sets_; |
81 | 95 |
82 DISALLOW_COPY_AND_ASSIGN(ParentChildIndex); | 96 DISALLOW_COPY_AND_ASSIGN(ParentChildIndex); |
83 }; | 97 }; |
84 | 98 |
85 } // namespace syncable | 99 } // namespace syncable |
86 } // namespace syncer | 100 } // namespace syncer |
87 | 101 |
88 #endif // SYNC_SYNCABLE_PARENT_CHILD_INDEX | 102 #endif // SYNC_SYNCABLE_PARENT_CHILD_INDEX |
OLD | NEW |