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.
5 #include "sync/sessions/session_state.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/values.h"
19 ConflictProgress::ConflictProgress()
20 : num_server_conflicting_items(0), num_hierarchy_conflicting_items(0),
21 num_encryption_conflicting_items(0) {
24 ConflictProgress::~ConflictProgress() {
27 bool ConflictProgress::HasSimpleConflictItem(const syncable::Id
& id
) const {
28 return simple_conflicting_item_ids_
.count(id
) > 0;
31 std::set
<syncable::Id
>::const_iterator
32 ConflictProgress::SimpleConflictingItemsBegin() const {
33 return simple_conflicting_item_ids_
.begin();
35 std::set
<syncable::Id
>::const_iterator
36 ConflictProgress::SimpleConflictingItemsEnd() const {
37 return simple_conflicting_item_ids_
.end();
40 void ConflictProgress::AddSimpleConflictingItemById(
41 const syncable::Id
& the_id
) {
42 simple_conflicting_item_ids_
.insert(the_id
);
45 void ConflictProgress::EraseSimpleConflictingItemById(
46 const syncable::Id
& the_id
) {
47 simple_conflicting_item_ids_
.erase(the_id
);
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
);
55 num_encryption_conflicting_items
++;
57 unresolvable_conflicting_item_ids_
.insert(the_id
);
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
);
65 num_hierarchy_conflicting_items
++;
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
);
74 num_server_conflicting_items
++;
78 UpdateProgress::UpdateProgress() {}
80 UpdateProgress::~UpdateProgress() {}
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
));
87 void UpdateProgress::AddAppliedUpdate(const UpdateAttemptResponse
& response
,
88 const syncable::Id
& id
) {
89 applied_updates_
.push_back(std::make_pair(response
, id
));
92 std::vector
<AppliedUpdate
>::iterator
UpdateProgress::AppliedUpdatesBegin() {
93 return applied_updates_
.begin();
96 std::vector
<VerifiedUpdate
>::const_iterator
97 UpdateProgress::VerifiedUpdatesBegin() const {
98 return verified_updates_
.begin();
101 std::vector
<AppliedUpdate
>::const_iterator
102 UpdateProgress::AppliedUpdatesEnd() const {
103 return applied_updates_
.end();
106 std::vector
<VerifiedUpdate
>::const_iterator
107 UpdateProgress::VerifiedUpdatesEnd() const {
108 return verified_updates_
.end();
111 int UpdateProgress::SuccessfullyAppliedUpdateCount() const {
113 for (std::vector
<AppliedUpdate
>::const_iterator it
=
114 applied_updates_
.begin();
115 it
!= applied_updates_
.end();
117 if (it
->first
== SUCCESS
)
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
) {
135 PerModelSafeGroupState::PerModelSafeGroupState() {
138 PerModelSafeGroupState::~PerModelSafeGroupState() {
141 } // namespace sessions
142 } // namespace syncer