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.
5 // Utility functions manipulating syncable::Entries, intended for use by the
8 #ifndef SYNC_ENGINE_SYNCER_UTIL_H_
9 #define SYNC_ENGINE_SYNCER_UTIL_H_
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"
24 } // namespace sync_pb
29 class BaseTransaction
;
30 class ModelNeutralWriteTransaction
;
31 } // namespace syncable
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
);
48 UpdateAttemptResponse
AttemptToUpdateEntry(
49 syncable::WriteTransaction
* const trans
,
50 syncable::MutableEntry
* const entry
,
51 Cryptographer
* cryptographer
);
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.
57 // The suffix parameter is the unique bookmark tag for the item being updated.
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
);
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
);
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
);
74 // Creates a new Entry iff no Entry exists with the given id.
75 void CreateNewEntry(syncable::ModelNeutralWriteTransaction
*trans
,
76 const syncable::Id
& id
);
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
);
83 VerifyCommitResult
ValidateCommitEntry(syncable::Entry
* entry
);
85 VerifyResult
VerifyNewEntry(const sync_pb::SyncEntity
& update
,
86 syncable::Entry
* target
,
89 // Assumes we have an existing entry; check here for updates that break
91 VerifyResult
VerifyUpdateConsistency(
92 syncable::ModelNeutralWriteTransaction
* trans
,
93 const sync_pb::SyncEntity
& update
,
95 const bool is_directory
,
97 syncable::ModelNeutralMutableEntry
* target
);
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
);
105 void MarkDeletedChildrenSynced(
106 syncable::Directory
* dir
,
107 syncable::BaseWriteTransaction
* trans
,
108 std::set
<syncable::Id
>* deleted_folders
);
110 } // namespace syncer
112 #endif // SYNC_ENGINE_SYNCER_UTIL_H_