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

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

Issue 386030: Relieve SyncerSession,SyncCycleState, SyncProcessState, SyncerSession, Syncer... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/sessions/session_state.h"
6
7 #include <set>
8 #include <vector>
9
10 using std::set;
11 using std::vector;
12
13 namespace browser_sync {
14 namespace sessions {
15
16 IdToConflictSetMap::const_iterator ConflictProgress::IdToConflictSetFind(
17 const syncable::Id& the_id) const {
18 return id_to_conflict_set_.find(the_id);
19 }
20
21 IdToConflictSetMap::const_iterator
22 ConflictProgress::IdToConflictSetBegin() const {
23 return id_to_conflict_set_.begin();
24 }
25
26 IdToConflictSetMap::const_iterator
27 ConflictProgress::IdToConflictSetEnd() const {
28 return id_to_conflict_set_.end();
29 }
30
31 IdToConflictSetMap::size_type ConflictProgress::IdToConflictSetSize() const {
32 return id_to_conflict_set_.size();
33 }
34
35 const ConflictSet* ConflictProgress::IdToConflictSetGet(
36 const syncable::Id& the_id) {
37 return id_to_conflict_set_[the_id];
38 }
39
40 std::set<ConflictSet*>::const_iterator
41 ConflictProgress::ConflictSetsBegin() const {
42 return conflict_sets_.begin();
43 }
44
45 std::set<ConflictSet*>::const_iterator
46 ConflictProgress::ConflictSetsEnd() const {
47 return conflict_sets_.end();
48 }
49
50 std::set<ConflictSet*>::size_type
51 ConflictProgress::ConflictSetsSize() const {
52 return conflict_sets_.size();
53 }
54
55 std::set<syncable::Id>::iterator
56 ConflictProgress::ConflictingItemsBegin() {
57 return conflicting_item_ids_.begin();
58 }
59 std::set<syncable::Id>::const_iterator
60 ConflictProgress::ConflictingItemsBeginConst() const {
61 return conflicting_item_ids_.begin();
62 }
63 std::set<syncable::Id>::const_iterator
64 ConflictProgress::ConflictingItemsEnd() const {
65 return conflicting_item_ids_.end();
66 }
67
68 void ConflictProgress::AddConflictingItemById(const syncable::Id& the_id) {
69 std::pair<std::set<syncable::Id>::iterator, bool> ret =
70 conflicting_item_ids_.insert(the_id);
71 progress_changed_ |= ret.second;
72 }
73
74 void ConflictProgress::EraseConflictingItemById(const syncable::Id& the_id) {
75 int items_erased = conflicting_item_ids_.erase(the_id);
76 progress_changed_ = items_erased != 0;
77 }
78
79 void ConflictProgress::MergeSets(const syncable::Id& id1,
80 const syncable::Id& id2) {
81 // There are no single item sets, we just leave those entries == 0
82 vector<syncable::Id>* set1 = id_to_conflict_set_[id1];
83 vector<syncable::Id>* set2 = id_to_conflict_set_[id2];
84 vector<syncable::Id>* rv = 0;
85 if (0 == set1 && 0 == set2) {
86 // Neither item currently has a set so we build one.
87 rv = new vector<syncable::Id>();
88 rv->push_back(id1);
89 if (id1 != id2) {
90 rv->push_back(id2);
91 } else {
92 LOG(WARNING) << "[BUG] Attempting to merge two identical conflict ids.";
93 }
94 conflict_sets_.insert(rv);
95 } else if (0 == set1) {
96 // Add the item to the existing set.
97 rv = set2;
98 rv->push_back(id1);
99 } else if (0 == set2) {
100 // Add the item to the existing set.
101 rv = set1;
102 rv->push_back(id2);
103 } else if (set1 == set2) {
104 // It's the same set already.
105 return;
106 } else {
107 // Merge the two sets.
108 rv = set1;
109 // Point all the second sets id's back to the first.
110 vector<syncable::Id>::iterator i;
111 for (i = set2->begin() ; i != set2->end() ; ++i) {
112 id_to_conflict_set_[*i] = rv;
113 }
114 // Copy the second set to the first.
115 rv->insert(rv->end(), set2->begin(), set2->end());
116 conflict_sets_.erase(set2);
117 delete set2;
118 }
119 id_to_conflict_set_[id1] = id_to_conflict_set_[id2] = rv;
120 }
121
122 void ConflictProgress::CleanupSets() {
123 // Clean up all the sets.
124 set<ConflictSet*>::iterator i;
125 for (i = conflict_sets_.begin(); i != conflict_sets_.end(); i++) {
126 delete *i;
127 }
128 conflict_sets_.clear();
129 id_to_conflict_set_.clear();
130 }
131
132 void UpdateProgress::AddVerifyResult(const VerifyResult& verify_result,
133 const sync_pb::SyncEntity& entity) {
134 verified_updates_.push_back(std::make_pair(verify_result, entity));
135 }
136
137 void UpdateProgress::AddAppliedUpdate(const UpdateAttemptResponse& response,
138 const syncable::Id& id) {
139 applied_updates_.push_back(std::make_pair(response, id));
140 }
141
142 std::vector<AppliedUpdate>::iterator UpdateProgress::AppliedUpdatesBegin() {
143 return applied_updates_.begin();
144 }
145
146 std::vector<VerifiedUpdate>::const_iterator
147 UpdateProgress::VerifiedUpdatesBegin() const {
148 return verified_updates_.begin();
149 }
150
151 std::vector<AppliedUpdate>::const_iterator
152 UpdateProgress::AppliedUpdatesEnd() const {
153 return applied_updates_.end();
154 }
155
156 std::vector<VerifiedUpdate>::const_iterator
157 UpdateProgress::VerifiedUpdatesEnd() const {
158 return verified_updates_.end();
159 }
160
161 int UpdateProgress::SuccessfullyAppliedUpdateCount() const {
162 int count = 0;
163 for (std::vector<AppliedUpdate>::const_iterator it =
164 applied_updates_.begin();
165 it != applied_updates_.end();
166 ++it) {
167 if (it->first == SUCCESS)
168 count++;
169 }
170 return count;
171 }
172
173 // Returns true if at least one update application failed due to a conflict
174 // during this sync cycle.
175 bool UpdateProgress::HasConflictingUpdates() const {
176 std::vector<AppliedUpdate>::const_iterator it;
177 for (it = applied_updates_.begin(); it != applied_updates_.end(); ++it) {
178 if (it->first == CONFLICT) {
179 return true;
180 }
181 }
182 return false;
183 }
184
185 } // namespace sessions
186 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions/session_state.h ('k') | chrome/browser/sync/sessions/status_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698