| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // A class to track the outstanding work required to bring the client back into | 5 // A class to track the outstanding work required to bring the client back into |
| 6 // sync with the server. | 6 // sync with the server. |
| 7 #ifndef SYNC_SESSIONS_NUDGE_TRACKER_H_ | 7 #ifndef SYNC_SESSIONS_NUDGE_TRACKER_H_ |
| 8 #define SYNC_SESSIONS_NUDGE_TRACKER_H_ | 8 #define SYNC_SESSIONS_NUDGE_TRACKER_H_ |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 NudgeTracker(); | 29 NudgeTracker(); |
| 30 ~NudgeTracker(); | 30 ~NudgeTracker(); |
| 31 | 31 |
| 32 // Returns true if there is a good reason for performing a sync cycle. | 32 // Returns true if there is a good reason for performing a sync cycle. |
| 33 // This does not take into account whether or not this is a good *time* to | 33 // This does not take into account whether or not this is a good *time* to |
| 34 // perform a sync cycle; that's the scheduler's job. | 34 // perform a sync cycle; that's the scheduler's job. |
| 35 bool IsSyncRequired() const; | 35 bool IsSyncRequired() const; |
| 36 | 36 |
| 37 // Returns true if there is a good reason for performing a get updates | 37 // Returns true if there is a good reason for performing a get updates |
| 38 // request as part of the next sync cycle. | 38 // request as part of the next sync cycle. |
| 39 bool IsGetUpdatesRequired(base::TimeTicks now) const; | 39 bool IsGetUpdatesRequired() const; |
| 40 | 40 |
| 41 // Return true if should perform a sync cycle for GU retry. | 41 // Return true if should perform a sync cycle for GU retry. |
| 42 bool IsRetryRequired(base::TimeTicks now) const; | 42 // |
| 43 // This is sensitive to changes in 'current time'. Make sure you're aware of |
| 44 // any nearby calls to ToggleRetryFlagIfRequired(). |
| 45 bool IsRetryRequired() const; |
| 43 | 46 |
| 44 // Tells this class that all required update fetching or committing has | 47 // Tells this class that all required update fetching or committing has |
| 45 // completed successfully. | 48 // completed successfully. |
| 46 void RecordSuccessfulSyncCycle(base::TimeTicks now); | 49 void RecordSuccessfulSyncCycle(); |
| 47 | 50 |
| 48 // Takes note of a local change. | 51 // Takes note of a local change. |
| 49 void RecordLocalChange(ModelTypeSet types); | 52 void RecordLocalChange(ModelTypeSet types); |
| 50 | 53 |
| 51 // Takes note of a locally issued request to refresh a data type. | 54 // Takes note of a locally issued request to refresh a data type. |
| 52 void RecordLocalRefreshRequest(ModelTypeSet types); | 55 void RecordLocalRefreshRequest(ModelTypeSet types); |
| 53 | 56 |
| 54 // Takes note of the receipt of an invalidation notice from the server. | 57 // Takes note of the receipt of an invalidation notice from the server. |
| 55 void RecordRemoteInvalidation( | 58 void RecordRemoteInvalidation( |
| 56 const ObjectIdInvalidationMap& invalidation_map); | 59 const ObjectIdInvalidationMap& invalidation_map); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 ModelType type, | 101 ModelType type, |
| 99 sync_pb::GetUpdateTriggers* msg) const; | 102 sync_pb::GetUpdateTriggers* msg) const; |
| 100 | 103 |
| 101 // Fills a ProgressMarker with single legacy notification hint expected by the | 104 // Fills a ProgressMarker with single legacy notification hint expected by the |
| 102 // sync server. Newer servers will rely on the data set by FillProtoMessage() | 105 // sync server. Newer servers will rely on the data set by FillProtoMessage() |
| 103 // instead of this. | 106 // instead of this. |
| 104 void SetLegacyNotificationHint( | 107 void SetLegacyNotificationHint( |
| 105 ModelType type, | 108 ModelType type, |
| 106 sync_pb::DataTypeProgressMarker* progress) const; | 109 sync_pb::DataTypeProgressMarker* progress) const; |
| 107 | 110 |
| 111 // Flips the flag if we're due for a retry. |
| 112 void ToggleRetryFlagIfRequired(base::TimeTicks now); |
| 113 |
| 108 // Adjusts the number of hints that can be stored locally. | 114 // Adjusts the number of hints that can be stored locally. |
| 109 void SetHintBufferSize(size_t size); | 115 void SetHintBufferSize(size_t size); |
| 110 | 116 |
| 111 void set_next_retry_time(base::TimeTicks next_retry_time) { | 117 // Schedules a retry GetUpdate request for some time in the future. |
| 112 next_retry_time_ = next_retry_time; | 118 // |
| 113 } | 119 // The effects of this change are not guaranteed to take effect until |
| 120 // ToggleRetryFlagIfRequired() is called. That function should be called |
| 121 // rarely (ie. only before a sync cycle, never during). |
| 122 void SetNextRetryTime(base::TimeTicks next_retry_time); |
| 114 | 123 |
| 115 private: | 124 private: |
| 116 typedef std::map<ModelType, DataTypeTracker> TypeTrackerMap; | 125 typedef std::map<ModelType, DataTypeTracker> TypeTrackerMap; |
| 117 | 126 |
| 118 TypeTrackerMap type_trackers_; | 127 TypeTrackerMap type_trackers_; |
| 119 | 128 |
| 120 // Merged updates source. This should be obsolete, but the server still | 129 // Merged updates source. This should be obsolete, but the server still |
| 121 // relies on it for some heuristics. | 130 // relies on it for some heuristics. |
| 122 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source_; | 131 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source_; |
| 123 | 132 |
| 124 // Tracks whether or not invalidations are currently enabled. | 133 // Tracks whether or not invalidations are currently enabled. |
| 125 bool invalidations_enabled_; | 134 bool invalidations_enabled_; |
| 126 | 135 |
| 127 // This flag is set if suspect that some technical malfunction or known bug | 136 // This flag is set if suspect that some technical malfunction or known bug |
| 128 // may have left us with some unserviced invalidations. | 137 // may have left us with some unserviced invalidations. |
| 129 // | 138 // |
| 130 // Keeps track of whether or not we're fully in sync with the invalidation | 139 // Keeps track of whether or not we're fully in sync with the invalidation |
| 131 // server. This can be false even if invalidations are enabled and working | 140 // server. This can be false even if invalidations are enabled and working |
| 132 // correctly. For example, until we get ack-tracking working properly, we | 141 // correctly. For example, until we get ack-tracking working properly, we |
| 133 // won't persist invalidations between restarts, so we may be out of sync when | 142 // won't persist invalidations between restarts, so we may be out of sync when |
| 134 // we restart. The only way to get back into sync is to have invalidations | 143 // we restart. The only way to get back into sync is to have invalidations |
| 135 // enabled, then complete a sync cycle to make sure we're fully up to date. | 144 // enabled, then complete a sync cycle to make sure we're fully up to date. |
| 136 bool invalidations_out_of_sync_; | 145 bool invalidations_out_of_sync_; |
| 137 | 146 |
| 138 size_t num_payloads_per_type_; | 147 size_t num_payloads_per_type_; |
| 139 | 148 |
| 140 base::TimeTicks last_successful_sync_time_; | 149 base::TimeTicks last_successful_sync_time_; |
| 141 | 150 |
| 142 // A retry GU should be issued after this time. | 151 // Time when the next retry is scheduled to execute. Will be null if no |
| 152 // retry is currently pending, or the is_retry_required flag is set. |
| 143 base::TimeTicks next_retry_time_; | 153 base::TimeTicks next_retry_time_; |
| 144 | 154 |
| 155 // Set to true when the nudge tracker believes we're due for a GU retry. |
| 156 bool is_retry_required_; |
| 157 |
| 145 DISALLOW_COPY_AND_ASSIGN(NudgeTracker); | 158 DISALLOW_COPY_AND_ASSIGN(NudgeTracker); |
| 146 }; | 159 }; |
| 147 | 160 |
| 148 } // namespace sessions | 161 } // namespace sessions |
| 149 } // namespace syncer | 162 } // namespace syncer |
| 150 | 163 |
| 151 #endif // SYNC_SESSIONS_NUDGE_TRACKER_H_ | 164 #endif // SYNC_SESSIONS_NUDGE_TRACKER_H_ |
| OLD | NEW |