| OLD | NEW |
| (Empty) |
| 1 // Copyright 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 #ifndef SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_ | |
| 6 #define SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_ | |
| 7 | |
| 8 #include <utility> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "sync/base/sync_export.h" | |
| 13 #include "sync/engine/syncer_command.h" | |
| 14 #include "sync/engine/syncer_util.h" | |
| 15 #include "sync/sessions/sync_session.h" | |
| 16 #include "sync/syncable/directory.h" | |
| 17 | |
| 18 using std::pair; | |
| 19 using std::vector; | |
| 20 | |
| 21 namespace syncer { | |
| 22 | |
| 23 namespace sessions { | |
| 24 class OrderedCommitSet; | |
| 25 } | |
| 26 | |
| 27 // A class that contains the code used to search the syncable::Directory for | |
| 28 // locally modified items that are ready to be committed to the server. | |
| 29 // | |
| 30 // See SyncerCommand documentation for more info. | |
| 31 class SYNC_EXPORT_PRIVATE GetCommitIdsCommand : public SyncerCommand { | |
| 32 friend class SyncerTest; | |
| 33 | |
| 34 public: | |
| 35 // The batch_size parameter is the maximum number of entries we are allowed | |
| 36 // to commit in a single batch. This value can be modified by the server. | |
| 37 // | |
| 38 // The ordered_commit_set parameter is an output parameter that will contain a | |
| 39 // set of items that are ready to commit. Its size shall not exceed the | |
| 40 // provided batch_size. This contents of this "set" will be ordered; see the | |
| 41 // comments in this class' implementation for details. | |
| 42 GetCommitIdsCommand(syncable::BaseTransaction* trans, | |
| 43 ModelTypeSet requested_types, | |
| 44 const size_t commit_batch_size, | |
| 45 sessions::OrderedCommitSet* ordered_commit_set); | |
| 46 virtual ~GetCommitIdsCommand(); | |
| 47 | |
| 48 // SyncerCommand implementation. | |
| 49 virtual SyncerError ExecuteImpl(sessions::SyncSession* session) OVERRIDE; | |
| 50 | |
| 51 // Builds a vector of IDs that should be committed. | |
| 52 void BuildCommitIds(syncable::BaseTransaction* write_transaction, | |
| 53 const ModelSafeRoutingInfo& routes, | |
| 54 const std::set<int64>& ready_unsynced_set); | |
| 55 | |
| 56 // Fill |ready_unsynced_set| with all entries from |unsynced_handles| that | |
| 57 // are ready to commit. | |
| 58 // An entry is not considered ready for commit if any are true: | |
| 59 // 1. It's in conflict. | |
| 60 // 2. It requires encryption (either the type is encrypted but a passphrase | |
| 61 // is missing from the cryptographer, or the entry itself wasn't properly | |
| 62 // encrypted). | |
| 63 // 3. It's type is currently throttled. | |
| 64 // 4. It's a delete but has not been committed. | |
| 65 void FilterUnreadyEntries( | |
| 66 syncable::BaseTransaction* trans, | |
| 67 ModelTypeSet throttled_types, | |
| 68 ModelTypeSet encrypted_types, | |
| 69 bool passphrase_missing, | |
| 70 const syncable::Directory::Metahandles& unsynced_handles, | |
| 71 std::set<int64>* ready_unsynced_set); | |
| 72 | |
| 73 private: | |
| 74 // Add all the uncommitted parents of |item| to |result| if they are ready to | |
| 75 // commit. Entries are added in root->child order and predecessor->successor | |
| 76 // order. | |
| 77 // Returns values: | |
| 78 // False: if a parent item was in conflict, and hence no child cannot be | |
| 79 // committed. | |
| 80 // True: if all parents were checked for commit readiness and were added to | |
| 81 // |result| as necessary. | |
| 82 bool AddUncommittedParentsAndTheirPredecessors( | |
| 83 syncable::BaseTransaction* trans, | |
| 84 const ModelSafeRoutingInfo& routes, | |
| 85 const std::set<int64>& ready_unsynced_set, | |
| 86 const syncable::Entry& item, | |
| 87 sessions::OrderedCommitSet* result) const; | |
| 88 | |
| 89 // OrderedCommitSet helpers for adding predecessors in order. | |
| 90 | |
| 91 // Adds |item| to |result| if it's ready for committing and was not already | |
| 92 // present. | |
| 93 // Prereq: |item| is unsynced. | |
| 94 void TryAddItem(const std::set<int64>& ready_unsynced_set, | |
| 95 const syncable::Entry& item, | |
| 96 sessions::OrderedCommitSet* result) const; | |
| 97 | |
| 98 // Adds |item| and all its unsynced predecessors to |result| as necessary. | |
| 99 // Entries that are unsynced but not ready to commit are not added to the | |
| 100 // list, though they do not stop the traversal. | |
| 101 void AddItemThenPredecessors(syncable::BaseTransaction* trans, | |
| 102 const std::set<int64>& ready_unsynced_set, | |
| 103 const syncable::Entry& item, | |
| 104 sessions::OrderedCommitSet* result) const; | |
| 105 | |
| 106 // Appends all commit ready predecessors of |item|, followed by |item| itself, | |
| 107 // to |commit_set|. | |
| 108 void AddPredecessorsThenItem(syncable::BaseTransaction* trans, | |
| 109 const ModelSafeRoutingInfo& routes, | |
| 110 const std::set<int64>& ready_unsynced_set, | |
| 111 const syncable::Entry& item, | |
| 112 sessions::OrderedCommitSet* commit_set) const; | |
| 113 | |
| 114 bool IsCommitBatchFull() const; | |
| 115 | |
| 116 void AddCreatesAndMoves(syncable::BaseTransaction* write_transaction, | |
| 117 const ModelSafeRoutingInfo& routes, | |
| 118 const std::set<int64>& ready_unsynced_set); | |
| 119 | |
| 120 void AddDeletes(syncable::BaseTransaction* write_transaction, | |
| 121 const std::set<int64>& ready_unsynced_set); | |
| 122 | |
| 123 // A pointer to a valid transaction not owned by this class. | |
| 124 syncable::BaseTransaction* trans_; | |
| 125 | |
| 126 // The set of types from which to draw commit IDs. | |
| 127 const ModelTypeSet requested_types_; | |
| 128 | |
| 129 // Input parameter; see constructor comment. | |
| 130 const size_t requested_commit_batch_size_; | |
| 131 | |
| 132 // Output parameter; see constructor comment. | |
| 133 sessions::OrderedCommitSet* commit_set_; | |
| 134 | |
| 135 DISALLOW_COPY_AND_ASSIGN(GetCommitIdsCommand); | |
| 136 }; | |
| 137 | |
| 138 } // namespace syncer | |
| 139 | |
| 140 #endif // SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_ | |
| OLD | NEW |