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

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

Issue 10038041: sync: Loop committing items without downloading updates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
OLDNEW
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 #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 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 // Same as above, but for ModelType of the item. 58 // Same as above, but for ModelType of the item.
59 syncable::ModelType GetModelTypeAt(const size_t position) const { 59 syncable::ModelType GetModelTypeAt(const size_t position) const {
60 return types_[position]; 60 return types_[position];
61 } 61 }
62 62
63 // Get the projection of commit ids onto the space of commit ids 63 // 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 64 // 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 65 // response one ModelSafeGroup at a time. See GetCommitIdAt for how the
66 // indices contained in the returned Projection can be used. 66 // indices contained in the returned Projection can be used.
67 const Projection& GetCommitIdProjection(browser_sync::ModelSafeGroup group) { 67 const Projection& GetCommitIdProjection(
68 return projections_[group]; 68 browser_sync::ModelSafeGroup group) const {
69 Projections::const_iterator i = projections_.find(group);
rlarocque 2012/04/13 02:02:22 Because operator[]() is non-const.
70 DCHECK(i != projections_.end());
71 return i->second;
69 } 72 }
70 73
71 int Size() const { 74 size_t Size() const {
72 return commit_ids_.size(); 75 return commit_ids_.size();
73 } 76 }
74 77
78 bool Empty() const {
79 return Size() == 0;
80 }
81
75 // Returns true iff any of the commit ids added to this set have model type 82 // Returns true iff any of the commit ids added to this set have model type
76 // BOOKMARKS. 83 // BOOKMARKS.
77 bool HasBookmarkCommitId() const; 84 bool HasBookmarkCommitId() const;
78 85
79 void Append(const OrderedCommitSet& other); 86 void Append(const OrderedCommitSet& other);
80 void AppendReverse(const OrderedCommitSet& other); 87 void AppendReverse(const OrderedCommitSet& other);
81 void Truncate(size_t max_size); 88 void Truncate(size_t max_size);
82 89
83 void operator=(const OrderedCommitSet& other); 90 void operator=(const OrderedCommitSet& other);
84 private: 91 private:
85 // A set of CommitIdProjections associated with particular ModelSafeGroups. 92 // A set of CommitIdProjections associated with particular ModelSafeGroups.
86 typedef std::map<browser_sync::ModelSafeGroup, Projection> Projections; 93 typedef std::map<browser_sync::ModelSafeGroup, Projection> Projections;
87 94
88 // Helper container for return value of GetCommitItemAt. 95 // Helper container for return value of GetCommitItemAt.
89 struct CommitItem { 96 struct CommitItem {
90 int64 meta; 97 int64 meta;
91 syncable::Id id; 98 syncable::Id id;
92 syncable::ModelType group; 99 syncable::ModelType group;
93 }; 100 };
94 101
95 CommitItem GetCommitItemAt(const int position) const; 102 CommitItem GetCommitItemAt(const size_t position) const;
96 103
97 // These lists are different views of the same items; e.g they are 104 // These lists are different views of the same items; e.g they are
98 // isomorphic. 105 // isomorphic.
99 std::set<int64> inserted_metahandles_; 106 std::set<int64> inserted_metahandles_;
100 std::vector<syncable::Id> commit_ids_; 107 std::vector<syncable::Id> commit_ids_;
101 std::vector<int64> metahandle_order_; 108 std::vector<int64> metahandle_order_;
102 Projections projections_; 109 Projections projections_;
103 110
104 // We need this because of operations like AppendReverse that take ids from 111 // We need this because of operations like AppendReverse that take ids from
105 // one OrderedCommitSet and insert into another -- we need to know the 112 // one OrderedCommitSet and insert into another -- we need to know the
106 // group for each ID so that the insertion can update the appropriate 113 // group for each ID so that the insertion can update the appropriate
107 // projection. We could store it in commit_ids_, but sometimes we want 114 // projection. We could store it in commit_ids_, but sometimes we want
108 // to just return the vector of Ids, so this is more straightforward 115 // to just return the vector of Ids, so this is more straightforward
109 // and shouldn't take up too much extra space since commit lists are small. 116 // and shouldn't take up too much extra space since commit lists are small.
110 std::vector<syncable::ModelType> types_; 117 std::vector<syncable::ModelType> types_;
111 118
112 browser_sync::ModelSafeRoutingInfo routes_; 119 browser_sync::ModelSafeRoutingInfo routes_;
113 }; 120 };
114 121
115 } // namespace sessions 122 } // namespace sessions
116 } // namespace browser_sync 123 } // namespace browser_sync
117 124
118 #endif // SYNC_SESSIONS_ORDERED_COMMIT_SET_H_ 125 #endif // SYNC_SESSIONS_ORDERED_COMMIT_SET_H_
119 126
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698