| 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 "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 Loading... |
| 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(base::TimeTicks now) { |
| 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(now); |
| 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 |
| 232 bool NudgeTracker::IsTypeBackedOff(ModelType type) const { |
| 233 DCHECK(type_trackers_.find(type) != type_trackers_.end()); |
| 234 return type_trackers_.find(type)->second->IsBackedOff(); |
| 235 } |
| 236 |
| 214 base::TimeDelta NudgeTracker::GetTimeUntilNextUnthrottle( | 237 base::TimeDelta NudgeTracker::GetTimeUntilNextUnthrottle( |
| 215 base::TimeTicks now) const { | 238 base::TimeTicks now) const { |
| 216 DCHECK(IsAnyTypeThrottled()) << "This function requires a pending unthrottle"; | 239 DCHECK(IsAnyTypeThrottled()) << "This function requires a pending unthrottle"; |
| 217 | 240 |
| 218 // Return min of GetTimeUntilUnthrottle() values for all IsThrottled() types. | 241 // Return min of GetTimeUntilUnthrottle() values for all IsThrottled() types. |
| 219 base::TimeDelta time_until_next_unthrottle = base::TimeDelta::Max(); | 242 base::TimeDelta time_until_next_unthrottle = base::TimeDelta::Max(); |
| 220 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); | 243 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| 221 it != type_trackers_.end(); ++it) { | 244 it != type_trackers_.end(); ++it) { |
| 222 if (it->second->IsThrottled()) { | 245 if (it->second->IsThrottled()) { |
| 223 time_until_next_unthrottle = std::min( | 246 time_until_next_unthrottle = std::min( |
| 224 time_until_next_unthrottle, it->second->GetTimeUntilUnthrottle(now)); | 247 time_until_next_unthrottle, it->second->GetTimeUntilUnthrottle(now)); |
| 225 } | 248 } |
| 226 } | 249 } |
| 227 DCHECK(!time_until_next_unthrottle.is_max()); | 250 DCHECK(!time_until_next_unthrottle.is_max()); |
| 228 | 251 |
| 229 return time_until_next_unthrottle; | 252 return time_until_next_unthrottle; |
| 230 } | 253 } |
| 231 | 254 |
| 255 base::TimeDelta NudgeTracker::GetTimeUntilNextUnbackoff( |
| 256 base::TimeTicks now) const { |
| 257 DCHECK(IsAnyTypeBackedOff()) << "This function requires a pending unbackoff"; |
| 258 |
| 259 // Return min of GetTimeUntilUnbackoff() values for all IsThrottled() types. |
| 260 base::TimeDelta time_until_next_unbackoff = base::TimeDelta::Max(); |
| 261 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| 262 it != type_trackers_.end(); ++it) { |
| 263 if (it->second->IsBackedOff()) { |
| 264 time_until_next_unbackoff = std::min( |
| 265 time_until_next_unbackoff, it->second->GetTimeUntilUnbackoff(now)); |
| 266 } |
| 267 } |
| 268 DCHECK(!time_until_next_unbackoff.is_max()); |
| 269 |
| 270 return time_until_next_unbackoff; |
| 271 } |
| 272 |
| 273 base::TimeDelta NudgeTracker::GetTypeLastBackoffInterval(ModelType type) const { |
| 274 TypeTrackerMap::const_iterator tracker_it = type_trackers_.find(type); |
| 275 if (tracker_it != type_trackers_.end()) { |
| 276 NOTREACHED(); |
| 277 return base::TimeDelta::FromSeconds(0); |
| 278 } |
| 279 |
| 280 return tracker_it->second->GetLastUnbackoffInterval(); |
| 281 } |
| 282 |
| 232 ModelTypeSet NudgeTracker::GetThrottledTypes() const { | 283 ModelTypeSet NudgeTracker::GetThrottledTypes() const { |
| 233 ModelTypeSet result; | 284 ModelTypeSet result; |
| 234 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); | 285 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| 235 it != type_trackers_.end(); ++it) { | 286 it != type_trackers_.end(); ++it) { |
| 236 if (it->second->IsThrottled()) { | 287 if (it->second->IsThrottled()) { |
| 237 result.Put(it->first); | 288 result.Put(it->first); |
| 238 } | 289 } |
| 239 } | 290 } |
| 240 return result; | 291 return result; |
| 241 } | 292 } |
| 242 | 293 |
| 294 ModelTypeSet NudgeTracker::GetBackedOffTypes() const { |
| 295 ModelTypeSet result; |
| 296 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| 297 it != type_trackers_.end(); ++it) { |
| 298 if (it->second->IsBackedOff()) { |
| 299 result.Put(it->first); |
| 300 } |
| 301 } |
| 302 return result; |
| 303 } |
| 304 |
| 243 ModelTypeSet NudgeTracker::GetNudgedTypes() const { | 305 ModelTypeSet NudgeTracker::GetNudgedTypes() const { |
| 244 ModelTypeSet result; | 306 ModelTypeSet result; |
| 245 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); | 307 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| 246 it != type_trackers_.end(); ++it) { | 308 it != type_trackers_.end(); ++it) { |
| 247 if (it->second->HasLocalChangePending()) { | 309 if (it->second->HasLocalChangePending()) { |
| 248 result.Put(it->first); | 310 result.Put(it->first); |
| 249 } | 311 } |
| 250 } | 312 } |
| 251 return result; | 313 return result; |
| 252 } | 314 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 GetDefaultDelayForType(type, minimum_local_nudge_delay_)); | 454 GetDefaultDelayForType(type, minimum_local_nudge_delay_)); |
| 393 } | 455 } |
| 394 } | 456 } |
| 395 } | 457 } |
| 396 | 458 |
| 397 void NudgeTracker::SetDefaultNudgeDelay(base::TimeDelta nudge_delay) { | 459 void NudgeTracker::SetDefaultNudgeDelay(base::TimeDelta nudge_delay) { |
| 398 minimum_local_nudge_delay_ = nudge_delay; | 460 minimum_local_nudge_delay_ = nudge_delay; |
| 399 } | 461 } |
| 400 | 462 |
| 401 } // namespace syncer | 463 } // namespace syncer |
| OLD | NEW |