| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sync/sessions/session_state.h" | |
| 6 | |
| 7 #include <set> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/values.h" | |
| 12 | |
| 13 using std::set; | |
| 14 using std::vector; | |
| 15 | |
| 16 namespace syncer { | |
| 17 namespace sessions { | |
| 18 | |
| 19 ConflictProgress::ConflictProgress() | |
| 20 : num_server_conflicting_items(0), num_hierarchy_conflicting_items(0), | |
| 21 num_encryption_conflicting_items(0) { | |
| 22 } | |
| 23 | |
| 24 ConflictProgress::~ConflictProgress() { | |
| 25 } | |
| 26 | |
| 27 bool ConflictProgress::HasSimpleConflictItem(const syncable::Id& id) const { | |
| 28 return simple_conflicting_item_ids_.count(id) > 0; | |
| 29 } | |
| 30 | |
| 31 std::set<syncable::Id>::const_iterator | |
| 32 ConflictProgress::SimpleConflictingItemsBegin() const { | |
| 33 return simple_conflicting_item_ids_.begin(); | |
| 34 } | |
| 35 std::set<syncable::Id>::const_iterator | |
| 36 ConflictProgress::SimpleConflictingItemsEnd() const { | |
| 37 return simple_conflicting_item_ids_.end(); | |
| 38 } | |
| 39 | |
| 40 void ConflictProgress::AddSimpleConflictingItemById( | |
| 41 const syncable::Id& the_id) { | |
| 42 simple_conflicting_item_ids_.insert(the_id); | |
| 43 } | |
| 44 | |
| 45 void ConflictProgress::EraseSimpleConflictingItemById( | |
| 46 const syncable::Id& the_id) { | |
| 47 simple_conflicting_item_ids_.erase(the_id); | |
| 48 } | |
| 49 | |
| 50 void ConflictProgress::AddEncryptionConflictingItemById( | |
| 51 const syncable::Id& the_id) { | |
| 52 std::pair<std::set<syncable::Id>::iterator, bool> ret = | |
| 53 unresolvable_conflicting_item_ids_.insert(the_id); | |
| 54 if (ret.second) { | |
| 55 num_encryption_conflicting_items++; | |
| 56 } | |
| 57 unresolvable_conflicting_item_ids_.insert(the_id); | |
| 58 } | |
| 59 | |
| 60 void ConflictProgress::AddHierarchyConflictingItemById( | |
| 61 const syncable::Id& the_id) { | |
| 62 std::pair<std::set<syncable::Id>::iterator, bool> ret = | |
| 63 unresolvable_conflicting_item_ids_.insert(the_id); | |
| 64 if (ret.second) { | |
| 65 num_hierarchy_conflicting_items++; | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void ConflictProgress::AddServerConflictingItemById( | |
| 70 const syncable::Id& the_id) { | |
| 71 std::pair<std::set<syncable::Id>::iterator, bool> ret = | |
| 72 unresolvable_conflicting_item_ids_.insert(the_id); | |
| 73 if (ret.second) { | |
| 74 num_server_conflicting_items++; | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 UpdateProgress::UpdateProgress() {} | |
| 79 | |
| 80 UpdateProgress::~UpdateProgress() {} | |
| 81 | |
| 82 void UpdateProgress::AddVerifyResult(const VerifyResult& verify_result, | |
| 83 const sync_pb::SyncEntity& entity) { | |
| 84 verified_updates_.push_back(std::make_pair(verify_result, entity)); | |
| 85 } | |
| 86 | |
| 87 void UpdateProgress::AddAppliedUpdate(const UpdateAttemptResponse& response, | |
| 88 const syncable::Id& id) { | |
| 89 applied_updates_.push_back(std::make_pair(response, id)); | |
| 90 } | |
| 91 | |
| 92 std::vector<AppliedUpdate>::iterator UpdateProgress::AppliedUpdatesBegin() { | |
| 93 return applied_updates_.begin(); | |
| 94 } | |
| 95 | |
| 96 std::vector<VerifiedUpdate>::const_iterator | |
| 97 UpdateProgress::VerifiedUpdatesBegin() const { | |
| 98 return verified_updates_.begin(); | |
| 99 } | |
| 100 | |
| 101 std::vector<AppliedUpdate>::const_iterator | |
| 102 UpdateProgress::AppliedUpdatesEnd() const { | |
| 103 return applied_updates_.end(); | |
| 104 } | |
| 105 | |
| 106 std::vector<VerifiedUpdate>::const_iterator | |
| 107 UpdateProgress::VerifiedUpdatesEnd() const { | |
| 108 return verified_updates_.end(); | |
| 109 } | |
| 110 | |
| 111 int UpdateProgress::SuccessfullyAppliedUpdateCount() const { | |
| 112 int count = 0; | |
| 113 for (std::vector<AppliedUpdate>::const_iterator it = | |
| 114 applied_updates_.begin(); | |
| 115 it != applied_updates_.end(); | |
| 116 ++it) { | |
| 117 if (it->first == SUCCESS) | |
| 118 count++; | |
| 119 } | |
| 120 return count; | |
| 121 } | |
| 122 | |
| 123 // Returns true if at least one update application failed due to a conflict | |
| 124 // during this sync cycle. | |
| 125 bool UpdateProgress::HasConflictingUpdates() const { | |
| 126 std::vector<AppliedUpdate>::const_iterator it; | |
| 127 for (it = applied_updates_.begin(); it != applied_updates_.end(); ++it) { | |
| 128 if (it->first != SUCCESS) { | |
| 129 return true; | |
| 130 } | |
| 131 } | |
| 132 return false; | |
| 133 } | |
| 134 | |
| 135 PerModelSafeGroupState::PerModelSafeGroupState() { | |
| 136 } | |
| 137 | |
| 138 PerModelSafeGroupState::~PerModelSafeGroupState() { | |
| 139 } | |
| 140 | |
| 141 } // namespace sessions | |
| 142 } // namespace syncer | |
| OLD | NEW |