| 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 std::set<syncable::Id>* StatusController::simple_conflict_ids() const { | |
| 26 const PerModelSafeGroupState* state = | |
| 27 GetModelSafeGroupState(true, group_restriction_); | |
| 28 return state ? &state->simple_conflict_ids : NULL; | |
| 29 } | |
| 30 | |
| 31 std::set<syncable::Id>* StatusController::mutable_simple_conflict_ids() { | |
| 32 return &GetOrCreateModelSafeGroupState( | |
| 33 true, group_restriction_)->simple_conflict_ids; | |
| 34 } | |
| 35 | |
| 36 const std::set<syncable::Id>* | |
| 37 StatusController::GetUnrestrictedSimpleConflictIds( | |
| 38 ModelSafeGroup group) const { | |
| 39 const PerModelSafeGroupState* state = GetModelSafeGroupState(false, group); | |
| 40 return state ? &state->simple_conflict_ids : NULL; | |
| 41 } | |
| 42 | |
| 43 const PerModelSafeGroupState* StatusController::GetModelSafeGroupState( | |
| 44 bool restrict, ModelSafeGroup group) const { | |
| 45 DCHECK_EQ(restrict, group_restriction_in_effect_); | |
| 46 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = | |
| 47 per_model_group_.find(group); | |
| 48 return (it == per_model_group_.end()) ? NULL : it->second; | |
| 49 } | |
| 50 | |
| 51 PerModelSafeGroupState* StatusController::GetOrCreateModelSafeGroupState( | |
| 52 bool restrict, ModelSafeGroup group) { | |
| 53 DCHECK_EQ(restrict, group_restriction_in_effect_); | |
| 54 std::map<ModelSafeGroup, PerModelSafeGroupState*>::iterator it = | |
| 55 per_model_group_.find(group); | |
| 56 if (it == per_model_group_.end()) { | |
| 57 PerModelSafeGroupState* state = new PerModelSafeGroupState(); | |
| 58 it = per_model_group_.insert(std::make_pair(group, state)).first; | |
| 59 } | |
| 60 return it->second; | |
| 61 } | |
| 62 | |
| 63 void StatusController::increment_num_updates_downloaded_by(int value) { | 24 void StatusController::increment_num_updates_downloaded_by(int value) { |
| 64 model_neutral_.num_updates_downloaded_total += value; | 25 model_neutral_.num_updates_downloaded_total += value; |
| 65 } | 26 } |
| 66 | 27 |
| 67 void StatusController::set_types_needing_local_migration(ModelTypeSet types) { | 28 void StatusController::set_types_needing_local_migration(ModelTypeSet types) { |
| 68 model_neutral_.types_needing_local_migration = types; | 29 model_neutral_.types_needing_local_migration = types; |
| 69 } | 30 } |
| 70 | 31 |
| 71 void StatusController::increment_num_tombstone_updates_downloaded_by( | 32 void StatusController::increment_num_tombstone_updates_downloaded_by( |
| 72 int value) { | 33 int value) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 92 } | 53 } |
| 93 | 54 |
| 94 void StatusController::increment_num_successful_bookmark_commits() { | 55 void StatusController::increment_num_successful_bookmark_commits() { |
| 95 model_neutral_.num_successful_bookmark_commits++; | 56 model_neutral_.num_successful_bookmark_commits++; |
| 96 } | 57 } |
| 97 | 58 |
| 98 void StatusController::increment_num_successful_commits() { | 59 void StatusController::increment_num_successful_commits() { |
| 99 model_neutral_.num_successful_commits++; | 60 model_neutral_.num_successful_commits++; |
| 100 } | 61 } |
| 101 | 62 |
| 102 void StatusController::increment_num_updates_applied() { | 63 void StatusController::increment_num_updates_applied_by(int value) { |
| 103 model_neutral_.num_updates_applied++; | 64 model_neutral_.num_updates_applied += value; |
| 104 } | 65 } |
| 105 | 66 |
| 106 void StatusController::increment_num_encryption_conflicts() { | 67 void StatusController::increment_num_encryption_conflicts_by(int value) { |
| 107 model_neutral_.num_encryption_conflicts++; | 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; |
| 108 } | 73 } |
| 109 | 74 |
| 110 void StatusController::increment_num_server_conflicts() { | 75 void StatusController::increment_num_server_conflicts() { |
| 111 model_neutral_.num_server_conflicts++; | 76 model_neutral_.num_server_conflicts++; |
| 112 } | 77 } |
| 113 | 78 |
| 114 void StatusController::set_num_hierarchy_conflicts(int value) { | |
| 115 model_neutral_.num_hierarchy_conflicts = value; | |
| 116 } | |
| 117 | |
| 118 void StatusController::increment_num_local_overwrites() { | 79 void StatusController::increment_num_local_overwrites() { |
| 119 model_neutral_.num_local_overwrites++; | 80 model_neutral_.num_local_overwrites++; |
| 120 } | 81 } |
| 121 | 82 |
| 122 void StatusController::increment_num_server_overwrites() { | 83 void StatusController::increment_num_server_overwrites() { |
| 123 model_neutral_.num_server_overwrites++; | 84 model_neutral_.num_server_overwrites++; |
| 124 } | 85 } |
| 125 | 86 |
| 126 void StatusController::set_sync_protocol_error( | 87 void StatusController::set_sync_protocol_error( |
| 127 const SyncProtocolError& error) { | 88 const SyncProtocolError& error) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 138 } | 99 } |
| 139 | 100 |
| 140 void StatusController::set_commit_result(const SyncerError result) { | 101 void StatusController::set_commit_result(const SyncerError result) { |
| 141 model_neutral_.commit_result = result; | 102 model_neutral_.commit_result = result; |
| 142 } | 103 } |
| 143 | 104 |
| 144 SyncerError StatusController::last_get_key_result() const { | 105 SyncerError StatusController::last_get_key_result() const { |
| 145 return model_neutral_.last_get_key_result; | 106 return model_neutral_.last_get_key_result; |
| 146 } | 107 } |
| 147 | 108 |
| 148 void StatusController::update_conflicts_resolved(bool resolved) { | |
| 149 model_neutral_.conflicts_resolved |= resolved; | |
| 150 } | |
| 151 void StatusController::reset_conflicts_resolved() { | |
| 152 model_neutral_.conflicts_resolved = false; | |
| 153 } | |
| 154 | |
| 155 // Returns the number of updates received from the sync server. | 109 // Returns the number of updates received from the sync server. |
| 156 int64 StatusController::CountUpdates() const { | 110 int64 StatusController::CountUpdates() const { |
| 157 const sync_pb::ClientToServerResponse& updates = | 111 const sync_pb::ClientToServerResponse& updates = |
| 158 model_neutral_.updates_response; | 112 model_neutral_.updates_response; |
| 159 if (updates.has_get_updates()) { | 113 if (updates.has_get_updates()) { |
| 160 return updates.get_updates().entries().size(); | 114 return updates.get_updates().entries().size(); |
| 161 } else { | 115 } else { |
| 162 return 0; | 116 return 0; |
| 163 } | 117 } |
| 164 } | 118 } |
| 165 | 119 |
| 166 bool StatusController::HasConflictingUpdates() const { | |
| 167 return TotalNumConflictingItems() > 0; | |
| 168 } | |
| 169 | |
| 170 int StatusController::num_updates_applied() const { | 120 int StatusController::num_updates_applied() const { |
| 171 return model_neutral_.num_updates_applied; | 121 return model_neutral_.num_updates_applied; |
| 172 } | 122 } |
| 173 | 123 |
| 124 int StatusController::num_server_overwrites() const { |
| 125 return model_neutral_.num_server_overwrites; |
| 126 } |
| 127 |
| 174 int StatusController::num_encryption_conflicts() const { | 128 int StatusController::num_encryption_conflicts() const { |
| 175 return model_neutral_.num_encryption_conflicts; | 129 return model_neutral_.num_encryption_conflicts; |
| 176 } | 130 } |
| 177 | 131 |
| 178 int StatusController::num_hierarchy_conflicts() const { | 132 int StatusController::num_hierarchy_conflicts() const { |
| 179 DCHECK(!group_restriction_in_effect_) | 133 DCHECK(!group_restriction_in_effect_) |
| 180 << "num_hierarchy_conflicts applies to all ModelSafeGroups"; | 134 << "num_hierarchy_conflicts applies to all ModelSafeGroups"; |
| 181 return model_neutral_.num_hierarchy_conflicts; | 135 return model_neutral_.num_hierarchy_conflicts; |
| 182 } | 136 } |
| 183 | 137 |
| 184 int StatusController::num_simple_conflicts() const { | |
| 185 DCHECK(!group_restriction_in_effect_) | |
| 186 << "num_simple_conflicts applies to all ModelSafeGroups"; | |
| 187 std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = | |
| 188 per_model_group_.begin(); | |
| 189 int sum = 0; | |
| 190 for (; it != per_model_group_.end(); ++it) { | |
| 191 sum += it->second->simple_conflict_ids.size(); | |
| 192 } | |
| 193 return sum; | |
| 194 } | |
| 195 | |
| 196 int StatusController::num_server_conflicts() const { | 138 int StatusController::num_server_conflicts() const { |
| 197 DCHECK(!group_restriction_in_effect_) | 139 DCHECK(!group_restriction_in_effect_) |
| 198 << "num_server_conflicts applies to all ModelSafeGroups"; | 140 << "num_server_conflicts applies to all ModelSafeGroups"; |
| 199 return model_neutral_.num_server_conflicts; | 141 return model_neutral_.num_server_conflicts; |
| 200 } | 142 } |
| 201 | 143 |
| 202 int StatusController::TotalNumConflictingItems() const { | 144 int StatusController::TotalNumConflictingItems() const { |
| 203 DCHECK(!group_restriction_in_effect_) | 145 DCHECK(!group_restriction_in_effect_) |
| 204 << "TotalNumConflictingItems applies to all ModelSafeGroups"; | 146 << "TotalNumConflictingItems applies to all ModelSafeGroups"; |
| 205 int sum = 0; | 147 int sum = 0; |
| 206 sum += num_simple_conflicts(); | |
| 207 sum += num_encryption_conflicts(); | 148 sum += num_encryption_conflicts(); |
| 208 sum += num_hierarchy_conflicts(); | 149 sum += num_hierarchy_conflicts(); |
| 209 sum += num_server_conflicts(); | 150 sum += num_server_conflicts(); |
| 210 return sum; | 151 return sum; |
| 211 } | 152 } |
| 212 | 153 |
| 213 bool StatusController::ServerSaysNothingMoreToDownload() const { | 154 bool StatusController::ServerSaysNothingMoreToDownload() const { |
| 214 if (!download_updates_succeeded()) | 155 if (!download_updates_succeeded()) |
| 215 return false; | 156 return false; |
| 216 | 157 |
| 217 if (!updates_response().get_updates().has_changes_remaining()) { | 158 if (!updates_response().get_updates().has_changes_remaining()) { |
| 218 NOTREACHED(); // Server should always send changes remaining. | 159 NOTREACHED(); // Server should always send changes remaining. |
| 219 return false; // Avoid looping forever. | 160 return false; // Avoid looping forever. |
| 220 } | 161 } |
| 221 // 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 |
| 222 // 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. |
| 223 return updates_response().get_updates().changes_remaining() == 0; | 164 return updates_response().get_updates().changes_remaining() == 0; |
| 224 } | 165 } |
| 225 | 166 |
| 226 void StatusController::set_debug_info_sent() { | 167 void StatusController::set_debug_info_sent() { |
| 227 model_neutral_.debug_info_sent = true; | 168 model_neutral_.debug_info_sent = true; |
| 228 } | 169 } |
| 229 | 170 |
| 230 bool StatusController::debug_info_sent() const { | 171 bool StatusController::debug_info_sent() const { |
| 231 return model_neutral_.debug_info_sent; | 172 return model_neutral_.debug_info_sent; |
| 232 } | 173 } |
| 233 | 174 |
| 234 } // namespace sessions | 175 } // namespace sessions |
| 235 } // namespace syncer | 176 } // namespace syncer |
| OLD | NEW |