Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/syncable_util.h" | 5 #include "sync/syncable/syncable_util.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/sha1.h" | 10 #include "base/sha1.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 int GetUnsyncedEntries(BaseTransaction* trans, | 21 int GetUnsyncedEntries(BaseTransaction* trans, |
| 22 std::vector<int64> *handles) { | 22 std::vector<int64> *handles) { |
| 23 trans->directory()->GetUnsyncedMetaHandles(trans, handles); | 23 trans->directory()->GetUnsyncedMetaHandles(trans, handles); |
| 24 DVLOG_IF(1, !handles->empty()) << "Have " << handles->size() | 24 DVLOG_IF(1, !handles->empty()) << "Have " << handles->size() |
| 25 << " unsynced items."; | 25 << " unsynced items."; |
| 26 return handles->size(); | 26 return handles->size(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 bool IsLegalNewParent(BaseTransaction* trans, const Id& entry_id, | 29 bool IsLegalNewParent(BaseTransaction* trans, const Id& entry_id, |
| 30 const Id& new_parent_id) { | 30 const Id& new_parent_id) { |
| 31 DCHECK(!entry_id.IsNull()); | |
| 31 if (entry_id.IsRoot()) | 32 if (entry_id.IsRoot()) |
| 32 return false; | 33 return false; |
| 34 if (new_parent_id.IsNull()) | |
| 35 return true; | |
|
Nicolas Zea
2015/01/26 23:21:53
Should this be false here for bookmarks?
stanisc
2015/01/28 07:30:06
Yes, I agree. I'll see if this check could be done
stanisc
2015/01/29 00:27:37
Done.
| |
| 33 // we have to ensure that the entry is not an ancestor of the new parent. | 36 // we have to ensure that the entry is not an ancestor of the new parent. |
| 34 Id ancestor_id = new_parent_id; | 37 Id ancestor_id = new_parent_id; |
| 35 while (!ancestor_id.IsRoot()) { | 38 while (!ancestor_id.IsRoot()) { |
| 36 if (entry_id == ancestor_id) | 39 if (entry_id == ancestor_id) |
| 37 return false; | 40 return false; |
| 38 Entry new_parent(trans, GET_BY_ID, ancestor_id); | 41 Entry new_parent(trans, GET_BY_ID, ancestor_id); |
| 39 if (!SyncAssert(new_parent.good(), | 42 if (!SyncAssert(new_parent.good(), |
| 40 FROM_HERE, | 43 FROM_HERE, |
| 41 "Invalid new parent", | 44 "Invalid new parent", |
| 42 trans)) | 45 trans)) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 59 << *entry << "\n\n" << old_entry; | 62 << *entry << "\n\n" << old_entry; |
| 60 } | 63 } |
| 61 if (entry->GetIsDir()) { | 64 if (entry->GetIsDir()) { |
| 62 // Get all child entries of the old id. | 65 // Get all child entries of the old id. |
| 63 Directory::Metahandles children; | 66 Directory::Metahandles children; |
| 64 trans->directory()->GetChildHandlesById(trans, old_id, &children); | 67 trans->directory()->GetChildHandlesById(trans, old_id, &children); |
| 65 Directory::Metahandles::iterator i = children.begin(); | 68 Directory::Metahandles::iterator i = children.begin(); |
| 66 while (i != children.end()) { | 69 while (i != children.end()) { |
| 67 ModelNeutralMutableEntry child_entry(trans, GET_BY_HANDLE, *i++); | 70 ModelNeutralMutableEntry child_entry(trans, GET_BY_HANDLE, *i++); |
| 68 CHECK(child_entry.good()); | 71 CHECK(child_entry.good()); |
| 69 // Use the unchecked setter here to avoid touching the child's | 72 // Change the parent ID of the entry unless it was unset (implicit) |
| 70 // UNIQUE_POSITION field. In this case, UNIQUE_POSITION among the | 73 if (!child_entry.GetParentId().IsNull()) { |
| 71 // children will be valid after the loop, since we update all the children | 74 // Use the unchecked setter here to avoid touching the child's |
| 72 // at once. | 75 // UNIQUE_POSITION field. In this case, UNIQUE_POSITION among the |
| 73 child_entry.PutParentIdPropertyOnly(new_id); | 76 // children will be valid after the loop, since we update all the |
| 77 // children at once. | |
| 78 child_entry.PutParentIdPropertyOnly(new_id); | |
| 79 } | |
| 74 } | 80 } |
| 75 } | 81 } |
| 76 } | 82 } |
| 77 | 83 |
| 78 // Function to handle runtime failures on syncable code. Rather than crashing, | 84 // Function to handle runtime failures on syncable code. Rather than crashing, |
| 79 // if the |condition| is false the following will happen: | 85 // if the |condition| is false the following will happen: |
| 80 // 1. Sets unrecoverable error on transaction. | 86 // 1. Sets unrecoverable error on transaction. |
| 81 // 2. Returns false. | 87 // 2. Returns false. |
| 82 bool SyncAssert(bool condition, | 88 bool SyncAssert(bool condition, |
| 83 const tracked_objects::Location& location, | 89 const tracked_objects::Location& location, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 107 | 113 |
| 108 std::string GenerateSyncableBookmarkHash( | 114 std::string GenerateSyncableBookmarkHash( |
| 109 const std::string& originator_cache_guid, | 115 const std::string& originator_cache_guid, |
| 110 const std::string& originator_client_item_id) { | 116 const std::string& originator_client_item_id) { |
| 111 return syncable::GenerateSyncableHash( | 117 return syncable::GenerateSyncableHash( |
| 112 BOOKMARKS, originator_cache_guid + originator_client_item_id); | 118 BOOKMARKS, originator_cache_guid + originator_client_item_id); |
| 113 } | 119 } |
| 114 | 120 |
| 115 } // namespace syncable | 121 } // namespace syncable |
| 116 } // namespace syncer | 122 } // namespace syncer |
| OLD | NEW |