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 #ifndef SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ | 5 #ifndef SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ |
6 #define SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ | 6 #define SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 const base::TimeDelta& new_delay) OVERRIDE; | 70 const base::TimeDelta& new_delay) OVERRIDE; |
71 virtual void OnShouldStopSyncingPermanently() OVERRIDE; | 71 virtual void OnShouldStopSyncingPermanently() OVERRIDE; |
72 virtual void OnSyncProtocolError( | 72 virtual void OnSyncProtocolError( |
73 const sessions::SyncSessionSnapshot& snapshot) OVERRIDE; | 73 const sessions::SyncSessionSnapshot& snapshot) OVERRIDE; |
74 | 74 |
75 // DDOS avoidance function. Calculates how long we should wait before trying | 75 // DDOS avoidance function. Calculates how long we should wait before trying |
76 // again after a failed sync attempt, where the last delay was |base_delay|. | 76 // again after a failed sync attempt, where the last delay was |base_delay|. |
77 // TODO(tim): Look at URLRequestThrottlerEntryInterface. | 77 // TODO(tim): Look at URLRequestThrottlerEntryInterface. |
78 static base::TimeDelta GetRecommendedDelay(const base::TimeDelta& base_delay); | 78 static base::TimeDelta GetRecommendedDelay(const base::TimeDelta& base_delay); |
79 | 79 |
| 80 // For integration tests only. Override initial backoff value. |
| 81 // TODO(tim): Remove this, use command line flag and plumb through. Done |
| 82 // this way to reduce diffs in hotfix. |
| 83 static void ForceShortInitialBackoffRetry(); |
| 84 |
80 private: | 85 private: |
81 enum JobProcessDecision { | 86 enum JobProcessDecision { |
82 // Indicates we should continue with the current job. | 87 // Indicates we should continue with the current job. |
83 CONTINUE, | 88 CONTINUE, |
84 // Indicates that we should save it to be processed later. | 89 // Indicates that we should save it to be processed later. |
85 SAVE, | 90 SAVE, |
86 // Indicates we should drop this job. | 91 // Indicates we should drop this job. |
87 DROP, | 92 DROP, |
88 }; | 93 }; |
89 | 94 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, ContinueConfiguration); | 141 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, ContinueConfiguration); |
137 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, | 142 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, |
138 SaveConfigurationWhileThrottled); | 143 SaveConfigurationWhileThrottled); |
139 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, | 144 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, |
140 SaveNudgeWhileThrottled); | 145 SaveNudgeWhileThrottled); |
141 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, | 146 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, |
142 ContinueCanaryJobConfig); | 147 ContinueCanaryJobConfig); |
143 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, | 148 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, |
144 ContinueNudgeWhileExponentialBackOff); | 149 ContinueNudgeWhileExponentialBackOff); |
145 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, TransientPollFailure); | 150 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, TransientPollFailure); |
| 151 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, GetInitialBackoffDelay); |
146 | 152 |
147 // A component used to get time delays associated with exponential backoff. | 153 // A component used to get time delays associated with exponential backoff. |
148 // Encapsulated into a class to facilitate testing. | 154 // Encapsulated into a class to facilitate testing. |
149 class DelayProvider { | 155 class DelayProvider { |
150 public: | 156 public: |
151 DelayProvider(); | 157 DelayProvider(); |
152 virtual base::TimeDelta GetDelay(const base::TimeDelta& last_delay); | 158 virtual base::TimeDelta GetDelay(const base::TimeDelta& last_delay); |
153 virtual ~DelayProvider(); | 159 virtual ~DelayProvider(); |
154 private: | 160 private: |
155 DISALLOW_COPY_AND_ASSIGN(DelayProvider); | 161 DISALLOW_COPY_AND_ASSIGN(DelayProvider); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 227 |
222 // Helper to configure polling intervals. Used by Start and ScheduleNextSync. | 228 // Helper to configure polling intervals. Used by Start and ScheduleNextSync. |
223 void AdjustPolling(const SyncSessionJob* old_job); | 229 void AdjustPolling(const SyncSessionJob* old_job); |
224 | 230 |
225 // Helper to restart waiting with |wait_interval_|'s timer. | 231 // Helper to restart waiting with |wait_interval_|'s timer. |
226 void RestartWaiting(); | 232 void RestartWaiting(); |
227 | 233 |
228 // Helper to ScheduleNextSync in case of consecutive sync errors. | 234 // Helper to ScheduleNextSync in case of consecutive sync errors. |
229 void HandleContinuationError(const SyncSessionJob& old_job); | 235 void HandleContinuationError(const SyncSessionJob& old_job); |
230 | 236 |
| 237 // Helper to calculate the initial value for exponential backoff. |
| 238 // See possible values and comments in polling_constants.h. |
| 239 base::TimeDelta GetInitialBackoffDelay( |
| 240 const sessions::ModelNeutralState& state) const; |
| 241 |
231 // Determines if it is legal to run |job| by checking current | 242 // Determines if it is legal to run |job| by checking current |
232 // operational mode, backoff or throttling, freshness | 243 // operational mode, backoff or throttling, freshness |
233 // (so we don't make redundant syncs), and connection. | 244 // (so we don't make redundant syncs), and connection. |
234 bool ShouldRunJob(const SyncSessionJob& job); | 245 bool ShouldRunJob(const SyncSessionJob& job); |
235 | 246 |
236 // Decide whether we should CONTINUE, SAVE or DROP the job. | 247 // Decide whether we should CONTINUE, SAVE or DROP the job. |
237 JobProcessDecision DecideOnJob(const SyncSessionJob& job); | 248 JobProcessDecision DecideOnJob(const SyncSessionJob& job); |
238 | 249 |
239 // Decide on whether to CONTINUE, SAVE or DROP the job when we are in | 250 // Decide on whether to CONTINUE, SAVE or DROP the job when we are in |
240 // backoff mode. | 251 // backoff mode. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 scoped_ptr<Syncer> syncer_; | 354 scoped_ptr<Syncer> syncer_; |
344 | 355 |
345 sessions::SyncSessionContext *session_context_; | 356 sessions::SyncSessionContext *session_context_; |
346 | 357 |
347 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); | 358 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); |
348 }; | 359 }; |
349 | 360 |
350 } // namespace syncer | 361 } // namespace syncer |
351 | 362 |
352 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ | 363 #endif // SYNC_ENGINE_SYNC_SCHEDULER_IMPL_H_ |
OLD | NEW |