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