| 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 // FIXME: rewrite this comment. | 
|    5 // StatusController handles all counter and status related number crunching and |    6 // StatusController handles all counter and status related number crunching and | 
|    6 // state tracking on behalf of a SyncSession.  It 'controls' the model data |    7 // state tracking on behalf of a SyncSession.  It 'controls' the model data | 
|    7 // defined in session_state.h.  The most important feature of StatusController |    8 // defined in session_state.h.  The most important feature of StatusController | 
|    8 // is the ScopedModelSafetyRestriction. When one of these is active, the |    9 // is the ScopedModelSafetyRestriction. When one of these is active, the | 
|    9 // underlying data set exposed via accessors is swapped out to the appropriate |   10 // underlying data set exposed via accessors is swapped out to the appropriate | 
|   10 // set for the restricted ModelSafeGroup behind the scenes.  For example, if |   11 // set for the restricted ModelSafeGroup behind the scenes.  For example, if | 
|   11 // GROUP_UI is set, then accessors such as conflict_progress() and commit_ids() |   12 // GROUP_UI is set, then accessors such as conflict_progress() and commit_ids() | 
|   12 // are implicitly restricted to returning only data pertaining to GROUP_UI. |   13 // are implicitly restricted to returning only data pertaining to GROUP_UI. | 
|   13 // You can see which parts of status fall into this "restricted" category, or |   14 // You can see which parts of status fall into this "restricted" category, or | 
|   14 // the global "shared" category for all model types, by looking at the struct |   15 // the global "shared" category for all model types, by looking at the struct | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|   33 #define SYNC_SESSIONS_STATUS_CONTROLLER_H_ |   34 #define SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 
|   34  |   35  | 
|   35 #include <map> |   36 #include <map> | 
|   36 #include <vector> |   37 #include <vector> | 
|   37  |   38  | 
|   38 #include "base/logging.h" |   39 #include "base/logging.h" | 
|   39 #include "base/stl_util.h" |   40 #include "base/stl_util.h" | 
|   40 #include "base/time.h" |   41 #include "base/time.h" | 
|   41 #include "sync/internal_api/public/sessions/model_neutral_state.h" |   42 #include "sync/internal_api/public/sessions/model_neutral_state.h" | 
|   42 #include "sync/sessions/ordered_commit_set.h" |   43 #include "sync/sessions/ordered_commit_set.h" | 
|   43 #include "sync/sessions/session_state.h" |  | 
|   44  |   44  | 
|   45 namespace syncer { |   45 namespace syncer { | 
|   46 namespace sessions { |   46 namespace sessions { | 
|   47  |   47  | 
|   48 class StatusController { |   48 class StatusController { | 
|   49  public: |   49  public: | 
|   50   explicit StatusController(const ModelSafeRoutingInfo& routes); |   50   explicit StatusController(const ModelSafeRoutingInfo& routes); | 
|   51   ~StatusController(); |   51   ~StatusController(); | 
|   52  |   52  | 
|   53   // Progress counters.  All const methods may return NULL if the |  | 
|   54   // progress structure doesn't exist, but all non-const methods |  | 
|   55   // auto-create. |  | 
|   56   const ConflictProgress* conflict_progress() const; |  | 
|   57   ConflictProgress* mutable_conflict_progress(); |  | 
|   58   const UpdateProgress* update_progress() const; |  | 
|   59   UpdateProgress* mutable_update_progress(); |  | 
|   60   const ConflictProgress* GetUnrestrictedConflictProgress( |  | 
|   61       ModelSafeGroup group) const; |  | 
|   62   ConflictProgress* GetUnrestrictedMutableConflictProgressForTest( |  | 
|   63       ModelSafeGroup group); |  | 
|   64   const UpdateProgress* GetUnrestrictedUpdateProgress( |  | 
|   65       ModelSafeGroup group) const; |  | 
|   66   UpdateProgress* GetUnrestrictedMutableUpdateProgressForTest( |  | 
|   67       ModelSafeGroup group); |  | 
|   68  |  | 
|   69   // ClientToServer messages. |   53   // ClientToServer messages. | 
|   70   const ModelTypeSet updates_request_types() const { |   54   const ModelTypeSet updates_request_types() const { | 
|   71     return model_neutral_.updates_request_types; |   55     return model_neutral_.updates_request_types; | 
|   72   } |   56   } | 
|   73   void set_updates_request_types(ModelTypeSet value) { |   57   void set_updates_request_types(ModelTypeSet value) { | 
|   74     model_neutral_.updates_request_types = value; |   58     model_neutral_.updates_request_types = value; | 
|   75   } |   59   } | 
|   76   const sync_pb::ClientToServerResponse& updates_response() const { |   60   const sync_pb::ClientToServerResponse& updates_response() const { | 
|   77     return model_neutral_.updates_response; |   61     return model_neutral_.updates_response; | 
|   78   } |   62   } | 
|   79   sync_pb::ClientToServerResponse* mutable_updates_response() { |   63   sync_pb::ClientToServerResponse* mutable_updates_response() { | 
|   80     return &model_neutral_.updates_response; |   64     return &model_neutral_.updates_response; | 
|   81   } |   65   } | 
|   82  |   66  | 
|   83   // Changelog related state. |   67   // Changelog related state. | 
|   84   int64 num_server_changes_remaining() const { |   68   int64 num_server_changes_remaining() const { | 
|   85     return model_neutral_.num_server_changes_remaining; |   69     return model_neutral_.num_server_changes_remaining; | 
|   86   } |   70   } | 
|   87  |   71  | 
|   88   const OrderedCommitSet::Projection& commit_id_projection( |   72   const OrderedCommitSet::Projection& commit_id_projection( | 
|   89       const sessions::OrderedCommitSet &commit_set) { |   73       const sessions::OrderedCommitSet &commit_set) { | 
|   90     DCHECK(group_restriction_in_effect_) |   74     DCHECK(group_restriction_in_effect_) | 
|   91         << "No group restriction for projection."; |   75         << "No group restriction for projection."; | 
|   92     return commit_set.GetCommitIdProjection(group_restriction_); |   76     return commit_set.GetCommitIdProjection(group_restriction_); | 
|   93   } |   77   } | 
|   94  |   78  | 
|   95   // Control parameters for sync cycles. |   79   // Various conflict counters.   | 
|   96   bool conflicts_resolved() const { |   80   // FIXME: probably unnecessary.  Maybe should just access members directly? | 
|   97     return model_neutral_.conflicts_resolved; |   81   int num_encryption_conflicts() const; | 
|   98   } |   82   int num_hierarchy_conflicts() const; | 
 |   83   int num_server_conflicts() const; | 
|   99  |   84  | 
|  100   // If a GetUpdates for any data type resulted in downloading an update that |   85   // Aggregate sum of all conflict types. | 
|  101   // is in conflict, this method returns true. |   86   int TotalNumConflictingItems() const; | 
|  102   // Note: this includes unresolvable conflicts. |  | 
|  103   bool HasConflictingUpdates() const; |  | 
|  104  |   87  | 
|  105   // Aggregate sums of various types of conflict counters accross all |   88   // Number of successfully applied updates. | 
|  106   // ConflictProgress objects (one for each ModelSafeGroup currently in-use). |   89   int num_updates_applied() const; | 
|  107   int TotalNumEncryptionConflictingItems() const; |  | 
|  108   int TotalNumHierarchyConflictingItems() const; |  | 
|  109   int TotalNumServerConflictingItems() const; |  | 
|  110   int TotalNumSimpleConflictingItems() const; |  | 
|  111  |   90  | 
|  112   // Aggregate sum of SimpleConflictingItemSize() and other |   91   int num_server_overwrites() const; | 
|  113   // ${Type}ConflictingItemSize() methods over all ConflictProgress objects (one |  | 
|  114   // for each ModelSafeGroup currently in-use). |  | 
|  115   int TotalNumConflictingItems() const; |  | 
|  116  |   92  | 
|  117   // Returns the number of updates received from the sync server. |   93   // Returns the number of updates received from the sync server. | 
|  118   int64 CountUpdates() const; |   94   int64 CountUpdates() const; | 
|  119  |   95  | 
|  120   // Returns true if the last download_updates_command received a valid |   96   // Returns true if the last download_updates_command received a valid | 
|  121   // server response. |   97   // server response. | 
|  122   bool download_updates_succeeded() const { |   98   bool download_updates_succeeded() const { | 
|  123     return model_neutral_.last_download_updates_result |   99     return model_neutral_.last_download_updates_result | 
|  124         == SYNCER_OK; |  100         == SYNCER_OK; | 
|  125   } |  101   } | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|  144   bool HasBookmarkCommitActivity() const { |  120   bool HasBookmarkCommitActivity() const { | 
|  145     return ActiveGroupRestrictionIncludesModel(BOOKMARKS); |  121     return ActiveGroupRestrictionIncludesModel(BOOKMARKS); | 
|  146   } |  122   } | 
|  147  |  123  | 
|  148   const ModelNeutralState& model_neutral_state() const { |  124   const ModelNeutralState& model_neutral_state() const { | 
|  149     return model_neutral_; |  125     return model_neutral_; | 
|  150   } |  126   } | 
|  151  |  127  | 
|  152   SyncerError last_get_key_result() const; |  128   SyncerError last_get_key_result() const; | 
|  153  |  129  | 
|  154   // A toolbelt full of methods for updating counters and flags. |  130   // Download counters. | 
|  155   void set_num_server_changes_remaining(int64 changes_remaining); |  131   void set_num_server_changes_remaining(int64 changes_remaining); | 
|  156   void set_num_successful_bookmark_commits(int value); |  | 
|  157   void increment_num_successful_commits(); |  | 
|  158   void increment_num_successful_bookmark_commits(); |  | 
|  159   void increment_num_updates_downloaded_by(int value); |  132   void increment_num_updates_downloaded_by(int value); | 
|  160   void increment_num_tombstone_updates_downloaded_by(int value); |  133   void increment_num_tombstone_updates_downloaded_by(int value); | 
|  161   void increment_num_reflected_updates_downloaded_by(int value); |  134   void increment_num_reflected_updates_downloaded_by(int value); | 
|  162   void set_types_needing_local_migration(ModelTypeSet types); |  135  | 
 |  136   // Update application and conflict resolution counters. | 
 |  137   void increment_num_updates_applied_by(int value); | 
 |  138   void increment_num_encryption_conflicts_by(int value); | 
 |  139   void increment_num_hierarchy_conflicts_by(int value); | 
 |  140   void increment_num_server_conflicts(); | 
|  163   void increment_num_local_overwrites(); |  141   void increment_num_local_overwrites(); | 
|  164   void increment_num_server_overwrites(); |  142   void increment_num_server_overwrites(); | 
 |  143  | 
 |  144   // Commit counters. | 
 |  145   void increment_num_successful_commits(); | 
 |  146   void increment_num_successful_bookmark_commits(); | 
 |  147   void set_num_successful_bookmark_commits(int value); | 
 |  148  | 
 |  149   // Server communication status tracking. | 
|  165   void set_sync_protocol_error(const SyncProtocolError& error); |  150   void set_sync_protocol_error(const SyncProtocolError& error); | 
|  166   void set_last_get_key_result(const SyncerError result); |  151   void set_last_get_key_result(const SyncerError result); | 
|  167   void set_last_download_updates_result(const SyncerError result); |  152   void set_last_download_updates_result(const SyncerError result); | 
|  168   void set_commit_result(const SyncerError result); |  153   void set_commit_result(const SyncerError result); | 
|  169  |  154  | 
|  170   void update_conflicts_resolved(bool resolved); |  155   // A very important flag used to inform frontend of need to migrate. | 
|  171   void reset_conflicts_resolved(); |  156   void set_types_needing_local_migration(ModelTypeSet types); | 
|  172  |  157  | 
|  173   void UpdateStartTime(); |  158   void UpdateStartTime(); | 
|  174  |  159  | 
|  175   void set_debug_info_sent(); |  160   void set_debug_info_sent(); | 
|  176  |  161  | 
|  177   bool debug_info_sent() const; |  162   bool debug_info_sent() const; | 
|  178  |  163  | 
|  179  private: |  164  private: | 
|  180   friend class ScopedModelSafeGroupRestriction; |  165   friend class ScopedModelSafeGroupRestriction; | 
|  181  |  166  | 
|  182   // Check whether a particular model is included by the active group |  167   // Check whether a particular model is included by the active group | 
|  183   // restriction. |  168   // restriction. | 
|  184   bool ActiveGroupRestrictionIncludesModel(ModelType model) const { |  169   bool ActiveGroupRestrictionIncludesModel(ModelType model) const { | 
|  185     if (!group_restriction_in_effect_) |  170     if (!group_restriction_in_effect_) | 
|  186       return true; |  171       return true; | 
|  187     ModelSafeRoutingInfo::const_iterator it = routing_info_.find(model); |  172     ModelSafeRoutingInfo::const_iterator it = routing_info_.find(model); | 
|  188     if (it == routing_info_.end()) |  173     if (it == routing_info_.end()) | 
|  189       return false; |  174       return false; | 
|  190     return group_restriction() == it->second; |  175     return group_restriction() == it->second; | 
|  191   } |  176   } | 
|  192  |  177  | 
|  193   // Returns the state, if it exists, or NULL otherwise. |  | 
|  194   const PerModelSafeGroupState* GetModelSafeGroupState( |  | 
|  195       bool restrict, ModelSafeGroup group) const; |  | 
|  196  |  | 
|  197   // Helper to lazily create objects for per-ModelSafeGroup state. |  | 
|  198   PerModelSafeGroupState* GetOrCreateModelSafeGroupState( |  | 
|  199       bool restrict, ModelSafeGroup group); |  | 
|  200  |  | 
|  201   ModelNeutralState model_neutral_; |  178   ModelNeutralState model_neutral_; | 
|  202   std::map<ModelSafeGroup, PerModelSafeGroupState*> per_model_group_; |  | 
|  203  |  | 
|  204   STLValueDeleter<std::map<ModelSafeGroup, PerModelSafeGroupState*> > |  | 
|  205       per_model_group_deleter_; |  | 
|  206  |  179  | 
|  207   // Used to fail read/write operations on state that don't obey the current |  180   // Used to fail read/write operations on state that don't obey the current | 
|  208   // active ModelSafeWorker contract. |  181   // active ModelSafeWorker contract. | 
|  209   bool group_restriction_in_effect_; |  182   bool group_restriction_in_effect_; | 
|  210   ModelSafeGroup group_restriction_; |  183   ModelSafeGroup group_restriction_; | 
|  211  |  184  | 
|  212   const ModelSafeRoutingInfo routing_info_; |  185   const ModelSafeRoutingInfo routing_info_; | 
|  213  |  186  | 
|  214   base::Time sync_start_time_; |  187   base::Time sync_start_time_; | 
|  215  |  188  | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
|  233   } |  206   } | 
|  234  private: |  207  private: | 
|  235   StatusController* status_; |  208   StatusController* status_; | 
|  236   DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); |  209   DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); | 
|  237 }; |  210 }; | 
|  238  |  211  | 
|  239 }  // namespace sessions |  212 }  // namespace sessions | 
|  240 }  // namespace syncer |  213 }  // namespace syncer | 
|  241  |  214  | 
|  242 #endif  // SYNC_SESSIONS_STATUS_CONTROLLER_H_ |  215 #endif  // SYNC_SESSIONS_STATUS_CONTROLLER_H_ | 
| OLD | NEW |