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

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

Issue 2376123003: [Sync] Move //components/sync to the syncer namespace. (Closed)
Patch Set: Fix tools and iOS. Created 4 years, 2 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 "components/sync/syncable/parent_child_index.h" 5 #include "components/sync/syncable/parent_child_index.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility>
8 9
9 #include "base/stl_util.h" 10 #include "base/stl_util.h"
10 #include "components/sync/syncable/entry_kernel.h" 11 #include "components/sync/syncable/entry_kernel.h"
11 #include "components/sync/syncable/syncable_id.h" 12 #include "components/sync/syncable/syncable_id.h"
12 13
13 namespace syncer { 14 namespace syncer {
14 namespace syncable { 15 namespace syncable {
15 16
16 bool ChildComparator::operator()(const EntryKernel* a, 17 bool ChildComparator::operator()(const EntryKernel* a,
17 const EntryKernel* b) const { 18 const EntryKernel* b) const {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 siblings = GetOrCreateModelTypeChildSet(model_type); 77 siblings = GetOrCreateModelTypeChildSet(model_type);
77 } 78 }
78 79
79 // If this is one of type root folder for a non-hierarchical type, associate 80 // If this is one of type root folder for a non-hierarchical type, associate
80 // its ID with the model type and the type's pre-defined child set with the 81 // its ID with the model type and the type's pre-defined child set with the
81 // type root ID. 82 // type root ID.
82 // TODO(stanisc): crbug/438313: Just TypeSupportsHierarchy condition should 83 // TODO(stanisc): crbug/438313: Just TypeSupportsHierarchy condition should
83 // theoretically be sufficient but in practice many tests don't properly 84 // theoretically be sufficient but in practice many tests don't properly
84 // initialize entries so TypeSupportsHierarchy ends up failing. Consider 85 // initialize entries so TypeSupportsHierarchy ends up failing. Consider
85 // tweaking TypeSupportsHierarchy and fixing all related test code. 86 // tweaking TypeSupportsHierarchy and fixing all related test code.
86 if (parent_id.IsRoot() && entry->ref(IS_DIR) && 87 if (parent_id.IsRoot() && entry->ref(IS_DIR) && 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( 97 parent_children_map_.insert(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 return siblings.get(); 169 return siblings.get();
170 } 170 }
171 171
172 /* static */ 172 /* static */
173 bool ParentChildIndex::ShouldUseParentId(const Id& parent_id, 173 bool ParentChildIndex::ShouldUseParentId(const Id& parent_id,
174 ModelType model_type) { 174 ModelType model_type) {
175 // For compatibility with legacy unit tests, in addition to hierarchical 175 // For compatibility with legacy unit tests, in addition to hierarchical
176 // entries, this returns true any entries directly under root and for entries 176 // entries, this returns true any entries directly under root and for entries
177 // of UNSPECIFIED model type. 177 // of UNSPECIFIED model type.
178 return parent_id.IsRoot() || TypeSupportsHierarchy(model_type) || 178 return parent_id.IsRoot() || TypeSupportsHierarchy(model_type) ||
179 !syncer::IsRealDataType(model_type); 179 !IsRealDataType(model_type);
180 } 180 }
181 181
182 const OrderedChildSetRef ParentChildIndex::GetChildSet(EntryKernel* e) const { 182 const OrderedChildSetRef ParentChildIndex::GetChildSet(EntryKernel* e) const {
183 ModelType model_type = e->GetModelType(); 183 ModelType model_type = e->GetModelType();
184 184
185 const Id& parent_id = e->ref(PARENT_ID); 185 const Id& parent_id = e->ref(PARENT_ID);
186 if (ShouldUseParentId(parent_id, model_type)) { 186 if (ShouldUseParentId(parent_id, model_type)) {
187 // Hierarchical type, lookup child set in the map. 187 // Hierarchical type, lookup child set in the map.
188 ParentChildrenMap::const_iterator it = parent_children_map_.find(parent_id); 188 ParentChildrenMap::const_iterator it = parent_children_map_.find(parent_id);
189 if (it == parent_children_map_.end()) 189 if (it == parent_children_map_.end())
(...skipping 17 matching lines...) Expand all
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

Powered by Google App Engine
This is Rietveld 408576698