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