| Index: components/sync/engine_impl/cycle/data_type_tracker.cc
|
| diff --git a/components/sync/engine_impl/cycle/data_type_tracker.cc b/components/sync/engine_impl/cycle/data_type_tracker.cc
|
| index 732bcdc172defb5868e7119ef21562d1018b11f0..fd377980709f642746dc5a67caba4df01afa9758 100644
|
| --- a/components/sync/engine_impl/cycle/data_type_tracker.cc
|
| +++ b/components/sync/engine_impl/cycle/data_type_tracker.cc
|
| @@ -7,10 +7,37 @@
|
| #include <algorithm>
|
|
|
| #include "base/logging.h"
|
| +#include "base/memory/ptr_util.h"
|
| #include "components/sync/engine_impl/cycle/nudge_tracker.h"
|
|
|
| namespace syncer {
|
|
|
| +namespace {
|
| +
|
| +#define ENUM_CASE(x) \
|
| + case x: \
|
| + return #x; \
|
| + break;
|
| +
|
| +} // namespace
|
| +
|
| +WaitInterval::WaitInterval() : mode(UNKNOWN) {}
|
| +
|
| +WaitInterval::WaitInterval(BlockingMode mode, base::TimeDelta length)
|
| + : mode(mode), length(length) {}
|
| +
|
| +WaitInterval::~WaitInterval() {}
|
| +
|
| +const char* WaitInterval::GetModeString(BlockingMode mode) {
|
| + switch (mode) {
|
| + ENUM_CASE(UNKNOWN);
|
| + ENUM_CASE(EXPONENTIAL_BACKOFF);
|
| + ENUM_CASE(THROTTLED);
|
| + }
|
| + NOTREACHED();
|
| + return "";
|
| +}
|
| +
|
| DataTypeTracker::DataTypeTracker()
|
| : local_nudge_count_(0),
|
| local_refresh_request_count_(0),
|
| @@ -99,7 +126,7 @@ void DataTypeTracker::RecordCommitConflict() {
|
| void DataTypeTracker::RecordSuccessfulSyncCycle() {
|
| // If we were throttled, then we would have been excluded from this cycle's
|
| // GetUpdates and Commit actions. Our state remains unchanged.
|
| - if (IsThrottled())
|
| + if (IsThrottled() || IsBackedOff())
|
| return;
|
|
|
| local_nudge_count_ = 0;
|
| @@ -131,11 +158,12 @@ void DataTypeTracker::UpdatePayloadBufferSize(size_t new_size) {
|
| }
|
|
|
| bool DataTypeTracker::IsSyncRequired() const {
|
| - return !IsThrottled() && (HasLocalChangePending() || IsGetUpdatesRequired());
|
| + return !IsThrottled() && !IsBackedOff() &&
|
| + (HasLocalChangePending() || IsGetUpdatesRequired());
|
| }
|
|
|
| bool DataTypeTracker::IsGetUpdatesRequired() const {
|
| - return !IsThrottled() &&
|
| + return !IsThrottled() && !IsBackedOff() &&
|
| (HasRefreshRequestPending() || HasPendingInvalidation() ||
|
| IsInitialSyncRequired() || IsSyncRequiredToResolveConflict());
|
| }
|
| @@ -164,6 +192,8 @@ void DataTypeTracker::SetLegacyNotificationHint(
|
| sync_pb::DataTypeProgressMarker* progress) const {
|
| DCHECK(!IsThrottled())
|
| << "We should not make requests if the type is throttled.";
|
| + DCHECK(!IsBackedOff())
|
| + << "We should not make requests if the type is backed off.";
|
|
|
| if (!pending_invalidations_.empty() &&
|
| !pending_invalidations_.back()->IsUnknownVersion()) {
|
| @@ -204,26 +234,47 @@ void DataTypeTracker::FillGetUpdatesTriggersMessage(
|
| }
|
|
|
| bool DataTypeTracker::IsThrottled() const {
|
| - return !unthrottle_time_.is_null();
|
| + return wait_interval_.get() &&
|
| + wait_interval_->mode == WaitInterval::THROTTLED;
|
| +}
|
| +
|
| +bool DataTypeTracker::IsBackedOff() const {
|
| + return wait_interval_.get() &&
|
| + wait_interval_->mode == WaitInterval::EXPONENTIAL_BACKOFF;
|
| }
|
|
|
| -base::TimeDelta DataTypeTracker::GetTimeUntilUnthrottle(
|
| - base::TimeTicks now) const {
|
| - if (!IsThrottled()) {
|
| +base::TimeDelta DataTypeTracker::GetTimeUntilUnblock() const {
|
| + DCHECK(IsThrottled() || IsBackedOff());
|
| + return std::max(base::TimeDelta::FromSeconds(0),
|
| + unblock_time_ - base::TimeTicks::Now());
|
| +}
|
| +
|
| +base::TimeDelta DataTypeTracker::GetLastBackoffInterval() const {
|
| + if (!IsBackedOff()) {
|
| NOTREACHED();
|
| return base::TimeDelta::FromSeconds(0);
|
| }
|
| - return std::max(base::TimeDelta::FromSeconds(0), unthrottle_time_ - now);
|
| + return wait_interval_->length;
|
| }
|
|
|
| void DataTypeTracker::ThrottleType(base::TimeDelta duration,
|
| base::TimeTicks now) {
|
| - unthrottle_time_ = std::max(unthrottle_time_, now + duration);
|
| + unblock_time_ = std::max(unblock_time_, now + duration);
|
| + wait_interval_ =
|
| + base::MakeUnique<WaitInterval>(WaitInterval::THROTTLED, duration);
|
| +}
|
| +
|
| +void DataTypeTracker::BackoffType(base::TimeDelta duration,
|
| + base::TimeTicks now) {
|
| + unblock_time_ = std::max(unblock_time_, now + duration);
|
| + wait_interval_ = base::MakeUnique<WaitInterval>(
|
| + WaitInterval::EXPONENTIAL_BACKOFF, duration);
|
| }
|
|
|
| -void DataTypeTracker::UpdateThrottleState(base::TimeTicks now) {
|
| - if (now >= unthrottle_time_) {
|
| - unthrottle_time_ = base::TimeTicks();
|
| +void DataTypeTracker::UpdateThrottleOrBackoffState() {
|
| + if (base::TimeTicks::Now() >= unblock_time_) {
|
| + unblock_time_ = base::TimeTicks();
|
| + wait_interval_.reset();
|
| }
|
| }
|
|
|
|
|