| 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 CHROME_BROWSER_SYNC_ENGINE_SYNCER_UTIL_H_ | |
| 9 #define CHROME_BROWSER_SYNC_ENGINE_SYNCER_UTIL_H_ | |
| 10 #pragma once | |
| 11 | |
| 12 #include <set> | |
| 13 #include <string> | |
| 14 #include <vector> | |
| 15 | |
| 16 #include "chrome/browser/sync/engine/syncer.h" | |
| 17 #include "chrome/browser/sync/engine/syncer_types.h" | |
| 18 #include "chrome/browser/sync/syncable/syncable.h" | |
| 19 #include "chrome/browser/sync/syncable/syncable_id.h" | |
| 20 | |
| 21 namespace browser_sync { | |
| 22 | |
| 23 class Cryptographer; | |
| 24 class SyncEntity; | |
| 25 | |
| 26 class SyncerUtil { | |
| 27 public: | |
| 28 static void ChangeEntryIDAndUpdateChildren( | |
| 29 syncable::WriteTransaction* trans, | |
| 30 syncable::MutableEntry* entry, | |
| 31 const syncable::Id& new_id, | |
| 32 syncable::Directory::ChildHandles* children); | |
| 33 | |
| 34 // Returns the number of unsynced entries. | |
| 35 static int GetUnsyncedEntries(syncable::BaseTransaction* trans, | |
| 36 std::vector<int64> *handles); | |
| 37 | |
| 38 static void ChangeEntryIDAndUpdateChildren(syncable::WriteTransaction* trans, | |
| 39 syncable::MutableEntry* entry, | |
| 40 const syncable::Id& new_id); | |
| 41 | |
| 42 // If the server sent down a client-tagged entry, or an entry whose | |
| 43 // commit response was lost, it is necessary to update a local entry | |
| 44 // with an ID that doesn't match the ID of the update. Here, we | |
| 45 // find the ID of such an entry, if it exists. This function may | |
| 46 // determine that |server_entry| should be dropped; if so, it returns | |
| 47 // the null ID -- callers must handle this case. When update application | |
| 48 // should proceed normally with a new local entry, this function will | |
| 49 // return server_entry.id(); the caller must create an entry with that | |
| 50 // ID. This function does not alter the database. | |
| 51 static syncable::Id FindLocalIdToUpdate( | |
| 52 syncable::BaseTransaction* trans, | |
| 53 const SyncEntity& server_entry); | |
| 54 | |
| 55 static UpdateAttemptResponse AttemptToUpdateEntry( | |
| 56 syncable::WriteTransaction* const trans, | |
| 57 syncable::MutableEntry* const entry, | |
| 58 ConflictResolver* resolver, | |
| 59 Cryptographer* cryptographer); | |
| 60 | |
| 61 // Pass in name to avoid redundant UTF8 conversion. | |
| 62 static void UpdateServerFieldsFromUpdate( | |
| 63 syncable::MutableEntry* local_entry, | |
| 64 const SyncEntity& server_entry, | |
| 65 const std::string& name); | |
| 66 | |
| 67 // Creates a new Entry iff no Entry exists with the given id. | |
| 68 static void CreateNewEntry(syncable::WriteTransaction *trans, | |
| 69 const syncable::Id& id); | |
| 70 | |
| 71 static void SplitServerInformationIntoNewEntry( | |
| 72 syncable::WriteTransaction* trans, | |
| 73 syncable::MutableEntry* entry); | |
| 74 | |
| 75 // This function is called on an entry when we can update the user-facing data | |
| 76 // from the server data. | |
| 77 static void UpdateLocalDataFromServerData(syncable::WriteTransaction* trans, | |
| 78 syncable::MutableEntry* entry); | |
| 79 | |
| 80 static VerifyCommitResult ValidateCommitEntry(syncable::Entry* entry); | |
| 81 | |
| 82 static VerifyResult VerifyNewEntry(const SyncEntity& update, | |
| 83 syncable::Entry* target, | |
| 84 const bool deleted); | |
| 85 | |
| 86 // Assumes we have an existing entry; check here for updates that break | |
| 87 // consistency rules. | |
| 88 static VerifyResult VerifyUpdateConsistency(syncable::WriteTransaction* trans, | |
| 89 const SyncEntity& update, | |
| 90 syncable::MutableEntry* target, | |
| 91 const bool deleted, | |
| 92 const bool is_directory, | |
| 93 syncable::ModelType model_type); | |
| 94 | |
| 95 // Assumes we have an existing entry; verify an update that seems to be | |
| 96 // expressing an 'undelete' | |
| 97 static VerifyResult VerifyUndelete(syncable::WriteTransaction* trans, | |
| 98 const SyncEntity& update, | |
| 99 syncable::MutableEntry* target); | |
| 100 | |
| 101 // Append |item|, followed by a chain of its predecessors selected by | |
| 102 // |inclusion_filter|, to the |commit_ids| vector and tag them as included by | |
| 103 // storing in the set |inserted_items|. |inclusion_filter| (typically one of | |
| 104 // IS_UNAPPLIED_UPDATE or IS_UNSYNCED) selects which type of predecessors to | |
| 105 // include. Returns true if |item| was added, and false if it was already in | |
| 106 // the list. | |
| 107 // | |
| 108 // Use AddPredecessorsThenItem instead of this method if you want the | |
| 109 // item to be the last, rather than first, item appended. | |
| 110 static bool AddItemThenPredecessors( | |
| 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); | |
| 116 | |
| 117 // Exactly like AddItemThenPredecessors, except items are appended in the | |
| 118 // reverse (and generally more useful) order: a chain of predecessors from | |
| 119 // far to near, and finally the item. | |
| 120 static void AddPredecessorsThenItem( | |
| 121 syncable::BaseTransaction* trans, | |
| 122 syncable::Entry* item, | |
| 123 syncable::IndexedBitField inclusion_filter, | |
| 124 syncable::MetahandleSet* inserted_items, | |
| 125 std::vector<syncable::Id>* commit_ids); | |
| 126 | |
| 127 static void MarkDeletedChildrenSynced( | |
| 128 syncable::Directory* dir, | |
| 129 std::set<syncable::Id>* deleted_folders); | |
| 130 | |
| 131 private: | |
| 132 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncerUtil); | |
| 133 }; | |
| 134 | |
| 135 } // namespace browser_sync | |
| 136 | |
| 137 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_UTIL_H_ | |
| OLD | NEW |