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

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

Issue 1139883007: Sync: ParentChildIndex fix for out of order deletion of entries by PurgeEntriesWithTypeIn. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 "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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 79
80 return children->insert(entry).second; 80 return children->insert(entry).second;
81 } 81 }
82 82
83 // Like the other containers used to help support the syncable::Directory, this 83 // Like the other containers used to help support the syncable::Directory, this
84 // one does not own any EntryKernels. This function removes references to the 84 // one does not own any EntryKernels. This function removes references to the
85 // given EntryKernel but does not delete it. 85 // given EntryKernel but does not delete it.
86 void ParentChildIndex::Remove(EntryKernel* e) { 86 void ParentChildIndex::Remove(EntryKernel* e) {
87 const Id& parent_id = GetParentId(e); 87 const Id& parent_id = GetParentId(e);
88 // Clear type root ID when removing a type root entry.
89 if (parent_id.IsRoot()) {
90 ModelType model_type = GetModelType(e);
91 // TODO(stanisc): the check is needed to work around some tests.
92 // See TODO above.
93 if (model_type_root_ids_[model_type] == e->ref(ID)) {
94 model_type_root_ids_[model_type] = Id();
95 }
96 }
97 88
98 ParentChildrenMap::iterator parent = parent_children_map_.find(parent_id); 89 ParentChildrenMap::iterator parent = parent_children_map_.find(parent_id);
99 DCHECK(parent != parent_children_map_.end()); 90 DCHECK(parent != parent_children_map_.end());
100 91
101 OrderedChildSet* children = parent->second; 92 OrderedChildSet* children = parent->second;
102 OrderedChildSet::iterator j = children->find(e); 93 OrderedChildSet::iterator j = children->find(e);
103 DCHECK(j != children->end()); 94 DCHECK(j != children->end());
104 95
105 children->erase(j); 96 children->erase(j);
106 if (children->empty()) { 97 if (children->empty()) {
(...skipping 12 matching lines...) Expand all
119 const OrderedChildSet* children = parent->second; 110 const OrderedChildSet* children = parent->second;
120 DCHECK(children && !children->empty()); 111 DCHECK(children && !children->empty());
121 return children->count(e) > 0; 112 return children->count(e) > 0;
122 } 113 }
123 114
124 const OrderedChildSet* ParentChildIndex::GetChildren(const Id& id) const { 115 const OrderedChildSet* ParentChildIndex::GetChildren(const Id& id) const {
125 DCHECK(!id.IsNull()); 116 DCHECK(!id.IsNull());
126 117
127 ParentChildrenMap::const_iterator parent = parent_children_map_.find(id); 118 ParentChildrenMap::const_iterator parent = parent_children_map_.find(id);
128 if (parent == parent_children_map_.end()) { 119 if (parent == parent_children_map_.end()) {
129 return NULL; 120 return nullptr;
130 } 121 }
131 122
132 // A successful lookup implies at least some children exist. 123 // A successful lookup implies at least some children exist.
133 DCHECK(!parent->second->empty()); 124 DCHECK(!parent->second->empty());
134 return parent->second; 125 return parent->second;
135 } 126 }
136 127
137 const OrderedChildSet* ParentChildIndex::GetChildren(EntryKernel* e) const { 128 const OrderedChildSet* ParentChildIndex::GetChildren(EntryKernel* e) const {
138 return GetChildren(e->ref(ID)); 129 return GetChildren(e->ref(ID));
139 } 130 }
(...skipping 23 matching lines...) Expand all
163 } 154 }
164 155
165 const Id& ParentChildIndex::GetModelTypeRootId(ModelType model_type) const { 156 const Id& ParentChildIndex::GetModelTypeRootId(ModelType model_type) const {
166 // TODO(stanisc): Review whether this approach is reliable enough. 157 // TODO(stanisc): Review whether this approach is reliable enough.
167 // Should this method simply enumerate children of root node ("r") instead? 158 // Should this method simply enumerate children of root node ("r") instead?
168 return model_type_root_ids_[model_type]; 159 return model_type_root_ids_[model_type];
169 } 160 }
170 161
171 } // namespace syncable 162 } // namespace syncable
172 } // namespace syncer 163 } // namespace syncer
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/typed_url_change_processor.cc ('k') | sync/syncable/parent_child_index_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698