| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 COMPONENTS_SYNC_ENGINE_IMPL_BACKOFF_DELAY_PROVIDER_H_ | 5 #ifndef COMPONENTS_SYNC_ENGINE_IMPL_BACKOFF_DELAY_PROVIDER_H_ |
| 6 #define COMPONENTS_SYNC_ENGINE_IMPL_BACKOFF_DELAY_PROVIDER_H_ | 6 #define COMPONENTS_SYNC_ENGINE_IMPL_BACKOFF_DELAY_PROVIDER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 | 10 |
| 11 namespace syncer { | 11 namespace syncer { |
| 12 | 12 |
| 13 namespace sessions { | |
| 14 struct ModelNeutralState; | 13 struct ModelNeutralState; |
| 15 } | |
| 16 | 14 |
| 17 // A component used to get time delays associated with exponential backoff. | 15 // A component used to get time delays associated with exponential backoff. |
| 18 class BackoffDelayProvider { | 16 class BackoffDelayProvider { |
| 19 public: | 17 public: |
| 20 // Factory function to create a standard BackoffDelayProvider. | 18 // Factory function to create a standard BackoffDelayProvider. |
| 21 static BackoffDelayProvider* FromDefaults(); | 19 static BackoffDelayProvider* FromDefaults(); |
| 22 | 20 |
| 23 // Similar to above, but causes sync to retry very quickly (see | 21 // Similar to above, but causes sync to retry very quickly (see |
| 24 // polling_constants.h) when it encounters an error before exponential | 22 // polling_constants.h) when it encounters an error before exponential |
| 25 // backoff. | 23 // backoff. |
| 26 // | 24 // |
| 27 // *** NOTE *** This should only be used if kSyncShortInitialRetryOverride | 25 // *** NOTE *** This should only be used if kSyncShortInitialRetryOverride |
| 28 // was passed to command line. | 26 // was passed to command line. |
| 29 static BackoffDelayProvider* WithShortInitialRetryOverride(); | 27 static BackoffDelayProvider* WithShortInitialRetryOverride(); |
| 30 | 28 |
| 31 virtual ~BackoffDelayProvider(); | 29 virtual ~BackoffDelayProvider(); |
| 32 | 30 |
| 33 // DDOS avoidance function. Calculates how long we should wait before trying | 31 // DDOS avoidance function. Calculates how long we should wait before trying |
| 34 // again after a failed sync attempt, where the last delay was |base_delay|. | 32 // again after a failed sync attempt, where the last delay was |base_delay|. |
| 35 // TODO(tim): Look at URLRequestThrottlerEntryInterface. | 33 // TODO(tim): Look at URLRequestThrottlerEntryInterface. |
| 36 virtual base::TimeDelta GetDelay(const base::TimeDelta& last_delay); | 34 virtual base::TimeDelta GetDelay(const base::TimeDelta& last_delay); |
| 37 | 35 |
| 38 // Helper to calculate the initial value for exponential backoff. | 36 // Helper to calculate the initial value for exponential backoff. |
| 39 // See possible values and comments in polling_constants.h. | 37 // See possible values and comments in polling_constants.h. |
| 40 virtual base::TimeDelta GetInitialDelay( | 38 virtual base::TimeDelta GetInitialDelay(const ModelNeutralState& state) const; |
| 41 const sessions::ModelNeutralState& state) const; | |
| 42 | 39 |
| 43 protected: | 40 protected: |
| 44 BackoffDelayProvider(const base::TimeDelta& default_initial_backoff, | 41 BackoffDelayProvider(const base::TimeDelta& default_initial_backoff, |
| 45 const base::TimeDelta& short_initial_backoff); | 42 const base::TimeDelta& short_initial_backoff); |
| 46 | 43 |
| 47 private: | 44 private: |
| 48 const base::TimeDelta default_initial_backoff_; | 45 const base::TimeDelta default_initial_backoff_; |
| 49 const base::TimeDelta short_initial_backoff_; | 46 const base::TimeDelta short_initial_backoff_; |
| 50 | 47 |
| 51 DISALLOW_COPY_AND_ASSIGN(BackoffDelayProvider); | 48 DISALLOW_COPY_AND_ASSIGN(BackoffDelayProvider); |
| 52 }; | 49 }; |
| 53 | 50 |
| 54 } // namespace syncer | 51 } // namespace syncer |
| 55 | 52 |
| 56 #endif // COMPONENTS_SYNC_ENGINE_IMPL_BACKOFF_DELAY_PROVIDER_H_ | 53 #endif // COMPONENTS_SYNC_ENGINE_IMPL_BACKOFF_DELAY_PROVIDER_H_ |
| OLD | NEW |