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()); |
| 32 DCHECK(!new_parent_id.IsNull()); |
31 if (entry_id.IsRoot()) | 33 if (entry_id.IsRoot()) |
32 return false; | 34 return false; |
33 // we have to ensure that the entry is not an ancestor of the new parent. | 35 // we have to ensure that the entry is not an ancestor of the new parent. |
34 Id ancestor_id = new_parent_id; | 36 Id ancestor_id = new_parent_id; |
35 while (!ancestor_id.IsRoot()) { | 37 while (!ancestor_id.IsRoot()) { |
36 if (entry_id == ancestor_id) | 38 if (entry_id == ancestor_id) |
37 return false; | 39 return false; |
38 Entry new_parent(trans, GET_BY_ID, ancestor_id); | 40 Entry new_parent(trans, GET_BY_ID, ancestor_id); |
39 if (!SyncAssert(new_parent.good(), | 41 if (!SyncAssert(new_parent.good(), |
40 FROM_HERE, | 42 FROM_HERE, |
(...skipping 18 matching lines...) Expand all Loading... |
59 << *entry << "\n\n" << old_entry; | 61 << *entry << "\n\n" << old_entry; |
60 } | 62 } |
61 if (entry->GetIsDir()) { | 63 if (entry->GetIsDir()) { |
62 // Get all child entries of the old id. | 64 // Get all child entries of the old id. |
63 Directory::Metahandles children; | 65 Directory::Metahandles children; |
64 trans->directory()->GetChildHandlesById(trans, old_id, &children); | 66 trans->directory()->GetChildHandlesById(trans, old_id, &children); |
65 Directory::Metahandles::iterator i = children.begin(); | 67 Directory::Metahandles::iterator i = children.begin(); |
66 while (i != children.end()) { | 68 while (i != children.end()) { |
67 ModelNeutralMutableEntry child_entry(trans, GET_BY_HANDLE, *i++); | 69 ModelNeutralMutableEntry child_entry(trans, GET_BY_HANDLE, *i++); |
68 CHECK(child_entry.good()); | 70 CHECK(child_entry.good()); |
69 // Use the unchecked setter here to avoid touching the child's | 71 // Change the parent ID of the entry unless it was unset (implicit) |
70 // UNIQUE_POSITION field. In this case, UNIQUE_POSITION among the | 72 if (!child_entry.GetParentId().IsNull()) { |
71 // children will be valid after the loop, since we update all the children | 73 // Use the unchecked setter here to avoid touching the child's |
72 // at once. | 74 // UNIQUE_POSITION field. In this case, UNIQUE_POSITION among the |
73 child_entry.PutParentIdPropertyOnly(new_id); | 75 // children will be valid after the loop, since we update all the |
| 76 // children at once. |
| 77 child_entry.PutParentIdPropertyOnly(new_id); |
| 78 } |
74 } | 79 } |
75 } | 80 } |
76 } | 81 } |
77 | 82 |
78 // Function to handle runtime failures on syncable code. Rather than crashing, | 83 // Function to handle runtime failures on syncable code. Rather than crashing, |
79 // if the |condition| is false the following will happen: | 84 // if the |condition| is false the following will happen: |
80 // 1. Sets unrecoverable error on transaction. | 85 // 1. Sets unrecoverable error on transaction. |
81 // 2. Returns false. | 86 // 2. Returns false. |
82 bool SyncAssert(bool condition, | 87 bool SyncAssert(bool condition, |
83 const tracked_objects::Location& location, | 88 const tracked_objects::Location& location, |
(...skipping 23 matching lines...) Expand all Loading... |
107 | 112 |
108 std::string GenerateSyncableBookmarkHash( | 113 std::string GenerateSyncableBookmarkHash( |
109 const std::string& originator_cache_guid, | 114 const std::string& originator_cache_guid, |
110 const std::string& originator_client_item_id) { | 115 const std::string& originator_client_item_id) { |
111 return syncable::GenerateSyncableHash( | 116 return syncable::GenerateSyncableHash( |
112 BOOKMARKS, originator_cache_guid + originator_client_item_id); | 117 BOOKMARKS, originator_cache_guid + originator_client_item_id); |
113 } | 118 } |
114 | 119 |
115 } // namespace syncable | 120 } // namespace syncable |
116 } // namespace syncer | 121 } // namespace syncer |
OLD | NEW |