OLD | NEW |
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 const SyncerStatus& syncer_status, | 107 const SyncerStatus& syncer_status, |
108 const ErrorCounters& errors, | 108 const ErrorCounters& errors, |
109 int64 num_server_changes_remaining, | 109 int64 num_server_changes_remaining, |
110 bool is_share_usable, | 110 bool is_share_usable, |
111 syncable::ModelTypeSet initial_sync_ended, | 111 syncable::ModelTypeSet initial_sync_ended, |
112 const std::string | 112 const std::string |
113 (&download_progress_markers)[syncable::MODEL_TYPE_COUNT], | 113 (&download_progress_markers)[syncable::MODEL_TYPE_COUNT], |
114 bool more_to_sync, | 114 bool more_to_sync, |
115 bool is_silenced, | 115 bool is_silenced, |
116 int64 unsynced_count, | 116 int64 unsynced_count, |
117 int num_blocking_conflicting_updates, | 117 int num_simple_conflicting_updates, |
118 int num_conflicting_updates, | 118 int num_conflicting_updates, |
119 bool did_commit_items, | 119 bool did_commit_items, |
120 const SyncSourceInfo& source, | 120 const SyncSourceInfo& source, |
121 size_t num_entries, | 121 size_t num_entries, |
122 base::Time sync_start_time, | 122 base::Time sync_start_time, |
123 bool retry_scheduled) | 123 bool retry_scheduled) |
124 : syncer_status(syncer_status), | 124 : syncer_status(syncer_status), |
125 errors(errors), | 125 errors(errors), |
126 num_server_changes_remaining(num_server_changes_remaining), | 126 num_server_changes_remaining(num_server_changes_remaining), |
127 is_share_usable(is_share_usable), | 127 is_share_usable(is_share_usable), |
128 initial_sync_ended(initial_sync_ended), | 128 initial_sync_ended(initial_sync_ended), |
129 download_progress_markers(), | 129 download_progress_markers(), |
130 has_more_to_sync(more_to_sync), | 130 has_more_to_sync(more_to_sync), |
131 is_silenced(is_silenced), | 131 is_silenced(is_silenced), |
132 unsynced_count(unsynced_count), | 132 unsynced_count(unsynced_count), |
133 num_blocking_conflicting_updates(num_blocking_conflicting_updates), | 133 num_simple_conflicting_updates(num_simple_conflicting_updates), |
134 num_conflicting_updates(num_conflicting_updates), | 134 num_conflicting_updates(num_conflicting_updates), |
135 did_commit_items(did_commit_items), | 135 did_commit_items(did_commit_items), |
136 source(source), | 136 source(source), |
137 num_entries(num_entries), | 137 num_entries(num_entries), |
138 sync_start_time(sync_start_time), | 138 sync_start_time(sync_start_time), |
139 retry_scheduled(retry_scheduled) { | 139 retry_scheduled(retry_scheduled) { |
140 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 140 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
141 i < syncable::MODEL_TYPE_COUNT; ++i) { | 141 i < syncable::MODEL_TYPE_COUNT; ++i) { |
142 const_cast<std::string&>(this->download_progress_markers[i]).assign( | 142 const_cast<std::string&>(this->download_progress_markers[i]).assign( |
143 download_progress_markers[i]); | 143 download_progress_markers[i]); |
(...skipping 12 matching lines...) Expand all Loading... |
156 value->SetBoolean("isShareUsable", is_share_usable); | 156 value->SetBoolean("isShareUsable", is_share_usable); |
157 value->Set("initialSyncEnded", | 157 value->Set("initialSyncEnded", |
158 syncable::ModelTypeSetToValue(initial_sync_ended)); | 158 syncable::ModelTypeSetToValue(initial_sync_ended)); |
159 value->Set("downloadProgressMarkers", | 159 value->Set("downloadProgressMarkers", |
160 DownloadProgressMarkersToValue(download_progress_markers)); | 160 DownloadProgressMarkersToValue(download_progress_markers)); |
161 value->SetBoolean("hasMoreToSync", has_more_to_sync); | 161 value->SetBoolean("hasMoreToSync", has_more_to_sync); |
162 value->SetBoolean("isSilenced", is_silenced); | 162 value->SetBoolean("isSilenced", is_silenced); |
163 // We don't care too much if we lose precision here, also. | 163 // We don't care too much if we lose precision here, also. |
164 value->SetInteger("unsyncedCount", | 164 value->SetInteger("unsyncedCount", |
165 static_cast<int>(unsynced_count)); | 165 static_cast<int>(unsynced_count)); |
166 value->SetInteger("numBlockingConflictingUpdates", | 166 value->SetInteger("numSimpleConflictingUpdates", |
167 num_blocking_conflicting_updates); | 167 num_simple_conflicting_updates); |
168 value->SetInteger("numConflictingUpdates", num_conflicting_updates); | 168 value->SetInteger("numConflictingUpdates", num_conflicting_updates); |
169 value->SetBoolean("didCommitItems", did_commit_items); | 169 value->SetBoolean("didCommitItems", did_commit_items); |
170 value->SetInteger("numEntries", num_entries); | 170 value->SetInteger("numEntries", num_entries); |
171 value->Set("source", source.ToValue()); | 171 value->Set("source", source.ToValue()); |
172 return value; | 172 return value; |
173 } | 173 } |
174 | 174 |
175 std::string SyncSessionSnapshot::ToString() const { | 175 std::string SyncSessionSnapshot::ToString() const { |
176 scoped_ptr<DictionaryValue> value(ToValue()); | 176 scoped_ptr<DictionaryValue> value(ToValue()); |
177 std::string json; | 177 std::string json; |
178 base::JSONWriter::Write(value.get(), true, &json); | 178 base::JSONWriter::Write(value.get(), true, &json); |
179 return json; | 179 return json; |
180 } | 180 } |
181 | 181 |
182 ConflictProgress::ConflictProgress(bool* dirty_flag) : dirty_(dirty_flag) {} | 182 ConflictProgress::ConflictProgress(bool* dirty_flag) |
| 183 : num_server_conflicting_items(0), num_hierarchy_conflicting_items(0), |
| 184 num_encryption_conflicting_items(0), dirty_(dirty_flag) { |
| 185 } |
183 | 186 |
184 ConflictProgress::~ConflictProgress() { | 187 ConflictProgress::~ConflictProgress() { |
185 CleanupSets(); | |
186 } | 188 } |
187 | 189 |
188 bool ConflictProgress::HasSimpleConflictItem(const syncable::Id& id) const { | 190 bool ConflictProgress::HasSimpleConflictItem(const syncable::Id& id) const { |
189 return conflicting_item_ids_.count(id) > 0 && | 191 return simple_conflicting_item_ids_.count(id) > 0; |
190 (IdToConflictSetFind(id) == IdToConflictSetEnd()); | |
191 } | |
192 | |
193 IdToConflictSetMap::const_iterator ConflictProgress::IdToConflictSetFind( | |
194 const syncable::Id& the_id) const { | |
195 return id_to_conflict_set_.find(the_id); | |
196 } | |
197 | |
198 IdToConflictSetMap::const_iterator | |
199 ConflictProgress::IdToConflictSetBegin() const { | |
200 return id_to_conflict_set_.begin(); | |
201 } | |
202 | |
203 IdToConflictSetMap::const_iterator | |
204 ConflictProgress::IdToConflictSetEnd() const { | |
205 return id_to_conflict_set_.end(); | |
206 } | |
207 | |
208 IdToConflictSetMap::size_type ConflictProgress::IdToConflictSetSize() const { | |
209 return id_to_conflict_set_.size(); | |
210 } | |
211 | |
212 const ConflictSet* ConflictProgress::IdToConflictSetGet( | |
213 const syncable::Id& the_id) { | |
214 return id_to_conflict_set_[the_id]; | |
215 } | |
216 | |
217 std::set<ConflictSet*>::const_iterator | |
218 ConflictProgress::ConflictSetsBegin() const { | |
219 return conflict_sets_.begin(); | |
220 } | |
221 | |
222 std::set<ConflictSet*>::const_iterator | |
223 ConflictProgress::ConflictSetsEnd() const { | |
224 return conflict_sets_.end(); | |
225 } | |
226 | |
227 std::set<ConflictSet*>::size_type | |
228 ConflictProgress::ConflictSetsSize() const { | |
229 return conflict_sets_.size(); | |
230 } | 192 } |
231 | 193 |
232 std::set<syncable::Id>::const_iterator | 194 std::set<syncable::Id>::const_iterator |
233 ConflictProgress::ConflictingItemsBegin() const { | 195 ConflictProgress::SimpleConflictingItemsBegin() const { |
234 return conflicting_item_ids_.begin(); | 196 return simple_conflicting_item_ids_.begin(); |
235 } | 197 } |
236 std::set<syncable::Id>::const_iterator | 198 std::set<syncable::Id>::const_iterator |
237 ConflictProgress::ConflictingItemsEnd() const { | 199 ConflictProgress::SimpleConflictingItemsEnd() const { |
238 return conflicting_item_ids_.end(); | 200 return simple_conflicting_item_ids_.end(); |
239 } | 201 } |
240 | 202 |
241 void ConflictProgress::AddConflictingItemById(const syncable::Id& the_id) { | 203 void ConflictProgress::AddSimpleConflictingItemById( |
| 204 const syncable::Id& the_id) { |
242 std::pair<std::set<syncable::Id>::iterator, bool> ret = | 205 std::pair<std::set<syncable::Id>::iterator, bool> ret = |
243 conflicting_item_ids_.insert(the_id); | 206 simple_conflicting_item_ids_.insert(the_id); |
244 if (ret.second) | 207 if (ret.second) |
245 *dirty_ = true; | 208 *dirty_ = true; |
246 } | 209 } |
247 | 210 |
248 void ConflictProgress::EraseConflictingItemById(const syncable::Id& the_id) { | 211 void ConflictProgress::EraseSimpleConflictingItemById( |
249 int items_erased = conflicting_item_ids_.erase(the_id); | 212 const syncable::Id& the_id) { |
| 213 int items_erased = simple_conflicting_item_ids_.erase(the_id); |
250 if (items_erased != 0) | 214 if (items_erased != 0) |
251 *dirty_ = true; | 215 *dirty_ = true; |
252 } | 216 } |
253 | 217 |
254 void ConflictProgress::AddNonblockingConflictingItemById( | 218 void ConflictProgress::AddEncryptionConflictingItemById( |
255 const syncable::Id& the_id) { | 219 const syncable::Id& the_id) { |
256 std::pair<std::set<syncable::Id>::iterator, bool> ret = | 220 std::pair<std::set<syncable::Id>::iterator, bool> ret = |
257 nonblocking_conflicting_item_ids_.insert(the_id); | 221 unresolvable_conflicting_item_ids_.insert(the_id); |
258 if (ret.second) | 222 if (ret.second) { |
| 223 num_encryption_conflicting_items++; |
259 *dirty_ = true; | 224 *dirty_ = true; |
| 225 } |
260 } | 226 } |
261 | 227 |
262 void ConflictProgress::EraseNonblockingConflictingItemById( | 228 void ConflictProgress::AddHierarchyConflictingItemById( |
263 const syncable::Id& the_id) { | 229 const syncable::Id& the_id) { |
264 int items_erased = nonblocking_conflicting_item_ids_.erase(the_id); | 230 std::pair<std::set<syncable::Id>::iterator, bool> ret = |
265 if (items_erased != 0) | 231 unresolvable_conflicting_item_ids_.insert(the_id); |
| 232 if (ret.second) { |
| 233 num_hierarchy_conflicting_items++; |
266 *dirty_ = true; | 234 *dirty_ = true; |
| 235 } |
267 } | 236 } |
268 | 237 |
269 void ConflictProgress::MergeSets(const syncable::Id& id1, | 238 void ConflictProgress::AddServerConflictingItemById( |
270 const syncable::Id& id2) { | 239 const syncable::Id& the_id) { |
271 // There are no single item sets, we just leave those entries == 0 | 240 std::pair<std::set<syncable::Id>::iterator, bool> ret = |
272 vector<syncable::Id>* set1 = id_to_conflict_set_[id1]; | 241 unresolvable_conflicting_item_ids_.insert(the_id); |
273 vector<syncable::Id>* set2 = id_to_conflict_set_[id2]; | 242 if (ret.second) { |
274 vector<syncable::Id>* rv = 0; | 243 num_server_conflicting_items++; |
275 if (0 == set1 && 0 == set2) { | 244 *dirty_ = true; |
276 // Neither item currently has a set so we build one. | |
277 rv = new vector<syncable::Id>(); | |
278 rv->push_back(id1); | |
279 if (id1 != id2) { | |
280 rv->push_back(id2); | |
281 } else { | |
282 LOG(WARNING) << "[BUG] Attempting to merge two identical conflict ids."; | |
283 } | |
284 conflict_sets_.insert(rv); | |
285 } else if (0 == set1) { | |
286 // Add the item to the existing set. | |
287 rv = set2; | |
288 rv->push_back(id1); | |
289 } else if (0 == set2) { | |
290 // Add the item to the existing set. | |
291 rv = set1; | |
292 rv->push_back(id2); | |
293 } else if (set1 == set2) { | |
294 // It's the same set already. | |
295 return; | |
296 } else { | |
297 // Merge the two sets. | |
298 rv = set1; | |
299 // Point all the second sets id's back to the first. | |
300 vector<syncable::Id>::iterator i; | |
301 for (i = set2->begin() ; i != set2->end() ; ++i) { | |
302 id_to_conflict_set_[*i] = rv; | |
303 } | |
304 // Copy the second set to the first. | |
305 rv->insert(rv->end(), set2->begin(), set2->end()); | |
306 conflict_sets_.erase(set2); | |
307 delete set2; | |
308 } | 245 } |
309 id_to_conflict_set_[id1] = id_to_conflict_set_[id2] = rv; | |
310 } | |
311 | |
312 void ConflictProgress::CleanupSets() { | |
313 // Clean up all the sets. | |
314 set<ConflictSet*>::iterator i; | |
315 for (i = conflict_sets_.begin(); i != conflict_sets_.end(); i++) { | |
316 delete *i; | |
317 } | |
318 conflict_sets_.clear(); | |
319 id_to_conflict_set_.clear(); | |
320 } | 246 } |
321 | 247 |
322 UpdateProgress::UpdateProgress() {} | 248 UpdateProgress::UpdateProgress() {} |
323 | 249 |
324 UpdateProgress::~UpdateProgress() {} | 250 UpdateProgress::~UpdateProgress() {} |
325 | 251 |
326 void UpdateProgress::AddVerifyResult(const VerifyResult& verify_result, | 252 void UpdateProgress::AddVerifyResult(const VerifyResult& verify_result, |
327 const sync_pb::SyncEntity& entity) { | 253 const sync_pb::SyncEntity& entity) { |
328 verified_updates_.push_back(std::make_pair(verify_result, entity)); | 254 verified_updates_.push_back(std::make_pair(verify_result, entity)); |
329 } | 255 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 count++; | 288 count++; |
363 } | 289 } |
364 return count; | 290 return count; |
365 } | 291 } |
366 | 292 |
367 // Returns true if at least one update application failed due to a conflict | 293 // Returns true if at least one update application failed due to a conflict |
368 // during this sync cycle. | 294 // during this sync cycle. |
369 bool UpdateProgress::HasConflictingUpdates() const { | 295 bool UpdateProgress::HasConflictingUpdates() const { |
370 std::vector<AppliedUpdate>::const_iterator it; | 296 std::vector<AppliedUpdate>::const_iterator it; |
371 for (it = applied_updates_.begin(); it != applied_updates_.end(); ++it) { | 297 for (it = applied_updates_.begin(); it != applied_updates_.end(); ++it) { |
372 if (it->first == CONFLICT) { | 298 if (it->first != SUCCESS) { |
373 return true; | 299 return true; |
374 } | 300 } |
375 } | 301 } |
376 return false; | 302 return false; |
377 } | 303 } |
378 | 304 |
379 AllModelTypeState::AllModelTypeState(bool* dirty_flag) | 305 AllModelTypeState::AllModelTypeState(bool* dirty_flag) |
380 : unsynced_handles(dirty_flag), | 306 : unsynced_handles(dirty_flag), |
381 syncer_status(dirty_flag), | 307 syncer_status(dirty_flag), |
382 error(dirty_flag), | 308 error(dirty_flag), |
383 num_server_changes_remaining(dirty_flag, 0), | 309 num_server_changes_remaining(dirty_flag, 0), |
384 commit_set(ModelSafeRoutingInfo()) { | 310 commit_set(ModelSafeRoutingInfo()) { |
385 } | 311 } |
386 | 312 |
387 AllModelTypeState::~AllModelTypeState() {} | 313 AllModelTypeState::~AllModelTypeState() {} |
388 | 314 |
389 PerModelSafeGroupState::PerModelSafeGroupState(bool* dirty_flag) | 315 PerModelSafeGroupState::PerModelSafeGroupState(bool* dirty_flag) |
390 : conflict_progress(dirty_flag) { | 316 : conflict_progress(dirty_flag) { |
391 } | 317 } |
392 | 318 |
393 PerModelSafeGroupState::~PerModelSafeGroupState() { | 319 PerModelSafeGroupState::~PerModelSafeGroupState() { |
394 } | 320 } |
395 | 321 |
396 } // namespace sessions | 322 } // namespace sessions |
397 } // namespace browser_sync | 323 } // namespace browser_sync |
OLD | NEW |