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 3 // found in the LICENSE file. 4 // 5 // Utility functions manipulating syncable::Entries, intended for use by the 6 // syncer. 7 8 #ifndef SYNC_ENGINE_SYNCER_UTIL_H_ 9 #define SYNC_ENGINE_SYNCER_UTIL_H_ 10 11 #include <set> 12 #include <string> 13 #include <vector> 14 15 #include "sync/engine/syncer.h" 16 #include "sync/engine/syncer_types.h" 17 #include "sync/syncable/entry_kernel.h" 18 #include "sync/syncable/metahandle_set.h" 19 #include "sync/syncable/mutable_entry.h" 20 #include "sync/syncable/syncable_id.h" 21 22 namespace sync_pb { 23 class SyncEntity; 24 } // namespace sync_pb 25 26 namespace syncer { 27 28 namespace syncable { 29 class BaseTransaction; 30 class ModelNeutralWriteTransaction; 31 } // namespace syncable 32 33 class Cryptographer; 34 35 // If the server sent down a client-tagged entry, or an entry whose 36 // commit response was lost, it is necessary to update a local entry 37 // with an ID that doesn't match the ID of the update. Here, we 38 // find the ID of such an entry, if it exists. This function may 39 // determine that |server_entry| should be dropped; if so, it returns 40 // the null ID -- callers must handle this case. When update application 41 // should proceed normally with a new local entry, this function will 42 // return server_entry.id(); the caller must create an entry with that 43 // ID. This function does not alter the database. 44 syncable::Id FindLocalIdToUpdate( 45 syncable::BaseTransaction* trans, 46 const sync_pb::SyncEntity& server_entry); 47 48 UpdateAttemptResponse AttemptToUpdateEntry( 49 syncable::WriteTransaction* const trans, 50 syncable::MutableEntry* const entry, 51 Cryptographer* cryptographer); 52 53 // Returns the most accurate position information available in this update. It 54 // prefers to use the unique_position() field, but will fall back to using the 55 // int64-based position_in_parent if necessary. 56 // 57 // The suffix parameter is the unique bookmark tag for the item being updated. 58 // 59 // Will return an invalid position if no valid position can be constructed, or 60 // if this type does not support positioning. 61 UniquePosition GetUpdatePosition(const sync_pb::SyncEntity& update, 62 const std::string& suffix); 63 64 // Fetch the cache_guid and item_id-based unique bookmark tag from an update. 65 // Will return an empty string if someting unexpected happens. 66 std::string GetUniqueBookmarkTagFromUpdate(const sync_pb::SyncEntity& update); 67 68 // Pass in name to avoid redundant UTF8 conversion. 69 void UpdateServerFieldsFromUpdate( 70 syncable::ModelNeutralMutableEntry* local_entry, 71 const sync_pb::SyncEntity& server_entry, 72 const std::string& name); 73 74 // Creates a new Entry iff no Entry exists with the given id. 75 void CreateNewEntry(syncable::ModelNeutralWriteTransaction *trans, 76 const syncable::Id& id); 77 78 // This function is called on an entry when we can update the user-facing data 79 // from the server data. 80 void UpdateLocalDataFromServerData(syncable::WriteTransaction* trans, 81 syncable::MutableEntry* entry); 82 83 VerifyCommitResult ValidateCommitEntry(syncable::Entry* entry); 84 85 VerifyResult VerifyNewEntry(const sync_pb::SyncEntity& update, 86 syncable::Entry* target, 87 const bool deleted); 88 89 // Assumes we have an existing entry; check here for updates that break 90 // consistency rules. 91 VerifyResult VerifyUpdateConsistency( 92 syncable::ModelNeutralWriteTransaction* trans, 93 const sync_pb::SyncEntity& update, 94 const bool deleted, 95 const bool is_directory, 96 ModelType model_type, 97 syncable::ModelNeutralMutableEntry* target); 98 99 // Assumes we have an existing entry; verify an update that seems to be 100 // expressing an 'undelete' 101 VerifyResult VerifyUndelete(syncable::ModelNeutralWriteTransaction* trans, 102 const sync_pb::SyncEntity& update, 103 syncable::ModelNeutralMutableEntry* target); 104 105 void MarkDeletedChildrenSynced( 106 syncable::Directory* dir, 107 syncable::BaseWriteTransaction* trans, 108 std::set<syncable::Id>* deleted_folders); 109 110 } // namespace syncer 111 112 #endif // SYNC_ENGINE_SYNCER_UTIL_H_ 113