OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sync/sessions/nudge_tracker.h" | 5 #include "sync/sessions/nudge_tracker.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "sync/internal_api/public/base/invalidation.h" | 8 #include "sync/internal_api/public/base/invalidation.h" |
9 #include "sync/notifier/invalidation_util.h" | 9 #include "sync/notifier/invalidation_util.h" |
10 #include "sync/notifier/object_id_invalidation_map.h" | 10 #include "sync/notifier/object_id_invalidation_map.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 } | 167 } |
168 | 168 |
169 bool NudgeTracker::IsTypeThrottled(ModelType type) const { | 169 bool NudgeTracker::IsTypeThrottled(ModelType type) const { |
170 DCHECK(type_trackers_.find(type) != type_trackers_.end()); | 170 DCHECK(type_trackers_.find(type) != type_trackers_.end()); |
171 return type_trackers_.find(type)->second.IsThrottled(); | 171 return type_trackers_.find(type)->second.IsThrottled(); |
172 } | 172 } |
173 | 173 |
174 base::TimeDelta NudgeTracker::GetTimeUntilNextUnthrottle( | 174 base::TimeDelta NudgeTracker::GetTimeUntilNextUnthrottle( |
175 base::TimeTicks now) const { | 175 base::TimeTicks now) const { |
176 DCHECK(IsAnyTypeThrottled()) << "This function requires a pending unthrottle"; | 176 DCHECK(IsAnyTypeThrottled()) << "This function requires a pending unthrottle"; |
177 const base::TimeDelta kMaxTimeDelta = | |
178 base::TimeDelta::FromInternalValue(kint64max); | |
179 | 177 |
180 // Return min of GetTimeUntilUnthrottle() values for all IsThrottled() types. | 178 // Return min of GetTimeUntilUnthrottle() values for all IsThrottled() types. |
181 base::TimeDelta time_until_next_unthrottle = kMaxTimeDelta; | 179 base::TimeDelta time_until_next_unthrottle = base::TimeDelta::Max(); |
182 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); | 180 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
183 it != type_trackers_.end(); ++it) { | 181 it != type_trackers_.end(); ++it) { |
184 if (it->second.IsThrottled()) { | 182 if (it->second.IsThrottled()) { |
185 time_until_next_unthrottle = | 183 time_until_next_unthrottle = |
186 std::min(time_until_next_unthrottle, | 184 std::min(time_until_next_unthrottle, |
187 it->second.GetTimeUntilUnthrottle(now)); | 185 it->second.GetTimeUntilUnthrottle(now)); |
188 } | 186 } |
189 } | 187 } |
190 DCHECK(kMaxTimeDelta != time_until_next_unthrottle); | 188 DCHECK(!time_until_next_unthrottle.is_max()); |
191 | 189 |
192 return time_until_next_unthrottle; | 190 return time_until_next_unthrottle; |
193 } | 191 } |
194 | 192 |
195 ModelTypeSet NudgeTracker::GetThrottledTypes() const { | 193 ModelTypeSet NudgeTracker::GetThrottledTypes() const { |
196 ModelTypeSet result; | 194 ModelTypeSet result; |
197 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); | 195 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
198 it != type_trackers_.end(); ++it) { | 196 it != type_trackers_.end(); ++it) { |
199 if (it->second.IsThrottled()) { | 197 if (it->second.IsThrottled()) { |
200 result.Put(it->first); | 198 result.Put(it->first); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 it->second.UpdatePayloadBufferSize(size); | 290 it->second.UpdatePayloadBufferSize(size); |
293 } | 291 } |
294 } | 292 } |
295 | 293 |
296 void NudgeTracker::SetNextRetryTime(base::TimeTicks retry_time) { | 294 void NudgeTracker::SetNextRetryTime(base::TimeTicks retry_time) { |
297 next_retry_time_ = retry_time; | 295 next_retry_time_ = retry_time; |
298 } | 296 } |
299 | 297 |
300 } // namespace sessions | 298 } // namespace sessions |
301 } // namespace syncer | 299 } // namespace syncer |
OLD | NEW |