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 #include "chrome/browser/sync/sessions/status_controller.h" | 5 #include "chrome/browser/sync/sessions/status_controller.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "chrome/browser/sync/syncable/model_type.h" | 8 #include "chrome/browser/sync/syncable/model_type.h" |
9 | 9 |
10 namespace browser_sync { | 10 namespace browser_sync { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 } | 55 } |
56 return per_model_type_[model]; | 56 return per_model_type_[model]; |
57 } | 57 } |
58 | 58 |
59 void StatusController::increment_num_conflicting_commits_by(int value) { | 59 void StatusController::increment_num_conflicting_commits_by(int value) { |
60 if (value == 0) | 60 if (value == 0) |
61 return; | 61 return; |
62 shared_.error_counters.mutate()->num_conflicting_commits += value; | 62 shared_.error_counters.mutate()->num_conflicting_commits += value; |
63 } | 63 } |
64 | 64 |
| 65 void StatusController::increment_num_updates_downloaded_by(int value) { |
| 66 shared_.syncer_status.mutate()->num_updates_downloaded += value; |
| 67 } |
| 68 |
| 69 void StatusController::increment_num_tombstone_updates_downloaded_by( |
| 70 int value) { |
| 71 shared_.syncer_status.mutate()->num_tombstone_updates_downloaded += value; |
| 72 } |
| 73 |
65 void StatusController::reset_num_conflicting_commits() { | 74 void StatusController::reset_num_conflicting_commits() { |
66 if (shared_.error_counters.value().num_conflicting_commits != 0) | 75 if (shared_.error_counters.value().num_conflicting_commits != 0) |
67 shared_.error_counters.mutate()->num_conflicting_commits = 0; | 76 shared_.error_counters.mutate()->num_conflicting_commits = 0; |
68 } | 77 } |
69 | 78 |
70 void StatusController::set_num_consecutive_transient_error_commits(int value) { | 79 void StatusController::set_num_consecutive_transient_error_commits(int value) { |
71 if (shared_.error_counters.value().consecutive_transient_error_commits != | 80 if (shared_.error_counters.value().consecutive_transient_error_commits != |
72 value) { | 81 value) { |
73 shared_.error_counters.mutate()->consecutive_transient_error_commits = | 82 shared_.error_counters.mutate()->consecutive_transient_error_commits = |
74 value; | 83 value; |
75 } | 84 } |
76 } | 85 } |
77 | 86 |
78 void StatusController::increment_num_consecutive_transient_error_commits_by( | 87 void StatusController::increment_num_consecutive_transient_error_commits_by( |
79 int value) { | 88 int value) { |
80 set_num_consecutive_transient_error_commits( | 89 set_num_consecutive_transient_error_commits( |
81 shared_.error_counters.value().consecutive_transient_error_commits + | 90 shared_.error_counters.value().consecutive_transient_error_commits + |
82 value); | 91 value); |
83 } | 92 } |
84 | 93 |
85 void StatusController::set_num_consecutive_errors(int value) { | 94 void StatusController::set_num_consecutive_errors(int value) { |
86 if (shared_.error_counters.value().consecutive_errors != value) | 95 if (shared_.error_counters.value().consecutive_errors != value) |
87 shared_.error_counters.mutate()->consecutive_errors = value; | 96 shared_.error_counters.mutate()->consecutive_errors = value; |
88 } | 97 } |
89 | 98 |
90 void StatusController::set_current_download_timestamp( | |
91 syncable::ModelType model, | |
92 int64 current_timestamp) { | |
93 PerModelTypeState* state = GetOrCreateModelTypeState(false, model); | |
94 if (current_timestamp > state->current_download_timestamp.value()) | |
95 *(state->current_download_timestamp.mutate()) = current_timestamp; | |
96 } | |
97 | |
98 void StatusController::set_num_server_changes_remaining( | 99 void StatusController::set_num_server_changes_remaining( |
99 int64 changes_remaining) { | 100 int64 changes_remaining) { |
100 if (shared_.num_server_changes_remaining.value() != changes_remaining) | 101 if (shared_.num_server_changes_remaining.value() != changes_remaining) |
101 *(shared_.num_server_changes_remaining.mutate()) = changes_remaining; | 102 *(shared_.num_server_changes_remaining.mutate()) = changes_remaining; |
102 } | 103 } |
103 | 104 |
104 void StatusController::set_invalid_store(bool invalid_store) { | 105 void StatusController::set_invalid_store(bool invalid_store) { |
105 if (shared_.syncer_status.value().invalid_store != invalid_store) | 106 if (shared_.syncer_status.value().invalid_store != invalid_store) |
106 shared_.syncer_status.mutate()->invalid_store = invalid_store; | 107 shared_.syncer_status.mutate()->invalid_store = invalid_store; |
107 } | 108 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 return 0; | 175 return 0; |
175 } | 176 } |
176 } | 177 } |
177 | 178 |
178 bool StatusController::CurrentCommitIdProjectionHasIndex(size_t index) { | 179 bool StatusController::CurrentCommitIdProjectionHasIndex(size_t index) { |
179 OrderedCommitSet::Projection proj = | 180 OrderedCommitSet::Projection proj = |
180 shared_.commit_set.GetCommitIdProjection(group_restriction_); | 181 shared_.commit_set.GetCommitIdProjection(group_restriction_); |
181 return std::binary_search(proj.begin(), proj.end(), index); | 182 return std::binary_search(proj.begin(), proj.end(), index); |
182 } | 183 } |
183 | 184 |
184 int64 StatusController::ComputeMaxLocalTimestamp() const { | |
185 std::map<syncable::ModelType, PerModelTypeState*>::const_iterator it = | |
186 per_model_type_.begin(); | |
187 int64 max_timestamp = 0; | |
188 for (; it != per_model_type_.end(); ++it) { | |
189 if (it->second->current_download_timestamp.value() > max_timestamp) | |
190 max_timestamp = it->second->current_download_timestamp.value(); | |
191 } | |
192 return max_timestamp; | |
193 } | |
194 | |
195 bool StatusController::HasConflictingUpdates() const { | 185 bool StatusController::HasConflictingUpdates() const { |
196 DCHECK(!group_restriction_in_effect_) | 186 DCHECK(!group_restriction_in_effect_) |
197 << "HasConflictingUpdates applies to all ModelSafeGroups"; | 187 << "HasConflictingUpdates applies to all ModelSafeGroups"; |
198 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = | 188 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = |
199 per_model_group_.begin(); | 189 per_model_group_.begin(); |
200 for (; it != per_model_group_.end(); ++it) { | 190 for (; it != per_model_group_.end(); ++it) { |
201 if (it->second->update_progress.HasConflictingUpdates()) | 191 if (it->second->update_progress.HasConflictingUpdates()) |
202 return true; | 192 return true; |
203 } | 193 } |
204 return false; | 194 return false; |
205 } | 195 } |
206 | 196 |
207 int StatusController::TotalNumConflictingItems() const { | 197 int StatusController::TotalNumConflictingItems() const { |
208 DCHECK(!group_restriction_in_effect_) | 198 DCHECK(!group_restriction_in_effect_) |
209 << "TotalNumConflictingItems applies to all ModelSafeGroups"; | 199 << "TotalNumConflictingItems applies to all ModelSafeGroups"; |
210 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = | 200 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = |
211 per_model_group_.begin(); | 201 per_model_group_.begin(); |
212 int sum = 0; | 202 int sum = 0; |
213 for (; it != per_model_group_.end(); ++it) { | 203 for (; it != per_model_group_.end(); ++it) { |
214 sum += it->second->conflict_progress.ConflictingItemsSize(); | 204 sum += it->second->conflict_progress.ConflictingItemsSize(); |
215 } | 205 } |
216 return sum; | 206 return sum; |
217 } | 207 } |
218 | 208 |
219 bool StatusController::ServerSaysNothingMoreToDownload() const { | 209 bool StatusController::ServerSaysNothingMoreToDownload() const { |
220 if (!download_updates_succeeded()) | 210 if (!download_updates_succeeded()) |
221 return false; | 211 return false; |
222 // If we didn't request every enabled datatype, then we can't say for | 212 |
223 // sure that there's nothing left to download. | 213 if (!updates_response().get_updates().has_changes_remaining()) { |
224 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 214 NOTREACHED(); // Server should always send changes remaining. |
225 if (!updates_request_parameters().data_types[i] && | 215 return false; // Avoid looping forever. |
226 routing_info_.count(syncable::ModelTypeFromInt(i)) != 0) { | |
227 return false; | |
228 } | |
229 } | 216 } |
230 // Changes remaining is an estimate, but if it's estimated to be | 217 // Changes remaining is an estimate, but if it's estimated to be |
231 // zero, that's firm and we don't have to ask again. | 218 // zero, that's firm and we don't have to ask again. |
232 if (updates_response().get_updates().has_changes_remaining() && | 219 return updates_response().get_updates().changes_remaining() == 0; |
233 updates_response().get_updates().changes_remaining() == 0) { | |
234 return true; | |
235 } | |
236 // Otherwise, the server can also indicate "you're up to date" | |
237 // by not sending a new timestamp. | |
238 return !updates_response().get_updates().has_new_timestamp(); | |
239 } | 220 } |
240 | 221 |
241 } // namespace sessions | 222 } // namespace sessions |
242 } // namespace browser_sync | 223 } // namespace browser_sync |
OLD | NEW |