syncer_util.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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/syncable_id.h" 20 21namespace sync_pb { 22class SyncEntity; 23} // namespace sync_pb 24 25namespace syncer { 26 27namespace syncable { 28class BaseTransaction; 29} // namespace syncable 30 31class Cryptographer; 32 33// If the server sent down a client-tagged entry, or an entry whose 34// commit response was lost, it is necessary to update a local entry 35// with an ID that doesn't match the ID of the update. Here, we 36// find the ID of such an entry, if it exists. This function may 37// determine that |server_entry| should be dropped; if so, it returns 38// the null ID -- callers must handle this case. When update application 39// should proceed normally with a new local entry, this function will 40// return server_entry.id(); the caller must create an entry with that 41// ID. This function does not alter the database. 42syncable::Id FindLocalIdToUpdate( 43 syncable::BaseTransaction* trans, 44 const sync_pb::SyncEntity& server_entry); 45 46UpdateAttemptResponse AttemptToUpdateEntry( 47 syncable::WriteTransaction* const trans, 48 syncable::MutableEntry* const entry, 49 Cryptographer* cryptographer); 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. 59UniquePosition 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. 64std::string GetUniqueBookmarkTagFromUpdate(const sync_pb::SyncEntity& update); 65 66// Pass in name to avoid redundant UTF8 conversion. 67void UpdateServerFieldsFromUpdate( 68 syncable::MutableEntry* local_entry, 69 const sync_pb::SyncEntity& server_entry, 70 const std::string& name); 71 72// Creates a new Entry iff no Entry exists with the given id. 73void CreateNewEntry(syncable::WriteTransaction *trans, 74 const syncable::Id& id); 75 76// This function is called on an entry when we can update the user-facing data 77// from the server data. 78void UpdateLocalDataFromServerData(syncable::WriteTransaction* trans, 79 syncable::MutableEntry* entry); 80 81VerifyCommitResult ValidateCommitEntry(syncable::Entry* entry); 82 83VerifyResult VerifyNewEntry(const sync_pb::SyncEntity& update, 84 syncable::Entry* target, 85 const bool deleted); 86 87// Assumes we have an existing entry; check here for updates that break 88// consistency rules. 89VerifyResult VerifyUpdateConsistency(syncable::WriteTransaction* trans, 90 const sync_pb::SyncEntity& update, 91 syncable::MutableEntry* target, 92 const bool deleted, 93 const bool is_directory, 94 ModelType model_type); 95 96// Assumes we have an existing entry; verify an update that seems to be 97// expressing an 'undelete' 98VerifyResult VerifyUndelete(syncable::WriteTransaction* trans, 99 const sync_pb::SyncEntity& update, 100 syncable::MutableEntry* target); 101 102void MarkDeletedChildrenSynced( 103 syncable::Directory* dir, 104 std::set<syncable::Id>* deleted_folders); 105 106} // namespace syncer 107 108#endif // SYNC_ENGINE_SYNCER_UTIL_H_ 109