| 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 "components/sync/engine_impl/backoff_delay_provider.h" | 5 #include "components/sync/engine_impl/backoff_delay_provider.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "components/sync/base/syncer_error.h" | 12 #include "components/sync/base/syncer_error.h" |
| 13 #include "components/sync/engine/cycle/model_neutral_state.h" |
| 13 #include "components/sync/engine/polling_constants.h" | 14 #include "components/sync/engine/polling_constants.h" |
| 14 #include "components/sync/sessions/model_neutral_state.h" | |
| 15 | 15 |
| 16 using base::TimeDelta; | 16 using base::TimeDelta; |
| 17 | 17 |
| 18 namespace syncer { | 18 namespace syncer { |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 BackoffDelayProvider* BackoffDelayProvider::FromDefaults() { | 21 BackoffDelayProvider* BackoffDelayProvider::FromDefaults() { |
| 22 return new BackoffDelayProvider( | 22 return new BackoffDelayProvider( |
| 23 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), | 23 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), |
| 24 TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)); | 24 TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 (rand_sign * (last_delay.InSeconds() / kBackoffRandomizationFactor)); | 57 (rand_sign * (last_delay.InSeconds() / kBackoffRandomizationFactor)); |
| 58 | 58 |
| 59 // Cap the backoff interval. | 59 // Cap the backoff interval. |
| 60 backoff_s = std::max(static_cast<int64_t>(1), | 60 backoff_s = std::max(static_cast<int64_t>(1), |
| 61 std::min(backoff_s, kMaxBackoffSeconds)); | 61 std::min(backoff_s, kMaxBackoffSeconds)); |
| 62 | 62 |
| 63 return TimeDelta::FromSeconds(backoff_s); | 63 return TimeDelta::FromSeconds(backoff_s); |
| 64 } | 64 } |
| 65 | 65 |
| 66 TimeDelta BackoffDelayProvider::GetInitialDelay( | 66 TimeDelta BackoffDelayProvider::GetInitialDelay( |
| 67 const sessions::ModelNeutralState& state) const { | 67 const ModelNeutralState& state) const { |
| 68 // NETWORK_CONNECTION_UNAVAILABLE implies we did not receive HTTP response | 68 // NETWORK_CONNECTION_UNAVAILABLE implies we did not receive HTTP response |
| 69 // from server because of some network error. If network is unavailable then | 69 // from server because of some network error. If network is unavailable then |
| 70 // on next connection type or address change scheduler will run canary job. | 70 // on next connection type or address change scheduler will run canary job. |
| 71 // Otherwise we'll retry in 30 seconds. | 71 // Otherwise we'll retry in 30 seconds. |
| 72 if (state.commit_result == NETWORK_CONNECTION_UNAVAILABLE || | 72 if (state.commit_result == NETWORK_CONNECTION_UNAVAILABLE || |
| 73 state.last_download_updates_result == NETWORK_CONNECTION_UNAVAILABLE) { | 73 state.last_download_updates_result == NETWORK_CONNECTION_UNAVAILABLE) { |
| 74 return default_initial_backoff_; | 74 return default_initial_backoff_; |
| 75 } | 75 } |
| 76 | 76 |
| 77 if (SyncerErrorIsError(state.last_get_key_result)) | 77 if (SyncerErrorIsError(state.last_get_key_result)) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 100 // TODO(sync): We shouldn't need to handle this in BackoffDelayProvider. | 100 // TODO(sync): We shouldn't need to handle this in BackoffDelayProvider. |
| 101 // There should be a way to deal with protocol errors before we get to this | 101 // There should be a way to deal with protocol errors before we get to this |
| 102 // point. | 102 // point. |
| 103 if (state.commit_result == SERVER_RETURN_CONFLICT) | 103 if (state.commit_result == SERVER_RETURN_CONFLICT) |
| 104 return short_initial_backoff_; | 104 return short_initial_backoff_; |
| 105 | 105 |
| 106 return default_initial_backoff_; | 106 return default_initial_backoff_; |
| 107 } | 107 } |
| 108 | 108 |
| 109 } // namespace syncer | 109 } // namespace syncer |
| OLD | NEW |