| 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 // 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 const ConflictProgress* GetUnrestrictedConflictProgress( | 64 const ConflictProgress* GetUnrestrictedConflictProgress( |
| 65 ModelSafeGroup group) const; | 65 ModelSafeGroup group) const; |
| 66 ConflictProgress* GetUnrestrictedMutableConflictProgressForTest( | 66 ConflictProgress* GetUnrestrictedMutableConflictProgressForTest( |
| 67 ModelSafeGroup group); | 67 ModelSafeGroup group); |
| 68 const UpdateProgress* GetUnrestrictedUpdateProgress( | 68 const UpdateProgress* GetUnrestrictedUpdateProgress( |
| 69 ModelSafeGroup group) const; | 69 ModelSafeGroup group) const; |
| 70 UpdateProgress* GetUnrestrictedMutableUpdateProgressForTest( | 70 UpdateProgress* GetUnrestrictedMutableUpdateProgressForTest( |
| 71 ModelSafeGroup group); | 71 ModelSafeGroup group); |
| 72 | 72 |
| 73 // ClientToServer messages. | 73 // ClientToServer messages. |
| 74 const ClientToServerMessage& commit_message() { | |
| 75 return shared_.commit_message; | |
| 76 } | |
| 77 ClientToServerMessage* mutable_commit_message() { | |
| 78 return &shared_.commit_message; | |
| 79 } | |
| 80 const ClientToServerResponse& commit_response() const { | |
| 81 return shared_.commit_response; | |
| 82 } | |
| 83 ClientToServerResponse* mutable_commit_response() { | |
| 84 return &shared_.commit_response; | |
| 85 } | |
| 86 const syncable::ModelTypeSet updates_request_types() const { | 74 const syncable::ModelTypeSet updates_request_types() const { |
| 87 return shared_.updates_request_types; | 75 return shared_.updates_request_types; |
| 88 } | 76 } |
| 89 void set_updates_request_types(syncable::ModelTypeSet value) { | 77 void set_updates_request_types(syncable::ModelTypeSet value) { |
| 90 shared_.updates_request_types = value; | 78 shared_.updates_request_types = value; |
| 91 } | 79 } |
| 92 const ClientToServerResponse& updates_response() const { | 80 const ClientToServerResponse& updates_response() const { |
| 93 return shared_.updates_response; | 81 return shared_.updates_response; |
| 94 } | 82 } |
| 95 ClientToServerResponse* mutable_updates_response() { | 83 ClientToServerResponse* mutable_updates_response() { |
| 96 return &shared_.updates_response; | 84 return &shared_.updates_response; |
| 97 } | 85 } |
| 98 | 86 |
| 99 // Errors and SyncerStatus. | 87 // Errors and SyncerStatus. |
| 100 const ErrorCounters& error() const { | 88 const ErrorCounters& error() const { |
| 101 return shared_.error.value(); | 89 return shared_.error.value(); |
| 102 } | 90 } |
| 103 const SyncerStatus& syncer_status() const { | 91 const SyncerStatus& syncer_status() const { |
| 104 return shared_.syncer_status.value(); | 92 return shared_.syncer_status.value(); |
| 105 } | 93 } |
| 106 | 94 |
| 107 // Changelog related state. | 95 // Changelog related state. |
| 108 int64 num_server_changes_remaining() const { | 96 int64 num_server_changes_remaining() const { |
| 109 return shared_.num_server_changes_remaining.value(); | 97 return shared_.num_server_changes_remaining.value(); |
| 110 } | 98 } |
| 111 | 99 |
| 112 // Commit path data. | 100 const OrderedCommitSet::Projection& commit_id_projection( |
| 113 const std::vector<syncable::Id>& commit_ids() const { | 101 const sessions::OrderedCommitSet &commit_set) { |
| 114 DCHECK(!group_restriction_in_effect_) << "Group restriction in effect!"; | |
| 115 return shared_.commit_set.GetAllCommitIds(); | |
| 116 } | |
| 117 const OrderedCommitSet::Projection& commit_id_projection() { | |
| 118 DCHECK(group_restriction_in_effect_) | 102 DCHECK(group_restriction_in_effect_) |
| 119 << "No group restriction for projection."; | 103 << "No group restriction for projection."; |
| 120 return shared_.commit_set.GetCommitIdProjection(group_restriction_); | 104 return commit_set.GetCommitIdProjection(group_restriction_); |
| 121 } | |
| 122 const syncable::Id& GetCommitIdAt(size_t index) { | |
| 123 DCHECK(CurrentCommitIdProjectionHasIndex(index)); | |
| 124 return shared_.commit_set.GetCommitIdAt(index); | |
| 125 } | |
| 126 syncable::ModelType GetCommitModelTypeAt(size_t index) { | |
| 127 DCHECK(CurrentCommitIdProjectionHasIndex(index)); | |
| 128 return shared_.commit_set.GetModelTypeAt(index); | |
| 129 } | |
| 130 syncable::ModelType GetUnrestrictedCommitModelTypeAt(size_t index) const { | |
| 131 DCHECK(!group_restriction_in_effect_) << "Group restriction in effect!"; | |
| 132 return shared_.commit_set.GetModelTypeAt(index); | |
| 133 } | |
| 134 const std::vector<int64>& unsynced_handles() const { | |
| 135 DCHECK(!group_restriction_in_effect_) | |
| 136 << "unsynced_handles is unrestricted."; | |
| 137 return shared_.unsynced_handles.value(); | |
| 138 } | 105 } |
| 139 | 106 |
| 140 // Control parameters for sync cycles. | 107 // Control parameters for sync cycles. |
| 141 bool conflicts_resolved() const { | 108 bool conflicts_resolved() const { |
| 142 return shared_.control_params.conflicts_resolved; | 109 return shared_.control_params.conflicts_resolved; |
| 143 } | 110 } |
| 144 bool did_commit_items() const { | |
| 145 return shared_.control_params.items_committed; | |
| 146 } | |
| 147 | 111 |
| 148 // If a GetUpdates for any data type resulted in downloading an update that | 112 // If a GetUpdates for any data type resulted in downloading an update that |
| 149 // is in conflict, this method returns true. | 113 // is in conflict, this method returns true. |
| 150 // Note: this includes unresolvable conflicts. | 114 // Note: this includes unresolvable conflicts. |
| 151 bool HasConflictingUpdates() const; | 115 bool HasConflictingUpdates() const; |
| 152 | 116 |
| 153 // Aggregate sums of various types of conflict counters accross all | 117 // Aggregate sums of various types of conflict counters accross all |
| 154 // ConflictProgress objects (one for each ModelSafeGroup currently in-use). | 118 // ConflictProgress objects (one for each ModelSafeGroup currently in-use). |
| 155 int TotalNumEncryptionConflictingItems() const; | 119 int TotalNumEncryptionConflictingItems() const; |
| 156 int TotalNumHierarchyConflictingItems() const; | 120 int TotalNumHierarchyConflictingItems() const; |
| 157 int TotalNumServerConflictingItems() const; | 121 int TotalNumServerConflictingItems() const; |
| 158 int TotalNumSimpleConflictingItems() const; | 122 int TotalNumSimpleConflictingItems() const; |
| 159 | 123 |
| 160 // Aggregate sum of SimpleConflictingItemSize() and other | 124 // Aggregate sum of SimpleConflictingItemSize() and other |
| 161 // ${Type}ConflictingItemSize() methods over all ConflictProgress objects (one | 125 // ${Type}ConflictingItemSize() methods over all ConflictProgress objects (one |
| 162 // for each ModelSafeGroup currently in-use). | 126 // for each ModelSafeGroup currently in-use). |
| 163 int TotalNumConflictingItems() const; | 127 int TotalNumConflictingItems() const; |
| 164 | 128 |
| 165 // Returns the number of updates received from the sync server. | 129 // Returns the number of updates received from the sync server. |
| 166 int64 CountUpdates() const; | 130 int64 CountUpdates() const; |
| 167 | 131 |
| 168 // Returns true iff any of the commit ids added during this session are | |
| 169 // bookmark related, and the bookmark group restriction is in effect. | |
| 170 bool HasBookmarkCommitActivity() const { | |
| 171 return ActiveGroupRestrictionIncludesModel(syncable::BOOKMARKS) && | |
| 172 shared_.commit_set.HasBookmarkCommitId(); | |
| 173 } | |
| 174 | |
| 175 // Returns true if the last download_updates_command received a valid | 132 // Returns true if the last download_updates_command received a valid |
| 176 // server response. | 133 // server response. |
| 177 bool download_updates_succeeded() const { | 134 bool download_updates_succeeded() const { |
| 178 return updates_response().has_get_updates(); | 135 return updates_response().has_get_updates(); |
| 179 } | 136 } |
| 180 | 137 |
| 181 // Returns true if the last updates response indicated that we were fully | 138 // Returns true if the last updates response indicated that we were fully |
| 182 // up to date. This is subtle: if it's false, it could either mean that | 139 // up to date. This is subtle: if it's false, it could either mean that |
| 183 // the server said there WAS more to download, or it could mean that we | 140 // the server said there WAS more to download, or it could mean that we |
| 184 // were unable to reach the server. If we didn't request every enabled | 141 // were unable to reach the server. If we didn't request every enabled |
| (...skipping 14 matching lines...) Expand all Loading... |
| 199 // restriction. | 156 // restriction. |
| 200 bool ActiveGroupRestrictionIncludesModel(syncable::ModelType model) const { | 157 bool ActiveGroupRestrictionIncludesModel(syncable::ModelType model) const { |
| 201 if (!group_restriction_in_effect_) | 158 if (!group_restriction_in_effect_) |
| 202 return true; | 159 return true; |
| 203 ModelSafeRoutingInfo::const_iterator it = routing_info_.find(model); | 160 ModelSafeRoutingInfo::const_iterator it = routing_info_.find(model); |
| 204 if (it == routing_info_.end()) | 161 if (it == routing_info_.end()) |
| 205 return false; | 162 return false; |
| 206 return group_restriction() == it->second; | 163 return group_restriction() == it->second; |
| 207 } | 164 } |
| 208 | 165 |
| 166 const SyncerError last_post_commit_result() const; |
| 167 const SyncerError last_process_commit_response_result() const; |
| 168 |
| 209 // A toolbelt full of methods for updating counters and flags. | 169 // A toolbelt full of methods for updating counters and flags. |
| 210 void set_num_server_changes_remaining(int64 changes_remaining); | 170 void set_num_server_changes_remaining(int64 changes_remaining); |
| 211 void set_invalid_store(bool invalid_store); | 171 void set_invalid_store(bool invalid_store); |
| 212 void set_num_successful_bookmark_commits(int value); | 172 void set_num_successful_bookmark_commits(int value); |
| 213 void increment_num_successful_commits(); | 173 void increment_num_successful_commits(); |
| 214 void increment_num_successful_bookmark_commits(); | 174 void increment_num_successful_bookmark_commits(); |
| 215 void increment_num_updates_downloaded_by(int value); | 175 void increment_num_updates_downloaded_by(int value); |
| 216 void increment_num_tombstone_updates_downloaded_by(int value); | 176 void increment_num_tombstone_updates_downloaded_by(int value); |
| 217 void increment_num_reflected_updates_downloaded_by(int value); | 177 void increment_num_reflected_updates_downloaded_by(int value); |
| 218 void set_types_needing_local_migration(syncable::ModelTypeSet types); | 178 void set_types_needing_local_migration(syncable::ModelTypeSet types); |
| 219 void set_unsynced_handles(const std::vector<int64>& unsynced_handles); | |
| 220 void increment_num_local_overwrites(); | 179 void increment_num_local_overwrites(); |
| 221 void increment_num_server_overwrites(); | 180 void increment_num_server_overwrites(); |
| 222 void set_sync_protocol_error(const SyncProtocolError& error); | 181 void set_sync_protocol_error(const SyncProtocolError& error); |
| 223 void set_last_download_updates_result(const SyncerError result); | 182 void set_last_download_updates_result(const SyncerError result); |
| 224 void set_last_post_commit_result(const SyncerError result); | 183 void set_last_post_commit_result(const SyncerError result); |
| 225 void set_last_process_commit_response_result(const SyncerError result); | 184 void set_last_process_commit_response_result(const SyncerError result); |
| 226 | 185 |
| 227 void set_commit_set(const OrderedCommitSet& commit_set); | |
| 228 void update_conflicts_resolved(bool resolved); | 186 void update_conflicts_resolved(bool resolved); |
| 229 void reset_conflicts_resolved(); | 187 void reset_conflicts_resolved(); |
| 230 void set_items_committed(); | |
| 231 | 188 |
| 232 void UpdateStartTime(); | 189 void UpdateStartTime(); |
| 233 | 190 |
| 234 void set_debug_info_sent(); | 191 void set_debug_info_sent(); |
| 235 | 192 |
| 236 bool debug_info_sent() const; | 193 bool debug_info_sent() const; |
| 237 | 194 |
| 238 private: | 195 private: |
| 239 friend class ScopedModelSafeGroupRestriction; | 196 friend class ScopedModelSafeGroupRestriction; |
| 240 | 197 |
| 241 // Returns true iff the commit id projection for |group_restriction_| | |
| 242 // references position |index| into the full set of commit ids in play. | |
| 243 bool CurrentCommitIdProjectionHasIndex(size_t index); | |
| 244 | |
| 245 // Returns the state, if it exists, or NULL otherwise. | 198 // Returns the state, if it exists, or NULL otherwise. |
| 246 const PerModelSafeGroupState* GetModelSafeGroupState( | 199 const PerModelSafeGroupState* GetModelSafeGroupState( |
| 247 bool restrict, ModelSafeGroup group) const; | 200 bool restrict, ModelSafeGroup group) const; |
| 248 | 201 |
| 249 // Helper to lazily create objects for per-ModelSafeGroup state. | 202 // Helper to lazily create objects for per-ModelSafeGroup state. |
| 250 PerModelSafeGroupState* GetOrCreateModelSafeGroupState( | 203 PerModelSafeGroupState* GetOrCreateModelSafeGroupState( |
| 251 bool restrict, ModelSafeGroup group); | 204 bool restrict, ModelSafeGroup group); |
| 252 | 205 |
| 253 AllModelTypeState shared_; | 206 AllModelTypeState shared_; |
| 254 std::map<ModelSafeGroup, PerModelSafeGroupState*> per_model_group_; | 207 std::map<ModelSafeGroup, PerModelSafeGroupState*> per_model_group_; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 242 } |
| 290 private: | 243 private: |
| 291 StatusController* status_; | 244 StatusController* status_; |
| 292 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); | 245 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); |
| 293 }; | 246 }; |
| 294 | 247 |
| 295 } | 248 } |
| 296 } | 249 } |
| 297 | 250 |
| 298 #endif // SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 251 #endif // SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
| OLD | NEW |