| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // StatusController handles all counter and status related number crunching and | 5 // StatusController handles all counter and status related number crunching and |
| 6 // state tracking on behalf of a SyncSession. It 'controls' the model data | 6 // state tracking on behalf of a SyncSession. It 'controls' the model data |
| 7 // defined in session_state.h. The most important feature of StatusController | 7 // defined in session_state.h. The most important feature of StatusController |
| 8 // is the ScopedModelSafetyRestriction. When one of these is active, the | 8 // is the ScopedModelSafetyRestriction. When one of these is active, the |
| 9 // underlying data set exposed via accessors is swapped out to the appropriate | 9 // underlying data set exposed via accessors is swapped out to the appropriate |
| 10 // set for the restricted ModelSafeGroup behind the scenes. For example, if | 10 // set for the restricted ModelSafeGroup behind the scenes. For example, if |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // notifications if no changes occurred. | 30 // notifications if no changes occurred. |
| 31 | 31 |
| 32 #ifndef CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 32 #ifndef CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
| 33 #define CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 33 #define CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
| 34 #pragma once | 34 #pragma once |
| 35 | 35 |
| 36 #include <vector> | 36 #include <vector> |
| 37 #include <map> | 37 #include <map> |
| 38 | 38 |
| 39 #include "base/stl_util.h" | 39 #include "base/stl_util.h" |
| 40 #include "base/time.h" |
| 40 #include "chrome/browser/sync/sessions/ordered_commit_set.h" | 41 #include "chrome/browser/sync/sessions/ordered_commit_set.h" |
| 41 #include "chrome/browser/sync/sessions/session_state.h" | 42 #include "chrome/browser/sync/sessions/session_state.h" |
| 42 | 43 |
| 43 namespace browser_sync { | 44 namespace browser_sync { |
| 44 namespace sessions { | 45 namespace sessions { |
| 45 | 46 |
| 46 class StatusController { | 47 class StatusController { |
| 47 public: | 48 public: |
| 48 explicit StatusController(const ModelSafeRoutingInfo& routes); | 49 explicit StatusController(const ModelSafeRoutingInfo& routes); |
| 49 ~StatusController(); | 50 ~StatusController(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // the server said there WAS more to download, or it could mean that we | 186 // the server said there WAS more to download, or it could mean that we |
| 186 // were unable to reach the server. If we didn't request every enabled | 187 // were unable to reach the server. If we didn't request every enabled |
| 187 // datatype, then we can't say for sure that there's nothing left to | 188 // datatype, then we can't say for sure that there's nothing left to |
| 188 // download: in that case, this also returns false. | 189 // download: in that case, this also returns false. |
| 189 bool ServerSaysNothingMoreToDownload() const; | 190 bool ServerSaysNothingMoreToDownload() const; |
| 190 | 191 |
| 191 ModelSafeGroup group_restriction() const { | 192 ModelSafeGroup group_restriction() const { |
| 192 return group_restriction_; | 193 return group_restriction_; |
| 193 } | 194 } |
| 194 | 195 |
| 196 base::Time sync_start_time() const { |
| 197 // The time at which we sent the first GetUpdates command for this sync. |
| 198 return sync_start_time_; |
| 199 } |
| 200 |
| 195 // Check whether a particular model is included by the active group | 201 // Check whether a particular model is included by the active group |
| 196 // restriction. | 202 // restriction. |
| 197 bool ActiveGroupRestrictionIncludesModel(syncable::ModelType model) const { | 203 bool ActiveGroupRestrictionIncludesModel(syncable::ModelType model) const { |
| 198 if (!group_restriction_in_effect_) | 204 if (!group_restriction_in_effect_) |
| 199 return true; | 205 return true; |
| 200 ModelSafeRoutingInfo::const_iterator it = routing_info_.find(model); | 206 ModelSafeRoutingInfo::const_iterator it = routing_info_.find(model); |
| 201 if (it == routing_info_.end()) | 207 if (it == routing_info_.end()) |
| 202 return false; | 208 return false; |
| 203 return group_restriction() == it->second; | 209 return group_restriction() == it->second; |
| 204 } | 210 } |
| 205 | 211 |
| 206 // A toolbelt full of methods for updating counters and flags. | 212 // A toolbelt full of methods for updating counters and flags. |
| 207 void increment_num_conflicting_commits_by(int value); | 213 void increment_num_conflicting_commits_by(int value); |
| 208 void reset_num_conflicting_commits(); | 214 void reset_num_conflicting_commits(); |
| 209 void set_num_consecutive_transient_error_commits(int value); | 215 void set_num_consecutive_transient_error_commits(int value); |
| 210 void increment_num_consecutive_transient_error_commits_by(int value); | 216 void increment_num_consecutive_transient_error_commits_by(int value); |
| 211 void set_num_consecutive_errors(int value); | 217 void set_num_consecutive_errors(int value); |
| 212 void increment_num_consecutive_errors(); | 218 void increment_num_consecutive_errors(); |
| 213 void increment_num_consecutive_errors_by(int value); | 219 void increment_num_consecutive_errors_by(int value); |
| 214 void set_num_server_changes_remaining(int64 changes_remaining); | 220 void set_num_server_changes_remaining(int64 changes_remaining); |
| 215 void set_invalid_store(bool invalid_store); | 221 void set_invalid_store(bool invalid_store); |
| 216 void set_syncer_stuck(bool syncer_stuck); | 222 void set_syncer_stuck(bool syncer_stuck); |
| 217 void set_syncing(bool syncing); | |
| 218 void set_num_successful_bookmark_commits(int value); | 223 void set_num_successful_bookmark_commits(int value); |
| 219 void increment_num_successful_commits(); | 224 void increment_num_successful_commits(); |
| 220 void increment_num_successful_bookmark_commits(); | 225 void increment_num_successful_bookmark_commits(); |
| 221 void increment_num_updates_downloaded_by(int value); | 226 void increment_num_updates_downloaded_by(int value); |
| 222 void increment_num_tombstone_updates_downloaded_by(int value); | 227 void increment_num_tombstone_updates_downloaded_by(int value); |
| 223 void set_types_needing_local_migration(const syncable::ModelTypeSet& types); | 228 void set_types_needing_local_migration(const syncable::ModelTypeSet& types); |
| 224 void set_unsynced_handles(const std::vector<int64>& unsynced_handles); | 229 void set_unsynced_handles(const std::vector<int64>& unsynced_handles); |
| 225 void increment_num_local_overwrites(); | 230 void increment_num_local_overwrites(); |
| 226 void increment_num_server_overwrites(); | 231 void increment_num_server_overwrites(); |
| 227 | 232 |
| 228 void set_commit_set(const OrderedCommitSet& commit_set); | 233 void set_commit_set(const OrderedCommitSet& commit_set); |
| 229 void update_conflict_sets_built(bool built); | 234 void update_conflict_sets_built(bool built); |
| 230 void update_conflicts_resolved(bool resolved); | 235 void update_conflicts_resolved(bool resolved); |
| 231 void reset_conflicts_resolved(); | 236 void reset_conflicts_resolved(); |
| 232 void set_items_committed(); | 237 void set_items_committed(); |
| 233 | 238 |
| 239 void SetSyncInProgressAndUpdateStartTime(bool sync_in_progress); |
| 240 |
| 234 private: | 241 private: |
| 235 friend class ScopedModelSafeGroupRestriction; | 242 friend class ScopedModelSafeGroupRestriction; |
| 236 | 243 |
| 237 // Returns true iff the commit id projection for |group_restriction_| | 244 // Returns true iff the commit id projection for |group_restriction_| |
| 238 // references position |index| into the full set of commit ids in play. | 245 // references position |index| into the full set of commit ids in play. |
| 239 bool CurrentCommitIdProjectionHasIndex(size_t index); | 246 bool CurrentCommitIdProjectionHasIndex(size_t index); |
| 240 | 247 |
| 241 // Helper to lazily create objects for per-ModelSafeGroup state. | 248 // Helper to lazily create objects for per-ModelSafeGroup state. |
| 242 PerModelSafeGroupState* GetOrCreateModelSafeGroupState(bool restrict, | 249 PerModelSafeGroupState* GetOrCreateModelSafeGroupState(bool restrict, |
| 243 ModelSafeGroup group); | 250 ModelSafeGroup group); |
| 244 | 251 |
| 245 AllModelTypeState shared_; | 252 AllModelTypeState shared_; |
| 246 std::map<ModelSafeGroup, PerModelSafeGroupState*> per_model_group_; | 253 std::map<ModelSafeGroup, PerModelSafeGroupState*> per_model_group_; |
| 247 | 254 |
| 248 STLValueDeleter<std::map<ModelSafeGroup, PerModelSafeGroupState*> > | 255 STLValueDeleter<std::map<ModelSafeGroup, PerModelSafeGroupState*> > |
| 249 per_model_group_deleter_; | 256 per_model_group_deleter_; |
| 250 | 257 |
| 251 // Set to true if any DirtyOnWrite pieces of state we maintain are changed. | 258 // Set to true if any DirtyOnWrite pieces of state we maintain are changed. |
| 252 // Reset to false by TestAndClearIsDirty. | 259 // Reset to false by TestAndClearIsDirty. |
| 253 bool is_dirty_; | 260 bool is_dirty_; |
| 254 | 261 |
| 255 // Used to fail read/write operations on state that don't obey the current | 262 // Used to fail read/write operations on state that don't obey the current |
| 256 // active ModelSafeWorker contract. | 263 // active ModelSafeWorker contract. |
| 257 bool group_restriction_in_effect_; | 264 bool group_restriction_in_effect_; |
| 258 ModelSafeGroup group_restriction_; | 265 ModelSafeGroup group_restriction_; |
| 259 | 266 |
| 260 const ModelSafeRoutingInfo routing_info_; | 267 const ModelSafeRoutingInfo routing_info_; |
| 261 | 268 |
| 269 base::Time sync_start_time_; |
| 270 |
| 262 DISALLOW_COPY_AND_ASSIGN(StatusController); | 271 DISALLOW_COPY_AND_ASSIGN(StatusController); |
| 263 }; | 272 }; |
| 264 | 273 |
| 265 // A utility to restrict access to only those parts of the given | 274 // A utility to restrict access to only those parts of the given |
| 266 // StatusController that pertain to the specified ModelSafeGroup. | 275 // StatusController that pertain to the specified ModelSafeGroup. |
| 267 class ScopedModelSafeGroupRestriction { | 276 class ScopedModelSafeGroupRestriction { |
| 268 public: | 277 public: |
| 269 ScopedModelSafeGroupRestriction(StatusController* to_restrict, | 278 ScopedModelSafeGroupRestriction(StatusController* to_restrict, |
| 270 ModelSafeGroup restriction) | 279 ModelSafeGroup restriction) |
| 271 : status_(to_restrict) { | 280 : status_(to_restrict) { |
| 272 DCHECK(!status_->group_restriction_in_effect_); | 281 DCHECK(!status_->group_restriction_in_effect_); |
| 273 status_->group_restriction_ = restriction; | 282 status_->group_restriction_ = restriction; |
| 274 status_->group_restriction_in_effect_ = true; | 283 status_->group_restriction_in_effect_ = true; |
| 275 } | 284 } |
| 276 ~ScopedModelSafeGroupRestriction() { | 285 ~ScopedModelSafeGroupRestriction() { |
| 277 DCHECK(status_->group_restriction_in_effect_); | 286 DCHECK(status_->group_restriction_in_effect_); |
| 278 status_->group_restriction_in_effect_ = false; | 287 status_->group_restriction_in_effect_ = false; |
| 279 } | 288 } |
| 280 private: | 289 private: |
| 281 StatusController* status_; | 290 StatusController* status_; |
| 282 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); | 291 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); |
| 283 }; | 292 }; |
| 284 | 293 |
| 285 } | 294 } |
| 286 } | 295 } |
| 287 | 296 |
| 288 #endif // CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 297 #endif // CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
| OLD | NEW |