chromeos: Fix StartupBrowserCreatorImpl::Launch crash.
[chromium-blink-merge.git] / sync / sessions / session_state.cc
blobcd998004b879f5c09fff28eaad33994c0111f2f1
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"
7 #include <set>
8 #include <vector>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/values.h"
13 using std::set;
14 using std::vector;
16 namespace syncer {
17 namespace sessions {
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);
54 if (ret.second) {
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);
64 if (ret.second) {
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);
73 if (ret.second) {
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 {
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++;
120 return count;
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;
132 return false;
135 PerModelSafeGroupState::PerModelSafeGroupState() {
138 PerModelSafeGroupState::~PerModelSafeGroupState() {
141 } // namespace sessions
142 } // namespace syncer