| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_ | 5 #ifndef CHROME_BROWSER_SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_ |
| 6 #define CHROME_BROWSER_SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_ | 6 #define CHROME_BROWSER_SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 friend class SyncerTest; | 24 friend class SyncerTest; |
| 25 | 25 |
| 26 public: | 26 public: |
| 27 explicit GetCommitIdsCommand(int commit_batch_size); | 27 explicit GetCommitIdsCommand(int commit_batch_size); |
| 28 virtual ~GetCommitIdsCommand(); | 28 virtual ~GetCommitIdsCommand(); |
| 29 | 29 |
| 30 // SyncerCommand implementation. | 30 // SyncerCommand implementation. |
| 31 virtual void ExecuteImpl(sessions::SyncSession* session) OVERRIDE; | 31 virtual void ExecuteImpl(sessions::SyncSession* session) OVERRIDE; |
| 32 | 32 |
| 33 // Builds a vector of IDs that should be committed. | 33 // Builds a vector of IDs that should be committed. |
| 34 void BuildCommitIds(const vector<int64>& unsynced_handles, | 34 void BuildCommitIds(syncable::WriteTransaction* write_transaction, |
| 35 syncable::WriteTransaction* write_transaction, | |
| 36 const ModelSafeRoutingInfo& routes, | 35 const ModelSafeRoutingInfo& routes, |
| 37 syncable::ModelTypeSet throttled_types); | 36 const std::set<int64>& ready_unsynced_set); |
| 38 | 37 |
| 39 // TODO(chron): Remove writes from this iterator. As a warning, this | 38 // Fill |ready_unsynced_set| with all entries from |unsynced_handles| that |
| 40 // iterator causes writes to entries and so isn't a pure iterator. | 39 // are ready to commit. |
| 41 // It will do Put(IS_UNSYNCED). Refactor this out later. | 40 // An entry is not considered ready for commit if any are true: |
| 42 class CommitMetahandleIterator { | 41 // 1. It's in conflict. |
| 43 public: | 42 // 2. It requires encryption (either the type is encrypted but a passphrase |
| 44 // TODO(chron): Cache ValidateCommitEntry responses across iterators to save | 43 // is missing from the cryptographer, or the entry itself wasn't properly |
| 45 // UTF8 conversion and filename checking | 44 // encrypted). |
| 46 CommitMetahandleIterator(const vector<int64>& unsynced_handles, | 45 // 3. It's type is currently throttled. |
| 47 syncable::WriteTransaction* write_transaction, | 46 // 4. It's a delete but has not been committed. |
| 48 sessions::OrderedCommitSet* commit_set) | |
| 49 : write_transaction_(write_transaction), | |
| 50 handle_iterator_(unsynced_handles.begin()), | |
| 51 unsynced_handles_end_(unsynced_handles.end()), | |
| 52 commit_set_(commit_set) { | |
| 53 | |
| 54 // TODO(chron): Remove writes from this iterator. | |
| 55 DCHECK(write_transaction_); | |
| 56 | |
| 57 if (Valid() && !ValidateMetahandleForCommit(*handle_iterator_)) | |
| 58 Increment(); | |
| 59 } | |
| 60 ~CommitMetahandleIterator() {} | |
| 61 | |
| 62 int64 Current() const { | |
| 63 DCHECK(Valid()); | |
| 64 return *handle_iterator_; | |
| 65 } | |
| 66 | |
| 67 bool Increment() { | |
| 68 if (!Valid()) | |
| 69 return false; | |
| 70 | |
| 71 for (++handle_iterator_; | |
| 72 handle_iterator_ != unsynced_handles_end_; | |
| 73 ++handle_iterator_) { | |
| 74 if (ValidateMetahandleForCommit(*handle_iterator_)) | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 78 return false; | |
| 79 } | |
| 80 | |
| 81 bool Valid() const { | |
| 82 return !(handle_iterator_ == unsynced_handles_end_); | |
| 83 } | |
| 84 | |
| 85 private: | |
| 86 bool ValidateMetahandleForCommit(int64 metahandle) { | |
| 87 if (commit_set_->HaveCommitItem(metahandle)) | |
| 88 return false; | |
| 89 | |
| 90 // We should really not WRITE in this iterator, but we can fix that | |
| 91 // later. We should move that somewhere else later. | |
| 92 syncable::MutableEntry entry(write_transaction_, | |
| 93 syncable::GET_BY_HANDLE, metahandle); | |
| 94 VerifyCommitResult verify_result = | |
| 95 SyncerUtil::ValidateCommitEntry(&entry); | |
| 96 if (verify_result == VERIFY_UNSYNCABLE) { | |
| 97 // Drop unsyncable entries. | |
| 98 entry.Put(syncable::IS_UNSYNCED, false); | |
| 99 } | |
| 100 return verify_result == VERIFY_OK; | |
| 101 } | |
| 102 | |
| 103 syncable::WriteTransaction* const write_transaction_; | |
| 104 vector<int64>::const_iterator handle_iterator_; | |
| 105 vector<int64>::const_iterator unsynced_handles_end_; | |
| 106 sessions::OrderedCommitSet* commit_set_; | |
| 107 | |
| 108 DISALLOW_COPY_AND_ASSIGN(CommitMetahandleIterator); | |
| 109 }; | |
| 110 | |
| 111 private: | |
| 112 // Removes all entries not ready for commit from |unsynced_handles|. | |
| 113 // An entry is considered unready for commit if: | |
| 114 // 1. It's in conflict or requires (re)encryption. Any datatype requiring | |
| 115 // encryption while the cryptographer is missing a passphrase is | |
| 116 // considered unready for commit. | |
| 117 // 2. Its type is currently throttled. | |
| 118 void FilterUnreadyEntries( | 47 void FilterUnreadyEntries( |
| 119 syncable::BaseTransaction* trans, | 48 syncable::BaseTransaction* trans, |
| 120 syncable::ModelTypeSet throttled_types, | 49 syncable::ModelTypeSet throttled_types, |
| 121 syncable::Directory::UnsyncedMetaHandles* unsynced_handles); | 50 syncable::ModelTypeSet encrypted_types, |
| 51 bool passphrase_missing, |
| 52 const syncable::Directory::UnsyncedMetaHandles& unsynced_handles, |
| 53 std::set<int64>* ready_unsynced_set); |
| 122 | 54 |
| 123 void AddUncommittedParentsAndTheirPredecessors( | 55 private: |
| 56 // Add all the uncommitted parents and their predecessors of |item| to |
| 57 // |result| if they are ready to commit. Entries are added in root->child |
| 58 // order and predecessor->successor order. |
| 59 // Returns values: |
| 60 // False: if a dependent item was in conflict, and hence no child cannot be |
| 61 // committed. |
| 62 // True: if all parents and their predecessors were checked for commit |
| 63 // readiness and were added to |result| as necessary. |
| 64 bool AddUncommittedParentsAndTheirPredecessors( |
| 124 syncable::BaseTransaction* trans, | 65 syncable::BaseTransaction* trans, |
| 125 syncable::Id parent_id, | |
| 126 const ModelSafeRoutingInfo& routes, | 66 const ModelSafeRoutingInfo& routes, |
| 127 syncable::ModelTypeSet throttled_types); | 67 const std::set<int64>& ready_unsynced_set, |
| 68 const syncable::Entry& item, |
| 69 sessions::OrderedCommitSet* result) const; |
| 128 | 70 |
| 129 // OrderedCommitSet helpers for adding predecessors in order. | 71 // OrderedCommitSet helpers for adding predecessors in order. |
| 130 // TODO(ncarter): Refactor these so that the |result| parameter goes away, | 72 |
| 131 // and AddItem doesn't need to consider two OrderedCommitSets. | 73 // Adds |item| to |result| if it's ready for committing and was not already |
| 132 bool AddItem(syncable::Entry* item, | 74 // present. |
| 133 syncable::ModelTypeSet throttled_types, | 75 // Prereq: |item| is unsynced. |
| 134 sessions::OrderedCommitSet* result); | 76 // Returns values: |
| 77 // False: if |item| was in conflict. |
| 78 // True: if |item| was checked for commit readiness and added to |result| |
| 79 // as necessary. |
| 80 bool AddItem(const std::set<int64>& ready_unsynced_set, |
| 81 const syncable::Entry& item, |
| 82 sessions::OrderedCommitSet* result) const; |
| 83 |
| 84 // Adds item and all it's unsynced predecessors to |result| as necessary, as |
| 85 // long as no item was in conflict. |
| 86 // Return values: |
| 87 // False: if there was an entry in conflict. |
| 88 // True: if all entries were checked for commit readiness and added to |
| 89 // |result| as necessary. |
| 135 bool AddItemThenPredecessors(syncable::BaseTransaction* trans, | 90 bool AddItemThenPredecessors(syncable::BaseTransaction* trans, |
| 136 syncable::ModelTypeSet throttled_types, | 91 const std::set<int64>& ready_unsynced_set, |
| 137 syncable::Entry* item, | 92 const syncable::Entry& item, |
| 138 syncable::IndexedBitField inclusion_filter, | 93 sessions::OrderedCommitSet* result) const; |
| 139 sessions::OrderedCommitSet* result); | |
| 140 void AddPredecessorsThenItem(syncable::BaseTransaction* trans, | |
| 141 syncable::ModelTypeSet throttled_types, | |
| 142 syncable::Entry* item, | |
| 143 syncable::IndexedBitField inclusion_filter, | |
| 144 const ModelSafeRoutingInfo& routes); | |
| 145 | 94 |
| 146 bool IsCommitBatchFull(); | 95 // Appends all commit ready predecessors of |item|, followed by |item| itself, |
| 96 // to |ordered_commit_set_|, iff item and all its predecessors not in |
| 97 // conflict. |
| 98 // Return values: |
| 99 // False: if there was an entry in conflict. |
| 100 // True: if all entries were checked for commit readiness and added to |
| 101 // |result| as necessary. |
| 102 bool AddPredecessorsThenItem(syncable::BaseTransaction* trans, |
| 103 const ModelSafeRoutingInfo& routes, |
| 104 const std::set<int64>& ready_unsynced_set, |
| 105 const syncable::Entry& item, |
| 106 sessions::OrderedCommitSet* result) const; |
| 147 | 107 |
| 148 void AddCreatesAndMoves(const vector<int64>& unsynced_handles, | 108 bool IsCommitBatchFull() const; |
| 149 syncable::WriteTransaction* write_transaction, | 109 |
| 110 void AddCreatesAndMoves(syncable::WriteTransaction* write_transaction, |
| 150 const ModelSafeRoutingInfo& routes, | 111 const ModelSafeRoutingInfo& routes, |
| 151 syncable::ModelTypeSet throttled_types); | 112 const std::set<int64>& ready_unsynced_set); |
| 152 | 113 |
| 153 void AddDeletes(const vector<int64>& unsynced_handles, | 114 void AddDeletes(syncable::WriteTransaction* write_transaction, |
| 154 syncable::WriteTransaction* write_transaction); | 115 const std::set<int64>& ready_unsynced_set); |
| 155 | 116 |
| 156 scoped_ptr<sessions::OrderedCommitSet> ordered_commit_set_; | 117 scoped_ptr<sessions::OrderedCommitSet> ordered_commit_set_; |
| 157 | 118 |
| 158 int requested_commit_batch_size_; | 119 int requested_commit_batch_size_; |
| 159 bool passphrase_missing_; | |
| 160 syncable::ModelTypeSet encrypted_types_; | |
| 161 | 120 |
| 162 DISALLOW_COPY_AND_ASSIGN(GetCommitIdsCommand); | 121 DISALLOW_COPY_AND_ASSIGN(GetCommitIdsCommand); |
| 163 }; | 122 }; |
| 164 | 123 |
| 165 } // namespace browser_sync | 124 } // namespace browser_sync |
| 166 | 125 |
| 167 #endif // CHROME_BROWSER_SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_ | 126 #endif // CHROME_BROWSER_SYNC_ENGINE_GET_COMMIT_IDS_COMMAND_H_ |
| OLD | NEW |