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