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

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

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: 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
« no previous file with comments | « components/sync/syncable/nigori_util.h ('k') | components/sync/syncable/syncable_id.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility>
8
9 #include "base/stl_util.h" 7 #include "base/stl_util.h"
10 #include "components/sync/syncable/entry_kernel.h" 8 #include "components/sync/syncable/entry_kernel.h"
11 9
12 namespace syncer { 10 namespace syncer {
13 namespace syncable { 11 namespace syncable {
14 12
15 bool ChildComparator::operator()(const EntryKernel* a, 13 bool ChildComparator::operator()(const EntryKernel* a,
16 const EntryKernel* b) const { 14 const EntryKernel* b) const {
17 const UniquePosition& a_pos = a->ref(UNIQUE_POSITION); 15 const UniquePosition& a_pos = a->ref(UNIQUE_POSITION);
18 const UniquePosition& b_pos = b->ref(UNIQUE_POSITION); 16 const UniquePosition& b_pos = b->ref(UNIQUE_POSITION);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 siblings = GetOrCreateModelTypeChildSet(model_type); 73 siblings = GetOrCreateModelTypeChildSet(model_type);
76 } 74 }
77 75
78 // If this is one of type root folder for a non-hierarchical type, associate 76 // If this is one of type root folder for a non-hierarchical type, associate
79 // its ID with the model type and the type's pre-defined child set with the 77 // its ID with the model type and the type's pre-defined child set with the
80 // type root ID. 78 // type root ID.
81 // TODO(stanisc): crbug/438313: Just TypeSupportsHierarchy condition should 79 // TODO(stanisc): crbug/438313: Just TypeSupportsHierarchy condition should
82 // theoretically be sufficient but in practice many tests don't properly 80 // theoretically be sufficient but in practice many tests don't properly
83 // initialize entries so TypeSupportsHierarchy ends up failing. Consider 81 // initialize entries so TypeSupportsHierarchy ends up failing. Consider
84 // tweaking TypeSupportsHierarchy and fixing all related test code. 82 // tweaking TypeSupportsHierarchy and fixing all related test code.
85 if (parent_id.IsRoot() && entry->ref(IS_DIR) && IsRealDataType(model_type) && 83 if (parent_id.IsRoot() && entry->ref(IS_DIR) &&
84 syncer::IsRealDataType(model_type) &&
86 !TypeSupportsHierarchy(model_type)) { 85 !TypeSupportsHierarchy(model_type)) {
87 const Id& type_root_id = entry->ref(ID); 86 const Id& type_root_id = entry->ref(ID);
88 87
89 // If the entry exists in the map it must already have the same 88 // If the entry exists in the map it must already have the same
90 // model type specific child set. It's possible another type root exists 89 // model type specific child set. It's possible another type root exists
91 // in parent_children_map_, but that's okay as the new type root will 90 // in parent_children_map_, but that's okay as the new type root will
92 // point to the same OrderedChildSet. As such, we just blindly store the 91 // point to the same OrderedChildSet. As such, we just blindly store the
93 // new type root ID and associate it to the (possibly existing) child set. 92 // new type root ID and associate it to the (possibly existing) child set.
94 model_type_root_ids_[model_type] = type_root_id; 93 model_type_root_ids_[model_type] = type_root_id;
95 parent_children_map_.insert( 94 parent_children_map_.insert(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 return siblings.get(); 166 return siblings.get();
168 } 167 }
169 168
170 /* static */ 169 /* static */
171 bool ParentChildIndex::ShouldUseParentId(const Id& parent_id, 170 bool ParentChildIndex::ShouldUseParentId(const Id& parent_id,
172 ModelType model_type) { 171 ModelType model_type) {
173 // For compatibility with legacy unit tests, in addition to hierarchical 172 // For compatibility with legacy unit tests, in addition to hierarchical
174 // entries, this returns true any entries directly under root and for entries 173 // entries, this returns true any entries directly under root and for entries
175 // of UNSPECIFIED model type. 174 // of UNSPECIFIED model type.
176 return parent_id.IsRoot() || TypeSupportsHierarchy(model_type) || 175 return parent_id.IsRoot() || TypeSupportsHierarchy(model_type) ||
177 !IsRealDataType(model_type); 176 !syncer::IsRealDataType(model_type);
178 } 177 }
179 178
180 const OrderedChildSetRef ParentChildIndex::GetChildSet(EntryKernel* e) const { 179 const OrderedChildSetRef ParentChildIndex::GetChildSet(EntryKernel* e) const {
181 ModelType model_type = e->GetModelType(); 180 ModelType model_type = e->GetModelType();
182 181
183 const Id& parent_id = e->ref(PARENT_ID); 182 const Id& parent_id = e->ref(PARENT_ID);
184 if (ShouldUseParentId(parent_id, model_type)) { 183 if (ShouldUseParentId(parent_id, model_type)) {
185 // Hierarchical type, lookup child set in the map. 184 // Hierarchical type, lookup child set in the map.
186 ParentChildrenMap::const_iterator it = parent_children_map_.find(parent_id); 185 ParentChildrenMap::const_iterator it = parent_children_map_.find(parent_id);
187 if (it == parent_children_map_.end()) 186 if (it == parent_children_map_.end())
(...skipping 17 matching lines...) Expand all
205 OrderedChildSetRef(new OrderedChildSet()); 204 OrderedChildSetRef(new OrderedChildSet());
206 return type_root_child_sets_[model_type]; 205 return type_root_child_sets_[model_type];
207 } 206 }
208 207
209 const Id& ParentChildIndex::GetModelTypeRootId(ModelType model_type) const { 208 const Id& ParentChildIndex::GetModelTypeRootId(ModelType model_type) const {
210 return model_type_root_ids_[model_type]; 209 return model_type_root_ids_[model_type];
211 } 210 }
212 211
213 } // namespace syncable 212 } // namespace syncable
214 } // namespace syncer 213 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/syncable/nigori_util.h ('k') | components/sync/syncable/syncable_id.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698