Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: components/sync/engine_impl/cycle/nudge_tracker.cc

Issue 2475043002: [Sync] Sync client should to exponential backoff when receive partial failure (Closed)
Patch Set: code review Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/sync/engine_impl/cycle/nudge_tracker.h" 5 #include "components/sync/engine_impl/cycle/nudge_tracker.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "components/sync/engine/polling_constants.h" 10 #include "components/sync/engine/polling_constants.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 void NudgeTracker::SetTypesThrottledUntil(ModelTypeSet types, 183 void NudgeTracker::SetTypesThrottledUntil(ModelTypeSet types,
184 base::TimeDelta length, 184 base::TimeDelta length,
185 base::TimeTicks now) { 185 base::TimeTicks now) {
186 for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { 186 for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) {
187 TypeTrackerMap::const_iterator tracker_it = type_trackers_.find(it.Get()); 187 TypeTrackerMap::const_iterator tracker_it = type_trackers_.find(it.Get());
188 tracker_it->second->ThrottleType(length, now); 188 tracker_it->second->ThrottleType(length, now);
189 } 189 }
190 } 190 }
191 191
192 void NudgeTracker::UpdateTypeThrottlingState(base::TimeTicks now) { 192 void NudgeTracker::SetTypeBackedOff(ModelType type,
193 base::TimeDelta length,
194 base::TimeTicks now) {
195 TypeTrackerMap::const_iterator tracker_it = type_trackers_.find(type);
196 DCHECK(tracker_it != type_trackers_.end());
197 tracker_it->second->BackoffType(length, now);
198 }
199
200 void NudgeTracker::UpdateTypeThrottlingAndBackoffState() {
193 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); 201 for (TypeTrackerMap::const_iterator it = type_trackers_.begin();
194 it != type_trackers_.end(); ++it) { 202 it != type_trackers_.end(); ++it) {
195 it->second->UpdateThrottleState(now); 203 it->second->UpdateThrottleOrBackoffState();
196 } 204 }
197 } 205 }
198 206
199 bool NudgeTracker::IsAnyTypeThrottled() const { 207 bool NudgeTracker::IsAnyTypeThrottled() const {
200 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); 208 for (TypeTrackerMap::const_iterator it = type_trackers_.begin();
201 it != type_trackers_.end(); ++it) { 209 it != type_trackers_.end(); ++it) {
202 if (it->second->IsThrottled()) { 210 if (it->second->IsThrottled()) {
203 return true; 211 return true;
204 } 212 }
205 } 213 }
206 return false; 214 return false;
207 } 215 }
208 216
217 bool NudgeTracker::IsAnyTypeBackedOff() const {
218 for (TypeTrackerMap::const_iterator it = type_trackers_.begin();
219 it != type_trackers_.end(); ++it) {
220 if (it->second->IsBackedOff()) {
221 return true;
222 }
223 }
224 return false;
225 }
226
209 bool NudgeTracker::IsTypeThrottled(ModelType type) const { 227 bool NudgeTracker::IsTypeThrottled(ModelType type) const {
210 DCHECK(type_trackers_.find(type) != type_trackers_.end()); 228 DCHECK(type_trackers_.find(type) != type_trackers_.end());
211 return type_trackers_.find(type)->second->IsThrottled(); 229 return type_trackers_.find(type)->second->IsThrottled();
212 } 230 }
213 231
214 base::TimeDelta NudgeTracker::GetTimeUntilNextUnthrottle( 232 bool NudgeTracker::IsTypeBackedOff(ModelType type) const {
215 base::TimeTicks now) const { 233 DCHECK(type_trackers_.find(type) != type_trackers_.end());
216 DCHECK(IsAnyTypeThrottled()) << "This function requires a pending unthrottle"; 234 return type_trackers_.find(type)->second->IsBackedOff();
235 }
217 236
218 // Return min of GetTimeUntilUnthrottle() values for all IsThrottled() types. 237 base::TimeDelta NudgeTracker::GetTimeUntilNextUnblock() const {
219 base::TimeDelta time_until_next_unthrottle = base::TimeDelta::Max(); 238 DCHECK(IsAnyTypeThrottled() || IsAnyTypeBackedOff())
239 << "This function requires a pending unthrottle or unbackoff";
240
241 // Return min of GetTimeUntilUnblock() values for all IsThrottled() and
242 // IsBackedOff() types.
243 base::TimeDelta time_until_next_unblock = base::TimeDelta::Max();
220 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); 244 for (TypeTrackerMap::const_iterator it = type_trackers_.begin();
221 it != type_trackers_.end(); ++it) { 245 it != type_trackers_.end(); ++it) {
222 if (it->second->IsThrottled()) { 246 if (it->second->IsThrottled() || it->second->IsBackedOff()) {
223 time_until_next_unthrottle = std::min( 247 time_until_next_unblock =
224 time_until_next_unthrottle, it->second->GetTimeUntilUnthrottle(now)); 248 std::min(time_until_next_unblock, it->second->GetTimeUntilUnblock());
225 } 249 }
226 } 250 }
227 DCHECK(!time_until_next_unthrottle.is_max()); 251 DCHECK(!time_until_next_unblock.is_max());
228 252
229 return time_until_next_unthrottle; 253 return time_until_next_unblock;
254 }
255
256 base::TimeDelta NudgeTracker::GetTypeLastBackoffInterval(ModelType type) const {
257 TypeTrackerMap::const_iterator tracker_it = type_trackers_.find(type);
258 if (tracker_it != type_trackers_.end()) {
259 NOTREACHED();
260 return base::TimeDelta::FromSeconds(0);
261 }
262
263 return tracker_it->second->GetLastBackoffInterval();
230 } 264 }
231 265
232 ModelTypeSet NudgeTracker::GetThrottledTypes() const { 266 ModelTypeSet NudgeTracker::GetThrottledTypes() const {
233 ModelTypeSet result; 267 ModelTypeSet result;
234 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); 268 for (TypeTrackerMap::const_iterator it = type_trackers_.begin();
235 it != type_trackers_.end(); ++it) { 269 it != type_trackers_.end(); ++it) {
236 if (it->second->IsThrottled()) { 270 if (it->second->IsThrottled()) {
237 result.Put(it->first); 271 result.Put(it->first);
238 } 272 }
239 } 273 }
240 return result; 274 return result;
241 } 275 }
242 276
277 ModelTypeSet NudgeTracker::GetBackedOffTypes() const {
278 ModelTypeSet result;
279 for (TypeTrackerMap::const_iterator it = type_trackers_.begin();
280 it != type_trackers_.end(); ++it) {
281 if (it->second->IsBackedOff()) {
282 result.Put(it->first);
283 }
284 }
285 return result;
286 }
287
243 ModelTypeSet NudgeTracker::GetNudgedTypes() const { 288 ModelTypeSet NudgeTracker::GetNudgedTypes() const {
244 ModelTypeSet result; 289 ModelTypeSet result;
245 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); 290 for (TypeTrackerMap::const_iterator it = type_trackers_.begin();
246 it != type_trackers_.end(); ++it) { 291 it != type_trackers_.end(); ++it) {
247 if (it->second->HasLocalChangePending()) { 292 if (it->second->HasLocalChangePending()) {
248 result.Put(it->first); 293 result.Put(it->first);
249 } 294 }
250 } 295 }
251 return result; 296 return result;
252 } 297 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 GetDefaultDelayForType(type, minimum_local_nudge_delay_)); 437 GetDefaultDelayForType(type, minimum_local_nudge_delay_));
393 } 438 }
394 } 439 }
395 } 440 }
396 441
397 void NudgeTracker::SetDefaultNudgeDelay(base::TimeDelta nudge_delay) { 442 void NudgeTracker::SetDefaultNudgeDelay(base::TimeDelta nudge_delay) {
398 minimum_local_nudge_delay_ = nudge_delay; 443 minimum_local_nudge_delay_ = nudge_delay;
399 } 444 }
400 445
401 } // namespace syncer 446 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698