OLD | NEW |
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 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 if (!e.GetIsDel()) { | 1185 if (!e.GetIsDel()) { |
1186 if (!SyncAssert(id != parentid, FROM_HERE, | 1186 if (!SyncAssert(id != parentid, FROM_HERE, |
1187 "Id should be different from parent id.", | 1187 "Id should be different from parent id.", |
1188 trans)) | 1188 trans)) |
1189 return false; | 1189 return false; |
1190 if (!SyncAssert(!e.GetNonUniqueName().empty(), FROM_HERE, | 1190 if (!SyncAssert(!e.GetNonUniqueName().empty(), FROM_HERE, |
1191 "Non unique name should not be empty.", | 1191 "Non unique name should not be empty.", |
1192 trans)) | 1192 trans)) |
1193 return false; | 1193 return false; |
1194 int safety_count = handles.size() + 1; | 1194 int safety_count = handles.size() + 1; |
| 1195 // TODO(stanisc): handle items with Null parentid |
1195 while (!parentid.IsRoot()) { | 1196 while (!parentid.IsRoot()) { |
1196 Entry parent(trans, GET_BY_ID, parentid); | 1197 Entry parent(trans, GET_BY_ID, parentid); |
1197 if (!SyncAssert(parent.good(), FROM_HERE, | 1198 if (!SyncAssert(parent.good(), FROM_HERE, |
1198 "Parent entry is not valid.", | 1199 "Parent entry is not valid.", |
1199 trans)) | 1200 trans)) |
1200 return false; | 1201 return false; |
1201 if (handles.end() == handles.find(parent.GetMetahandle())) | 1202 if (handles.end() == handles.find(parent.GetMetahandle())) |
1202 break; // Skip further checking if parent was unmodified. | 1203 break; // Skip further checking if parent was unmodified. |
1203 if (!SyncAssert(parent.GetIsDir(), FROM_HERE, | 1204 if (!SyncAssert(parent.GetIsDir(), FROM_HERE, |
1204 "Parent should be a directory", | 1205 "Parent should be a directory", |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1385 ScopedKernelLock lock(this); | 1386 ScopedKernelLock lock(this); |
1386 ScopedParentChildIndexUpdater updater(lock, e, &kernel_->parent_child_index); | 1387 ScopedParentChildIndexUpdater updater(lock, e, &kernel_->parent_child_index); |
1387 | 1388 |
1388 // Note: The ScopedParentChildIndexUpdater will update this set for us as we | 1389 // Note: The ScopedParentChildIndexUpdater will update this set for us as we |
1389 // leave this function. | 1390 // leave this function. |
1390 const OrderedChildSet* siblings = | 1391 const OrderedChildSet* siblings = |
1391 kernel_->parent_child_index.GetChildren(e->ref(PARENT_ID)); | 1392 kernel_->parent_child_index.GetChildren(e->ref(PARENT_ID)); |
1392 | 1393 |
1393 if (!siblings) { | 1394 if (!siblings) { |
1394 // This parent currently has no other children. | 1395 // This parent currently has no other children. |
1395 DCHECK(predecessor->ref(ID).IsRoot()); | 1396 DCHECK(predecessor == NULL); |
1396 UniquePosition pos = UniquePosition::InitialPosition(suffix); | 1397 UniquePosition pos = UniquePosition::InitialPosition(suffix); |
1397 e->put(UNIQUE_POSITION, pos); | 1398 e->put(UNIQUE_POSITION, pos); |
1398 return; | 1399 return; |
1399 } | 1400 } |
1400 | 1401 |
1401 if (predecessor->ref(ID).IsRoot()) { | 1402 if (predecessor == NULL) { |
1402 // We have at least one sibling, and we're inserting to the left of them. | 1403 // We have at least one sibling, and we're inserting to the left of them. |
1403 UniquePosition successor_pos = (*siblings->begin())->ref(UNIQUE_POSITION); | 1404 UniquePosition successor_pos = (*siblings->begin())->ref(UNIQUE_POSITION); |
1404 | 1405 |
1405 UniquePosition pos; | 1406 UniquePosition pos; |
1406 if (!successor_pos.IsValid()) { | 1407 if (!successor_pos.IsValid()) { |
1407 // If all our successors are of non-positionable types, just create an | 1408 // If all our successors are of non-positionable types, just create an |
1408 // initial position. We arbitrarily choose to sort invalid positions to | 1409 // initial position. We arbitrarily choose to sort invalid positions to |
1409 // the right of the valid positions. | 1410 // the right of the valid positions. |
1410 // | 1411 // |
1411 // We really shouldn't need to support this. See TODO above. | 1412 // We really shouldn't need to support this. See TODO above. |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1523 // TODO(maniscalco): Eliminate redundant metadata storage (bug 415203). | 1524 // TODO(maniscalco): Eliminate redundant metadata storage (bug 415203). |
1524 std::set_difference(not_on_server_id_set.begin(), | 1525 std::set_difference(not_on_server_id_set.begin(), |
1525 not_on_server_id_set.end(), | 1526 not_on_server_id_set.end(), |
1526 on_server_id_set.begin(), | 1527 on_server_id_set.begin(), |
1527 on_server_id_set.end(), | 1528 on_server_id_set.end(), |
1528 std::inserter(*id_set, id_set->end())); | 1529 std::inserter(*id_set, id_set->end())); |
1529 } | 1530 } |
1530 | 1531 |
1531 } // namespace syncable | 1532 } // namespace syncable |
1532 } // namespace syncer | 1533 } // namespace syncer |
OLD | NEW |