| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // ClientToServer messages. | 75 // ClientToServer messages. |
| 76 ClientToServerMessage* mutable_commit_message() { | 76 ClientToServerMessage* mutable_commit_message() { |
| 77 return &shared_.commit_message; | 77 return &shared_.commit_message; |
| 78 } | 78 } |
| 79 const ClientToServerResponse& commit_response() const { | 79 const ClientToServerResponse& commit_response() const { |
| 80 return shared_.commit_response; | 80 return shared_.commit_response; |
| 81 } | 81 } |
| 82 ClientToServerResponse* mutable_commit_response() { | 82 ClientToServerResponse* mutable_commit_response() { |
| 83 return &shared_.commit_response; | 83 return &shared_.commit_response; |
| 84 } | 84 } |
| 85 const ClientToServerResponse& updates_response() { | 85 const ClientToServerResponse& updates_response() const { |
| 86 return shared_.updates_response; | 86 return shared_.updates_response; |
| 87 } | 87 } |
| 88 ClientToServerResponse* mutable_updates_response() { | 88 ClientToServerResponse* mutable_updates_response() { |
| 89 return &shared_.updates_response; | 89 return &shared_.updates_response; |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Errors and SyncerStatus. | 92 // Errors and SyncerStatus. |
| 93 const ErrorCounters& error_counters() const { | 93 const ErrorCounters& error_counters() const { |
| 94 return shared_.error_counters.value(); | 94 return shared_.error_counters.value(); |
| 95 } | 95 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return shared_.unsynced_handles.value(); | 128 return shared_.unsynced_handles.value(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 // Control parameters for sync cycles. | 131 // Control parameters for sync cycles. |
| 132 bool conflict_sets_built() const { | 132 bool conflict_sets_built() const { |
| 133 return shared_.control_params.conflict_sets_built; | 133 return shared_.control_params.conflict_sets_built; |
| 134 } | 134 } |
| 135 bool conflicts_resolved() const { | 135 bool conflicts_resolved() const { |
| 136 return shared_.control_params.conflicts_resolved; | 136 return shared_.control_params.conflicts_resolved; |
| 137 } | 137 } |
| 138 bool got_new_timestamp() const { | |
| 139 return shared_.control_params.got_new_timestamp; | |
| 140 } | |
| 141 bool did_commit_items() const { | 138 bool did_commit_items() const { |
| 142 return shared_.control_params.items_committed; | 139 return shared_.control_params.items_committed; |
| 143 } | 140 } |
| 144 | 141 |
| 145 // If a GetUpdates for any data type resulted in downloading an update that | 142 // If a GetUpdates for any data type resulted in downloading an update that |
| 146 // is in conflict, this method returns true. | 143 // is in conflict, this method returns true. |
| 147 bool HasConflictingUpdates() const; | 144 bool HasConflictingUpdates() const; |
| 148 | 145 |
| 149 // Aggregate sum of ConflictingItemSize() over all ConflictProgress objects | 146 // Aggregate sum of ConflictingItemSize() over all ConflictProgress objects |
| 150 // (one for each ModelSafeGroup currently in-use). | 147 // (one for each ModelSafeGroup currently in-use). |
| 151 int TotalNumConflictingItems() const; | 148 int TotalNumConflictingItems() const; |
| 152 | 149 |
| 153 // Returns the number of updates received from the sync server. | 150 // Returns the number of updates received from the sync server. |
| 154 int64 CountUpdates() const; | 151 int64 CountUpdates() const; |
| 155 | 152 |
| 156 // Returns true iff any of the commit ids added during this session are | 153 // Returns true iff any of the commit ids added during this session are |
| 157 // bookmark related. | 154 // bookmark related. |
| 158 bool HasBookmarkCommitActivity() const { | 155 bool HasBookmarkCommitActivity() const { |
| 159 return shared_.commit_set.HasBookmarkCommitId(); | 156 return shared_.commit_set.HasBookmarkCommitId(); |
| 160 } | 157 } |
| 161 | 158 |
| 162 bool got_zero_updates() const { return CountUpdates() == 0; } | 159 // Returns true if the last download_updates_command received a valid |
| 160 // server response. |
| 161 bool download_updates_succeeded() const { |
| 162 return updates_response().has_get_updates(); |
| 163 } |
| 164 |
| 165 // Returns true if the last updates response indicated that we were fully |
| 166 // up to date. This is subtle: if it's false, it could either mean that |
| 167 // the server said there WAS more to download, or it could mean that we |
| 168 // were unable to reach the server. |
| 169 bool server_says_nothing_more_to_download() const { |
| 170 if (!download_updates_succeeded()) |
| 171 return false; |
| 172 // The server indicates "you're up to date" by not sending a new |
| 173 // timestamp. |
| 174 return !updates_response().get_updates().has_new_timestamp(); |
| 175 } |
| 163 | 176 |
| 164 ModelSafeGroup group_restriction() const { | 177 ModelSafeGroup group_restriction() const { |
| 165 return group_restriction_; | 178 return group_restriction_; |
| 166 } | 179 } |
| 167 | 180 |
| 168 // A toolbelt full of methods for updating counters and flags. | 181 // A toolbelt full of methods for updating counters and flags. |
| 169 void increment_num_conflicting_commits_by(int value); | 182 void increment_num_conflicting_commits_by(int value); |
| 170 void reset_num_conflicting_commits(); | 183 void reset_num_conflicting_commits(); |
| 171 void set_num_consecutive_transient_error_commits(int value); | 184 void set_num_consecutive_transient_error_commits(int value); |
| 172 void increment_num_consecutive_transient_error_commits_by(int value); | 185 void increment_num_consecutive_transient_error_commits_by(int value); |
| 173 void set_num_consecutive_errors(int value); | 186 void set_num_consecutive_errors(int value); |
| 174 void increment_num_consecutive_errors(); | 187 void increment_num_consecutive_errors(); |
| 175 void increment_num_consecutive_errors_by(int value); | 188 void increment_num_consecutive_errors_by(int value); |
| 176 void set_got_new_timestamp(); | |
| 177 void set_current_sync_timestamp(syncable::ModelType model, | 189 void set_current_sync_timestamp(syncable::ModelType model, |
| 178 int64 current_timestamp); | 190 int64 current_timestamp); |
| 179 void set_num_server_changes_remaining(int64 changes_remaining); | 191 void set_num_server_changes_remaining(int64 changes_remaining); |
| 180 void set_over_quota(bool over_quota); | 192 void set_over_quota(bool over_quota); |
| 181 void set_invalid_store(bool invalid_store); | 193 void set_invalid_store(bool invalid_store); |
| 182 void set_syncer_stuck(bool syncer_stuck); | 194 void set_syncer_stuck(bool syncer_stuck); |
| 183 void set_syncing(bool syncing); | 195 void set_syncing(bool syncing); |
| 184 void set_num_successful_bookmark_commits(int value); | 196 void set_num_successful_bookmark_commits(int value); |
| 185 void increment_num_successful_commits(); | 197 void increment_num_successful_commits(); |
| 186 void increment_num_successful_bookmark_commits(); | 198 void increment_num_successful_bookmark_commits(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } | 258 } |
| 247 private: | 259 private: |
| 248 StatusController* status_; | 260 StatusController* status_; |
| 249 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); | 261 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); |
| 250 }; | 262 }; |
| 251 | 263 |
| 252 } | 264 } |
| 253 } | 265 } |
| 254 | 266 |
| 255 #endif // CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 267 #endif // CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
| OLD | NEW |