| OLD | NEW |
| 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 // Utility functions manipulating syncable::Entries, intended for use by the | 5 // Utility functions manipulating syncable::Entries, intended for use by the |
| 6 // syncer. | 6 // syncer. |
| 7 | 7 |
| 8 #ifndef SYNC_ENGINE_SYNCER_UTIL_H_ | 8 #ifndef SYNC_ENGINE_SYNCER_UTIL_H_ |
| 9 #define SYNC_ENGINE_SYNCER_UTIL_H_ | 9 #define SYNC_ENGINE_SYNCER_UTIL_H_ |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // ID. This function does not alter the database. | 41 // ID. This function does not alter the database. |
| 42 syncable::Id FindLocalIdToUpdate( | 42 syncable::Id FindLocalIdToUpdate( |
| 43 syncable::BaseTransaction* trans, | 43 syncable::BaseTransaction* trans, |
| 44 const sync_pb::SyncEntity& server_entry); | 44 const sync_pb::SyncEntity& server_entry); |
| 45 | 45 |
| 46 UpdateAttemptResponse AttemptToUpdateEntry( | 46 UpdateAttemptResponse AttemptToUpdateEntry( |
| 47 syncable::WriteTransaction* const trans, | 47 syncable::WriteTransaction* const trans, |
| 48 syncable::MutableEntry* const entry, | 48 syncable::MutableEntry* const entry, |
| 49 Cryptographer* cryptographer); | 49 Cryptographer* cryptographer); |
| 50 | 50 |
| 51 // Returns the most accurate position information available in this update. It |
| 52 // prefers to use the unique_position() field, but will fall back to using the |
| 53 // int64-based position_in_parent if necessary. |
| 54 // |
| 55 // The suffix parameter is the unique bookmark tag for the item being updated. |
| 56 // |
| 57 // Will return an invalid position if no valid position can be constructed, or |
| 58 // if this type does not support positioning. |
| 59 UniquePosition GetUpdatePosition(const sync_pb::SyncEntity& update, |
| 60 const std::string& suffix); |
| 61 |
| 62 // Fetch the cache_guid and item_id-based unique bookmark tag from an update. |
| 63 // Will return an empty string if someting unexpected happens. |
| 64 std::string GetUniqueBookmarkTagFromUpdate(const sync_pb::SyncEntity& update); |
| 65 |
| 51 // Pass in name to avoid redundant UTF8 conversion. | 66 // Pass in name to avoid redundant UTF8 conversion. |
| 52 void UpdateServerFieldsFromUpdate( | 67 void UpdateServerFieldsFromUpdate( |
| 53 syncable::MutableEntry* local_entry, | 68 syncable::MutableEntry* local_entry, |
| 54 const sync_pb::SyncEntity& server_entry, | 69 const sync_pb::SyncEntity& server_entry, |
| 55 const std::string& name); | 70 const std::string& name); |
| 56 | 71 |
| 57 // Creates a new Entry iff no Entry exists with the given id. | 72 // Creates a new Entry iff no Entry exists with the given id. |
| 58 void CreateNewEntry(syncable::WriteTransaction *trans, | 73 void CreateNewEntry(syncable::WriteTransaction *trans, |
| 59 const syncable::Id& id); | 74 const syncable::Id& id); |
| 60 | 75 |
| 61 void SplitServerInformationIntoNewEntry( | |
| 62 syncable::WriteTransaction* trans, | |
| 63 syncable::MutableEntry* entry); | |
| 64 | |
| 65 // This function is called on an entry when we can update the user-facing data | 76 // This function is called on an entry when we can update the user-facing data |
| 66 // from the server data. | 77 // from the server data. |
| 67 void UpdateLocalDataFromServerData(syncable::WriteTransaction* trans, | 78 void UpdateLocalDataFromServerData(syncable::WriteTransaction* trans, |
| 68 syncable::MutableEntry* entry); | 79 syncable::MutableEntry* entry); |
| 69 | 80 |
| 70 VerifyCommitResult ValidateCommitEntry(syncable::Entry* entry); | 81 VerifyCommitResult ValidateCommitEntry(syncable::Entry* entry); |
| 71 | 82 |
| 72 VerifyResult VerifyNewEntry(const sync_pb::SyncEntity& update, | 83 VerifyResult VerifyNewEntry(const sync_pb::SyncEntity& update, |
| 73 syncable::Entry* target, | 84 syncable::Entry* target, |
| 74 const bool deleted); | 85 const bool deleted); |
| 75 | 86 |
| 76 // Assumes we have an existing entry; check here for updates that break | 87 // Assumes we have an existing entry; check here for updates that break |
| 77 // consistency rules. | 88 // consistency rules. |
| 78 VerifyResult VerifyUpdateConsistency(syncable::WriteTransaction* trans, | 89 VerifyResult VerifyUpdateConsistency(syncable::WriteTransaction* trans, |
| 79 const sync_pb::SyncEntity& update, | 90 const sync_pb::SyncEntity& update, |
| 80 syncable::MutableEntry* target, | 91 syncable::MutableEntry* target, |
| 81 const bool deleted, | 92 const bool deleted, |
| 82 const bool is_directory, | 93 const bool is_directory, |
| 83 ModelType model_type); | 94 ModelType model_type); |
| 84 | 95 |
| 85 // Assumes we have an existing entry; verify an update that seems to be | 96 // Assumes we have an existing entry; verify an update that seems to be |
| 86 // expressing an 'undelete' | 97 // expressing an 'undelete' |
| 87 VerifyResult VerifyUndelete(syncable::WriteTransaction* trans, | 98 VerifyResult VerifyUndelete(syncable::WriteTransaction* trans, |
| 88 const sync_pb::SyncEntity& update, | 99 const sync_pb::SyncEntity& update, |
| 89 syncable::MutableEntry* target); | 100 syncable::MutableEntry* target); |
| 90 | 101 |
| 91 // Append |item|, followed by a chain of its predecessors selected by | |
| 92 // |inclusion_filter|, to the |commit_ids| vector and tag them as included by | |
| 93 // storing in the set |inserted_items|. |inclusion_filter| (typically one of | |
| 94 // IS_UNAPPLIED_UPDATE or IS_UNSYNCED) selects which type of predecessors to | |
| 95 // include. Returns true if |item| was added, and false if it was already in | |
| 96 // the list. | |
| 97 // | |
| 98 // Use AddPredecessorsThenItem instead of this method if you want the | |
| 99 // item to be the last, rather than first, item appended. | |
| 100 bool AddItemThenPredecessors( | |
| 101 syncable::BaseTransaction* trans, | |
| 102 syncable::Entry* item, | |
| 103 syncable::IndexedBitField inclusion_filter, | |
| 104 syncable::MetahandleSet* inserted_items, | |
| 105 std::vector<syncable::Id>* commit_ids); | |
| 106 | |
| 107 // Exactly like AddItemThenPredecessors, except items are appended in the | |
| 108 // reverse (and generally more useful) order: a chain of predecessors from | |
| 109 // far to near, and finally the item. | |
| 110 void AddPredecessorsThenItem( | |
| 111 syncable::BaseTransaction* trans, | |
| 112 syncable::Entry* item, | |
| 113 syncable::IndexedBitField inclusion_filter, | |
| 114 syncable::MetahandleSet* inserted_items, | |
| 115 std::vector<syncable::Id>* commit_ids); | |
| 116 | |
| 117 void MarkDeletedChildrenSynced( | 102 void MarkDeletedChildrenSynced( |
| 118 syncable::Directory* dir, | 103 syncable::Directory* dir, |
| 119 std::set<syncable::Id>* deleted_folders); | 104 std::set<syncable::Id>* deleted_folders); |
| 120 | 105 |
| 121 } // namespace syncer | 106 } // namespace syncer |
| 122 | 107 |
| 123 #endif // SYNC_ENGINE_SYNCER_UTIL_H_ | 108 #endif // SYNC_ENGINE_SYNCER_UTIL_H_ |
| OLD | NEW |