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

Side by Side Diff: chrome/browser/sync/sessions/session_state.cc

Issue 9305001: sync: Remove the remaining conflict sets code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Additional comments Created 8 years, 10 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 #include "chrome/browser/sync/sessions/session_state.h" 5 #include "chrome/browser/sync/sessions/session_state.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 std::string SyncSessionSnapshot::ToString() const { 180 std::string SyncSessionSnapshot::ToString() const {
181 scoped_ptr<DictionaryValue> value(ToValue()); 181 scoped_ptr<DictionaryValue> value(ToValue());
182 std::string json; 182 std::string json;
183 base::JSONWriter::Write(value.get(), true, &json); 183 base::JSONWriter::Write(value.get(), true, &json);
184 return json; 184 return json;
185 } 185 }
186 186
187 ConflictProgress::ConflictProgress(bool* dirty_flag) : dirty_(dirty_flag) {} 187 ConflictProgress::ConflictProgress(bool* dirty_flag) : dirty_(dirty_flag) {}
188 188
189 ConflictProgress::~ConflictProgress() { 189 ConflictProgress::~ConflictProgress() {
190 CleanupSets();
191 } 190 }
192 191
193 bool ConflictProgress::HasSimpleConflictItem(const syncable::Id& id) const { 192 bool ConflictProgress::HasSimpleConflictItem(const syncable::Id& id) const {
194 return conflicting_item_ids_.count(id) > 0 && 193 return conflicting_item_ids_.count(id) > 0;
195 (IdToConflictSetFind(id) == IdToConflictSetEnd());
196 }
197
198 IdToConflictSetMap::const_iterator ConflictProgress::IdToConflictSetFind(
199 const syncable::Id& the_id) const {
200 return id_to_conflict_set_.find(the_id);
201 }
202
203 IdToConflictSetMap::const_iterator
204 ConflictProgress::IdToConflictSetBegin() const {
205 return id_to_conflict_set_.begin();
206 }
207
208 IdToConflictSetMap::const_iterator
209 ConflictProgress::IdToConflictSetEnd() const {
210 return id_to_conflict_set_.end();
211 }
212
213 IdToConflictSetMap::size_type ConflictProgress::IdToConflictSetSize() const {
214 return id_to_conflict_set_.size();
215 }
216
217 const ConflictSet* ConflictProgress::IdToConflictSetGet(
218 const syncable::Id& the_id) {
219 return id_to_conflict_set_[the_id];
220 }
221
222 std::set<ConflictSet*>::const_iterator
223 ConflictProgress::ConflictSetsBegin() const {
224 return conflict_sets_.begin();
225 }
226
227 std::set<ConflictSet*>::const_iterator
228 ConflictProgress::ConflictSetsEnd() const {
229 return conflict_sets_.end();
230 }
231
232 std::set<ConflictSet*>::size_type
233 ConflictProgress::ConflictSetsSize() const {
234 return conflict_sets_.size();
235 } 194 }
236 195
237 std::set<syncable::Id>::const_iterator 196 std::set<syncable::Id>::const_iterator
238 ConflictProgress::ConflictingItemsBegin() const { 197 ConflictProgress::ConflictingItemsBegin() const {
239 return conflicting_item_ids_.begin(); 198 return conflicting_item_ids_.begin();
240 } 199 }
241 std::set<syncable::Id>::const_iterator 200 std::set<syncable::Id>::const_iterator
242 ConflictProgress::ConflictingItemsEnd() const { 201 ConflictProgress::ConflictingItemsEnd() const {
243 return conflicting_item_ids_.end(); 202 return conflicting_item_ids_.end();
244 } 203 }
(...skipping 12 matching lines...) Expand all
257 } 216 }
258 217
259 void ConflictProgress::AddNonblockingConflictingItemById( 218 void ConflictProgress::AddNonblockingConflictingItemById(
260 const syncable::Id& the_id) { 219 const syncable::Id& the_id) {
261 std::pair<std::set<syncable::Id>::iterator, bool> ret = 220 std::pair<std::set<syncable::Id>::iterator, bool> ret =
262 nonblocking_conflicting_item_ids_.insert(the_id); 221 nonblocking_conflicting_item_ids_.insert(the_id);
263 if (ret.second) 222 if (ret.second)
264 *dirty_ = true; 223 *dirty_ = true;
265 } 224 }
266 225
267 void ConflictProgress::EraseNonblockingConflictingItemById( 226 void ConflictProgress::AddHierarchyConflictingItemById(
268 const syncable::Id& the_id) { 227 const syncable::Id& the_id) {
269 int items_erased = nonblocking_conflicting_item_ids_.erase(the_id); 228 std::pair<std::set<syncable::Id>::iterator, bool> ret =
270 if (items_erased != 0) 229 hierarchy_conflicting_item_ids_.insert(the_id);
230 if (ret.second)
271 *dirty_ = true; 231 *dirty_ = true;
272 } 232 }
273 233
274 void ConflictProgress::MergeSets(const syncable::Id& id1,
275 const syncable::Id& id2) {
276 // There are no single item sets, we just leave those entries == 0
277 vector<syncable::Id>* set1 = id_to_conflict_set_[id1];
278 vector<syncable::Id>* set2 = id_to_conflict_set_[id2];
279 vector<syncable::Id>* rv = 0;
280 if (0 == set1 && 0 == set2) {
281 // Neither item currently has a set so we build one.
282 rv = new vector<syncable::Id>();
283 rv->push_back(id1);
284 if (id1 != id2) {
285 rv->push_back(id2);
286 } else {
287 LOG(WARNING) << "[BUG] Attempting to merge two identical conflict ids.";
288 }
289 conflict_sets_.insert(rv);
290 } else if (0 == set1) {
291 // Add the item to the existing set.
292 rv = set2;
293 rv->push_back(id1);
294 } else if (0 == set2) {
295 // Add the item to the existing set.
296 rv = set1;
297 rv->push_back(id2);
298 } else if (set1 == set2) {
299 // It's the same set already.
300 return;
301 } else {
302 // Merge the two sets.
303 rv = set1;
304 // Point all the second sets id's back to the first.
305 vector<syncable::Id>::iterator i;
306 for (i = set2->begin() ; i != set2->end() ; ++i) {
307 id_to_conflict_set_[*i] = rv;
308 }
309 // Copy the second set to the first.
310 rv->insert(rv->end(), set2->begin(), set2->end());
311 conflict_sets_.erase(set2);
312 delete set2;
313 }
314 id_to_conflict_set_[id1] = id_to_conflict_set_[id2] = rv;
315 }
316
317 void ConflictProgress::CleanupSets() {
318 // Clean up all the sets.
319 set<ConflictSet*>::iterator i;
320 for (i = conflict_sets_.begin(); i != conflict_sets_.end(); i++) {
321 delete *i;
322 }
323 conflict_sets_.clear();
324 id_to_conflict_set_.clear();
325 }
326
327 UpdateProgress::UpdateProgress() {} 234 UpdateProgress::UpdateProgress() {}
328 235
329 UpdateProgress::~UpdateProgress() {} 236 UpdateProgress::~UpdateProgress() {}
330 237
331 void UpdateProgress::AddVerifyResult(const VerifyResult& verify_result, 238 void UpdateProgress::AddVerifyResult(const VerifyResult& verify_result,
332 const sync_pb::SyncEntity& entity) { 239 const sync_pb::SyncEntity& entity) {
333 verified_updates_.push_back(std::make_pair(verify_result, entity)); 240 verified_updates_.push_back(std::make_pair(verify_result, entity));
334 } 241 }
335 242
336 void UpdateProgress::AddAppliedUpdate(const UpdateAttemptResponse& response, 243 void UpdateProgress::AddAppliedUpdate(const UpdateAttemptResponse& response,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 300
394 PerModelSafeGroupState::PerModelSafeGroupState(bool* dirty_flag) 301 PerModelSafeGroupState::PerModelSafeGroupState(bool* dirty_flag)
395 : conflict_progress(dirty_flag) { 302 : conflict_progress(dirty_flag) {
396 } 303 }
397 304
398 PerModelSafeGroupState::~PerModelSafeGroupState() { 305 PerModelSafeGroupState::~PerModelSafeGroupState() {
399 } 306 }
400 307
401 } // namespace sessions 308 } // namespace sessions
402 } // namespace browser_sync 309 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698