#ifndef SYNC_SESSIONS_SESSION_STATE_H_
#define SYNC_SESSIONS_SESSION_STATE_H_
#include <set>
#include <vector>
#include "sync/engine/syncer_types.h"
#include "sync/protocol/sync.pb.h"
#include "sync/syncable/syncable_id.h"
namespace syncer {
namespace sessions {
class ConflictProgress {
public:
explicit ConflictProgress();
~ConflictProgress();
bool HasSimpleConflictItem(const syncable::Id &id) const;
void AddSimpleConflictingItemById(const syncable::Id& the_id);
void EraseSimpleConflictingItemById(const syncable::Id& the_id);
std::set<syncable::Id>::const_iterator SimpleConflictingItemsBegin() const;
std::set<syncable::Id>::const_iterator SimpleConflictingItemsEnd() const;
int SimpleConflictingItemsSize() const {
return simple_conflicting_item_ids_.size();
}
void AddEncryptionConflictingItemById(const syncable::Id& the_id);
int EncryptionConflictingItemsSize() const {
return num_encryption_conflicting_items;
}
void AddHierarchyConflictingItemById(const syncable::Id& id);
int HierarchyConflictingItemsSize() const {
return num_hierarchy_conflicting_items;
}
void AddServerConflictingItemById(const syncable::Id& id);
int ServerConflictingItemsSize() const {
return num_server_conflicting_items;
}
private:
std::set<syncable::Id> simple_conflicting_item_ids_;
std::set<syncable::Id> unresolvable_conflicting_item_ids_;
size_t num_server_conflicting_items;
size_t num_hierarchy_conflicting_items;
size_t num_encryption_conflicting_items;
};
typedef std::pair<VerifyResult, sync_pb::SyncEntity> VerifiedUpdate;
typedef std::pair<UpdateAttemptResponse, syncable::Id> AppliedUpdate;
class UpdateProgress {
public:
UpdateProgress();
~UpdateProgress();
void AddVerifyResult(const VerifyResult& verify_result,
const sync_pb::SyncEntity& entity);
void AddAppliedUpdate(const UpdateAttemptResponse& response,
const syncable::Id& id);
std::vector<AppliedUpdate>::iterator AppliedUpdatesBegin();
std::vector<VerifiedUpdate>::const_iterator VerifiedUpdatesBegin() const;
std::vector<AppliedUpdate>::const_iterator AppliedUpdatesEnd() const;
std::vector<VerifiedUpdate>::const_iterator VerifiedUpdatesEnd() const;
int AppliedUpdatesSize() const { return applied_updates_.size(); }
int VerifiedUpdatesSize() const { return verified_updates_.size(); }
bool HasVerifiedUpdates() const { return !verified_updates_.empty(); }
bool HasAppliedUpdates() const { return !applied_updates_.empty(); }
void ClearVerifiedUpdates() { verified_updates_.clear(); }
int SuccessfullyAppliedUpdateCount() const;
bool HasConflictingUpdates() const;
private:
std::vector<VerifiedUpdate> verified_updates_;
std::vector<AppliedUpdate> applied_updates_;
};
struct PerModelSafeGroupState {
explicit PerModelSafeGroupState();
~PerModelSafeGroupState();
UpdateProgress update_progress;
ConflictProgress conflict_progress;
};
}
}
#endif