| 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_H_ | 5 #ifndef SYNC_SYNCABLE_PARENT_CHILD_INDEX_H_ |
| 6 #define SYNC_SYNCABLE_PARENT_CHILD_INDEX_H_ | 6 #define SYNC_SYNCABLE_PARENT_CHILD_INDEX_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> |
| 9 #include <set> | 10 #include <set> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/scoped_vector.h" | |
| 14 #include "sync/base/sync_export.h" | 14 #include "sync/base/sync_export.h" |
| 15 #include "sync/internal_api/public/base/model_type.h" | 15 #include "sync/internal_api/public/base/model_type.h" |
| 16 #include "sync/syncable/syncable_id.h" | 16 #include "sync/syncable/syncable_id.h" |
| 17 | 17 |
| 18 namespace syncer { | 18 namespace syncer { |
| 19 namespace syncable { | 19 namespace syncable { |
| 20 | 20 |
| 21 struct EntryKernel; | 21 struct EntryKernel; |
| 22 class ParentChildIndex; | 22 class ParentChildIndex; |
| 23 | 23 |
| 24 // A node ordering function. | 24 // A node ordering function. |
| 25 struct SYNC_EXPORT ChildComparator { | 25 struct SYNC_EXPORT ChildComparator { |
| 26 bool operator() (const EntryKernel* a, const EntryKernel* b) const; | 26 bool operator() (const EntryKernel* a, const EntryKernel* b) const; |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 // An ordered set of nodes. | 29 // An ordered set of nodes. |
| 30 typedef std::set<EntryKernel*, ChildComparator> OrderedChildSet; | 30 typedef std::set<EntryKernel*, ChildComparator> OrderedChildSet; |
| 31 typedef std::shared_ptr<OrderedChildSet> OrderedChildSetRef; |
| 31 | 32 |
| 32 // Container that tracks parent-child relationships. | 33 // Container that tracks parent-child relationships. |
| 33 // Provides fast lookup of all items under a given parent. | 34 // Provides fast lookup of all items under a given parent. |
| 34 class SYNC_EXPORT ParentChildIndex { | 35 class SYNC_EXPORT ParentChildIndex { |
| 35 public: | 36 public: |
| 36 ParentChildIndex(); | 37 ParentChildIndex(); |
| 37 ~ParentChildIndex(); | 38 ~ParentChildIndex(); |
| 38 | 39 |
| 39 // Returns whether or not this entry belongs in the index. | 40 // Returns whether or not this entry belongs in the index. |
| 40 // True for all non-deleted, non-root entries. | 41 // True for all non-deleted, non-root entries. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 56 // Returns all children of the entry. Returns NULL if the node has no | 57 // Returns all children of the entry. Returns NULL if the node has no |
| 57 // children. | 58 // children. |
| 58 const OrderedChildSet* GetChildren(EntryKernel* e) const; | 59 const OrderedChildSet* GetChildren(EntryKernel* e) const; |
| 59 | 60 |
| 60 // Returns all siblings of the entry. | 61 // Returns all siblings of the entry. |
| 61 const OrderedChildSet* GetSiblings(EntryKernel* e) const; | 62 const OrderedChildSet* GetSiblings(EntryKernel* e) const; |
| 62 | 63 |
| 63 private: | 64 private: |
| 64 friend class ParentChildIndexTest; | 65 friend class ParentChildIndexTest; |
| 65 | 66 |
| 66 typedef std::map<Id, OrderedChildSet*> ParentChildrenMap; | 67 typedef std::map<Id, OrderedChildSetRef> ParentChildrenMap; |
| 67 typedef std::vector<Id> TypeRootIds; | 68 typedef std::vector<Id> TypeRootIds; |
| 68 typedef ScopedVector<OrderedChildSet> TypeRootChildSets; | 69 typedef std::vector<OrderedChildSetRef> TypeRootChildSets; |
| 69 | 70 |
| 70 static bool ShouldUseParentId(const Id& parent_id, ModelType model_type); | 71 static bool ShouldUseParentId(const Id& parent_id, ModelType model_type); |
| 71 | 72 |
| 72 // Returns OrderedChildSet that should contain the specified entry | 73 // Returns OrderedChildSet that should contain the specified entry |
| 73 // based on the entry's Parent ID or model type. | 74 // based on the entry's Parent ID or model type. |
| 74 const OrderedChildSet* GetChildSet(EntryKernel* e) const; | 75 const OrderedChildSetRef GetChildSet(EntryKernel* e) const; |
| 75 | 76 |
| 76 // Returns OrderedChildSet that contain entries of the |model_type| type. | 77 // Returns OrderedChildSet that contain entries of the |model_type| type. |
| 77 const OrderedChildSet* GetModelTypeChildSet(ModelType model_type) const; | 78 const OrderedChildSetRef GetModelTypeChildSet(ModelType model_type) const; |
| 78 | 79 |
| 79 // Returns mutable OrderedChildSet that contain entries of the |model_type| | 80 // Returns mutable OrderedChildSet that contain entries of the |model_type| |
| 80 // type. Create one as necessary. | 81 // type. Create one as necessary. |
| 81 OrderedChildSet* GetOrCreateModelTypeChildSet(ModelType model_type); | 82 OrderedChildSetRef GetOrCreateModelTypeChildSet(ModelType model_type); |
| 82 | 83 |
| 83 // Returns previously cached model type root ID for the given |model_type|. | 84 // Returns previously cached model type root ID for the given |model_type|. |
| 84 const Id& GetModelTypeRootId(ModelType model_type) const; | 85 const Id& GetModelTypeRootId(ModelType model_type) const; |
| 85 | 86 |
| 86 // A map of parent IDs to children. | 87 // A map of parent IDs to children. |
| 87 // Parents with no children are not included in this map. | 88 // Parents with no children are not included in this map. |
| 88 ParentChildrenMap parent_children_map_; | 89 ParentChildrenMap parent_children_map_; |
| 89 | 90 |
| 90 // This array tracks model type roots IDs. | 91 // This array tracks model type roots IDs. |
| 91 TypeRootIds model_type_root_ids_; | 92 TypeRootIds model_type_root_ids_; |
| 92 | 93 |
| 93 // This array contains pre-defined child sets for | 94 // This array contains pre-defined child sets for |
| 94 // non-hierarchical types (types with flat hierarchy) that support entries | 95 // non-hierarchical types (types with flat hierarchy) that support entries |
| 95 // with implicit parent. | 96 // with implicit parent. |
| 96 TypeRootChildSets type_root_child_sets_; | 97 TypeRootChildSets type_root_child_sets_; |
| 97 | 98 |
| 98 DISALLOW_COPY_AND_ASSIGN(ParentChildIndex); | 99 DISALLOW_COPY_AND_ASSIGN(ParentChildIndex); |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 } // namespace syncable | 102 } // namespace syncable |
| 102 } // namespace syncer | 103 } // namespace syncer |
| 103 | 104 |
| 104 #endif // SYNC_SYNCABLE_PARENT_CHILD_INDEX_H_ | 105 #endif // SYNC_SYNCABLE_PARENT_CHILD_INDEX_H_ |
| OLD | NEW |