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

Side by Side Diff: chrome/browser/sync/engine/get_commit_ids_command.cc

Issue 8851006: [Sync] Replace all instances of ModelTypeSet with ModelEnumSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 9 years 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) 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 #include "chrome/browser/sync/engine/get_commit_ids_command.h" 5 #include "chrome/browser/sync/engine/get_commit_ids_command.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 26 matching lines...) Expand all
37 &all_unsynced_handles); 37 &all_unsynced_handles);
38 38
39 Cryptographer* cryptographer = 39 Cryptographer* cryptographer =
40 session->context()->directory_manager()->GetCryptographer( 40 session->context()->directory_manager()->GetCryptographer(
41 session->write_transaction()); 41 session->write_transaction());
42 if (cryptographer) { 42 if (cryptographer) {
43 encrypted_types_ = cryptographer->GetEncryptedTypes(); 43 encrypted_types_ = cryptographer->GetEncryptedTypes();
44 passphrase_missing_ = cryptographer->has_pending_keys(); 44 passphrase_missing_ = cryptographer->has_pending_keys();
45 }; 45 };
46 46
47 const syncable::ModelTypeSet& throttled_types = 47 const syncable::ModelEnumSet throttled_types =
48 session->context()->GetThrottledTypes(); 48 session->context()->GetThrottledTypes();
49 // We filter out all unready entries from the set of unsynced handles to 49 // We filter out all unready entries from the set of unsynced handles to
50 // ensure we don't trigger useless sync cycles attempting to retry due to 50 // ensure we don't trigger useless sync cycles attempting to retry due to
51 // there being work to do. (see ScheduleNextSync in sync_scheduler) 51 // there being work to do. (see ScheduleNextSync in sync_scheduler)
52 FilterUnreadyEntries(session->write_transaction(), 52 FilterUnreadyEntries(session->write_transaction(),
53 throttled_types, 53 throttled_types,
54 &all_unsynced_handles); 54 &all_unsynced_handles);
55 55
56 StatusController* status = session->mutable_status_controller(); 56 StatusController* status = session->mutable_status_controller();
57 status->set_unsynced_handles(all_unsynced_handles); 57 status->set_unsynced_handles(all_unsynced_handles);
58 BuildCommitIds(status->unsynced_handles(), session->write_transaction(), 58 BuildCommitIds(status->unsynced_handles(), session->write_transaction(),
59 session->routing_info(), throttled_types); 59 session->routing_info(), throttled_types);
60 60
61 const vector<syncable::Id>& verified_commit_ids = 61 const vector<syncable::Id>& verified_commit_ids =
62 ordered_commit_set_->GetAllCommitIds(); 62 ordered_commit_set_->GetAllCommitIds();
63 63
64 for (size_t i = 0; i < verified_commit_ids.size(); i++) 64 for (size_t i = 0; i < verified_commit_ids.size(); i++)
65 DVLOG(1) << "Debug commit batch result:" << verified_commit_ids[i]; 65 DVLOG(1) << "Debug commit batch result:" << verified_commit_ids[i];
66 66
67 status->set_commit_set(*ordered_commit_set_.get()); 67 status->set_commit_set(*ordered_commit_set_.get());
68 } 68 }
69 69
70 namespace { 70 namespace {
71 71
72 // An entry ready for commit is defined as: 72 // An entry ready for commit is defined as:
73 // 1. Not in conflict (SERVER_VERSION == BASE_VERSION || SERVER_VERSION == 0) 73 // 1. Not in conflict (SERVER_VERSION == BASE_VERSION || SERVER_VERSION == 0)
74 // and not requiring encryption (any entry containing an encrypted datatype 74 // and not requiring encryption (any entry containing an encrypted datatype
75 // while the cryptographer requires a passphrase is not ready for commit.) 75 // while the cryptographer requires a passphrase is not ready for commit.)
76 // 2. Its type is not currently throttled. 76 // 2. Its type is not currently throttled.
77 bool IsEntryReadyForCommit(const syncable::ModelTypeSet& encrypted_types, 77 bool IsEntryReadyForCommit(syncable::ModelEnumSet encrypted_types,
78 bool passphrase_missing, 78 bool passphrase_missing,
79 const syncable::Entry& entry, 79 const syncable::Entry& entry,
80 const syncable::ModelTypeSet& throttled_types) { 80 syncable::ModelEnumSet throttled_types) {
81 if (!entry.Get(syncable::IS_UNSYNCED)) 81 if (!entry.Get(syncable::IS_UNSYNCED))
82 return false; 82 return false;
83 83
84 if (entry.Get(syncable::SERVER_VERSION) > 0 && 84 if (entry.Get(syncable::SERVER_VERSION) > 0 &&
85 (entry.Get(syncable::SERVER_VERSION) > 85 (entry.Get(syncable::SERVER_VERSION) >
86 entry.Get(syncable::BASE_VERSION))) { 86 entry.Get(syncable::BASE_VERSION))) {
87 // The local and server versions don't match. The item must be in 87 // The local and server versions don't match. The item must be in
88 // conflict, so there's no point in attempting to commit. 88 // conflict, so there's no point in attempting to commit.
89 DCHECK(entry.Get(syncable::IS_UNAPPLIED_UPDATE)); // In conflict. 89 DCHECK(entry.Get(syncable::IS_UNAPPLIED_UPDATE)); // In conflict.
90 // TODO(zea): switch this to DVLOG once it's clear bug 100660 is fixed. 90 // TODO(zea): switch this to DVLOG once it's clear bug 100660 is fixed.
91 DVLOG(1) << "Excluding entry from commit due to version mismatch " 91 DVLOG(1) << "Excluding entry from commit due to version mismatch "
92 << entry; 92 << entry;
93 return false; 93 return false;
94 } 94 }
95 95
96 syncable::ModelType type = entry.GetModelType(); 96 const syncable::ModelType type = entry.GetModelType();
97 if (encrypted_types.count(type) > 0 && 97 if (syncable::IsRealDataType(type) && encrypted_types.Has(type) &&
98 (passphrase_missing || 98 (passphrase_missing ||
99 syncable::EntryNeedsEncryption(encrypted_types, entry))) { 99 syncable::EntryNeedsEncryption(encrypted_types, entry))) {
100 // This entry requires encryption but is not properly encrypted (possibly 100 // This entry requires encryption but is not properly encrypted (possibly
101 // due to the cryptographer not being initialized or the user hasn't 101 // due to the cryptographer not being initialized or the user hasn't
102 // provided the most recent passphrase). 102 // provided the most recent passphrase).
103 // TODO(zea): switch this to DVLOG once it's clear bug 100660 is fixed. 103 // TODO(zea): switch this to DVLOG once it's clear bug 100660 is fixed.
104 DVLOG(1) << "Excluding entry from commit due to lack of encryption " 104 DVLOG(1) << "Excluding entry from commit due to lack of encryption "
105 << entry; 105 << entry;
106 return false; 106 return false;
107 } 107 }
108 108
109 // Look at the throttled types. 109 // Look at the throttled types.
110 if (throttled_types.count(type) > 0) 110 if (syncable::IsRealDataType(type) && throttled_types.Has(type))
111 return false; 111 return false;
112 112
113 return true; 113 return true;
114 } 114 }
115 115
116 } // namespace 116 } // namespace
117 117
118 void GetCommitIdsCommand::FilterUnreadyEntries( 118 void GetCommitIdsCommand::FilterUnreadyEntries(
119 syncable::BaseTransaction* trans, 119 syncable::BaseTransaction* trans,
120 const syncable::ModelTypeSet& throttled_types, 120 syncable::ModelEnumSet throttled_types,
121 syncable::Directory::UnsyncedMetaHandles* unsynced_handles) { 121 syncable::Directory::UnsyncedMetaHandles* unsynced_handles) {
122 syncable::Directory::UnsyncedMetaHandles::iterator iter; 122 syncable::Directory::UnsyncedMetaHandles::iterator iter;
123 syncable::Directory::UnsyncedMetaHandles new_unsynced_handles; 123 syncable::Directory::UnsyncedMetaHandles new_unsynced_handles;
124 new_unsynced_handles.reserve(unsynced_handles->size()); 124 new_unsynced_handles.reserve(unsynced_handles->size());
125 for (iter = unsynced_handles->begin(); 125 for (iter = unsynced_handles->begin();
126 iter != unsynced_handles->end(); 126 iter != unsynced_handles->end();
127 ++iter) { 127 ++iter) {
128 syncable::Entry entry(trans, syncable::GET_BY_HANDLE, *iter); 128 syncable::Entry entry(trans, syncable::GET_BY_HANDLE, *iter);
129 if (IsEntryReadyForCommit(encrypted_types_, 129 if (IsEntryReadyForCommit(encrypted_types_,
130 passphrase_missing_, 130 passphrase_missing_,
131 entry, 131 entry,
132 throttled_types)) 132 throttled_types))
133 new_unsynced_handles.push_back(*iter); 133 new_unsynced_handles.push_back(*iter);
134 } 134 }
135 if (new_unsynced_handles.size() != unsynced_handles->size()) 135 if (new_unsynced_handles.size() != unsynced_handles->size())
136 unsynced_handles->swap(new_unsynced_handles); 136 unsynced_handles->swap(new_unsynced_handles);
137 } 137 }
138 138
139 void GetCommitIdsCommand::AddUncommittedParentsAndTheirPredecessors( 139 void GetCommitIdsCommand::AddUncommittedParentsAndTheirPredecessors(
140 syncable::BaseTransaction* trans, 140 syncable::BaseTransaction* trans,
141 syncable::Id parent_id, 141 syncable::Id parent_id,
142 const ModelSafeRoutingInfo& routes, 142 const ModelSafeRoutingInfo& routes,
143 const syncable::ModelTypeSet& throttled_types) { 143 syncable::ModelEnumSet throttled_types) {
144 OrderedCommitSet item_dependencies(routes); 144 OrderedCommitSet item_dependencies(routes);
145 145
146 // Climb the tree adding entries leaf -> root. 146 // Climb the tree adding entries leaf -> root.
147 while (!parent_id.ServerKnows()) { 147 while (!parent_id.ServerKnows()) {
148 syncable::Entry parent(trans, syncable::GET_BY_ID, parent_id); 148 syncable::Entry parent(trans, syncable::GET_BY_ID, parent_id);
149 CHECK(parent.good()) << "Bad user-only parent in item path."; 149 CHECK(parent.good()) << "Bad user-only parent in item path.";
150 int64 handle = parent.Get(syncable::META_HANDLE); 150 int64 handle = parent.Get(syncable::META_HANDLE);
151 if (ordered_commit_set_->HaveCommitItem(handle) || 151 if (ordered_commit_set_->HaveCommitItem(handle) ||
152 item_dependencies.HaveCommitItem(handle)) { 152 item_dependencies.HaveCommitItem(handle)) {
153 break; 153 break;
154 } 154 }
155 if (!AddItemThenPredecessors(trans, throttled_types, &parent, 155 if (!AddItemThenPredecessors(trans, throttled_types, &parent,
156 syncable::IS_UNSYNCED, 156 syncable::IS_UNSYNCED,
157 &item_dependencies)) { 157 &item_dependencies)) {
158 break; // Parent was already present in the set. 158 break; // Parent was already present in the set.
159 } 159 }
160 parent_id = parent.Get(syncable::PARENT_ID); 160 parent_id = parent.Get(syncable::PARENT_ID);
161 } 161 }
162 162
163 // Reverse what we added to get the correct order. 163 // Reverse what we added to get the correct order.
164 ordered_commit_set_->AppendReverse(item_dependencies); 164 ordered_commit_set_->AppendReverse(item_dependencies);
165 } 165 }
166 166
167 bool GetCommitIdsCommand::AddItem(syncable::Entry* item, 167 bool GetCommitIdsCommand::AddItem(syncable::Entry* item,
168 const syncable::ModelTypeSet& throttled_types, 168 syncable::ModelEnumSet throttled_types,
169 OrderedCommitSet* result) { 169 OrderedCommitSet* result) {
170 if (!IsEntryReadyForCommit(encrypted_types_, passphrase_missing_, *item, 170 if (!IsEntryReadyForCommit(encrypted_types_, passphrase_missing_, *item,
171 throttled_types)) 171 throttled_types))
172 return false; 172 return false;
173 int64 item_handle = item->Get(syncable::META_HANDLE); 173 int64 item_handle = item->Get(syncable::META_HANDLE);
174 if (result->HaveCommitItem(item_handle) || 174 if (result->HaveCommitItem(item_handle) ||
175 ordered_commit_set_->HaveCommitItem(item_handle)) { 175 ordered_commit_set_->HaveCommitItem(item_handle)) {
176 return false; 176 return false;
177 } 177 }
178 result->AddCommitItem(item_handle, item->Get(syncable::ID), 178 result->AddCommitItem(item_handle, item->Get(syncable::ID),
179 item->GetModelType()); 179 item->GetModelType());
180 return true; 180 return true;
181 } 181 }
182 182
183 bool GetCommitIdsCommand::AddItemThenPredecessors( 183 bool GetCommitIdsCommand::AddItemThenPredecessors(
184 syncable::BaseTransaction* trans, 184 syncable::BaseTransaction* trans,
185 const syncable::ModelTypeSet& throttled_types, 185 syncable::ModelEnumSet throttled_types,
186 syncable::Entry* item, 186 syncable::Entry* item,
187 syncable::IndexedBitField inclusion_filter, 187 syncable::IndexedBitField inclusion_filter,
188 OrderedCommitSet* result) { 188 OrderedCommitSet* result) {
189 if (!AddItem(item, throttled_types, result)) 189 if (!AddItem(item, throttled_types, result))
190 return false; 190 return false;
191 if (item->Get(syncable::IS_DEL)) 191 if (item->Get(syncable::IS_DEL))
192 return true; // Deleted items have no predecessors. 192 return true; // Deleted items have no predecessors.
193 193
194 syncable::Id prev_id = item->Get(syncable::PREV_ID); 194 syncable::Id prev_id = item->Get(syncable::PREV_ID);
195 while (!prev_id.IsRoot()) { 195 while (!prev_id.IsRoot()) {
196 syncable::Entry prev(trans, syncable::GET_BY_ID, prev_id); 196 syncable::Entry prev(trans, syncable::GET_BY_ID, prev_id);
197 CHECK(prev.good()) << "Bad id when walking predecessors."; 197 CHECK(prev.good()) << "Bad id when walking predecessors.";
198 if (!prev.Get(inclusion_filter)) 198 if (!prev.Get(inclusion_filter))
199 break; 199 break;
200 if (!AddItem(&prev, throttled_types, result)) 200 if (!AddItem(&prev, throttled_types, result))
201 break; 201 break;
202 prev_id = prev.Get(syncable::PREV_ID); 202 prev_id = prev.Get(syncable::PREV_ID);
203 } 203 }
204 return true; 204 return true;
205 } 205 }
206 206
207 void GetCommitIdsCommand::AddPredecessorsThenItem( 207 void GetCommitIdsCommand::AddPredecessorsThenItem(
208 syncable::BaseTransaction* trans, 208 syncable::BaseTransaction* trans,
209 const syncable::ModelTypeSet& throttled_types, 209 syncable::ModelEnumSet throttled_types,
210 syncable::Entry* item, 210 syncable::Entry* item,
211 syncable::IndexedBitField inclusion_filter, 211 syncable::IndexedBitField inclusion_filter,
212 const ModelSafeRoutingInfo& routes) { 212 const ModelSafeRoutingInfo& routes) {
213 OrderedCommitSet item_dependencies(routes); 213 OrderedCommitSet item_dependencies(routes);
214 AddItemThenPredecessors(trans, throttled_types, item, inclusion_filter, 214 AddItemThenPredecessors(trans, throttled_types, item, inclusion_filter,
215 &item_dependencies); 215 &item_dependencies);
216 216
217 // Reverse what we added to get the correct order. 217 // Reverse what we added to get the correct order.
218 ordered_commit_set_->AppendReverse(item_dependencies); 218 ordered_commit_set_->AppendReverse(item_dependencies);
219 } 219 }
220 220
221 bool GetCommitIdsCommand::IsCommitBatchFull() { 221 bool GetCommitIdsCommand::IsCommitBatchFull() {
222 return ordered_commit_set_->Size() >= requested_commit_batch_size_; 222 return ordered_commit_set_->Size() >= requested_commit_batch_size_;
223 } 223 }
224 224
225 void GetCommitIdsCommand::AddCreatesAndMoves( 225 void GetCommitIdsCommand::AddCreatesAndMoves(
226 const vector<int64>& unsynced_handles, 226 const vector<int64>& unsynced_handles,
227 syncable::WriteTransaction* write_transaction, 227 syncable::WriteTransaction* write_transaction,
228 const ModelSafeRoutingInfo& routes, 228 const ModelSafeRoutingInfo& routes,
229 const syncable::ModelTypeSet& throttled_types) { 229 syncable::ModelEnumSet throttled_types) {
230 // Add moves and creates, and prepend their uncommitted parents. 230 // Add moves and creates, and prepend their uncommitted parents.
231 for (CommitMetahandleIterator iterator(unsynced_handles, write_transaction, 231 for (CommitMetahandleIterator iterator(unsynced_handles, write_transaction,
232 ordered_commit_set_.get()); 232 ordered_commit_set_.get());
233 !IsCommitBatchFull() && iterator.Valid(); 233 !IsCommitBatchFull() && iterator.Valid();
234 iterator.Increment()) { 234 iterator.Increment()) {
235 int64 metahandle = iterator.Current(); 235 int64 metahandle = iterator.Current();
236 236
237 syncable::Entry entry(write_transaction, 237 syncable::Entry entry(write_transaction,
238 syncable::GET_BY_HANDLE, 238 syncable::GET_BY_HANDLE,
239 metahandle); 239 metahandle);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 ordered_commit_set_->AddCommitItem(metahandle, entry.Get(syncable::ID), 330 ordered_commit_set_->AddCommitItem(metahandle, entry.Get(syncable::ID),
331 entry.GetModelType()); 331 entry.GetModelType());
332 } 332 }
333 } 333 }
334 } 334 }
335 } 335 }
336 336
337 void GetCommitIdsCommand::BuildCommitIds(const vector<int64>& unsynced_handles, 337 void GetCommitIdsCommand::BuildCommitIds(const vector<int64>& unsynced_handles,
338 syncable::WriteTransaction* write_transaction, 338 syncable::WriteTransaction* write_transaction,
339 const ModelSafeRoutingInfo& routes, 339 const ModelSafeRoutingInfo& routes,
340 const syncable::ModelTypeSet& throttled_types) { 340 syncable::ModelEnumSet throttled_types) {
341 ordered_commit_set_.reset(new OrderedCommitSet(routes)); 341 ordered_commit_set_.reset(new OrderedCommitSet(routes));
342 // Commits follow these rules: 342 // Commits follow these rules:
343 // 1. Moves or creates are preceded by needed folder creates, from 343 // 1. Moves or creates are preceded by needed folder creates, from
344 // root to leaf. For folders whose contents are ordered, moves 344 // root to leaf. For folders whose contents are ordered, moves
345 // and creates appear in order. 345 // and creates appear in order.
346 // 2. Moves/Creates before deletes. 346 // 2. Moves/Creates before deletes.
347 // 3. Deletes, collapsed. 347 // 3. Deletes, collapsed.
348 // We commit deleted moves under deleted items as moves when collapsing 348 // We commit deleted moves under deleted items as moves when collapsing
349 // delete trees. 349 // delete trees.
350 350
351 // Add moves and creates, and prepend their uncommitted parents. 351 // Add moves and creates, and prepend their uncommitted parents.
352 AddCreatesAndMoves(unsynced_handles, write_transaction, routes, 352 AddCreatesAndMoves(unsynced_handles, write_transaction, routes,
353 throttled_types); 353 throttled_types);
354 354
355 // Add all deletes. 355 // Add all deletes.
356 AddDeletes(unsynced_handles, write_transaction); 356 AddDeletes(unsynced_handles, write_transaction);
357 } 357 }
358 358
359 } // namespace browser_sync 359 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698