| 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 #include "sync/sessions/status_controller.h" | 5 #include "sync/sessions/status_controller.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "sync/internal_api/public/base/model_type.h" | 10 #include "sync/internal_api/public/base/model_type.h" |
| 11 #include "sync/protocol/sync_protocol_error.h" | 11 #include "sync/protocol/sync_protocol_error.h" |
| 12 | 12 |
| 13 namespace syncer { | 13 namespace syncer { |
| 14 namespace sessions { | 14 namespace sessions { |
| 15 | 15 |
| 16 StatusController::StatusController(const ModelSafeRoutingInfo& routes) | 16 StatusController::StatusController(const ModelSafeRoutingInfo& routes) |
| 17 : per_model_group_deleter_(&per_model_group_), | 17 : group_restriction_in_effect_(false), |
| 18 group_restriction_in_effect_(false), | |
| 19 group_restriction_(GROUP_PASSIVE), | 18 group_restriction_(GROUP_PASSIVE), |
| 20 routing_info_(routes) { | 19 routing_info_(routes) { |
| 21 } | 20 } |
| 22 | 21 |
| 23 StatusController::~StatusController() {} | 22 StatusController::~StatusController() {} |
| 24 | 23 |
| 25 const UpdateProgress* StatusController::update_progress() const { | |
| 26 const PerModelSafeGroupState* state = | |
| 27 GetModelSafeGroupState(true, group_restriction_); | |
| 28 return state ? &state->update_progress : NULL; | |
| 29 } | |
| 30 | |
| 31 UpdateProgress* StatusController::mutable_update_progress() { | |
| 32 return &GetOrCreateModelSafeGroupState( | |
| 33 true, group_restriction_)->update_progress; | |
| 34 } | |
| 35 | |
| 36 const ConflictProgress* StatusController::conflict_progress() const { | |
| 37 const PerModelSafeGroupState* state = | |
| 38 GetModelSafeGroupState(true, group_restriction_); | |
| 39 return state ? &state->conflict_progress : NULL; | |
| 40 } | |
| 41 | |
| 42 ConflictProgress* StatusController::mutable_conflict_progress() { | |
| 43 return &GetOrCreateModelSafeGroupState( | |
| 44 true, group_restriction_)->conflict_progress; | |
| 45 } | |
| 46 | |
| 47 const ConflictProgress* StatusController::GetUnrestrictedConflictProgress( | |
| 48 ModelSafeGroup group) const { | |
| 49 const PerModelSafeGroupState* state = | |
| 50 GetModelSafeGroupState(false, group); | |
| 51 return state ? &state->conflict_progress : NULL; | |
| 52 } | |
| 53 | |
| 54 ConflictProgress* | |
| 55 StatusController::GetUnrestrictedMutableConflictProgressForTest( | |
| 56 ModelSafeGroup group) { | |
| 57 return &GetOrCreateModelSafeGroupState(false, group)->conflict_progress; | |
| 58 } | |
| 59 | |
| 60 const UpdateProgress* StatusController::GetUnrestrictedUpdateProgress( | |
| 61 ModelSafeGroup group) const { | |
| 62 const PerModelSafeGroupState* state = | |
| 63 GetModelSafeGroupState(false, group); | |
| 64 return state ? &state->update_progress : NULL; | |
| 65 } | |
| 66 | |
| 67 UpdateProgress* | |
| 68 StatusController::GetUnrestrictedMutableUpdateProgressForTest( | |
| 69 ModelSafeGroup group) { | |
| 70 return &GetOrCreateModelSafeGroupState(false, group)->update_progress; | |
| 71 } | |
| 72 | |
| 73 const PerModelSafeGroupState* StatusController::GetModelSafeGroupState( | |
| 74 bool restrict, ModelSafeGroup group) const { | |
| 75 DCHECK_EQ(restrict, group_restriction_in_effect_); | |
| 76 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = | |
| 77 per_model_group_.find(group); | |
| 78 return (it == per_model_group_.end()) ? NULL : it->second; | |
| 79 } | |
| 80 | |
| 81 PerModelSafeGroupState* StatusController::GetOrCreateModelSafeGroupState( | |
| 82 bool restrict, ModelSafeGroup group) { | |
| 83 DCHECK_EQ(restrict, group_restriction_in_effect_); | |
| 84 std::map<ModelSafeGroup, PerModelSafeGroupState*>::iterator it = | |
| 85 per_model_group_.find(group); | |
| 86 if (it == per_model_group_.end()) { | |
| 87 PerModelSafeGroupState* state = new PerModelSafeGroupState(); | |
| 88 it = per_model_group_.insert(std::make_pair(group, state)).first; | |
| 89 } | |
| 90 return it->second; | |
| 91 } | |
| 92 | |
| 93 void StatusController::increment_num_updates_downloaded_by(int value) { | 24 void StatusController::increment_num_updates_downloaded_by(int value) { |
| 94 model_neutral_.num_updates_downloaded_total += value; | 25 model_neutral_.num_updates_downloaded_total += value; |
| 95 } | 26 } |
| 96 | 27 |
| 97 void StatusController::set_types_needing_local_migration(ModelTypeSet types) { | 28 void StatusController::set_types_needing_local_migration(ModelTypeSet types) { |
| 98 model_neutral_.types_needing_local_migration = types; | 29 model_neutral_.types_needing_local_migration = types; |
| 99 } | 30 } |
| 100 | 31 |
| 101 void StatusController::increment_num_tombstone_updates_downloaded_by( | 32 void StatusController::increment_num_tombstone_updates_downloaded_by( |
| 102 int value) { | 33 int value) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 122 } | 53 } |
| 123 | 54 |
| 124 void StatusController::increment_num_successful_bookmark_commits() { | 55 void StatusController::increment_num_successful_bookmark_commits() { |
| 125 model_neutral_.num_successful_bookmark_commits++; | 56 model_neutral_.num_successful_bookmark_commits++; |
| 126 } | 57 } |
| 127 | 58 |
| 128 void StatusController::increment_num_successful_commits() { | 59 void StatusController::increment_num_successful_commits() { |
| 129 model_neutral_.num_successful_commits++; | 60 model_neutral_.num_successful_commits++; |
| 130 } | 61 } |
| 131 | 62 |
| 63 void StatusController::increment_num_updates_applied_by(int value) { |
| 64 model_neutral_.num_updates_applied += value; |
| 65 } |
| 66 |
| 67 void StatusController::increment_num_encryption_conflicts_by(int value) { |
| 68 model_neutral_.num_encryption_conflicts += value; |
| 69 } |
| 70 |
| 71 void StatusController::increment_num_hierarchy_conflicts_by(int value) { |
| 72 model_neutral_.num_hierarchy_conflicts += value; |
| 73 } |
| 74 |
| 75 void StatusController::increment_num_server_conflicts() { |
| 76 model_neutral_.num_server_conflicts++; |
| 77 } |
| 78 |
| 132 void StatusController::increment_num_local_overwrites() { | 79 void StatusController::increment_num_local_overwrites() { |
| 133 model_neutral_.num_local_overwrites++; | 80 model_neutral_.num_local_overwrites++; |
| 134 } | 81 } |
| 135 | 82 |
| 136 void StatusController::increment_num_server_overwrites() { | 83 void StatusController::increment_num_server_overwrites() { |
| 137 model_neutral_.num_server_overwrites++; | 84 model_neutral_.num_server_overwrites++; |
| 138 } | 85 } |
| 139 | 86 |
| 140 void StatusController::set_sync_protocol_error( | 87 void StatusController::set_sync_protocol_error( |
| 141 const SyncProtocolError& error) { | 88 const SyncProtocolError& error) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 152 } | 99 } |
| 153 | 100 |
| 154 void StatusController::set_commit_result(const SyncerError result) { | 101 void StatusController::set_commit_result(const SyncerError result) { |
| 155 model_neutral_.commit_result = result; | 102 model_neutral_.commit_result = result; |
| 156 } | 103 } |
| 157 | 104 |
| 158 SyncerError StatusController::last_get_key_result() const { | 105 SyncerError StatusController::last_get_key_result() const { |
| 159 return model_neutral_.last_get_key_result; | 106 return model_neutral_.last_get_key_result; |
| 160 } | 107 } |
| 161 | 108 |
| 162 void StatusController::update_conflicts_resolved(bool resolved) { | |
| 163 model_neutral_.conflicts_resolved |= resolved; | |
| 164 } | |
| 165 void StatusController::reset_conflicts_resolved() { | |
| 166 model_neutral_.conflicts_resolved = false; | |
| 167 } | |
| 168 | |
| 169 // Returns the number of updates received from the sync server. | 109 // Returns the number of updates received from the sync server. |
| 170 int64 StatusController::CountUpdates() const { | 110 int64 StatusController::CountUpdates() const { |
| 171 const sync_pb::ClientToServerResponse& updates = | 111 const sync_pb::ClientToServerResponse& updates = |
| 172 model_neutral_.updates_response; | 112 model_neutral_.updates_response; |
| 173 if (updates.has_get_updates()) { | 113 if (updates.has_get_updates()) { |
| 174 return updates.get_updates().entries().size(); | 114 return updates.get_updates().entries().size(); |
| 175 } else { | 115 } else { |
| 176 return 0; | 116 return 0; |
| 177 } | 117 } |
| 178 } | 118 } |
| 179 | 119 |
| 180 bool StatusController::HasConflictingUpdates() const { | 120 int StatusController::num_updates_applied() const { |
| 181 DCHECK(!group_restriction_in_effect_) | 121 return model_neutral_.num_updates_applied; |
| 182 << "HasConflictingUpdates applies to all ModelSafeGroups"; | |
| 183 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = | |
| 184 per_model_group_.begin(); | |
| 185 for (; it != per_model_group_.end(); ++it) { | |
| 186 if (it->second->update_progress.HasConflictingUpdates()) | |
| 187 return true; | |
| 188 } | |
| 189 return false; | |
| 190 } | 122 } |
| 191 | 123 |
| 192 int StatusController::TotalNumEncryptionConflictingItems() const { | 124 int StatusController::num_server_overwrites() const { |
| 193 DCHECK(!group_restriction_in_effect_) | 125 return model_neutral_.num_server_overwrites; |
| 194 << "TotalNumEncryptionConflictingItems applies to all ModelSafeGroups"; | |
| 195 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = | |
| 196 per_model_group_.begin(); | |
| 197 int sum = 0; | |
| 198 for (; it != per_model_group_.end(); ++it) { | |
| 199 sum += it->second->conflict_progress.EncryptionConflictingItemsSize(); | |
| 200 } | |
| 201 return sum; | |
| 202 } | 126 } |
| 203 | 127 |
| 204 int StatusController::TotalNumHierarchyConflictingItems() const { | 128 int StatusController::num_encryption_conflicts() const { |
| 205 DCHECK(!group_restriction_in_effect_) | 129 return model_neutral_.num_encryption_conflicts; |
| 206 << "TotalNumHierarchyConflictingItems applies to all ModelSafeGroups"; | |
| 207 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = | |
| 208 per_model_group_.begin(); | |
| 209 int sum = 0; | |
| 210 for (; it != per_model_group_.end(); ++it) { | |
| 211 sum += it->second->conflict_progress.HierarchyConflictingItemsSize(); | |
| 212 } | |
| 213 return sum; | |
| 214 } | 130 } |
| 215 | 131 |
| 216 int StatusController::TotalNumSimpleConflictingItems() const { | 132 int StatusController::num_hierarchy_conflicts() const { |
| 217 DCHECK(!group_restriction_in_effect_) | 133 DCHECK(!group_restriction_in_effect_) |
| 218 << "TotalNumSimpleConflictingItems applies to all ModelSafeGroups"; | 134 << "num_hierarchy_conflicts applies to all ModelSafeGroups"; |
| 219 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = | 135 return model_neutral_.num_hierarchy_conflicts; |
| 220 per_model_group_.begin(); | |
| 221 int sum = 0; | |
| 222 for (; it != per_model_group_.end(); ++it) { | |
| 223 sum += it->second->conflict_progress.SimpleConflictingItemsSize(); | |
| 224 } | |
| 225 return sum; | |
| 226 } | 136 } |
| 227 | 137 |
| 228 int StatusController::TotalNumServerConflictingItems() const { | 138 int StatusController::num_server_conflicts() const { |
| 229 DCHECK(!group_restriction_in_effect_) | 139 DCHECK(!group_restriction_in_effect_) |
| 230 << "TotalNumServerConflictingItems applies to all ModelSafeGroups"; | 140 << "num_server_conflicts applies to all ModelSafeGroups"; |
| 231 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = | 141 return model_neutral_.num_server_conflicts; |
| 232 per_model_group_.begin(); | |
| 233 int sum = 0; | |
| 234 for (; it != per_model_group_.end(); ++it) { | |
| 235 sum += it->second->conflict_progress.ServerConflictingItemsSize(); | |
| 236 } | |
| 237 return sum; | |
| 238 } | 142 } |
| 239 | 143 |
| 240 int StatusController::TotalNumConflictingItems() const { | 144 int StatusController::TotalNumConflictingItems() const { |
| 241 DCHECK(!group_restriction_in_effect_) | 145 DCHECK(!group_restriction_in_effect_) |
| 242 << "TotalNumConflictingItems applies to all ModelSafeGroups"; | 146 << "TotalNumConflictingItems applies to all ModelSafeGroups"; |
| 243 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = | |
| 244 per_model_group_.begin(); | |
| 245 int sum = 0; | 147 int sum = 0; |
| 246 for (; it != per_model_group_.end(); ++it) { | 148 sum += num_encryption_conflicts(); |
| 247 sum += it->second->conflict_progress.SimpleConflictingItemsSize(); | 149 sum += num_hierarchy_conflicts(); |
| 248 sum += it->second->conflict_progress.EncryptionConflictingItemsSize(); | 150 sum += num_server_conflicts(); |
| 249 sum += it->second->conflict_progress.HierarchyConflictingItemsSize(); | |
| 250 sum += it->second->conflict_progress.ServerConflictingItemsSize(); | |
| 251 } | |
| 252 return sum; | 151 return sum; |
| 253 } | 152 } |
| 254 | 153 |
| 255 bool StatusController::ServerSaysNothingMoreToDownload() const { | 154 bool StatusController::ServerSaysNothingMoreToDownload() const { |
| 256 if (!download_updates_succeeded()) | 155 if (!download_updates_succeeded()) |
| 257 return false; | 156 return false; |
| 258 | 157 |
| 259 if (!updates_response().get_updates().has_changes_remaining()) { | 158 if (!updates_response().get_updates().has_changes_remaining()) { |
| 260 NOTREACHED(); // Server should always send changes remaining. | 159 NOTREACHED(); // Server should always send changes remaining. |
| 261 return false; // Avoid looping forever. | 160 return false; // Avoid looping forever. |
| 262 } | 161 } |
| 263 // Changes remaining is an estimate, but if it's estimated to be | 162 // Changes remaining is an estimate, but if it's estimated to be |
| 264 // zero, that's firm and we don't have to ask again. | 163 // zero, that's firm and we don't have to ask again. |
| 265 return updates_response().get_updates().changes_remaining() == 0; | 164 return updates_response().get_updates().changes_remaining() == 0; |
| 266 } | 165 } |
| 267 | 166 |
| 268 void StatusController::set_debug_info_sent() { | 167 void StatusController::set_debug_info_sent() { |
| 269 model_neutral_.debug_info_sent = true; | 168 model_neutral_.debug_info_sent = true; |
| 270 } | 169 } |
| 271 | 170 |
| 272 bool StatusController::debug_info_sent() const { | 171 bool StatusController::debug_info_sent() const { |
| 273 return model_neutral_.debug_info_sent; | 172 return model_neutral_.debug_info_sent; |
| 274 } | 173 } |
| 275 | 174 |
| 276 } // namespace sessions | 175 } // namespace sessions |
| 277 } // namespace syncer | 176 } // namespace syncer |
| OLD | NEW |