diff options
Diffstat (limited to 'sync/sessions/data_type_tracker.cc')
-rw-r--r-- | sync/sessions/data_type_tracker.cc | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/sync/sessions/data_type_tracker.cc b/sync/sessions/data_type_tracker.cc index 639ccc0..857b86a 100644 --- a/sync/sessions/data_type_tracker.cc +++ b/sync/sessions/data_type_tracker.cc @@ -37,6 +37,11 @@ void DataTypeTracker::RecordRemoteInvalidation( } 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()) + return; + local_nudge_count_ = 0; local_refresh_request_count_ = 0; pending_payloads_.clear(); @@ -50,11 +55,10 @@ void DataTypeTracker::UpdatePayloadBufferSize(size_t new_size) { } bool DataTypeTracker::IsSyncRequired() const { - return local_nudge_count_ > 0 || IsGetUpdatesRequired(); -} - -bool DataTypeTracker::IsGetUpdatesRequired() const { - return local_refresh_request_count_ > 0 || !pending_payloads_.empty(); + return !IsThrottled() && + (local_nudge_count_ > 0 || + local_refresh_request_count_ > 0 || + !pending_payloads_.empty()); } bool DataTypeTracker::HasLocalChangePending() const { @@ -87,5 +91,30 @@ void DataTypeTracker::FillGetUpdatesTriggersMessage( // msg->set_server_dropped_hints(server_payload_oveflow_); } +bool DataTypeTracker::IsThrottled() const { + return !unthrottle_time_.is_null(); +} + +base::TimeDelta DataTypeTracker::GetTimeUntilUnthrottle( + base::TimeTicks now) const { + if (!IsThrottled()) { + NOTREACHED(); + return base::TimeDelta::FromSeconds(0); + } + return std::max(base::TimeDelta::FromSeconds(0), + unthrottle_time_ - now); +} + +void DataTypeTracker::ThrottleType(base::TimeDelta duration, + base::TimeTicks now) { + unthrottle_time_ = std::max(unthrottle_time_, now + duration); +} + +void DataTypeTracker::UpdateThrottleState(base::TimeTicks now) { + if (now >= unthrottle_time_) { + unthrottle_time_ = base::TimeTicks(); + } +} + } // namespace sessions } // namespace syncer |