| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 bool HasConflictingUpdates() const; | 144 bool HasConflictingUpdates() const; |
| 145 | 145 |
| 146 // Aggregate sum of ConflictingItemSize() over all ConflictProgress objects | 146 // Aggregate sum of ConflictingItemSize() over all ConflictProgress objects |
| 147 // (one for each ModelSafeGroup currently in-use). | 147 // (one for each ModelSafeGroup currently in-use). |
| 148 int TotalNumConflictingItems() const; | 148 int TotalNumConflictingItems() const; |
| 149 | 149 |
| 150 // Returns the number of updates received from the sync server. | 150 // Returns the number of updates received from the sync server. |
| 151 int64 CountUpdates() const; | 151 int64 CountUpdates() const; |
| 152 | 152 |
| 153 // 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 |
| 154 // bookmark related. | 154 // bookmark related, and the bookmark group restriction is in effect. |
| 155 bool HasBookmarkCommitActivity() const { | 155 bool HasBookmarkCommitActivity() const { |
| 156 return shared_.commit_set.HasBookmarkCommitId(); | 156 return ActiveGroupRestrictionIncludesModel(syncable::BOOKMARKS) && |
| 157 shared_.commit_set.HasBookmarkCommitId(); |
| 157 } | 158 } |
| 158 | 159 |
| 159 // Returns true if the last download_updates_command received a valid | 160 // Returns true if the last download_updates_command received a valid |
| 160 // server response. | 161 // server response. |
| 161 bool download_updates_succeeded() const { | 162 bool download_updates_succeeded() const { |
| 162 return updates_response().has_get_updates(); | 163 return updates_response().has_get_updates(); |
| 163 } | 164 } |
| 164 | 165 |
| 165 // Returns true if the last updates response indicated that we were fully | 166 // 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 // 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 // the server said there WAS more to download, or it could mean that we |
| 168 // were unable to reach the server. | 169 // were unable to reach the server. |
| 169 bool server_says_nothing_more_to_download() const { | 170 bool server_says_nothing_more_to_download() const { |
| 170 if (!download_updates_succeeded()) | 171 if (!download_updates_succeeded()) |
| 171 return false; | 172 return false; |
| 172 // The server indicates "you're up to date" by not sending a new | 173 // The server indicates "you're up to date" by not sending a new |
| 173 // timestamp. | 174 // timestamp. |
| 174 return !updates_response().get_updates().has_new_timestamp(); | 175 return !updates_response().get_updates().has_new_timestamp(); |
| 175 } | 176 } |
| 176 | 177 |
| 177 ModelSafeGroup group_restriction() const { | 178 ModelSafeGroup group_restriction() const { |
| 178 return group_restriction_; | 179 return group_restriction_; |
| 179 } | 180 } |
| 180 | 181 |
| 182 // Check whether a particular model is included by the active group |
| 183 // restriction. |
| 184 bool ActiveGroupRestrictionIncludesModel(syncable::ModelType model) const { |
| 185 DCHECK(group_restriction_in_effect_); |
| 186 ModelSafeRoutingInfo::const_iterator it = routing_info_.find(model); |
| 187 if (it == routing_info_.end()) |
| 188 return false; |
| 189 return group_restriction() == it->second; |
| 190 } |
| 191 |
| 181 // A toolbelt full of methods for updating counters and flags. | 192 // A toolbelt full of methods for updating counters and flags. |
| 182 void increment_num_conflicting_commits_by(int value); | 193 void increment_num_conflicting_commits_by(int value); |
| 183 void reset_num_conflicting_commits(); | 194 void reset_num_conflicting_commits(); |
| 184 void set_num_consecutive_transient_error_commits(int value); | 195 void set_num_consecutive_transient_error_commits(int value); |
| 185 void increment_num_consecutive_transient_error_commits_by(int value); | 196 void increment_num_consecutive_transient_error_commits_by(int value); |
| 186 void set_num_consecutive_errors(int value); | 197 void set_num_consecutive_errors(int value); |
| 187 void increment_num_consecutive_errors(); | 198 void increment_num_consecutive_errors(); |
| 188 void increment_num_consecutive_errors_by(int value); | 199 void increment_num_consecutive_errors_by(int value); |
| 189 void set_current_sync_timestamp(syncable::ModelType model, | 200 void set_current_sync_timestamp(syncable::ModelType model, |
| 190 int64 current_timestamp); | 201 int64 current_timestamp); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 } | 269 } |
| 259 private: | 270 private: |
| 260 StatusController* status_; | 271 StatusController* status_; |
| 261 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); | 272 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); |
| 262 }; | 273 }; |
| 263 | 274 |
| 264 } | 275 } |
| 265 } | 276 } |
| 266 | 277 |
| 267 #endif // CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 278 #endif // CHROME_BROWSER_SYNC_SESSIONS_STATUS_CONTROLLER_H_ |
| OLD | NEW |