More bring up of ui code on iOS.
[chromium-blink-merge.git] / sync / engine / syncer_util.h
blob108622cacf1db97ffef3ddea86c9730e3a1e1aac
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.
8 #ifndef SYNC_ENGINE_SYNCER_UTIL_H_
9 #define SYNC_ENGINE_SYNCER_UTIL_H_
11 #include <set>
12 #include <string>
13 #include <vector>
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"
21 namespace sync_pb {
22 class SyncEntity;
23 } // namespace sync_pb
25 namespace syncer {
27 namespace syncable {
28 class BaseTransaction;
29 } // namespace syncable
31 class Cryptographer;
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.
42 syncable::Id FindLocalIdToUpdate(
43 syncable::BaseTransaction* trans,
44 const sync_pb::SyncEntity& server_entry);
46 UpdateAttemptResponse AttemptToUpdateEntry(
47 syncable::WriteTransaction* const trans,
48 syncable::MutableEntry* const entry,
49 Cryptographer* cryptographer);
51 // Pass in name to avoid redundant UTF8 conversion.
52 void UpdateServerFieldsFromUpdate(
53 syncable::MutableEntry* local_entry,
54 const sync_pb::SyncEntity& server_entry,
55 const std::string& name);
57 // Creates a new Entry iff no Entry exists with the given id.
58 void CreateNewEntry(syncable::WriteTransaction *trans,
59 const syncable::Id& id);
61 void SplitServerInformationIntoNewEntry(
62 syncable::WriteTransaction* trans,
63 syncable::MutableEntry* entry);
65 // This function is called on an entry when we can update the user-facing data
66 // from the server data.
67 void UpdateLocalDataFromServerData(syncable::WriteTransaction* trans,
68 syncable::MutableEntry* entry);
70 VerifyCommitResult ValidateCommitEntry(syncable::Entry* entry);
72 VerifyResult VerifyNewEntry(const sync_pb::SyncEntity& update,
73 syncable::Entry* target,
74 const bool deleted);
76 // Assumes we have an existing entry; check here for updates that break
77 // consistency rules.
78 VerifyResult VerifyUpdateConsistency(syncable::WriteTransaction* trans,
79 const sync_pb::SyncEntity& update,
80 syncable::MutableEntry* target,
81 const bool deleted,
82 const bool is_directory,
83 ModelType model_type);
85 // Assumes we have an existing entry; verify an update that seems to be
86 // expressing an 'undelete'
87 VerifyResult VerifyUndelete(syncable::WriteTransaction* trans,
88 const sync_pb::SyncEntity& update,
89 syncable::MutableEntry* target);
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.
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);
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);
117 void MarkDeletedChildrenSynced(
118 syncable::Directory* dir,
119 std::set<syncable::Id>* deleted_folders);
121 } // namespace syncer
123 #endif // SYNC_ENGINE_SYNCER_UTIL_H_