Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: sync/syncable/parent_child_index.h

Issue 1226213002: Sync: Support nodes with implicit permanent folders: Node Browser and out-of-order loading from DB (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed memory leak Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 typedef std::map<Id, OrderedChildSet*> ParentChildrenMap;
64 63
65 // Determines entry's model type. 64 struct ChildSetEntry {
Nicolas Zea 2015/07/09 20:36:34 Comment about what this does? In particular would
stanisc 2015/07/09 21:45:17 The main problem is that entries might be inserted
stanisc 2015/07/09 23:59:27 Done. Reimplemented this without ChildSetEntry.
66 static ModelType GetModelType(EntryKernel* e); 65 ChildSetEntry(OrderedChildSet* child_set, bool owned)
66 : child_set_(child_set), owned_(owned) {}
67 67
68 // Returns parent ID for the entry which is either its PARENT_ID value 68 OrderedChildSet* const& child_set() const { return child_set_; }
69 // or derived from its model type. 69 bool owned() const { return owned_; }
70 const Id& GetParentId(EntryKernel* e) const; 70
71 static const ChildSetEntry& Empty();
72
73 private:
74 OrderedChildSet* child_set_;
75 bool owned_;
76 };
77
78 typedef std::map<Id, ChildSetEntry> ParentChildrenMap;
79
80 static bool ShouldUseParentId(const Id& parent_id, ModelType model_type);
81
82 // Returns OrderedChildSet that should contain the specified entry
83 // based on the entry's Parent ID or model type.
84 const OrderedChildSet* GetChildSet(EntryKernel* e) const;
85
86 // Inserts a new child set in the map. The ownership depends on
87 // |child_set_entry.owned()| flag.
88 void InsertChildSet(const Id& id, const ChildSetEntry& child_set_entry);
71 89
72 // Returns previously cached model type root ID for the given |model_type|. 90 // Returns previously cached model type root ID for the given |model_type|.
73 const Id& GetModelTypeRootId(ModelType model_type) const; 91 const Id& GetModelTypeRootId(ModelType model_type) const;
74 92
75 // A map of parent IDs to children. 93 // A map of parent IDs to children.
76 // Parents with no children are not included in this map. 94 // Parents with no children are not included in this map.
77 ParentChildrenMap parent_children_map_; 95 ParentChildrenMap parent_children_map_;
78 96
79 // This array tracks model type roots IDs. 97 // This array tracks model type roots IDs.
80 Id model_type_root_ids_[MODEL_TYPE_COUNT]; 98 Id model_type_root_ids_[MODEL_TYPE_COUNT];
99 // This array contains pre-defined child sets for
Nicolas Zea 2015/07/09 20:36:34 nit: newline above
stanisc 2015/07/09 23:59:27 Done.
100 // non-hierarchical types (types with flat hierarchy) that support entries
101 // with implicit parent.
102 OrderedChildSet type_root_child_sets_[MODEL_TYPE_COUNT];
81 103
82 DISALLOW_COPY_AND_ASSIGN(ParentChildIndex); 104 DISALLOW_COPY_AND_ASSIGN(ParentChildIndex);
83 }; 105 };
84 106
85 } // namespace syncable 107 } // namespace syncable
86 } // namespace syncer 108 } // namespace syncer
87 109
88 #endif // SYNC_SYNCABLE_PARENT_CHILD_INDEX 110 #endif // SYNC_SYNCABLE_PARENT_CHILD_INDEX
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698