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

Side by Side Diff: sync/syncable/directory.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 | « no previous file | sync/syncable/directory_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/directory.h" 5 #include "sync/syncable/directory.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 return; // This directory has no children. 327 return; // This directory has no children.
328 328
329 // Add our children to the list of items to be traversed. 329 // Add our children to the list of items to be traversed.
330 child_sets->push_back(descendants); 330 child_sets->push_back(descendants);
331 } 331 }
332 332
333 int Directory::GetPositionIndex( 333 int Directory::GetPositionIndex(
334 BaseTransaction* trans, 334 BaseTransaction* trans,
335 EntryKernel* kernel) const { 335 EntryKernel* kernel) const {
336 const OrderedChildSet* siblings = 336 const OrderedChildSet* siblings =
337 kernel_->parent_child_index.GetChildren(kernel->ref(PARENT_ID)); 337 kernel_->parent_child_index.GetSiblings(kernel);
338 338
339 OrderedChildSet::const_iterator it = siblings->find(kernel); 339 OrderedChildSet::const_iterator it = siblings->find(kernel);
340 return std::distance(siblings->begin(), it); 340 return std::distance(siblings->begin(), it);
341 } 341 }
342 342
343 bool Directory::InsertEntry(BaseWriteTransaction* trans, EntryKernel* entry) { 343 bool Directory::InsertEntry(BaseWriteTransaction* trans, EntryKernel* entry) {
344 ScopedKernelLock lock(this); 344 ScopedKernelLock lock(this);
345 return InsertEntry(lock, trans, entry); 345 return InsertEntry(lock, trans, entry);
346 } 346 }
347 347
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 if (!children) 1353 if (!children)
1354 return Id(); 1354 return Id();
1355 1355
1356 return (*children->begin())->ref(ID); 1356 return (*children->begin())->ref(ID);
1357 } 1357 }
1358 1358
1359 syncable::Id Directory::GetPredecessorId(EntryKernel* e) { 1359 syncable::Id Directory::GetPredecessorId(EntryKernel* e) {
1360 ScopedKernelLock lock(this); 1360 ScopedKernelLock lock(this);
1361 1361
1362 DCHECK(ParentChildIndex::ShouldInclude(e)); 1362 DCHECK(ParentChildIndex::ShouldInclude(e));
1363 const OrderedChildSet* children = 1363 const OrderedChildSet* siblings = kernel_->parent_child_index.GetSiblings(e);
1364 kernel_->parent_child_index.GetChildren(e->ref(PARENT_ID)); 1364 OrderedChildSet::const_iterator i = siblings->find(e);
1365 DCHECK(children && !children->empty()); 1365 DCHECK(i != siblings->end());
1366 OrderedChildSet::const_iterator i = children->find(e);
1367 DCHECK(i != children->end());
1368 1366
1369 if (i == children->begin()) { 1367 if (i == siblings->begin()) {
1370 return Id(); 1368 return Id();
1371 } else { 1369 } else {
1372 i--; 1370 i--;
1373 return (*i)->ref(ID); 1371 return (*i)->ref(ID);
1374 } 1372 }
1375 } 1373 }
1376 1374
1377 syncable::Id Directory::GetSuccessorId(EntryKernel* e) { 1375 syncable::Id Directory::GetSuccessorId(EntryKernel* e) {
1378 ScopedKernelLock lock(this); 1376 ScopedKernelLock lock(this);
1379 1377
1380 DCHECK(ParentChildIndex::ShouldInclude(e)); 1378 DCHECK(ParentChildIndex::ShouldInclude(e));
1381 const OrderedChildSet* children = 1379 const OrderedChildSet* siblings = kernel_->parent_child_index.GetSiblings(e);
1382 kernel_->parent_child_index.GetChildren(e->ref(PARENT_ID)); 1380 OrderedChildSet::const_iterator i = siblings->find(e);
1383 DCHECK(children && !children->empty()); 1381 DCHECK(i != siblings->end());
1384 OrderedChildSet::const_iterator i = children->find(e);
1385 DCHECK(i != children->end());
1386 1382
1387 i++; 1383 i++;
1388 if (i == children->end()) { 1384 if (i == siblings->end()) {
1389 return Id(); 1385 return Id();
1390 } else { 1386 } else {
1391 return (*i)->ref(ID); 1387 return (*i)->ref(ID);
1392 } 1388 }
1393 } 1389 }
1394 1390
1395 // TODO(rlarocque): Remove all support for placing ShouldMaintainPosition() 1391 // TODO(rlarocque): Remove all support for placing ShouldMaintainPosition()
1396 // items as siblings of items that do not maintain postions. It is required 1392 // items as siblings of items that do not maintain postions. It is required
1397 // only for tests. See crbug.com/178282. 1393 // only for tests. See crbug.com/178282.
1398 void Directory::PutPredecessor(EntryKernel* e, EntryKernel* predecessor) { 1394 void Directory::PutPredecessor(EntryKernel* e, EntryKernel* predecessor) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 // TODO(maniscalco): Eliminate redundant metadata storage (bug 415203). 1541 // TODO(maniscalco): Eliminate redundant metadata storage (bug 415203).
1546 std::set_difference(not_on_server_id_set.begin(), 1542 std::set_difference(not_on_server_id_set.begin(),
1547 not_on_server_id_set.end(), 1543 not_on_server_id_set.end(),
1548 on_server_id_set.begin(), 1544 on_server_id_set.begin(),
1549 on_server_id_set.end(), 1545 on_server_id_set.end(),
1550 std::inserter(*id_set, id_set->end())); 1546 std::inserter(*id_set, id_set->end()));
1551 } 1547 }
1552 1548
1553 } // namespace syncable 1549 } // namespace syncable
1554 } // namespace syncer 1550 } // namespace syncer
OLDNEW
« no previous file with comments | « no previous file | sync/syncable/directory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698