Commit 9c06ccf8 authored by Mikel Astiz's avatar Mikel Astiz Committed by Commit Bot

[sync] Trivially adopt base::TimeDelta for constants

base::TimeDelta has a constexpr constructor and can be used for
constants, preventing bugs and avoiding the need for clarifying
comments.

Bug: 1152797
Change-Id: I9cd5168af01d8e9b17e83524ef37e10b50ceda44
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2556641Reviewed-by: default avatarVictor Vianna <victorvianna@google.com>
Commit-Queue: Victor Vianna <victorvianna@google.com>
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#831094}
parent 574cee3d
...@@ -25,13 +25,13 @@ DelayInfo CalculateDelay(int64_t current_delay) { ...@@ -25,13 +25,13 @@ DelayInfo CalculateDelay(int64_t current_delay) {
syncer::kBackoffRandomizationFactor); syncer::kBackoffRandomizationFactor);
delay_info.max_delay = backoff_s + current_delay/2; delay_info.max_delay = backoff_s + current_delay/2;
delay_info.min_delay = delay_info.min_delay = std::max(
std::max(static_cast<int64_t>(1), static_cast<int64_t>(1),
std::min(delay_info.min_delay, syncer::kMaxBackoffSeconds)); std::min(delay_info.min_delay, syncer::kMaxBackoffTime.InSeconds()));
delay_info.max_delay = delay_info.max_delay = std::max(
std::max(static_cast<int64_t>(1), static_cast<int64_t>(1),
std::min(delay_info.max_delay, syncer::kMaxBackoffSeconds)); std::min(delay_info.max_delay, syncer::kMaxBackoffTime.InSeconds()));
return delay_info; return delay_info;
} }
...@@ -111,4 +111,3 @@ void RetryVerifier::VerifyRetryInterval(const syncer::SyncCycleSnapshot& snap) { ...@@ -111,4 +111,3 @@ void RetryVerifier::VerifyRetryInterval(const syncer::SyncCycleSnapshot& snap) {
return; return;
} }
} }
...@@ -18,6 +18,7 @@ class SyncCycleSnapshot; ...@@ -18,6 +18,7 @@ class SyncCycleSnapshot;
// place somewhere in this range. The algorithm that calculates the retry wait // place somewhere in this range. The algorithm that calculates the retry wait
// time uses rand functions. // time uses rand functions.
struct DelayInfo { struct DelayInfo {
// TODO(crbug.com/1152797): Adopt base::TimeDelta in this file.
int64_t min_delay; int64_t min_delay;
int64_t max_delay; int64_t max_delay;
}; };
......
...@@ -49,8 +49,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientPollingSyncTest, ShouldInitializePollPrefs) { ...@@ -49,8 +49,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientPollingSyncTest, ShouldInitializePollPrefs) {
// Execute a sync cycle and verify the client set up (and persisted) the // Execute a sync cycle and verify the client set up (and persisted) the
// default value. // default value.
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
EXPECT_THAT(sync_prefs.GetPollInterval().InSeconds(), EXPECT_THAT(sync_prefs.GetPollInterval(), Eq(syncer::kDefaultPollInterval));
Eq(syncer::kDefaultPollIntervalSeconds));
} }
// This test verifies that updates of the poll interval get persisted // This test verifies that updates of the poll interval get persisted
......
...@@ -607,8 +607,7 @@ void ProfileSyncService::StartUpSlowEngineComponents() { ...@@ -607,8 +607,7 @@ void ProfileSyncService::StartUpSlowEngineComponents() {
params.invalidation_versions = sync_prefs_.GetInvalidationVersions(); params.invalidation_versions = sync_prefs_.GetInvalidationVersions();
params.poll_interval = sync_prefs_.GetPollInterval(); params.poll_interval = sync_prefs_.GetPollInterval();
if (params.poll_interval.is_zero()) { if (params.poll_interval.is_zero()) {
params.poll_interval = params.poll_interval = kDefaultPollInterval;
base::TimeDelta::FromSeconds(kDefaultPollIntervalSeconds);
} }
if (!IsLocalSyncEnabled()) { if (!IsLocalSyncEnabled()) {
......
...@@ -22,7 +22,8 @@ namespace { ...@@ -22,7 +22,8 @@ namespace {
// The amount of time we'll wait to initialize sync if no data type requests // The amount of time we'll wait to initialize sync if no data type requests
// immediately initialization. // immediately initialization.
const int kDefaultDeferredInitDelaySeconds = 10; constexpr base::TimeDelta kDefaultDeferredInitDelay =
base::TimeDelta::FromSeconds(10);
base::TimeDelta GetDeferredInitDelay() { base::TimeDelta GetDeferredInitDelay() {
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
...@@ -37,7 +38,7 @@ base::TimeDelta GetDeferredInitDelay() { ...@@ -37,7 +38,7 @@ base::TimeDelta GetDeferredInitDelay() {
return base::TimeDelta::FromSeconds(timeout); return base::TimeDelta::FromSeconds(timeout);
} }
} }
return base::TimeDelta::FromSeconds(kDefaultDeferredInitDelaySeconds); return kDefaultDeferredInitDelay;
} }
bool IsDeferredStartupEnabled() { bool IsDeferredStartupEnabled() {
......
...@@ -28,7 +28,7 @@ const char kEventEndpoint[] = "event"; ...@@ -28,7 +28,7 @@ const char kEventEndpoint[] = "event";
// plenty of time. Since sync is off when this request is started, we don't // plenty of time. Since sync is off when this request is started, we don't
// want anything sync-related hanging around for very long from a human // want anything sync-related hanging around for very long from a human
// perspective either. This seems like a good compromise. // perspective either. This seems like a good compromise.
const int kRequestTimeoutSeconds = 10; constexpr base::TimeDelta kRequestTimeout = base::TimeDelta::FromSeconds(10);
} // namespace } // namespace
...@@ -106,8 +106,8 @@ void SyncStoppedReporter::ReportSyncStopped(const std::string& access_token, ...@@ -106,8 +106,8 @@ void SyncStoppedReporter::ReportSyncStopped(const std::string& access_token,
url_loader_factory_.get(), url_loader_factory_.get(),
base::BindOnce(&SyncStoppedReporter::OnSimpleLoaderComplete, base::BindOnce(&SyncStoppedReporter::OnSimpleLoaderComplete,
base::Unretained(this))); base::Unretained(this)));
timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kRequestTimeoutSeconds), timer_.Start(FROM_HERE, kRequestTimeout, this,
this, &SyncStoppedReporter::OnTimeout); &SyncStoppedReporter::OnTimeout);
} }
void SyncStoppedReporter::OnSimpleLoaderComplete( void SyncStoppedReporter::OnSimpleLoaderComplete(
......
...@@ -34,7 +34,7 @@ namespace { ...@@ -34,7 +34,7 @@ namespace {
// It's possible for an http request to be silently stalled. We set a time // It's possible for an http request to be silently stalled. We set a time
// limit for all http requests, beyond which the request is cancelled and // limit for all http requests, beyond which the request is cancelled and
// treated as a transient failure. // treated as a transient failure.
const int kMaxHttpRequestTimeSeconds = 60 * 5; // 5 minutes. constexpr base::TimeDelta kMaxHttpRequestTime = base::TimeDelta::FromMinutes(5);
// Helper method for logging timeouts via UMA. // Helper method for logging timeouts via UMA.
void LogTimeout(bool timed_out) { void LogTimeout(bool timed_out) {
...@@ -185,7 +185,7 @@ void HttpBridge::MakeAsynchronousPost() { ...@@ -185,7 +185,7 @@ void HttpBridge::MakeAsynchronousPost() {
fetch_state_.http_request_timeout_timer = fetch_state_.http_request_timeout_timer =
std::make_unique<base::OneShotTimer>(); std::make_unique<base::OneShotTimer>();
fetch_state_.http_request_timeout_timer->Start( fetch_state_.http_request_timeout_timer->Start(
FROM_HERE, base::TimeDelta::FromSeconds(kMaxHttpRequestTimeSeconds), FROM_HERE, kMaxHttpRequestTime,
base::BindOnce(&HttpBridge::OnURLLoadTimedOut, this)); base::BindOnce(&HttpBridge::OnURLLoadTimedOut, this));
// Some tests inject |url_loader_factory_| created to operated on the // Some tests inject |url_loader_factory_| created to operated on the
......
...@@ -10,10 +10,10 @@ namespace syncer { ...@@ -10,10 +10,10 @@ namespace syncer {
// We use high values here to ensure that failure to receive poll updates from // We use high values here to ensure that failure to receive poll updates from
// the server doesn't result in rapid-fire polling from the client due to low // the server doesn't result in rapid-fire polling from the client due to low
// local limits. // local limits.
const int64_t kDefaultPollIntervalSeconds = 3600 * 8; const base::TimeDelta kDefaultPollInterval = base::TimeDelta::FromHours(8);
// Maximum interval for exponential backoff. // Maximum interval for exponential backoff.
const int64_t kMaxBackoffSeconds = 60 * 10; // 10 minutes. const base::TimeDelta kMaxBackoffTime = base::TimeDelta::FromMinutes(10);
// Backoff interval randomization factor. // Backoff interval randomization factor.
const int kBackoffRandomizationFactor = 2; const int kBackoffRandomizationFactor = 2;
...@@ -21,16 +21,19 @@ const int kBackoffRandomizationFactor = 2; ...@@ -21,16 +21,19 @@ const int kBackoffRandomizationFactor = 2;
// After a failure contacting sync servers, specifies how long to wait before // After a failure contacting sync servers, specifies how long to wait before
// reattempting and entering exponential backoff if consecutive failures // reattempting and entering exponential backoff if consecutive failures
// occur. // occur.
const int kInitialBackoffRetrySeconds = 30; // 30 seconds. const base::TimeDelta kInitialBackoffRetryTime =
base::TimeDelta::FromSeconds(30);
// A dangerously short retry value that would not actually protect servers from // A dangerously short retry value that would not actually protect servers from
// DDoS if it were used as a seed for exponential backoff, although the client // DDoS if it were used as a seed for exponential backoff, although the client
// would still follow exponential backoff. Useful for debugging and tests (when // would still follow exponential backoff. Useful for debugging and tests (when
// you don't want to wait 5 minutes). // you don't want to wait 5 minutes).
const int kInitialBackoffShortRetrySeconds = 1; const base::TimeDelta kInitialBackoffShortRetryTime =
base::TimeDelta::FromSeconds(1);
// Similar to kInitialBackoffRetrySeconds above, but only to be used in // Similar to kInitialBackoffRetryTime above, but only to be used in
// certain exceptional error cases, such as MIGRATION_DONE. // certain exceptional error cases, such as MIGRATION_DONE.
const int kInitialBackoffImmediateRetrySeconds = 0; const base::TimeDelta kInitialBackoffImmediateRetryTime =
base::TimeDelta::FromSeconds(0);
} // namespace syncer } // namespace syncer
...@@ -7,15 +7,17 @@ ...@@ -7,15 +7,17 @@
#include <stdint.h> #include <stdint.h>
#include "base/time/time.h"
namespace syncer { namespace syncer {
// Constants used by SyncScheduler when polling servers for updates. // Constants used by SyncScheduler when polling servers for updates.
extern const int64_t kDefaultPollIntervalSeconds; extern const base::TimeDelta kDefaultPollInterval;
extern const int64_t kMaxBackoffSeconds; extern const base::TimeDelta kMaxBackoffTime;
extern const int kBackoffRandomizationFactor; extern const int kBackoffRandomizationFactor;
extern const int kInitialBackoffRetrySeconds; extern const base::TimeDelta kInitialBackoffRetryTime;
extern const int kInitialBackoffShortRetrySeconds; extern const base::TimeDelta kInitialBackoffShortRetryTime;
extern const int kInitialBackoffImmediateRetrySeconds; extern const base::TimeDelta kInitialBackoffImmediateRetryTime;
} // namespace syncer } // namespace syncer
......
...@@ -14,16 +14,13 @@ ...@@ -14,16 +14,13 @@
#include "components/sync/engine/cycle/model_neutral_state.h" #include "components/sync/engine/cycle/model_neutral_state.h"
#include "components/sync/engine/polling_constants.h" #include "components/sync/engine/polling_constants.h"
using base::TimeDelta;
namespace syncer { namespace syncer {
// static // static
std::unique_ptr<BackoffDelayProvider> BackoffDelayProvider::FromDefaults() { std::unique_ptr<BackoffDelayProvider> BackoffDelayProvider::FromDefaults() {
// base::WrapUnique() used because the constructor is private. // base::WrapUnique() used because the constructor is private.
return base::WrapUnique(new BackoffDelayProvider( return base::WrapUnique(new BackoffDelayProvider(
TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), kInitialBackoffRetryTime, kInitialBackoffImmediateRetryTime));
TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)));
} }
// static // static
...@@ -31,8 +28,7 @@ std::unique_ptr<BackoffDelayProvider> ...@@ -31,8 +28,7 @@ std::unique_ptr<BackoffDelayProvider>
BackoffDelayProvider::WithShortInitialRetryOverride() { BackoffDelayProvider::WithShortInitialRetryOverride() {
// base::WrapUnique() used because the constructor is private. // base::WrapUnique() used because the constructor is private.
return base::WrapUnique(new BackoffDelayProvider( return base::WrapUnique(new BackoffDelayProvider(
TimeDelta::FromSeconds(kInitialBackoffShortRetrySeconds), kInitialBackoffShortRetryTime, kInitialBackoffImmediateRetryTime));
TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)));
} }
BackoffDelayProvider::BackoffDelayProvider( BackoffDelayProvider::BackoffDelayProvider(
...@@ -43,31 +39,30 @@ BackoffDelayProvider::BackoffDelayProvider( ...@@ -43,31 +39,30 @@ BackoffDelayProvider::BackoffDelayProvider(
BackoffDelayProvider::~BackoffDelayProvider() {} BackoffDelayProvider::~BackoffDelayProvider() {}
TimeDelta BackoffDelayProvider::GetDelay(const base::TimeDelta& last_delay) { base::TimeDelta BackoffDelayProvider::GetDelay(
if (last_delay.InSeconds() >= kMaxBackoffSeconds) const base::TimeDelta& last_delay) {
return TimeDelta::FromSeconds(kMaxBackoffSeconds); if (last_delay >= kMaxBackoffTime)
return kMaxBackoffTime;
// This calculates approx. base_delay_seconds * 2 +/- base_delay_seconds / 2 // This calculates approx. base_delay * 2 +/- base_delay / 2
int64_t backoff_s = base::TimeDelta backoff = std::max(base::TimeDelta::FromSeconds(1),
std::max(static_cast<int64_t>(1), last_delay * kBackoffRandomizationFactor);
last_delay.InSeconds() * kBackoffRandomizationFactor);
// Flip a coin to randomize backoff interval by +/- 50%. // Flip a coin to randomize backoff interval by +/- 50%.
int rand_sign = base::RandInt(0, 1) * 2 - 1; int rand_sign = base::RandInt(0, 1) * 2 - 1;
// Truncation is adequate for rounding here. // Truncation is adequate for rounding here.
backoff_s = base::TimeDelta jitter =
backoff_s + (last_delay / kBackoffRandomizationFactor)
(rand_sign * (last_delay.InSeconds() / kBackoffRandomizationFactor)); .FloorToMultiple(base::TimeDelta::FromSeconds(1));
backoff += rand_sign * jitter;
// Cap the backoff interval.
backoff_s = std::max(static_cast<int64_t>(1), // Clamp backoff between 1 second and |kMaxBackoffTime|.
std::min(backoff_s, kMaxBackoffSeconds)); return std::max(base::TimeDelta::FromSeconds(1),
std::min(backoff, kMaxBackoffTime));
return TimeDelta::FromSeconds(backoff_s);
} }
TimeDelta BackoffDelayProvider::GetInitialDelay( base::TimeDelta BackoffDelayProvider::GetInitialDelay(
const ModelNeutralState& state) const { const ModelNeutralState& state) const {
// NETWORK_CONNECTION_UNAVAILABLE implies we did not receive HTTP response // NETWORK_CONNECTION_UNAVAILABLE implies we did not receive HTTP response
// from server because of some network error. If network is unavailable then // from server because of some network error. If network is unavailable then
......
...@@ -30,10 +30,9 @@ TEST_F(BackoffDelayProviderTest, GetRecommendedDelay) { ...@@ -30,10 +30,9 @@ TEST_F(BackoffDelayProviderTest, GetRecommendedDelay) {
delay->GetDelay(TimeDelta::FromSeconds(50))); delay->GetDelay(TimeDelta::FromSeconds(50)));
EXPECT_LE(TimeDelta::FromSeconds(10), EXPECT_LE(TimeDelta::FromSeconds(10),
delay->GetDelay(TimeDelta::FromSeconds(10))); delay->GetDelay(TimeDelta::FromSeconds(10)));
EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds), EXPECT_EQ(kMaxBackoffTime, delay->GetDelay(kMaxBackoffTime));
delay->GetDelay(TimeDelta::FromSeconds(kMaxBackoffSeconds))); EXPECT_EQ(kMaxBackoffTime,
EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds), delay->GetDelay(kMaxBackoffTime + TimeDelta::FromSeconds(1)));
delay->GetDelay(TimeDelta::FromSeconds(kMaxBackoffSeconds + 1)));
} }
TEST_F(BackoffDelayProviderTest, GetInitialDelay) { TEST_F(BackoffDelayProviderTest, GetInitialDelay) {
...@@ -42,48 +41,39 @@ TEST_F(BackoffDelayProviderTest, GetInitialDelay) { ...@@ -42,48 +41,39 @@ TEST_F(BackoffDelayProviderTest, GetInitialDelay) {
ModelNeutralState state; ModelNeutralState state;
state.last_get_key_result = state.last_get_key_result =
SyncerError::HttpError(net::HTTP_INTERNAL_SERVER_ERROR); SyncerError::HttpError(net::HTTP_INTERNAL_SERVER_ERROR);
EXPECT_EQ(kInitialBackoffRetrySeconds, EXPECT_EQ(kInitialBackoffRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
state.last_get_key_result = SyncerError(); state.last_get_key_result = SyncerError();
state.last_download_updates_result = state.last_download_updates_result =
SyncerError(SyncerError::SERVER_RETURN_MIGRATION_DONE); SyncerError(SyncerError::SERVER_RETURN_MIGRATION_DONE);
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds, EXPECT_EQ(kInitialBackoffImmediateRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = state.last_download_updates_result =
SyncerError::NetworkConnectionUnavailable(net::ERR_FAILED); SyncerError::NetworkConnectionUnavailable(net::ERR_FAILED);
EXPECT_EQ(kInitialBackoffRetrySeconds, EXPECT_EQ(kInitialBackoffRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = state.last_download_updates_result =
SyncerError(SyncerError::SERVER_RETURN_TRANSIENT_ERROR); SyncerError(SyncerError::SERVER_RETURN_TRANSIENT_ERROR);
EXPECT_EQ(kInitialBackoffRetrySeconds, EXPECT_EQ(kInitialBackoffRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = state.last_download_updates_result =
SyncerError(SyncerError::SERVER_RESPONSE_VALIDATION_FAILED); SyncerError(SyncerError::SERVER_RESPONSE_VALIDATION_FAILED);
EXPECT_EQ(kInitialBackoffRetrySeconds, EXPECT_EQ(kInitialBackoffRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = state.last_download_updates_result =
SyncerError(SyncerError::DATATYPE_TRIGGERED_RETRY); SyncerError(SyncerError::DATATYPE_TRIGGERED_RETRY);
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds, EXPECT_EQ(kInitialBackoffImmediateRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = SyncerError(SyncerError::SYNCER_OK); state.last_download_updates_result = SyncerError(SyncerError::SYNCER_OK);
state.commit_result = SyncerError(SyncerError::SERVER_RETURN_MIGRATION_DONE); state.commit_result = SyncerError(SyncerError::SERVER_RETURN_MIGRATION_DONE);
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds, EXPECT_EQ(kInitialBackoffImmediateRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
state.commit_result = state.commit_result =
SyncerError::NetworkConnectionUnavailable(net::ERR_FAILED); SyncerError::NetworkConnectionUnavailable(net::ERR_FAILED);
EXPECT_EQ(kInitialBackoffRetrySeconds, EXPECT_EQ(kInitialBackoffRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
state.commit_result = SyncerError(SyncerError::SERVER_RETURN_CONFLICT); state.commit_result = SyncerError(SyncerError::SERVER_RETURN_CONFLICT);
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds, EXPECT_EQ(kInitialBackoffImmediateRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
} }
TEST_F(BackoffDelayProviderTest, GetInitialDelayWithOverride) { TEST_F(BackoffDelayProviderTest, GetInitialDelayWithOverride) {
...@@ -92,38 +82,31 @@ TEST_F(BackoffDelayProviderTest, GetInitialDelayWithOverride) { ...@@ -92,38 +82,31 @@ TEST_F(BackoffDelayProviderTest, GetInitialDelayWithOverride) {
ModelNeutralState state; ModelNeutralState state;
state.last_get_key_result = state.last_get_key_result =
SyncerError::HttpError(net::HTTP_INTERNAL_SERVER_ERROR); SyncerError::HttpError(net::HTTP_INTERNAL_SERVER_ERROR);
EXPECT_EQ(kInitialBackoffShortRetrySeconds, EXPECT_EQ(kInitialBackoffShortRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
state.last_get_key_result = SyncerError(); state.last_get_key_result = SyncerError();
state.last_download_updates_result = state.last_download_updates_result =
SyncerError(SyncerError::SERVER_RETURN_MIGRATION_DONE); SyncerError(SyncerError::SERVER_RETURN_MIGRATION_DONE);
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds, EXPECT_EQ(kInitialBackoffImmediateRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = state.last_download_updates_result =
SyncerError(SyncerError::SERVER_RETURN_TRANSIENT_ERROR); SyncerError(SyncerError::SERVER_RETURN_TRANSIENT_ERROR);
EXPECT_EQ(kInitialBackoffShortRetrySeconds, EXPECT_EQ(kInitialBackoffShortRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = state.last_download_updates_result =
SyncerError(SyncerError::SERVER_RESPONSE_VALIDATION_FAILED); SyncerError(SyncerError::SERVER_RESPONSE_VALIDATION_FAILED);
EXPECT_EQ(kInitialBackoffShortRetrySeconds, EXPECT_EQ(kInitialBackoffShortRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = state.last_download_updates_result =
SyncerError(SyncerError::DATATYPE_TRIGGERED_RETRY); SyncerError(SyncerError::DATATYPE_TRIGGERED_RETRY);
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds, EXPECT_EQ(kInitialBackoffImmediateRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = SyncerError(SyncerError::SYNCER_OK); state.last_download_updates_result = SyncerError(SyncerError::SYNCER_OK);
state.commit_result = SyncerError(SyncerError::SERVER_RETURN_MIGRATION_DONE); state.commit_result = SyncerError(SyncerError::SERVER_RETURN_MIGRATION_DONE);
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds, EXPECT_EQ(kInitialBackoffImmediateRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
state.commit_result = SyncerError(SyncerError::SERVER_RETURN_CONFLICT); state.commit_result = SyncerError(SyncerError::SERVER_RETURN_CONFLICT);
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds, EXPECT_EQ(kInitialBackoffImmediateRetryTime, delay->GetInitialDelay(state));
delay->GetInitialDelay(state).InSeconds());
} }
} // namespace syncer } // namespace syncer
...@@ -15,10 +15,14 @@ namespace syncer { ...@@ -15,10 +15,14 @@ namespace syncer {
namespace { namespace {
// Delays for syncer nudges. // Delays for syncer nudges.
const int kDefaultNudgeDelayMilliseconds = 200; constexpr base::TimeDelta kDefaultNudgeDelay =
const int kSlowNudgeDelayMilliseconds = 2000; base::TimeDelta::FromMilliseconds(200);
const int kSyncRefreshDelayMilliseconds = 500; constexpr base::TimeDelta kSlowNudgeDelay =
const int kSyncSchedulerDelayMilliseconds = 250; base::TimeDelta::FromMilliseconds(2000);
constexpr base::TimeDelta kSyncRefreshDelay =
base::TimeDelta::FromMilliseconds(500);
constexpr base::TimeDelta kSyncSchedulerDelay =
base::TimeDelta::FromMilliseconds(250);
base::TimeDelta GetSharingMessageDelay(base::TimeDelta default_delay) { base::TimeDelta GetSharingMessageDelay(base::TimeDelta default_delay) {
if (!base::FeatureList::IsEnabled( if (!base::FeatureList::IsEnabled(
...@@ -37,13 +41,13 @@ base::TimeDelta GetDefaultDelayForType(ModelType model_type, ...@@ -37,13 +41,13 @@ base::TimeDelta GetDefaultDelayForType(ModelType model_type,
case USER_EVENTS: case USER_EVENTS:
// Accompany types rely on nudges from other types, and hence have long // Accompany types rely on nudges from other types, and hence have long
// nudge delays. // nudge delays.
return base::TimeDelta::FromSeconds(kDefaultPollIntervalSeconds); return kDefaultPollInterval;
case BOOKMARKS: case BOOKMARKS:
case PREFERENCES: case PREFERENCES:
case SESSIONS: case SESSIONS:
// Types with sometimes automatic changes get longer delays to allow more // Types with sometimes automatic changes get longer delays to allow more
// coalescing. // coalescing.
return base::TimeDelta::FromMilliseconds(kSlowNudgeDelayMilliseconds); return kSlowNudgeDelay;
case SHARING_MESSAGE: case SHARING_MESSAGE:
return GetSharingMessageDelay(minimum_delay); return GetSharingMessageDelay(minimum_delay);
default: default:
...@@ -56,12 +60,9 @@ base::TimeDelta GetDefaultDelayForType(ModelType model_type, ...@@ -56,12 +60,9 @@ base::TimeDelta GetDefaultDelayForType(ModelType model_type,
NudgeTracker::NudgeTracker() NudgeTracker::NudgeTracker()
: invalidations_enabled_(false), : invalidations_enabled_(false),
invalidations_out_of_sync_(true), invalidations_out_of_sync_(true),
minimum_local_nudge_delay_( minimum_local_nudge_delay_(kDefaultNudgeDelay),
base::TimeDelta::FromMilliseconds(kDefaultNudgeDelayMilliseconds)), local_refresh_nudge_delay_(kSyncRefreshDelay),
local_refresh_nudge_delay_( remote_invalidation_nudge_delay_(kSyncSchedulerDelay) {
base::TimeDelta::FromMilliseconds(kSyncRefreshDelayMilliseconds)),
remote_invalidation_nudge_delay_(
base::TimeDelta::FromMilliseconds(kSyncSchedulerDelayMilliseconds)) {
// Default initialize all the type trackers. // Default initialize all the type trackers.
for (ModelType type : ProtocolTypes()) { for (ModelType type : ProtocolTypes()) {
type_trackers_.emplace( type_trackers_.emplace(
...@@ -144,8 +145,7 @@ void NudgeTracker::RecordInitialSyncDone(ModelTypeSet types) { ...@@ -144,8 +145,7 @@ void NudgeTracker::RecordInitialSyncDone(ModelTypeSet types) {
base::TimeDelta NudgeTracker::RecordLocalChange(ModelTypeSet types) { base::TimeDelta NudgeTracker::RecordLocalChange(ModelTypeSet types) {
// Start with the longest delay. // Start with the longest delay.
base::TimeDelta delay = base::TimeDelta delay = kDefaultPollInterval;
base::TimeDelta::FromSeconds(kDefaultPollIntervalSeconds);
for (ModelType type : types) { for (ModelType type : types) {
TypeTrackerMap::const_iterator tracker_it = type_trackers_.find(type); TypeTrackerMap::const_iterator tracker_it = type_trackers_.find(type);
DCHECK(tracker_it != type_trackers_.end()); DCHECK(tracker_it != type_trackers_.end());
......
...@@ -829,8 +829,7 @@ void SyncSchedulerImpl::OnTypesThrottled(ModelTypeSet types, ...@@ -829,8 +829,7 @@ void SyncSchedulerImpl::OnTypesThrottled(ModelTypeSet types,
void SyncSchedulerImpl::OnTypesBackedOff(ModelTypeSet types) { void SyncSchedulerImpl::OnTypesBackedOff(ModelTypeSet types) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (ModelType type : types) { for (ModelType type : types) {
TimeDelta last_backoff_time = TimeDelta last_backoff_time = kInitialBackoffRetryTime;
TimeDelta::FromSeconds(kInitialBackoffRetrySeconds);
if (nudge_tracker_.GetTypeBlockingMode(type) == if (nudge_tracker_.GetTypeBlockingMode(type) ==
WaitInterval::EXPONENTIAL_BACKOFF_RETRYING) { WaitInterval::EXPONENTIAL_BACKOFF_RETRYING) {
last_backoff_time = nudge_tracker_.GetTypeLastBackoffInterval(type); last_backoff_time = nudge_tracker_.GetTypeLastBackoffInterval(type);
......
...@@ -241,9 +241,8 @@ class SyncSchedulerImplTest : public testing::Test { ...@@ -241,9 +241,8 @@ class SyncSchedulerImplTest : public testing::Test {
class MockDelayProvider : public BackoffDelayProvider { class MockDelayProvider : public BackoffDelayProvider {
public: public:
MockDelayProvider() MockDelayProvider()
: BackoffDelayProvider( : BackoffDelayProvider(kInitialBackoffRetryTime,
TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), kInitialBackoffImmediateRetryTime) {}
TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)) {}
MOCK_METHOD(TimeDelta, GetDelay, (const TimeDelta&), (override)); MOCK_METHOD(TimeDelta, GetDelay, (const TimeDelta&), (override));
}; };
...@@ -1499,7 +1498,7 @@ TEST_F(SyncSchedulerImplTest, BackoffElevation) { ...@@ -1499,7 +1498,7 @@ TEST_F(SyncSchedulerImplTest, BackoffElevation) {
DoAll(Invoke(SimulateCommitFailed), DoAll(Invoke(SimulateCommitFailed),
RecordSyncShareMultiple(&times, kMinNumSamples, false))); RecordSyncShareMultiple(&times, kMinNumSamples, false)));
const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); const TimeDelta first = kInitialBackoffRetryTime;
const TimeDelta second = TimeDelta::FromMilliseconds(20); const TimeDelta second = TimeDelta::FromMilliseconds(20);
const TimeDelta third = TimeDelta::FromMilliseconds(30); const TimeDelta third = TimeDelta::FromMilliseconds(30);
const TimeDelta fourth = TimeDelta::FromMilliseconds(40); const TimeDelta fourth = TimeDelta::FromMilliseconds(40);
......
...@@ -30,7 +30,8 @@ namespace syncer { ...@@ -30,7 +30,8 @@ namespace syncer {
namespace { namespace {
// Time to backoff syncing after receiving a throttled response. // Time to backoff syncing after receiving a throttled response.
const int kSyncDelayAfterThrottled = 2 * 60 * 60; // 2 hours constexpr base::TimeDelta kSyncDelayAfterThrottled =
base::TimeDelta::FromHours(2);
void LogResponseProfilingData(const ClientToServerResponse& response) { void LogResponseProfilingData(const ClientToServerResponse& response) {
if (response.has_profiling_data()) { if (response.has_profiling_data()) {
...@@ -383,8 +384,7 @@ bool SyncerProtoUtil::PostAndProcessHeaders(ServerConnectionManager* scm, ...@@ -383,8 +384,7 @@ bool SyncerProtoUtil::PostAndProcessHeaders(ServerConnectionManager* scm,
base::TimeDelta SyncerProtoUtil::GetThrottleDelay( base::TimeDelta SyncerProtoUtil::GetThrottleDelay(
const ClientToServerResponse& response) { const ClientToServerResponse& response) {
base::TimeDelta throttle_delay = base::TimeDelta throttle_delay = kSyncDelayAfterThrottled;
base::TimeDelta::FromSeconds(kSyncDelayAfterThrottled);
if (response.has_client_command()) { if (response.has_client_command()) {
const sync_pb::ClientCommand& command = response.client_command(); const sync_pb::ClientCommand& command = response.client_command();
if (command.has_throttle_delay_seconds()) { if (command.has_throttle_delay_seconds()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment