| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Utility functions manipulating syncable::Entries, intended for use by the | 5 // Utility functions manipulating syncable::Entries, intended for use by the |
| 6 // syncer. | 6 // syncer. |
| 7 | 7 |
| 8 #ifndef SYNC_ENGINE_SYNCER_UTIL_H_ | 8 #ifndef SYNC_ENGINE_SYNCER_UTIL_H_ |
| 9 #define SYNC_ENGINE_SYNCER_UTIL_H_ | 9 #define SYNC_ENGINE_SYNCER_UTIL_H_ |
| 10 #pragma once | 10 #pragma once |
| 11 | 11 |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "sync/engine/syncer.h" | 16 #include "sync/engine/syncer.h" |
| 17 #include "sync/engine/syncer_types.h" | 17 #include "sync/engine/syncer_types.h" |
| 18 #include "sync/syncable/entry_kernel.h" | 18 #include "sync/syncable/entry_kernel.h" |
| 19 #include "sync/syncable/metahandle_set.h" | 19 #include "sync/syncable/metahandle_set.h" |
| 20 #include "sync/syncable/syncable_id.h" | 20 #include "sync/syncable/syncable_id.h" |
| 21 | 21 |
| 22 namespace sync_pb { |
| 23 class SyncEntity; |
| 24 } |
| 25 |
| 22 namespace syncer { | 26 namespace syncer { |
| 23 | |
| 24 class Cryptographer; | 27 class Cryptographer; |
| 25 class SyncEntity; | |
| 26 | 28 |
| 27 // If the server sent down a client-tagged entry, or an entry whose | 29 // If the server sent down a client-tagged entry, or an entry whose |
| 28 // commit response was lost, it is necessary to update a local entry | 30 // commit response was lost, it is necessary to update a local entry |
| 29 // with an ID that doesn't match the ID of the update. Here, we | 31 // with an ID that doesn't match the ID of the update. Here, we |
| 30 // find the ID of such an entry, if it exists. This function may | 32 // find the ID of such an entry, if it exists. This function may |
| 31 // determine that |server_entry| should be dropped; if so, it returns | 33 // determine that |server_entry| should be dropped; if so, it returns |
| 32 // the null ID -- callers must handle this case. When update application | 34 // the null ID -- callers must handle this case. When update application |
| 33 // should proceed normally with a new local entry, this function will | 35 // should proceed normally with a new local entry, this function will |
| 34 // return server_entry.id(); the caller must create an entry with that | 36 // return server_entry.id(); the caller must create an entry with that |
| 35 // ID. This function does not alter the database. | 37 // ID. This function does not alter the database. |
| 36 syncable::Id FindLocalIdToUpdate( | 38 syncable::Id FindLocalIdToUpdate( |
| 37 syncable::BaseTransaction* trans, | 39 syncable::BaseTransaction* trans, |
| 38 const SyncEntity& server_entry); | 40 const sync_pb::SyncEntity& server_entry); |
| 39 | 41 |
| 40 UpdateAttemptResponse AttemptToUpdateEntry( | 42 UpdateAttemptResponse AttemptToUpdateEntry( |
| 41 syncable::WriteTransaction* const trans, | 43 syncable::WriteTransaction* const trans, |
| 42 syncable::MutableEntry* const entry, | 44 syncable::MutableEntry* const entry, |
| 43 ConflictResolver* resolver, | 45 ConflictResolver* resolver, |
| 44 Cryptographer* cryptographer); | 46 Cryptographer* cryptographer); |
| 45 | 47 |
| 46 // Pass in name to avoid redundant UTF8 conversion. | 48 // Pass in name to avoid redundant UTF8 conversion. |
| 47 void UpdateServerFieldsFromUpdate( | 49 void UpdateServerFieldsFromUpdate( |
| 48 syncable::MutableEntry* local_entry, | 50 syncable::MutableEntry* local_entry, |
| 49 const SyncEntity& server_entry, | 51 const sync_pb::SyncEntity& server_entry, |
| 50 const std::string& name); | 52 const std::string& name); |
| 51 | 53 |
| 52 // Creates a new Entry iff no Entry exists with the given id. | 54 // Creates a new Entry iff no Entry exists with the given id. |
| 53 void CreateNewEntry(syncable::WriteTransaction *trans, | 55 void CreateNewEntry(syncable::WriteTransaction *trans, |
| 54 const syncable::Id& id); | 56 const syncable::Id& id); |
| 55 | 57 |
| 56 void SplitServerInformationIntoNewEntry( | 58 void SplitServerInformationIntoNewEntry( |
| 57 syncable::WriteTransaction* trans, | 59 syncable::WriteTransaction* trans, |
| 58 syncable::MutableEntry* entry); | 60 syncable::MutableEntry* entry); |
| 59 | 61 |
| 60 // This function is called on an entry when we can update the user-facing data | 62 // This function is called on an entry when we can update the user-facing data |
| 61 // from the server data. | 63 // from the server data. |
| 62 void UpdateLocalDataFromServerData(syncable::WriteTransaction* trans, | 64 void UpdateLocalDataFromServerData(syncable::WriteTransaction* trans, |
| 63 syncable::MutableEntry* entry); | 65 syncable::MutableEntry* entry); |
| 64 | 66 |
| 65 VerifyCommitResult ValidateCommitEntry(syncable::Entry* entry); | 67 VerifyCommitResult ValidateCommitEntry(syncable::Entry* entry); |
| 66 | 68 |
| 67 VerifyResult VerifyNewEntry(const SyncEntity& update, | 69 VerifyResult VerifyNewEntry(const sync_pb::SyncEntity& update, |
| 68 syncable::Entry* target, | 70 syncable::Entry* target, |
| 69 const bool deleted); | 71 const bool deleted); |
| 70 | 72 |
| 71 // Assumes we have an existing entry; check here for updates that break | 73 // Assumes we have an existing entry; check here for updates that break |
| 72 // consistency rules. | 74 // consistency rules. |
| 73 VerifyResult VerifyUpdateConsistency(syncable::WriteTransaction* trans, | 75 VerifyResult VerifyUpdateConsistency(syncable::WriteTransaction* trans, |
| 74 const SyncEntity& update, | 76 const sync_pb::SyncEntity& update, |
| 75 syncable::MutableEntry* target, | 77 syncable::MutableEntry* target, |
| 76 const bool deleted, | 78 const bool deleted, |
| 77 const bool is_directory, | 79 const bool is_directory, |
| 78 syncer::ModelType model_type); | 80 syncer::ModelType model_type); |
| 79 | 81 |
| 80 // Assumes we have an existing entry; verify an update that seems to be | 82 // Assumes we have an existing entry; verify an update that seems to be |
| 81 // expressing an 'undelete' | 83 // expressing an 'undelete' |
| 82 VerifyResult VerifyUndelete(syncable::WriteTransaction* trans, | 84 VerifyResult VerifyUndelete(syncable::WriteTransaction* trans, |
| 83 const SyncEntity& update, | 85 const sync_pb::SyncEntity& update, |
| 84 syncable::MutableEntry* target); | 86 syncable::MutableEntry* target); |
| 85 | 87 |
| 86 // Append |item|, followed by a chain of its predecessors selected by | 88 // Append |item|, followed by a chain of its predecessors selected by |
| 87 // |inclusion_filter|, to the |commit_ids| vector and tag them as included by | 89 // |inclusion_filter|, to the |commit_ids| vector and tag them as included by |
| 88 // storing in the set |inserted_items|. |inclusion_filter| (typically one of | 90 // storing in the set |inserted_items|. |inclusion_filter| (typically one of |
| 89 // IS_UNAPPLIED_UPDATE or IS_UNSYNCED) selects which type of predecessors to | 91 // IS_UNAPPLIED_UPDATE or IS_UNSYNCED) selects which type of predecessors to |
| 90 // include. Returns true if |item| was added, and false if it was already in | 92 // include. Returns true if |item| was added, and false if it was already in |
| 91 // the list. | 93 // the list. |
| 92 // | 94 // |
| 93 // Use AddPredecessorsThenItem instead of this method if you want the | 95 // Use AddPredecessorsThenItem instead of this method if you want the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 109 syncable::MetahandleSet* inserted_items, | 111 syncable::MetahandleSet* inserted_items, |
| 110 std::vector<syncable::Id>* commit_ids); | 112 std::vector<syncable::Id>* commit_ids); |
| 111 | 113 |
| 112 void MarkDeletedChildrenSynced( | 114 void MarkDeletedChildrenSynced( |
| 113 syncable::Directory* dir, | 115 syncable::Directory* dir, |
| 114 std::set<syncable::Id>* deleted_folders); | 116 std::set<syncable::Id>* deleted_folders); |
| 115 | 117 |
| 116 } // namespace syncer | 118 } // namespace syncer |
| 117 | 119 |
| 118 #endif // SYNC_ENGINE_SYNCER_UTIL_H_ | 120 #endif // SYNC_ENGINE_SYNCER_UTIL_H_ |
| OLD | NEW |