| 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 shared_.error.value().last_download_updates_result | 135 return shared_.error.value().last_download_updates_result |
| 179 == SYNCER_OK; | 136 == SYNCER_OK; |
| 180 } | 137 } |
| 181 | 138 |
| 182 // Returns true if the last updates response indicated that we were fully | 139 // Returns true if the last updates response indicated that we were fully |
| 183 // up to date. This is subtle: if it's false, it could either mean that | 140 // up to date. This is subtle: if it's false, it could either mean that |
| 184 // the server said there WAS more to download, or it could mean that we | 141 // the server said there WAS more to download, or it could mean that we |
| 185 // were unable to reach the server. If we didn't request every enabled | 142 // were unable to reach the server. If we didn't request every enabled |
| 186 // datatype, then we can't say for sure that there's nothing left to | 143 // datatype, then we can't say for sure that there's nothing left to |
| 187 // download: in that case, this also returns false. | 144 // download: in that case, this also returns false. |
| 188 bool ServerSaysNothingMoreToDownload() const; | 145 bool ServerSaysNothingMoreToDownload() const; |
| 189 | 146 |
| 190 ModelSafeGroup group_restriction() const { | 147 ModelSafeGroup group_restriction() const { |
| 191 return group_restriction_; | 148 return group_restriction_; |
| 192 } | 149 } |
| 193 | 150 |
| 194 base::Time sync_start_time() const { | 151 base::Time sync_start_time() const { |
| 195 // The time at which we sent the first GetUpdates command for this sync. | 152 // The time at which we sent the first GetUpdates command for this sync. |
| 196 return sync_start_time_; | 153 return sync_start_time_; |
| 197 } | 154 } |
| 198 | 155 |
| 199 // Check whether a particular model is included by the active group | 156 bool HasBookmarkCommitActivity() const { |
| 200 // restriction. | 157 return ActiveGroupRestrictionIncludesModel(syncable::BOOKMARKS); |
| 201 bool ActiveGroupRestrictionIncludesModel(syncable::ModelType model) const { | |
| 202 if (!group_restriction_in_effect_) | |
| 203 return true; | |
| 204 ModelSafeRoutingInfo::const_iterator it = routing_info_.find(model); | |
| 205 if (it == routing_info_.end()) | |
| 206 return false; | |
| 207 return group_restriction() == it->second; | |
| 208 } | 158 } |
| 209 | 159 |
| 160 SyncerError last_post_commit_result() const; |
| 161 SyncerError last_process_commit_response_result() const; |
| 162 |
| 210 // A toolbelt full of methods for updating counters and flags. | 163 // A toolbelt full of methods for updating counters and flags. |
| 211 void set_num_server_changes_remaining(int64 changes_remaining); | 164 void set_num_server_changes_remaining(int64 changes_remaining); |
| 212 void set_invalid_store(bool invalid_store); | 165 void set_invalid_store(bool invalid_store); |
| 213 void set_num_successful_bookmark_commits(int value); | 166 void set_num_successful_bookmark_commits(int value); |
| 214 void increment_num_successful_commits(); | 167 void increment_num_successful_commits(); |
| 215 void increment_num_successful_bookmark_commits(); | 168 void increment_num_successful_bookmark_commits(); |
| 216 void increment_num_updates_downloaded_by(int value); | 169 void increment_num_updates_downloaded_by(int value); |
| 217 void increment_num_tombstone_updates_downloaded_by(int value); | 170 void increment_num_tombstone_updates_downloaded_by(int value); |
| 218 void increment_num_reflected_updates_downloaded_by(int value); | 171 void increment_num_reflected_updates_downloaded_by(int value); |
| 219 void set_types_needing_local_migration(syncable::ModelTypeSet types); | 172 void set_types_needing_local_migration(syncable::ModelTypeSet types); |
| 220 void set_unsynced_handles(const std::vector<int64>& unsynced_handles); | |
| 221 void increment_num_local_overwrites(); | 173 void increment_num_local_overwrites(); |
| 222 void increment_num_server_overwrites(); | 174 void increment_num_server_overwrites(); |
| 223 void set_sync_protocol_error(const SyncProtocolError& error); | 175 void set_sync_protocol_error(const SyncProtocolError& error); |
| 224 void set_last_download_updates_result(const SyncerError result); | 176 void set_last_download_updates_result(const SyncerError result); |
| 225 void set_last_post_commit_result(const SyncerError result); | 177 void set_last_post_commit_result(const SyncerError result); |
| 226 void set_last_process_commit_response_result(const SyncerError result); | 178 void set_last_process_commit_response_result(const SyncerError result); |
| 227 | 179 |
| 228 void set_commit_set(const OrderedCommitSet& commit_set); | |
| 229 void update_conflicts_resolved(bool resolved); | 180 void update_conflicts_resolved(bool resolved); |
| 230 void reset_conflicts_resolved(); | 181 void reset_conflicts_resolved(); |
| 231 void set_items_committed(); | |
| 232 | 182 |
| 233 void UpdateStartTime(); | 183 void UpdateStartTime(); |
| 234 | 184 |
| 235 void set_debug_info_sent(); | 185 void set_debug_info_sent(); |
| 236 | 186 |
| 237 bool debug_info_sent() const; | 187 bool debug_info_sent() const; |
| 238 | 188 |
| 239 private: | 189 private: |
| 240 friend class ScopedModelSafeGroupRestriction; | 190 friend class ScopedModelSafeGroupRestriction; |
| 241 | 191 |
| 242 // Returns true iff the commit id projection for |group_restriction_| | 192 // Check whether a particular model is included by the active group |
| 243 // references position |index| into the full set of commit ids in play. | 193 // restriction. |
| 244 bool CurrentCommitIdProjectionHasIndex(size_t index); | 194 bool ActiveGroupRestrictionIncludesModel(syncable::ModelType model) const { |
| 195 if (!group_restriction_in_effect_) |
| 196 return true; |
| 197 ModelSafeRoutingInfo::const_iterator it = routing_info_.find(model); |
| 198 if (it == routing_info_.end()) |
| 199 return false; |
| 200 return group_restriction() == it->second; |
| 201 } |
| 245 | 202 |
| 246 // Returns the state, if it exists, or NULL otherwise. | 203 // Returns the state, if it exists, or NULL otherwise. |
| 247 const PerModelSafeGroupState* GetModelSafeGroupState( | 204 const PerModelSafeGroupState* GetModelSafeGroupState( |
| 248 bool restrict, ModelSafeGroup group) const; | 205 bool restrict, ModelSafeGroup group) const; |
| 249 | 206 |
| 250 // Helper to lazily create objects for per-ModelSafeGroup state. | 207 // Helper to lazily create objects for per-ModelSafeGroup state. |
| 251 PerModelSafeGroupState* GetOrCreateModelSafeGroupState( | 208 PerModelSafeGroupState* GetOrCreateModelSafeGroupState( |
| 252 bool restrict, ModelSafeGroup group); | 209 bool restrict, ModelSafeGroup group); |
| 253 | 210 |
| 254 AllModelTypeState shared_; | 211 AllModelTypeState shared_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 247 } |
| 291 private: | 248 private: |
| 292 StatusController* status_; | 249 StatusController* status_; |
| 293 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); | 250 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); |
| 294 }; | 251 }; |
| 295 | 252 |
| 296 } | 253 } |
| 297 } | 254 } |
| 298 | 255 |
| 299 #endif // SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 256 #endif // SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
| OLD | NEW |