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 // The 'sessions' namespace comprises all the pieces of state that are
6 // combined to form a SyncSession instance. In that way, it can be thought of
7 // as an extension of the SyncSession type itself. Session scoping gives
8 // context to things like "conflict progress", "update progress", etc, and the
9 // separation this file provides allows clients to only include the parts they
10 // need rather than the entire session stack.
12 #ifndef SYNC_SESSIONS_SESSION_STATE_H_
13 #define SYNC_SESSIONS_SESSION_STATE_H_
18 #include "sync/engine/syncer_types.h"
19 #include "sync/protocol/sync.pb.h"
20 #include "sync/syncable/syncable_id.h"
25 typedef std::pair
<VerifyResult
, sync_pb::SyncEntity
> VerifiedUpdate
;
26 typedef std::pair
<UpdateAttemptResponse
, syncable::Id
> AppliedUpdate
;
28 // Tracks update application and verification.
29 class UpdateProgress
{
34 void AddVerifyResult(const VerifyResult
& verify_result
,
35 const sync_pb::SyncEntity
& entity
);
37 // Log a successful or failing update attempt.
38 void AddAppliedUpdate(const UpdateAttemptResponse
& response
,
39 const syncable::Id
& id
);
42 std::vector
<AppliedUpdate
>::iterator
AppliedUpdatesBegin();
43 std::vector
<VerifiedUpdate
>::const_iterator
VerifiedUpdatesBegin() const;
44 std::vector
<AppliedUpdate
>::const_iterator
AppliedUpdatesEnd() const;
45 std::vector
<VerifiedUpdate
>::const_iterator
VerifiedUpdatesEnd() const;
47 // Returns the number of update application attempts. This includes both
48 // failures and successes.
49 int AppliedUpdatesSize() const { return applied_updates_
.size(); }
50 int VerifiedUpdatesSize() const { return verified_updates_
.size(); }
51 bool HasVerifiedUpdates() const { return !verified_updates_
.empty(); }
52 bool HasAppliedUpdates() const { return !applied_updates_
.empty(); }
53 void ClearVerifiedUpdates() { verified_updates_
.clear(); }
55 // Count the number of successful update applications that have happend this
56 // cycle. Note that if an item is successfully applied twice, it will be
57 // double counted here.
58 int SuccessfullyAppliedUpdateCount() const;
60 // Returns true if at least one update application failed due to a conflict
61 // during this sync cycle.
62 bool HasConflictingUpdates() const;
65 // Container for updates that passed verification.
66 std::vector
<VerifiedUpdate
> verified_updates_
;
68 // Stores the result of the various ApplyUpdate attempts we've made.
69 // May contain duplicate entries.
70 std::vector
<AppliedUpdate
> applied_updates_
;
73 // Grouping of all state that applies to a single ModelSafeGroup.
74 struct PerModelSafeGroupState
{
75 explicit PerModelSafeGroupState();
76 ~PerModelSafeGroupState();
78 UpdateProgress update_progress
;
79 std::set
<syncable::Id
> simple_conflict_ids
;
82 } // namespace sessions
85 #endif // SYNC_SESSIONS_SESSION_STATE_H_