| 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 // 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. | |
| 11 | |
| 12 #ifndef SYNC_SESSIONS_SESSION_STATE_H_ | |
| 13 #define SYNC_SESSIONS_SESSION_STATE_H_ | |
| 14 | |
| 15 #include <set> | |
| 16 #include <vector> | |
| 17 | |
| 18 #include "sync/engine/syncer_types.h" | |
| 19 #include "sync/protocol/sync.pb.h" | |
| 20 #include "sync/syncable/syncable_id.h" | |
| 21 | |
| 22 namespace syncer { | |
| 23 namespace sessions { | |
| 24 | |
| 25 // Tracks progress of conflicts and their resolutions. | |
| 26 class ConflictProgress { | |
| 27 public: | |
| 28 explicit ConflictProgress(); | |
| 29 ~ConflictProgress(); | |
| 30 | |
| 31 bool HasSimpleConflictItem(const syncable::Id &id) const; | |
| 32 | |
| 33 // Various mutators for tracking commit conflicts. | |
| 34 void AddSimpleConflictingItemById(const syncable::Id& the_id); | |
| 35 void EraseSimpleConflictingItemById(const syncable::Id& the_id); | |
| 36 std::set<syncable::Id>::const_iterator SimpleConflictingItemsBegin() const; | |
| 37 std::set<syncable::Id>::const_iterator SimpleConflictingItemsEnd() const; | |
| 38 int SimpleConflictingItemsSize() const { | |
| 39 return simple_conflicting_item_ids_.size(); | |
| 40 } | |
| 41 | |
| 42 // Mutators for unresolvable conflicting items (see description below). | |
| 43 void AddEncryptionConflictingItemById(const syncable::Id& the_id); | |
| 44 int EncryptionConflictingItemsSize() const { | |
| 45 return num_encryption_conflicting_items; | |
| 46 } | |
| 47 | |
| 48 void AddHierarchyConflictingItemById(const syncable::Id& id); | |
| 49 int HierarchyConflictingItemsSize() const { | |
| 50 return num_hierarchy_conflicting_items; | |
| 51 } | |
| 52 | |
| 53 void AddServerConflictingItemById(const syncable::Id& id); | |
| 54 int ServerConflictingItemsSize() const { | |
| 55 return num_server_conflicting_items; | |
| 56 } | |
| 57 | |
| 58 private: | |
| 59 // Conflicts that occur when local and server changes collide and can be | |
| 60 // resolved locally. | |
| 61 std::set<syncable::Id> simple_conflicting_item_ids_; | |
| 62 | |
| 63 // Unresolvable conflicts are not processed by the conflict resolver. We wait | |
| 64 // and hope the server will provide us with an update that resolves these | |
| 65 // conflicts. | |
| 66 std::set<syncable::Id> unresolvable_conflicting_item_ids_; | |
| 67 | |
| 68 size_t num_server_conflicting_items; | |
| 69 size_t num_hierarchy_conflicting_items; | |
| 70 size_t num_encryption_conflicting_items; | |
| 71 }; | |
| 72 | |
| 73 typedef std::pair<VerifyResult, sync_pb::SyncEntity> VerifiedUpdate; | |
| 74 typedef std::pair<UpdateAttemptResponse, syncable::Id> AppliedUpdate; | |
| 75 | |
| 76 // Tracks update application and verification. | |
| 77 class UpdateProgress { | |
| 78 public: | |
| 79 UpdateProgress(); | |
| 80 ~UpdateProgress(); | |
| 81 | |
| 82 void AddVerifyResult(const VerifyResult& verify_result, | |
| 83 const sync_pb::SyncEntity& entity); | |
| 84 | |
| 85 // Log a successful or failing update attempt. | |
| 86 void AddAppliedUpdate(const UpdateAttemptResponse& response, | |
| 87 const syncable::Id& id); | |
| 88 | |
| 89 // Various iterators. | |
| 90 std::vector<AppliedUpdate>::iterator AppliedUpdatesBegin(); | |
| 91 std::vector<VerifiedUpdate>::const_iterator VerifiedUpdatesBegin() const; | |
| 92 std::vector<AppliedUpdate>::const_iterator AppliedUpdatesEnd() const; | |
| 93 std::vector<VerifiedUpdate>::const_iterator VerifiedUpdatesEnd() const; | |
| 94 | |
| 95 // Returns the number of update application attempts. This includes both | |
| 96 // failures and successes. | |
| 97 int AppliedUpdatesSize() const { return applied_updates_.size(); } | |
| 98 int VerifiedUpdatesSize() const { return verified_updates_.size(); } | |
| 99 bool HasVerifiedUpdates() const { return !verified_updates_.empty(); } | |
| 100 bool HasAppliedUpdates() const { return !applied_updates_.empty(); } | |
| 101 void ClearVerifiedUpdates() { verified_updates_.clear(); } | |
| 102 | |
| 103 // Count the number of successful update applications that have happend this | |
| 104 // cycle. Note that if an item is successfully applied twice, it will be | |
| 105 // double counted here. | |
| 106 int SuccessfullyAppliedUpdateCount() const; | |
| 107 | |
| 108 // Returns true if at least one update application failed due to a conflict | |
| 109 // during this sync cycle. | |
| 110 bool HasConflictingUpdates() const; | |
| 111 | |
| 112 private: | |
| 113 // Container for updates that passed verification. | |
| 114 std::vector<VerifiedUpdate> verified_updates_; | |
| 115 | |
| 116 // Stores the result of the various ApplyUpdate attempts we've made. | |
| 117 // May contain duplicate entries. | |
| 118 std::vector<AppliedUpdate> applied_updates_; | |
| 119 }; | |
| 120 | |
| 121 // Grouping of all state that applies to a single ModelSafeGroup. | |
| 122 struct PerModelSafeGroupState { | |
| 123 explicit PerModelSafeGroupState(); | |
| 124 ~PerModelSafeGroupState(); | |
| 125 | |
| 126 UpdateProgress update_progress; | |
| 127 ConflictProgress conflict_progress; | |
| 128 }; | |
| 129 | |
| 130 } // namespace sessions | |
| 131 } // namespace syncer | |
| 132 | |
| 133 #endif // SYNC_SESSIONS_SESSION_STATE_H_ | |
| OLD | NEW |