| 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_SESSIONS_ORDERED_COMMIT_SET_H_ | |
| 6 #define SYNC_SESSIONS_ORDERED_COMMIT_SET_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "sync/base/sync_export.h" | |
| 13 #include "sync/internal_api/public/base/model_type.h" | |
| 14 #include "sync/internal_api/public/engine/model_safe_worker.h" | |
| 15 | |
| 16 namespace syncer { | |
| 17 namespace sessions { | |
| 18 | |
| 19 // TODO(ncarter): This code is more generic than just Commit and can | |
| 20 // be reused elsewhere (e.g. ChangeReorderBuffer do similar things). Merge | |
| 21 // all these implementations. | |
| 22 class SYNC_EXPORT_PRIVATE OrderedCommitSet { | |
| 23 public: | |
| 24 // TODO(chron): Reserve space according to batch size? | |
| 25 OrderedCommitSet(); | |
| 26 ~OrderedCommitSet(); | |
| 27 | |
| 28 bool HaveCommitItem(const int64 metahandle) const { | |
| 29 return inserted_metahandles_.count(metahandle) > 0; | |
| 30 } | |
| 31 | |
| 32 void AddCommitItem(const int64 metahandle, ModelType type); | |
| 33 void AddCommitItems(const std::vector<int64> metahandles, ModelType type); | |
| 34 | |
| 35 const std::vector<int64>& GetAllCommitHandles() const { | |
| 36 return metahandle_order_; | |
| 37 } | |
| 38 | |
| 39 // Return the handle at index |position| in this OrderedCommitSet. Note that | |
| 40 // the index uniquely identifies the same logical item in each of: | |
| 41 // 1) this OrderedCommitSet | |
| 42 // 2) the CommitRequest sent to the server | |
| 43 // 3) the list of EntryResponse objects in the CommitResponse. | |
| 44 // These together allow re-association of the pre-commit Id with the | |
| 45 // actual committed entry. | |
| 46 int64 GetCommitHandleAt(const size_t position) const { | |
| 47 return metahandle_order_[position]; | |
| 48 } | |
| 49 | |
| 50 // Same as above, but for ModelType of the item. | |
| 51 ModelType GetModelTypeAt(const size_t position) const { | |
| 52 return types_[position]; | |
| 53 } | |
| 54 | |
| 55 size_t Size() const { | |
| 56 return metahandle_order_.size(); | |
| 57 } | |
| 58 | |
| 59 bool Empty() const { | |
| 60 return Size() == 0; | |
| 61 } | |
| 62 | |
| 63 // Returns all the types that are included in this list. | |
| 64 ModelTypeSet Types() const { | |
| 65 return types_in_list_; | |
| 66 } | |
| 67 | |
| 68 // Returns true iff any of the commit ids added to this set have model type | |
| 69 // BOOKMARKS. | |
| 70 bool HasBookmarkCommitId() const; | |
| 71 | |
| 72 void Append(const OrderedCommitSet& other); | |
| 73 void AppendReverse(const OrderedCommitSet& other); | |
| 74 void Truncate(size_t max_size); | |
| 75 | |
| 76 // Removes all entries from this set. | |
| 77 void Clear(); | |
| 78 | |
| 79 void operator=(const OrderedCommitSet& other); | |
| 80 private: | |
| 81 // Helper container for return value of GetCommitItemAt. | |
| 82 struct CommitItem { | |
| 83 int64 meta; | |
| 84 ModelType group; | |
| 85 }; | |
| 86 | |
| 87 CommitItem GetCommitItemAt(const size_t position) const; | |
| 88 | |
| 89 // These lists are different views of the same items; e.g they are | |
| 90 // isomorphic. | |
| 91 std::set<int64> inserted_metahandles_; | |
| 92 std::vector<int64> metahandle_order_; | |
| 93 | |
| 94 // We need this because of operations like AppendReverse that take ids from | |
| 95 // one OrderedCommitSet and insert into another -- we need to know the | |
| 96 // group for each ID so that the insertion can update the appropriate | |
| 97 // projection. | |
| 98 std::vector<ModelType> types_; | |
| 99 | |
| 100 // The set of types which are included in this particular list. | |
| 101 ModelTypeSet types_in_list_; | |
| 102 }; | |
| 103 | |
| 104 } // namespace sessions | |
| 105 } // namespace syncer | |
| 106 | |
| 107 #endif // SYNC_SESSIONS_ORDERED_COMMIT_SET_H_ | |
| 108 | |
| OLD | NEW |