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