| 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     : per_model_group_deleter_(&per_model_group_), | 
|   18       group_restriction_in_effect_(false), |   18       group_restriction_in_effect_(false), | 
|   19       group_restriction_(GROUP_PASSIVE), |   19       group_restriction_(GROUP_PASSIVE), | 
|   20       routing_info_(routes) { |   20       routing_info_(routes) { | 
|   21 } |   21 } | 
|   22  |   22  | 
|   23 StatusController::~StatusController() {} |   23 StatusController::~StatusController() {} | 
|   24  |   24  | 
|   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 std::set<syncable::Id>* StatusController::simple_conflict_ids() const { |   25 const std::set<syncable::Id>* StatusController::simple_conflict_ids() const { | 
|   37   const PerModelSafeGroupState* state = |   26   const PerModelSafeGroupState* state = | 
|   38       GetModelSafeGroupState(true, group_restriction_); |   27       GetModelSafeGroupState(true, group_restriction_); | 
|   39   return state ? &state->simple_conflict_ids : NULL; |   28   return state ? &state->simple_conflict_ids : NULL; | 
|   40 } |   29 } | 
|   41  |   30  | 
|   42 std::set<syncable::Id>* StatusController::mutable_simple_conflict_ids() { |   31 std::set<syncable::Id>* StatusController::mutable_simple_conflict_ids() { | 
|   43   return &GetOrCreateModelSafeGroupState( |   32   return &GetOrCreateModelSafeGroupState( | 
|   44       true, group_restriction_)->simple_conflict_ids; |   33       true, group_restriction_)->simple_conflict_ids; | 
|   45 } |   34 } | 
|   46  |   35  | 
|   47 const std::set<syncable::Id>* |   36 const std::set<syncable::Id>* | 
|   48     StatusController::GetUnrestrictedSimpleConflictIds( |   37     StatusController::GetUnrestrictedSimpleConflictIds( | 
|   49         ModelSafeGroup group) const { |   38         ModelSafeGroup group) const { | 
|   50   const PerModelSafeGroupState* state = GetModelSafeGroupState(false, group); |   39   const PerModelSafeGroupState* state = GetModelSafeGroupState(false, group); | 
|   51   return state ? &state->simple_conflict_ids : NULL; |   40   return state ? &state->simple_conflict_ids : NULL; | 
|   52 } |   41 } | 
|   53  |   42  | 
|   54 const UpdateProgress* StatusController::GetUnrestrictedUpdateProgress( |  | 
|   55     ModelSafeGroup group) const { |  | 
|   56   const PerModelSafeGroupState* state = GetModelSafeGroupState(false, group); |  | 
|   57   return state ? &state->update_progress : NULL; |  | 
|   58 } |  | 
|   59  |  | 
|   60 UpdateProgress* |  | 
|   61     StatusController::GetUnrestrictedMutableUpdateProgressForTest( |  | 
|   62         ModelSafeGroup group) { |  | 
|   63   return &GetOrCreateModelSafeGroupState(false, group)->update_progress; |  | 
|   64 } |  | 
|   65  |  | 
|   66 const PerModelSafeGroupState* StatusController::GetModelSafeGroupState( |   43 const PerModelSafeGroupState* StatusController::GetModelSafeGroupState( | 
|   67     bool restrict, ModelSafeGroup group) const { |   44     bool restrict, ModelSafeGroup group) const { | 
|   68   DCHECK_EQ(restrict, group_restriction_in_effect_); |   45   DCHECK_EQ(restrict, group_restriction_in_effect_); | 
|   69   std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = |   46   std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = | 
|   70       per_model_group_.find(group); |   47       per_model_group_.find(group); | 
|   71   return (it == per_model_group_.end()) ? NULL : it->second; |   48   return (it == per_model_group_.end()) ? NULL : it->second; | 
|   72 } |   49 } | 
|   73  |   50  | 
|   74 PerModelSafeGroupState* StatusController::GetOrCreateModelSafeGroupState( |   51 PerModelSafeGroupState* StatusController::GetOrCreateModelSafeGroupState( | 
|   75     bool restrict, ModelSafeGroup group) { |   52     bool restrict, ModelSafeGroup group) { | 
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  180   const sync_pb::ClientToServerResponse& updates = |  157   const sync_pb::ClientToServerResponse& updates = | 
|  181       model_neutral_.updates_response; |  158       model_neutral_.updates_response; | 
|  182   if (updates.has_get_updates()) { |  159   if (updates.has_get_updates()) { | 
|  183     return updates.get_updates().entries().size(); |  160     return updates.get_updates().entries().size(); | 
|  184   } else { |  161   } else { | 
|  185     return 0; |  162     return 0; | 
|  186   } |  163   } | 
|  187 } |  164 } | 
|  188  |  165  | 
|  189 bool StatusController::HasConflictingUpdates() const { |  166 bool StatusController::HasConflictingUpdates() const { | 
|  190   DCHECK(!group_restriction_in_effect_) |  167   return TotalNumConflictingItems() > 0; | 
|  191       << "HasConflictingUpdates applies to all ModelSafeGroups"; |  168 } | 
|  192   std::map<ModelSafeGroup, PerModelSafeGroupState*>::const_iterator it = |  169  | 
|  193     per_model_group_.begin(); |  170 int StatusController::num_updates_applied() const { | 
|  194   for (; it != per_model_group_.end(); ++it) { |  171   return model_neutral_.num_updates_applied; | 
|  195     if (it->second->update_progress.HasConflictingUpdates()) |  | 
|  196       return true; |  | 
|  197   } |  | 
|  198   return false; |  | 
|  199 } |  172 } | 
|  200  |  173  | 
|  201 int StatusController::num_encryption_conflicts() const { |  174 int StatusController::num_encryption_conflicts() const { | 
|  202   return model_neutral_.num_encryption_conflicts; |  175   return model_neutral_.num_encryption_conflicts; | 
|  203 } |  176 } | 
|  204  |  177  | 
|  205 int StatusController::num_hierarchy_conflicts() const { |  178 int StatusController::num_hierarchy_conflicts() const { | 
|  206   DCHECK(!group_restriction_in_effect_) |  179   DCHECK(!group_restriction_in_effect_) | 
|  207       << "num_hierarchy_conflicts applies to all ModelSafeGroups"; |  180       << "num_hierarchy_conflicts applies to all ModelSafeGroups"; | 
|  208   return model_neutral_.num_hierarchy_conflicts; |  181   return model_neutral_.num_hierarchy_conflicts; | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  253 void StatusController::set_debug_info_sent() { |  226 void StatusController::set_debug_info_sent() { | 
|  254   model_neutral_.debug_info_sent = true; |  227   model_neutral_.debug_info_sent = true; | 
|  255 } |  228 } | 
|  256  |  229  | 
|  257 bool StatusController::debug_info_sent() const { |  230 bool StatusController::debug_info_sent() const { | 
|  258   return model_neutral_.debug_info_sent; |  231   return model_neutral_.debug_info_sent; | 
|  259 } |  232 } | 
|  260  |  233  | 
|  261 }  // namespace sessions |  234 }  // namespace sessions | 
|  262 }  // namespace syncer |  235 }  // namespace syncer | 
| OLD | NEW |