Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: sync/sessions/ordered_commit_set.h

Issue 23694004: sync: Remove IDs from OrderedCommitSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/syncer_unittest.cc ('k') | sync/sessions/ordered_commit_set.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 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 SYNC_SESSIONS_ORDERED_COMMIT_SET_H_ 5 #ifndef SYNC_SESSIONS_ORDERED_COMMIT_SET_H_
6 #define SYNC_SESSIONS_ORDERED_COMMIT_SET_H_ 6 #define SYNC_SESSIONS_ORDERED_COMMIT_SET_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
11 11
12 #include "sync/base/sync_export.h" 12 #include "sync/base/sync_export.h"
13 #include "sync/internal_api/public/base/model_type.h" 13 #include "sync/internal_api/public/base/model_type.h"
14 #include "sync/internal_api/public/engine/model_safe_worker.h" 14 #include "sync/internal_api/public/engine/model_safe_worker.h"
15 #include "sync/syncable/syncable_id.h"
16 15
17 namespace syncer { 16 namespace syncer {
18 namespace sessions { 17 namespace sessions {
19 18
20 // TODO(ncarter): This code is more generic than just Commit and can 19 // TODO(ncarter): This code is more generic than just Commit and can
21 // be reused elsewhere (e.g. ChangeReorderBuffer do similar things). Merge 20 // be reused elsewhere (e.g. ChangeReorderBuffer do similar things). Merge
22 // all these implementations. 21 // all these implementations.
23 class SYNC_EXPORT_PRIVATE OrderedCommitSet { 22 class SYNC_EXPORT_PRIVATE OrderedCommitSet {
24 public: 23 public:
25 // A list of indices into the full list of commit ids such that: 24 // A list of indices into the full list of commit ids such that:
26 // 1 - each element is an index belonging to a particular ModelSafeGroup. 25 // 1 - each element is an index belonging to a particular ModelSafeGroup.
27 // 2 - the vector is in sorted (smallest to largest) order. 26 // 2 - the vector is in sorted (smallest to largest) order.
28 // 3 - each element is a valid index for GetCommitItemAt. 27 // 3 - each element is a valid index for GetCommitItemAt.
29 // See GetCommitIdProjection for usage. 28 // See GetCommitIdProjection for usage.
30 typedef std::vector<size_t> Projection; 29 typedef std::vector<size_t> Projection;
31 30
32 // TODO(chron): Reserve space according to batch size? 31 // TODO(chron): Reserve space according to batch size?
33 explicit OrderedCommitSet(const ModelSafeRoutingInfo& routes); 32 explicit OrderedCommitSet(const ModelSafeRoutingInfo& routes);
34 ~OrderedCommitSet(); 33 ~OrderedCommitSet();
35 34
36 bool HaveCommitItem(const int64 metahandle) const { 35 bool HaveCommitItem(const int64 metahandle) const {
37 return inserted_metahandles_.count(metahandle) > 0; 36 return inserted_metahandles_.count(metahandle) > 0;
38 } 37 }
39 38
40 void AddCommitItem(const int64 metahandle, const syncable::Id& commit_id, 39 void AddCommitItem(const int64 metahandle, ModelType type);
41 ModelType type); 40 void AddCommitItems(const std::vector<int64> metahandles, ModelType type);
42 41
43 const std::vector<syncable::Id>& GetAllCommitIds() const { 42 const std::vector<int64>& GetAllCommitHandles() const {
44 return commit_ids_; 43 return metahandle_order_;
45 } 44 }
46 45
47 // Return the Id at index |position| in this OrderedCommitSet. Note that 46 // Return the handle at index |position| in this OrderedCommitSet. Note that
48 // the index uniquely identifies the same logical item in each of: 47 // the index uniquely identifies the same logical item in each of:
49 // 1) this OrderedCommitSet 48 // 1) this OrderedCommitSet
50 // 2) the CommitRequest sent to the server 49 // 2) the CommitRequest sent to the server
51 // 3) the list of EntryResponse objects in the CommitResponse. 50 // 3) the list of EntryResponse objects in the CommitResponse.
52 // These together allow re-association of the pre-commit Id with the 51 // These together allow re-association of the pre-commit Id with the
53 // actual committed entry. 52 // actual committed entry.
54 const syncable::Id& GetCommitIdAt(const size_t position) const { 53 int64 GetCommitHandleAt(const size_t position) const {
55 return commit_ids_[position]; 54 return metahandle_order_[position];
56 } 55 }
57 56
58 // Same as above, but for ModelType of the item. 57 // Same as above, but for ModelType of the item.
59 ModelType GetModelTypeAt(const size_t position) const { 58 ModelType GetModelTypeAt(const size_t position) const {
60 return types_[position]; 59 return types_[position];
61 } 60 }
62 61
63 // Get the projection of commit ids onto the space of commit ids 62 // Get the projection of commit ids onto the space of commit ids
64 // belonging to |group|. This is useful when you need to process a commit 63 // belonging to |group|. This is useful when you need to process a commit
65 // response one ModelSafeGroup at a time. See GetCommitIdAt for how the 64 // response one ModelSafeGroup at a time. See GetCommitIdAt for how the
66 // indices contained in the returned Projection can be used. 65 // indices contained in the returned Projection can be used.
67 const Projection& GetCommitIdProjection( 66 const Projection& GetCommitIdProjection(
68 ModelSafeGroup group) const; 67 ModelSafeGroup group) const;
69 68
70 size_t Size() const { 69 size_t Size() const {
71 return commit_ids_.size(); 70 return metahandle_order_.size();
72 } 71 }
73 72
74 bool Empty() const { 73 bool Empty() const {
75 return Size() == 0; 74 return Size() == 0;
76 } 75 }
77 76
78 // Returns all the types that are included in this list. 77 // Returns all the types that are included in this list.
79 ModelTypeSet Types() const { 78 ModelTypeSet Types() const {
80 return types_in_list_; 79 return types_in_list_;
81 } 80 }
(...skipping 10 matching lines...) Expand all
92 void Clear(); 91 void Clear();
93 92
94 void operator=(const OrderedCommitSet& other); 93 void operator=(const OrderedCommitSet& other);
95 private: 94 private:
96 // A set of CommitIdProjections associated with particular ModelSafeGroups. 95 // A set of CommitIdProjections associated with particular ModelSafeGroups.
97 typedef std::map<ModelSafeGroup, Projection> Projections; 96 typedef std::map<ModelSafeGroup, Projection> Projections;
98 97
99 // Helper container for return value of GetCommitItemAt. 98 // Helper container for return value of GetCommitItemAt.
100 struct CommitItem { 99 struct CommitItem {
101 int64 meta; 100 int64 meta;
102 syncable::Id id;
103 ModelType group; 101 ModelType group;
104 }; 102 };
105 103
106 CommitItem GetCommitItemAt(const size_t position) const; 104 CommitItem GetCommitItemAt(const size_t position) const;
107 105
108 // These lists are different views of the same items; e.g they are 106 // These lists are different views of the same items; e.g they are
109 // isomorphic. 107 // isomorphic.
110 std::set<int64> inserted_metahandles_; 108 std::set<int64> inserted_metahandles_;
111 std::vector<syncable::Id> commit_ids_;
112 std::vector<int64> metahandle_order_; 109 std::vector<int64> metahandle_order_;
113 Projections projections_; 110 Projections projections_;
114 111
115 // We need this because of operations like AppendReverse that take ids from 112 // We need this because of operations like AppendReverse that take ids from
116 // one OrderedCommitSet and insert into another -- we need to know the 113 // one OrderedCommitSet and insert into another -- we need to know the
117 // group for each ID so that the insertion can update the appropriate 114 // group for each ID so that the insertion can update the appropriate
118 // projection. We could store it in commit_ids_, but sometimes we want 115 // projection.
119 // to just return the vector of Ids, so this is more straightforward
120 // and shouldn't take up too much extra space since commit lists are small.
121 std::vector<ModelType> types_; 116 std::vector<ModelType> types_;
122 117
123 // The set of types which are included in this particular list. 118 // The set of types which are included in this particular list.
124 ModelTypeSet types_in_list_; 119 ModelTypeSet types_in_list_;
125 120
126 ModelSafeRoutingInfo routes_; 121 ModelSafeRoutingInfo routes_;
127 }; 122 };
128 123
129 } // namespace sessions 124 } // namespace sessions
130 } // namespace syncer 125 } // namespace syncer
131 126
132 #endif // SYNC_SESSIONS_ORDERED_COMMIT_SET_H_ 127 #endif // SYNC_SESSIONS_ORDERED_COMMIT_SET_H_
133 128
OLDNEW
« no previous file with comments | « sync/engine/syncer_unittest.cc ('k') | sync/sessions/ordered_commit_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698