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

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

Issue 8638001: [Sync] Made some sync session member functions const (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix latent bug in StatusController Created 9 years, 1 month 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/build_and_process_conflict_sets_command.h" 5 #include "chrome/browser/sync/engine/build_and_process_conflict_sets_command.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <sstream> 9 #include <sstream>
10 #include <vector> 10 #include <vector>
(...skipping 14 matching lines...) Expand all
25 using sessions::UpdateProgress; 25 using sessions::UpdateProgress;
26 using std::set; 26 using std::set;
27 using std::string; 27 using std::string;
28 using std::vector; 28 using std::vector;
29 29
30 BuildAndProcessConflictSetsCommand::BuildAndProcessConflictSetsCommand() {} 30 BuildAndProcessConflictSetsCommand::BuildAndProcessConflictSetsCommand() {}
31 BuildAndProcessConflictSetsCommand::~BuildAndProcessConflictSetsCommand() {} 31 BuildAndProcessConflictSetsCommand::~BuildAndProcessConflictSetsCommand() {}
32 32
33 void BuildAndProcessConflictSetsCommand::ModelChangingExecuteImpl( 33 void BuildAndProcessConflictSetsCommand::ModelChangingExecuteImpl(
34 SyncSession* session) { 34 SyncSession* session) {
35 session->status_controller()->update_conflict_sets_built( 35 session->mutable_status_controller()->update_conflict_sets_built(
36 BuildAndProcessConflictSets(session)); 36 BuildAndProcessConflictSets(session));
37 } 37 }
38 38
39 bool BuildAndProcessConflictSetsCommand::BuildAndProcessConflictSets( 39 bool BuildAndProcessConflictSetsCommand::BuildAndProcessConflictSets(
40 SyncSession* session) { 40 SyncSession* session) {
41 syncable::ScopedDirLookup dir(session->context()->directory_manager(), 41 syncable::ScopedDirLookup dir(session->context()->directory_manager(),
42 session->context()->account_name()); 42 session->context()->account_name());
43 if (!dir.good()) 43 if (!dir.good())
44 return false; 44 return false;
45 bool had_single_direction_sets = false; 45 bool had_single_direction_sets = false;
46 { // Scope for transaction. 46 { // Scope for transaction.
47 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir); 47 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir);
48 BuildConflictSets(&trans, 48 BuildConflictSets(&trans,
49 session->status_controller()->mutable_conflict_progress()); 49 session->mutable_status_controller()->mutable_conflict_progress());
50 had_single_direction_sets = ProcessSingleDirectionConflictSets(&trans, 50 had_single_direction_sets = ProcessSingleDirectionConflictSets(&trans,
51 session->context()->resolver(), 51 session->context()->resolver(),
52 session->context()->directory_manager()->GetCryptographer(&trans), 52 session->context()->directory_manager()->GetCryptographer(&trans),
53 session->status_controller(), session->routing_info()); 53 session->mutable_status_controller(), session->routing_info());
54 // We applied some updates transactionally, lets try syncing again. 54 // We applied some updates transactionally, lets try syncing again.
55 if (had_single_direction_sets) 55 if (had_single_direction_sets)
56 return true; 56 return true;
57 } 57 }
58 return false; 58 return false;
59 } 59 }
60 60
61 bool BuildAndProcessConflictSetsCommand::ProcessSingleDirectionConflictSets( 61 bool BuildAndProcessConflictSetsCommand::ProcessSingleDirectionConflictSets(
62 syncable::WriteTransaction* trans, ConflictResolver* resolver, 62 syncable::WriteTransaction* trans, ConflictResolver* resolver,
63 Cryptographer* cryptographer, StatusController* status, 63 Cryptographer* cryptographer, StatusController* status,
64 const ModelSafeRoutingInfo& routes) { 64 const ModelSafeRoutingInfo& routes) {
65 if (!status->conflict_progress())
66 return false;
65 bool rv = false; 67 bool rv = false;
66 set<ConflictSet*>::const_iterator all_sets_iterator; 68 set<ConflictSet*>::const_iterator all_sets_iterator;
67 for (all_sets_iterator = status->conflict_progress().ConflictSetsBegin(); 69 for (all_sets_iterator = status->conflict_progress()->ConflictSetsBegin();
68 all_sets_iterator != status->conflict_progress().ConflictSetsEnd();) { 70 all_sets_iterator != status->conflict_progress()->ConflictSetsEnd();) {
69 const ConflictSet* conflict_set = *all_sets_iterator; 71 const ConflictSet* conflict_set = *all_sets_iterator;
70 CHECK_GE(conflict_set->size(), 2U); 72 CHECK_GE(conflict_set->size(), 2U);
71 // We scan the set to see if it consists of changes of only one type. 73 // We scan the set to see if it consists of changes of only one type.
72 ConflictSet::const_iterator i; 74 ConflictSet::const_iterator i;
73 size_t unsynced_count = 0, unapplied_count = 0; 75 size_t unsynced_count = 0, unapplied_count = 0;
74 for (i = conflict_set->begin(); i != conflict_set->end(); ++i) { 76 for (i = conflict_set->begin(); i != conflict_set->end(); ++i) {
75 syncable::Entry entry(trans, syncable::GET_BY_ID, *i); 77 syncable::Entry entry(trans, syncable::GET_BY_ID, *i);
76 CHECK(entry.good()); 78 CHECK(entry.good());
77 if (entry.Get(syncable::IS_UNSYNCED)) 79 if (entry.Get(syncable::IS_UNSYNCED))
78 unsynced_count++; 80 unsynced_count++;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 222 }
221 applicator.SaveProgressIntoSessionState(status->mutable_conflict_progress(), 223 applicator.SaveProgressIntoSessionState(status->mutable_conflict_progress(),
222 status->mutable_update_progress()); 224 status->mutable_update_progress());
223 return true; 225 return true;
224 } 226 }
225 227
226 void BuildAndProcessConflictSetsCommand::BuildConflictSets( 228 void BuildAndProcessConflictSetsCommand::BuildConflictSets(
227 syncable::BaseTransaction* trans, 229 syncable::BaseTransaction* trans,
228 ConflictProgress* conflict_progress) { 230 ConflictProgress* conflict_progress) {
229 conflict_progress->CleanupSets(); 231 conflict_progress->CleanupSets();
230 set<syncable::Id>::iterator i = conflict_progress->ConflictingItemsBegin(); 232 set<syncable::Id>::const_iterator i =
233 conflict_progress->ConflictingItemsBegin();
231 while (i != conflict_progress->ConflictingItemsEnd()) { 234 while (i != conflict_progress->ConflictingItemsEnd()) {
232 syncable::Entry entry(trans, syncable::GET_BY_ID, *i); 235 syncable::Entry entry(trans, syncable::GET_BY_ID, *i);
233 if (!entry.good() || 236 if (!entry.good() ||
234 (!entry.Get(syncable::IS_UNSYNCED) && 237 (!entry.Get(syncable::IS_UNSYNCED) &&
235 !entry.Get(syncable::IS_UNAPPLIED_UPDATE))) { 238 !entry.Get(syncable::IS_UNAPPLIED_UPDATE))) {
236 // This can happen very rarely. It means we had a simply conflicting item 239 // This can happen very rarely. It means we had a simply conflicting item
237 // that randomly committed; its ID could have changed during the commit. 240 // that randomly committed; its ID could have changed during the commit.
238 // We drop the entry as it's no longer conflicting. 241 // We drop the entry as it's no longer conflicting.
239 conflict_progress->EraseConflictingItemById(*(i++)); 242 conflict_progress->EraseConflictingItemById(*(i++));
240 continue; 243 continue;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 LocallyDeletedPathChecker checker; 405 LocallyDeletedPathChecker checker;
403 if (!checker.CausingConflict(parent, *entry)) 406 if (!checker.CausingConflict(parent, *entry))
404 return; 407 return;
405 conflict_progress->MergeSets(entry->Get(syncable::ID), 408 conflict_progress->MergeSets(entry->Get(syncable::ID),
406 parent.Get(syncable::ID)); 409 parent.Get(syncable::ID));
407 CrawlDeletedTreeMergingSets(trans, parent, conflict_progress, checker); 410 CrawlDeletedTreeMergingSets(trans, parent, conflict_progress, checker);
408 } 411 }
409 } 412 }
410 413
411 } // namespace browser_sync 414 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/apply_updates_command_unittest.cc ('k') | chrome/browser/sync/engine/build_commit_command.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698