Chromium Code Reviews| Index: components/sync/engine_impl/cycle/nudge_tracker.cc |
| diff --git a/components/sync/engine_impl/cycle/nudge_tracker.cc b/components/sync/engine_impl/cycle/nudge_tracker.cc |
| index cef95f2379a827f22735c7b445a76e35c802db94..1cf2391d92258e4de317f360801839e2190f2bd6 100644 |
| --- a/components/sync/engine_impl/cycle/nudge_tracker.cc |
| +++ b/components/sync/engine_impl/cycle/nudge_tracker.cc |
| @@ -189,51 +189,71 @@ void NudgeTracker::SetTypesThrottledUntil(ModelTypeSet types, |
| } |
| } |
| -void NudgeTracker::UpdateTypeThrottlingState(base::TimeTicks now) { |
| +void NudgeTracker::SetTypeBackedOff(ModelType type, |
| + base::TimeDelta length, |
| + base::TimeTicks now) { |
| + TypeTrackerMap::const_iterator tracker_it = type_trackers_.find(type); |
| + DCHECK(tracker_it != type_trackers_.end()); |
| + tracker_it->second->BackOffType(length, now); |
| +} |
| + |
| +void NudgeTracker::UpdateTypeThrottlingAndBackoffState() { |
| for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| it != type_trackers_.end(); ++it) { |
| - it->second->UpdateThrottleState(now); |
| + it->second->UpdateThrottleOrBackoffState(); |
| } |
| } |
| -bool NudgeTracker::IsAnyTypeThrottled() const { |
| +bool NudgeTracker::IsAnyTypeBlocked() const { |
| for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| it != type_trackers_.end(); ++it) { |
| - if (it->second->IsThrottled()) { |
| + if (it->second->IsBlocked()) { |
| return true; |
| } |
| } |
| return false; |
| } |
| -bool NudgeTracker::IsTypeThrottled(ModelType type) const { |
| +bool NudgeTracker::IsTypeBlocked(ModelType type) const { |
| + DCHECK(type_trackers_.find(type) != type_trackers_.end()); |
| + return type_trackers_.find(type)->second->IsBlocked(); |
| +} |
| + |
| +WaitInterval::BlockingMode NudgeTracker::GetTypeBlockingMode( |
| + ModelType type) const { |
| DCHECK(type_trackers_.find(type) != type_trackers_.end()); |
| - return type_trackers_.find(type)->second->IsThrottled(); |
| + return type_trackers_.find(type)->second->GetBlockingMode(); |
| } |
| -base::TimeDelta NudgeTracker::GetTimeUntilNextUnthrottle( |
| - base::TimeTicks now) const { |
| - DCHECK(IsAnyTypeThrottled()) << "This function requires a pending unthrottle"; |
| +base::TimeDelta NudgeTracker::GetTimeUntilNextUnblock() const { |
| + DCHECK(IsAnyTypeBlocked()) << "This function requires a pending unblock."; |
| - // Return min of GetTimeUntilUnthrottle() values for all IsThrottled() types. |
| - base::TimeDelta time_until_next_unthrottle = base::TimeDelta::Max(); |
| + // Return min of GetTimeUntilUnblock() values for all IsBlocked() types. |
| + base::TimeDelta time_until_next_unblock = base::TimeDelta::Max(); |
| for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| it != type_trackers_.end(); ++it) { |
| - if (it->second->IsThrottled()) { |
| - time_until_next_unthrottle = std::min( |
| - time_until_next_unthrottle, it->second->GetTimeUntilUnthrottle(now)); |
| + if (it->second->IsBlocked()) { |
| + time_until_next_unblock = |
| + std::min(time_until_next_unblock, it->second->GetTimeUntilUnblock()); |
| } |
| } |
| - DCHECK(!time_until_next_unthrottle.is_max()); |
| + DCHECK(!time_until_next_unblock.is_max()); |
| + |
| + return time_until_next_unblock; |
| +} |
| + |
| +base::TimeDelta NudgeTracker::GetTypeLastBackoffInterval(ModelType type) const { |
| + TypeTrackerMap::const_iterator tracker_it = type_trackers_.find(type); |
| + DCHECK(tracker_it != type_trackers_.end()); |
|
Nicolas Zea
2016/11/14 21:57:15
nit: DCHECK_NE?
Gang Wu
2016/11/15 01:59:32
Cannot use DCHECK_NE, compiler will failed on logg
|
| - return time_until_next_unthrottle; |
| + return tracker_it->second->GetLastBackoffInterval(); |
| } |
| -ModelTypeSet NudgeTracker::GetThrottledTypes() const { |
| +ModelTypeSet NudgeTracker::GetBlockedTypes() const { |
| ModelTypeSet result; |
| for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| it != type_trackers_.end(); ++it) { |
| - if (it->second->IsThrottled()) { |
| + if (it->second->IsBlocked()) { |
| result.Put(it->first); |
| } |
| } |
| @@ -298,16 +318,16 @@ sync_pb::GetUpdatesCallerInfo::GetUpdatesSource NudgeTracker::GetLegacySource() |
| for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| it != type_trackers_.end(); ++it) { |
| const DataTypeTracker& tracker = *it->second; |
| - if (!tracker.IsThrottled() && tracker.HasPendingInvalidation()) { |
| + if (!tracker.IsBlocked() && tracker.HasPendingInvalidation()) { |
| has_invalidation_pending = true; |
| } |
| - if (!tracker.IsThrottled() && tracker.HasRefreshRequestPending()) { |
| + if (!tracker.IsBlocked() && tracker.HasRefreshRequestPending()) { |
| has_refresh_request_pending = true; |
| } |
| - if (!tracker.IsThrottled() && tracker.HasLocalChangePending()) { |
| + if (!tracker.IsBlocked() && tracker.HasLocalChangePending()) { |
| has_commit_pending = true; |
| } |
| - if (!tracker.IsThrottled() && tracker.IsInitialSyncRequired()) { |
| + if (!tracker.IsBlocked() && tracker.IsInitialSyncRequired()) { |
| is_initial_sync_required = true; |
| } |
| } |