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

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

Issue 1008993004: Sync: Handle empty (implicit) ParentId in GetPredecessorId and GetSuccessorId (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added extra unit test. Created 5 years, 9 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 | « sync/syncable/parent_child_index.h ('k') | sync/syncable/parent_child_index_unittest.cc » ('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 "sync/syncable/parent_child_index.h" 5 #include "sync/syncable/parent_child_index.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 8
9 #include "sync/syncable/entry_kernel.h" 9 #include "sync/syncable/entry_kernel.h"
10 #include "sync/syncable/syncable_id.h" 10 #include "sync/syncable/syncable_id.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 ParentChildrenMap::const_iterator parent = 113 ParentChildrenMap::const_iterator parent =
114 parent_children_map_.find(parent_id); 114 parent_children_map_.find(parent_id);
115 if (parent == parent_children_map_.end()) { 115 if (parent == parent_children_map_.end()) {
116 return false; 116 return false;
117 } 117 }
118 const OrderedChildSet* children = parent->second; 118 const OrderedChildSet* children = parent->second;
119 DCHECK(children && !children->empty()); 119 DCHECK(children && !children->empty());
120 return children->count(e) > 0; 120 return children->count(e) > 0;
121 } 121 }
122 122
123 const OrderedChildSet* ParentChildIndex::GetChildren(const syncable::Id& id) { 123 const OrderedChildSet* ParentChildIndex::GetChildren(const Id& id) const {
124 ParentChildrenMap::iterator parent = parent_children_map_.find(id); 124 DCHECK(!id.IsNull());
125
126 ParentChildrenMap::const_iterator parent = parent_children_map_.find(id);
125 if (parent == parent_children_map_.end()) { 127 if (parent == parent_children_map_.end()) {
126 return NULL; 128 return NULL;
127 } 129 }
128 130
129 // A successful lookup implies at least some children exist. 131 // A successful lookup implies at least some children exist.
130 DCHECK(!parent->second->empty()); 132 DCHECK(!parent->second->empty());
131 return parent->second; 133 return parent->second;
132 } 134 }
133 135
136 const OrderedChildSet* ParentChildIndex::GetChildren(EntryKernel* e) const {
137 return GetChildren(e->ref(ID));
138 }
139
140 const OrderedChildSet* ParentChildIndex::GetSiblings(EntryKernel* e) const {
141 DCHECK(Contains(e));
142 const OrderedChildSet* siblings = GetChildren(GetParentId(e));
143 DCHECK(siblings && !siblings->empty());
144 return siblings;
145 }
146
134 const Id& ParentChildIndex::GetParentId(EntryKernel* e) const { 147 const Id& ParentChildIndex::GetParentId(EntryKernel* e) const {
135 const Id& parent_id = e->ref(PARENT_ID); 148 const Id& parent_id = e->ref(PARENT_ID);
136 if (!parent_id.IsNull()) { 149 if (!parent_id.IsNull()) {
137 return parent_id; 150 return parent_id;
138 } 151 }
139 return GetModelTypeRootId(GetModelType(e)); 152 return GetModelTypeRootId(GetModelType(e));
140 } 153 }
141 154
142 ModelType ParentChildIndex::GetModelType(EntryKernel* e) { 155 ModelType ParentChildIndex::GetModelType(EntryKernel* e) {
143 // TODO(stanisc): is there a more effective way to find out model type? 156 // TODO(stanisc): is there a more effective way to find out model type?
144 ModelType model_type = e->GetModelType(); 157 ModelType model_type = e->GetModelType();
145 if (!syncer::IsRealDataType(model_type)) { 158 if (!syncer::IsRealDataType(model_type)) {
146 model_type = e->GetServerModelType(); 159 model_type = e->GetServerModelType();
147 } 160 }
148 return model_type; 161 return model_type;
149 } 162 }
150 163
151 const Id& ParentChildIndex::GetModelTypeRootId(ModelType model_type) const { 164 const Id& ParentChildIndex::GetModelTypeRootId(ModelType model_type) const {
152 // TODO(stanisc): Review whether this approach is reliable enough. 165 // TODO(stanisc): Review whether this approach is reliable enough.
153 // Should this method simply enumerate children of root node ("r") instead? 166 // Should this method simply enumerate children of root node ("r") instead?
154 return model_type_root_ids_[model_type]; 167 return model_type_root_ids_[model_type];
155 } 168 }
156 169
157 } // namespace syncable 170 } // namespace syncable
158 } // namespace syncer 171 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/parent_child_index.h ('k') | sync/syncable/parent_child_index_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698