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

Side by Side Diff: components/sync/syncable/parent_child_index.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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 #include "sync/syncable/parent_child_index.h" 5 #include "components/sync/syncable/parent_child_index.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "sync/syncable/entry_kernel.h" 10 #include "components/sync/syncable/entry_kernel.h"
11 #include "sync/syncable/syncable_id.h" 11 #include "components/sync/syncable/syncable_id.h"
12 12
13 namespace syncer { 13 namespace syncer {
14 namespace syncable { 14 namespace syncable {
15 15
16 bool ChildComparator::operator()(const EntryKernel* a, 16 bool ChildComparator::operator()(const EntryKernel* a,
17 const EntryKernel* b) const { 17 const EntryKernel* b) const {
18 const UniquePosition& a_pos = a->ref(UNIQUE_POSITION); 18 const UniquePosition& a_pos = a->ref(UNIQUE_POSITION);
19 const UniquePosition& b_pos = b->ref(UNIQUE_POSITION); 19 const UniquePosition& b_pos = b->ref(UNIQUE_POSITION);
20 20
21 if (a_pos.IsValid() && b_pos.IsValid()) { 21 if (a_pos.IsValid() && b_pos.IsValid()) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 syncer::IsRealDataType(model_type) && 87 syncer::IsRealDataType(model_type) &&
88 !TypeSupportsHierarchy(model_type)) { 88 !TypeSupportsHierarchy(model_type)) {
89 const Id& type_root_id = entry->ref(ID); 89 const Id& type_root_id = entry->ref(ID);
90 90
91 // If the entry exists in the map it must already have the same 91 // If the entry exists in the map it must already have the same
92 // model type specific child set. It's possible another type root exists 92 // model type specific child set. It's possible another type root exists
93 // in parent_children_map_, but that's okay as the new type root will 93 // in parent_children_map_, but that's okay as the new type root will
94 // point to the same OrderedChildSet. As such, we just blindly store the 94 // point to the same OrderedChildSet. As such, we just blindly store the
95 // new type root ID and associate it to the (possibly existing) child set. 95 // new type root ID and associate it to the (possibly existing) child set.
96 model_type_root_ids_[model_type] = type_root_id; 96 model_type_root_ids_[model_type] = type_root_id;
97 parent_children_map_.insert(std::make_pair( 97 parent_children_map_.insert(
98 type_root_id, GetOrCreateModelTypeChildSet(model_type))); 98 std::make_pair(type_root_id, GetOrCreateModelTypeChildSet(model_type)));
99 } 99 }
100 100
101 // Finally, insert the entry in the child set. 101 // Finally, insert the entry in the child set.
102 return siblings->insert(entry).second; 102 return siblings->insert(entry).second;
103 } 103 }
104 104
105 // Like the other containers used to help support the syncable::Directory, this 105 // Like the other containers used to help support the syncable::Directory, this
106 // one does not own any EntryKernels. This function removes references to the 106 // one does not own any EntryKernels. This function removes references to the
107 // given EntryKernel but does not delete it. 107 // given EntryKernel but does not delete it.
108 void ParentChildIndex::Remove(EntryKernel* e) { 108 void ParentChildIndex::Remove(EntryKernel* e) {
(...skipping 20 matching lines...) Expand all
129 129
130 // Erase the entry from the child set. 130 // Erase the entry from the child set.
131 siblings->erase(j); 131 siblings->erase(j);
132 // If the set is now empty and isn't shareable with |type_root_child_sets_|, 132 // If the set is now empty and isn't shareable with |type_root_child_sets_|,
133 // erase it from the map. 133 // erase it from the map.
134 if (siblings->empty() && should_erase) { 134 if (siblings->empty() && should_erase) {
135 parent_children_map_.erase(sibling_iterator); 135 parent_children_map_.erase(sibling_iterator);
136 } 136 }
137 } 137 }
138 138
139 bool ParentChildIndex::Contains(EntryKernel *e) const { 139 bool ParentChildIndex::Contains(EntryKernel* e) const {
140 const OrderedChildSetRef siblings = GetChildSet(e); 140 const OrderedChildSetRef siblings = GetChildSet(e);
141 return siblings && siblings->count(e) > 0; 141 return siblings && siblings->count(e) > 0;
142 } 142 }
143 143
144 const OrderedChildSet* ParentChildIndex::GetChildren(const Id& id) const { 144 const OrderedChildSet* ParentChildIndex::GetChildren(const Id& id) const {
145 DCHECK(!id.IsNull()); 145 DCHECK(!id.IsNull());
146 146
147 ParentChildrenMap::const_iterator parent = parent_children_map_.find(id); 147 ParentChildrenMap::const_iterator parent = parent_children_map_.find(id);
148 if (parent == parent_children_map_.end()) { 148 if (parent == parent_children_map_.end()) {
149 return nullptr; 149 return nullptr;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 OrderedChildSetRef(new OrderedChildSet()); 207 OrderedChildSetRef(new OrderedChildSet());
208 return type_root_child_sets_[model_type]; 208 return type_root_child_sets_[model_type];
209 } 209 }
210 210
211 const Id& ParentChildIndex::GetModelTypeRootId(ModelType model_type) const { 211 const Id& ParentChildIndex::GetModelTypeRootId(ModelType model_type) const {
212 return model_type_root_ids_[model_type]; 212 return model_type_root_ids_[model_type];
213 } 213 }
214 214
215 } // namespace syncable 215 } // namespace syncable
216 } // namespace syncer 216 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/syncable/parent_child_index.h ('k') | components/sync/syncable/parent_child_index_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698