| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // The 'sessions' namespace comprises all the pieces of state that are | 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 | 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 | 7 // as an extension of the SyncSession type itself. Session scoping gives |
| 8 // context to things like "conflict progress", "update progress", etc, and the | 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 | 9 // separation this file provides allows clients to only include the parts they |
| 10 // need rather than the entire session stack. | 10 // need rather than the entire session stack. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // points to StatusController::is_dirty_. | 206 // points to StatusController::is_dirty_. |
| 207 bool* dirty_; | 207 bool* dirty_; |
| 208 }; | 208 }; |
| 209 | 209 |
| 210 typedef std::pair<VerifyResult, sync_pb::SyncEntity> VerifiedUpdate; | 210 typedef std::pair<VerifyResult, sync_pb::SyncEntity> VerifiedUpdate; |
| 211 typedef std::pair<UpdateAttemptResponse, syncable::Id> AppliedUpdate; | 211 typedef std::pair<UpdateAttemptResponse, syncable::Id> AppliedUpdate; |
| 212 | 212 |
| 213 // Tracks update application and verification. | 213 // Tracks update application and verification. |
| 214 class UpdateProgress { | 214 class UpdateProgress { |
| 215 public: | 215 public: |
| 216 UpdateProgress(); | 216 UpdateProgress(ModelSafeGroup group, const ModelSafeRoutingInfo& routes); |
| 217 ~UpdateProgress(); | 217 ~UpdateProgress(); |
| 218 | 218 |
| 219 void AddVerifyResult(const VerifyResult& verify_result, | 219 void AddVerifyResult(const VerifyResult& verify_result, |
| 220 const sync_pb::SyncEntity& entity); | 220 const sync_pb::SyncEntity& entity); |
| 221 | 221 |
| 222 // Log a successful or failing update attempt. | 222 // Log a successful or failing update attempt. |
| 223 void AddAppliedUpdate(const UpdateAttemptResponse& response, | 223 void AddAppliedUpdate(const UpdateAttemptResponse& response, |
| 224 const syncable::Id& id); | 224 const syncable::Id& id); |
| 225 | 225 |
| 226 // Fills our unapplied updates state from the set indexed in the directory for |
| 227 // each ModelType in our ModelSafeGroup (using types_in_model_safe_group). |
| 228 void CollectUpdatesToApply( |
| 229 syncable::Directory* dir, |
| 230 syncable::BaseTransaction* trans); |
| 231 |
| 226 // Various iterators. | 232 // Various iterators. |
| 227 std::vector<AppliedUpdate>::iterator AppliedUpdatesBegin(); | |
| 228 std::vector<VerifiedUpdate>::const_iterator VerifiedUpdatesBegin() const; | 233 std::vector<VerifiedUpdate>::const_iterator VerifiedUpdatesBegin() const; |
| 229 std::vector<AppliedUpdate>::const_iterator AppliedUpdatesEnd() const; | |
| 230 std::vector<VerifiedUpdate>::const_iterator VerifiedUpdatesEnd() const; | 234 std::vector<VerifiedUpdate>::const_iterator VerifiedUpdatesEnd() const; |
| 231 | 235 |
| 232 // Returns the number of update application attempts. This includes both | 236 // Returns the number of update application attempts. This includes both |
| 233 // failures and successes. | 237 // failures and successes. |
| 234 int AppliedUpdatesSize() const { return applied_updates_.size(); } | 238 int AppliedUpdatesSize() const { return applied_updates_.size(); } |
| 235 int VerifiedUpdatesSize() const { return verified_updates_.size(); } | 239 int VerifiedUpdatesSize() const { return verified_updates_.size(); } |
| 236 bool HasVerifiedUpdates() const { return !verified_updates_.empty(); } | 240 bool HasVerifiedUpdates() const { return !verified_updates_.empty(); } |
| 237 bool HasAppliedUpdates() const { return !applied_updates_.empty(); } | |
| 238 void ClearVerifiedUpdates() { verified_updates_.clear(); } | 241 void ClearVerifiedUpdates() { verified_updates_.clear(); } |
| 239 | 242 |
| 243 std::vector<int64>* unapplied_updates() { |
| 244 return &unapplied_updates_; |
| 245 } |
| 246 |
| 247 bool HasUnappliedUpdates() const { return !unapplied_updates_.empty(); } |
| 248 |
| 240 // Count the number of successful update applications that have happend this | 249 // Count the number of successful update applications that have happend this |
| 241 // cycle. Note that if an item is successfully applied twice, it will be | 250 // cycle. Note that if an item is successfully applied twice, it will be |
| 242 // double counted here. | 251 // double counted here. |
| 243 int SuccessfullyAppliedUpdateCount() const; | 252 int SuccessfullyAppliedUpdateCount() const; |
| 244 | 253 |
| 245 // Returns true if at least one update application failed due to a conflict | 254 // Returns true if at least one update application failed due to a conflict |
| 246 // during this sync cycle. | 255 // during this sync cycle. |
| 247 bool HasConflictingUpdates() const; | 256 bool HasConflictingUpdates() const; |
| 248 | 257 |
| 249 private: | 258 private: |
| 250 // Container for updates that passed verification. | 259 // Container for updates that passed verification. |
| 251 std::vector<VerifiedUpdate> verified_updates_; | 260 std::vector<VerifiedUpdate> verified_updates_; |
| 252 | 261 |
| 253 // Stores the result of the various ApplyUpdate attempts we've made. | 262 // Stores the result of the various ApplyUpdate attempts we've made. |
| 254 // May contain duplicate entries. | 263 // May contain duplicate entries. |
| 255 std::vector<AppliedUpdate> applied_updates_; | 264 std::vector<AppliedUpdate> applied_updates_; |
| 265 |
| 266 std::vector<int64> unapplied_updates_; |
| 267 |
| 268 // The set of types corresponding to the ModelSafeGroup we are tracking |
| 269 // update progress for, generated on construction from the routing info. |
| 270 const syncable::FullModelTypeSet types_in_model_safe_group_; |
| 256 }; | 271 }; |
| 257 | 272 |
| 258 struct SyncCycleControlParameters { | 273 struct SyncCycleControlParameters { |
| 259 SyncCycleControlParameters() : conflicts_resolved(false), | 274 SyncCycleControlParameters() : conflicts_resolved(false), |
| 260 items_committed(false), | 275 items_committed(false), |
| 261 debug_info_sent(false) {} | 276 debug_info_sent(false) {} |
| 262 // Set to true by ResolveConflictsCommand if any forward progress was made. | 277 // Set to true by ResolveConflictsCommand if any forward progress was made. |
| 263 bool conflicts_resolved; | 278 bool conflicts_resolved; |
| 264 | 279 |
| 265 // Set to true by PostCommitMessageCommand if any commits were successful. | 280 // Set to true by PostCommitMessageCommand if any commits were successful. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 DirtyOnWrite<std::vector<int64> > unsynced_handles; | 327 DirtyOnWrite<std::vector<int64> > unsynced_handles; |
| 313 DirtyOnWrite<SyncerStatus> syncer_status; | 328 DirtyOnWrite<SyncerStatus> syncer_status; |
| 314 DirtyOnWrite<ErrorCounters> error; | 329 DirtyOnWrite<ErrorCounters> error; |
| 315 SyncCycleControlParameters control_params; | 330 SyncCycleControlParameters control_params; |
| 316 DirtyOnWrite<int64> num_server_changes_remaining; | 331 DirtyOnWrite<int64> num_server_changes_remaining; |
| 317 OrderedCommitSet commit_set; | 332 OrderedCommitSet commit_set; |
| 318 }; | 333 }; |
| 319 | 334 |
| 320 // Grouping of all state that applies to a single ModelSafeGroup. | 335 // Grouping of all state that applies to a single ModelSafeGroup. |
| 321 struct PerModelSafeGroupState { | 336 struct PerModelSafeGroupState { |
| 322 explicit PerModelSafeGroupState(bool* dirty_flag); | 337 PerModelSafeGroupState(bool* dirty_flag, |
| 338 ModelSafeGroup group, |
| 339 const ModelSafeRoutingInfo& routes); |
| 323 ~PerModelSafeGroupState(); | 340 ~PerModelSafeGroupState(); |
| 324 | 341 |
| 325 UpdateProgress update_progress; | 342 UpdateProgress update_progress; |
| 326 ConflictProgress conflict_progress; | 343 ConflictProgress conflict_progress; |
| 327 }; | 344 }; |
| 328 | 345 |
| 329 } // namespace sessions | 346 } // namespace sessions |
| 330 } // namespace browser_sync | 347 } // namespace browser_sync |
| 331 | 348 |
| 332 #endif // SYNC_SESSIONS_SESSION_STATE_H_ | 349 #endif // SYNC_SESSIONS_SESSION_STATE_H_ |
| OLD | NEW |