| Index: sync/engine/sync_scheduler_impl.cc
|
| diff --git a/sync/engine/sync_scheduler_impl.cc b/sync/engine/sync_scheduler_impl.cc
|
| index 6db3260fd93539794f0be2b16e8135d1c8133186..ff177b4f8347ec1bcd5582ee5c4873bb1cf948ec 100644
|
| --- a/sync/engine/sync_scheduler_impl.cc
|
| +++ b/sync/engine/sync_scheduler_impl.cc
|
| @@ -12,7 +12,7 @@
|
| #include "base/location.h"
|
| #include "base/logging.h"
|
| #include "base/message_loop.h"
|
| -#include "base/rand_util.h"
|
| +#include "sync/engine/backoff_delay_provider.h"
|
| #include "sync/engine/syncer.h"
|
| #include "sync/engine/throttled_data_type_tracker.h"
|
| #include "sync/protocol/proto_enum_conversions.h"
|
| @@ -32,11 +32,6 @@ using sync_pb::GetUpdatesCallerInfo;
|
|
|
| namespace {
|
|
|
| -// For integration tests only. Override initial backoff value.
|
| -// TODO(tim): Remove this egregiousness, use command line flag and plumb
|
| -// through. Done this way to reduce diffs in hotfix.
|
| -static bool g_force_short_retry = false;
|
| -
|
| bool ShouldRequestEarlyExit(const SyncProtocolError& error) {
|
| switch (error.error_type) {
|
| case SYNC_SUCCESS:
|
| @@ -85,9 +80,6 @@ ConfigurationParams::ConfigurationParams(
|
| }
|
| ConfigurationParams::~ConfigurationParams() {}
|
|
|
| -SyncSchedulerImpl::DelayProvider::DelayProvider() {}
|
| -SyncSchedulerImpl::DelayProvider::~DelayProvider() {}
|
| -
|
| SyncSchedulerImpl::WaitInterval::WaitInterval()
|
| : mode(UNKNOWN),
|
| had_nudge(false) {
|
| @@ -140,11 +132,6 @@ const char* SyncSchedulerImpl::SyncSessionJob::GetPurposeString(
|
| return "";
|
| }
|
|
|
| -TimeDelta SyncSchedulerImpl::DelayProvider::GetDelay(
|
| - const base::TimeDelta& last_delay) {
|
| - return SyncSchedulerImpl::GetRecommendedDelay(last_delay);
|
| -}
|
| -
|
| GetUpdatesCallerInfo::GetUpdatesSource GetUpdatesFromNudgeSource(
|
| NudgeSource source) {
|
| switch (source) {
|
| @@ -197,6 +184,7 @@ bool IsConfigRelatedUpdateSourceValue(
|
| } // namespace
|
|
|
| SyncSchedulerImpl::SyncSchedulerImpl(const std::string& name,
|
| + BackoffDelayProvider* delay_provider,
|
| sessions::SyncSessionContext* context,
|
| Syncer* syncer)
|
| : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
|
| @@ -216,7 +204,7 @@ SyncSchedulerImpl::SyncSchedulerImpl(const std::string& name,
|
| // Start with assuming everything is fine with the connection.
|
| // At the end of the sync cycle we would have the correct status.
|
| connection_code_(HttpResponse::SERVER_CONNECTION_OK),
|
| - delay_provider_(new DelayProvider()),
|
| + delay_provider_(delay_provider),
|
| syncer_(syncer),
|
| session_context_(context) {
|
| DCHECK(sync_loop_);
|
| @@ -903,43 +891,6 @@ void SyncSchedulerImpl::RestartWaiting() {
|
| this, &SyncSchedulerImpl::DoCanaryJob);
|
| }
|
|
|
| -namespace {
|
| -// TODO(tim): Move this function to syncer_error.h.
|
| -// Return true if the command in question was attempted and did not complete
|
| -// successfully.
|
| -bool IsError(SyncerError error) {
|
| - return error != UNSET && error != SYNCER_OK;
|
| -}
|
| -} // namespace
|
| -
|
| -// static
|
| -void SyncSchedulerImpl::ForceShortInitialBackoffRetry() {
|
| - g_force_short_retry = true;
|
| -}
|
| -
|
| -TimeDelta SyncSchedulerImpl::GetInitialBackoffDelay(
|
| - const sessions::ModelNeutralState& state) const {
|
| - // TODO(tim): Remove this, provide integration-test-only mechanism
|
| - // for override.
|
| - if (g_force_short_retry) {
|
| - return TimeDelta::FromSeconds(kInitialBackoffShortRetrySeconds);
|
| - }
|
| -
|
| - if (IsError(state.last_get_key_result))
|
| - return TimeDelta::FromSeconds(kInitialBackoffRetrySeconds);
|
| - // Note: If we received a MIGRATION_DONE on download updates, then commit
|
| - // should not have taken place. Moreover, if we receive a MIGRATION_DONE
|
| - // on commit, it means that download updates succeeded. Therefore, we only
|
| - // need to check if either code is equal to SERVER_RETURN_MIGRATION_DONE,
|
| - // and not if there were any more serious errors requiring the long retry.
|
| - if (state.last_download_updates_result == SERVER_RETURN_MIGRATION_DONE ||
|
| - state.commit_result == SERVER_RETURN_MIGRATION_DONE) {
|
| - return TimeDelta::FromSeconds(kInitialBackoffShortRetrySeconds);
|
| - }
|
| -
|
| - return TimeDelta::FromSeconds(kInitialBackoffRetrySeconds);
|
| -}
|
| -
|
| void SyncSchedulerImpl::HandleContinuationError(
|
| const SyncSessionJob& old_job) {
|
| DCHECK_EQ(MessageLoop::current(), sync_loop_);
|
| @@ -951,7 +902,7 @@ void SyncSchedulerImpl::HandleContinuationError(
|
|
|
| TimeDelta length = delay_provider_->GetDelay(
|
| IsBackingOff() ? wait_interval_->length :
|
| - GetInitialBackoffDelay(
|
| + delay_provider_->GetInitialDelay(
|
| old_job.session->status_controller().model_neutral_state()));
|
|
|
| SDVLOG(2) << "In handle continuation error with "
|
| @@ -984,30 +935,6 @@ void SyncSchedulerImpl::HandleContinuationError(
|
| RestartWaiting();
|
| }
|
|
|
| -// static
|
| -TimeDelta SyncSchedulerImpl::GetRecommendedDelay(const TimeDelta& last_delay) {
|
| - if (last_delay.InSeconds() >= kMaxBackoffSeconds)
|
| - return TimeDelta::FromSeconds(kMaxBackoffSeconds);
|
| -
|
| - // This calculates approx. base_delay_seconds * 2 +/- base_delay_seconds / 2
|
| - int64 backoff_s =
|
| - std::max(static_cast<int64>(1),
|
| - last_delay.InSeconds() * kBackoffRandomizationFactor);
|
| -
|
| - // Flip a coin to randomize backoff interval by +/- 50%.
|
| - int rand_sign = base::RandInt(0, 1) * 2 - 1;
|
| -
|
| - // Truncation is adequate for rounding here.
|
| - backoff_s = backoff_s +
|
| - (rand_sign * (last_delay.InSeconds() / kBackoffRandomizationFactor));
|
| -
|
| - // Cap the backoff interval.
|
| - backoff_s = std::max(static_cast<int64>(1),
|
| - std::min(backoff_s, kMaxBackoffSeconds));
|
| -
|
| - return TimeDelta::FromSeconds(backoff_s);
|
| -}
|
| -
|
| void SyncSchedulerImpl::RequestStop(const base::Closure& callback) {
|
| syncer_->RequestEarlyExit(); // Safe to call from any thread.
|
| DCHECK(weak_handle_this_.IsInitialized());
|
|
|