| 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() { |
| 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::IsAnyTypeBlocked() 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->IsBlocked()) { |
| 203 return true; | 211 return true; |
| 204 } | 212 } |
| 205 } | 213 } |
| 206 return false; | 214 return false; |
| 207 } | 215 } |
| 208 | 216 |
| 209 bool NudgeTracker::IsTypeThrottled(ModelType type) const { | 217 bool NudgeTracker::IsTypeBlocked(ModelType type) const { |
| 210 DCHECK(type_trackers_.find(type) != type_trackers_.end()); | 218 DCHECK(type_trackers_.find(type) != type_trackers_.end()); |
| 211 return type_trackers_.find(type)->second->IsThrottled(); | 219 return type_trackers_.find(type)->second->IsBlocked(); |
| 212 } | 220 } |
| 213 | 221 |
| 214 base::TimeDelta NudgeTracker::GetTimeUntilNextUnthrottle( | 222 WaitInterval::BlockingMode NudgeTracker::GetTypeBlockingMode( |
| 215 base::TimeTicks now) const { | 223 ModelType type) const { |
| 216 DCHECK(IsAnyTypeThrottled()) << "This function requires a pending unthrottle"; | 224 DCHECK(type_trackers_.find(type) != type_trackers_.end()); |
| 225 return type_trackers_.find(type)->second->GetBlockingMode(); |
| 226 } |
| 217 | 227 |
| 218 // Return min of GetTimeUntilUnthrottle() values for all IsThrottled() types. | 228 base::TimeDelta NudgeTracker::GetTimeUntilNextUnblock() const { |
| 219 base::TimeDelta time_until_next_unthrottle = base::TimeDelta::Max(); | 229 DCHECK(IsAnyTypeBlocked()) << "This function requires a pending unblock."; |
| 230 |
| 231 // Return min of GetTimeUntilUnblock() values for all IsBlocked() types. |
| 232 base::TimeDelta time_until_next_unblock = base::TimeDelta::Max(); |
| 220 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); | 233 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| 221 it != type_trackers_.end(); ++it) { | 234 it != type_trackers_.end(); ++it) { |
| 222 if (it->second->IsThrottled()) { | 235 if (it->second->IsBlocked()) { |
| 223 time_until_next_unthrottle = std::min( | 236 time_until_next_unblock = |
| 224 time_until_next_unthrottle, it->second->GetTimeUntilUnthrottle(now)); | 237 std::min(time_until_next_unblock, it->second->GetTimeUntilUnblock()); |
| 225 } | 238 } |
| 226 } | 239 } |
| 227 DCHECK(!time_until_next_unthrottle.is_max()); | 240 DCHECK(!time_until_next_unblock.is_max()); |
| 228 | 241 |
| 229 return time_until_next_unthrottle; | 242 return time_until_next_unblock; |
| 230 } | 243 } |
| 231 | 244 |
| 232 ModelTypeSet NudgeTracker::GetThrottledTypes() const { | 245 base::TimeDelta NudgeTracker::GetTypeLastBackoffInterval(ModelType type) const { |
| 246 TypeTrackerMap::const_iterator tracker_it = type_trackers_.find(type); |
| 247 DCHECK(tracker_it != type_trackers_.end()); |
| 248 |
| 249 return tracker_it->second->GetLastBackoffInterval(); |
| 250 } |
| 251 |
| 252 ModelTypeSet NudgeTracker::GetBlockedTypes() const { |
| 233 ModelTypeSet result; | 253 ModelTypeSet result; |
| 234 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); | 254 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| 235 it != type_trackers_.end(); ++it) { | 255 it != type_trackers_.end(); ++it) { |
| 236 if (it->second->IsThrottled()) { | 256 if (it->second->IsBlocked()) { |
| 237 result.Put(it->first); | 257 result.Put(it->first); |
| 238 } | 258 } |
| 239 } | 259 } |
| 240 return result; | 260 return result; |
| 241 } | 261 } |
| 242 | 262 |
| 243 ModelTypeSet NudgeTracker::GetNudgedTypes() const { | 263 ModelTypeSet NudgeTracker::GetNudgedTypes() const { |
| 244 ModelTypeSet result; | 264 ModelTypeSet result; |
| 245 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); | 265 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| 246 it != type_trackers_.end(); ++it) { | 266 it != type_trackers_.end(); ++it) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 // favor of 'origin'. | 311 // favor of 'origin'. |
| 292 bool has_invalidation_pending = false; | 312 bool has_invalidation_pending = false; |
| 293 bool has_refresh_request_pending = false; | 313 bool has_refresh_request_pending = false; |
| 294 bool has_commit_pending = false; | 314 bool has_commit_pending = false; |
| 295 bool is_initial_sync_required = false; | 315 bool is_initial_sync_required = false; |
| 296 bool has_retry = IsRetryRequired(); | 316 bool has_retry = IsRetryRequired(); |
| 297 | 317 |
| 298 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); | 318 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| 299 it != type_trackers_.end(); ++it) { | 319 it != type_trackers_.end(); ++it) { |
| 300 const DataTypeTracker& tracker = *it->second; | 320 const DataTypeTracker& tracker = *it->second; |
| 301 if (!tracker.IsThrottled() && tracker.HasPendingInvalidation()) { | 321 if (!tracker.IsBlocked() && tracker.HasPendingInvalidation()) { |
| 302 has_invalidation_pending = true; | 322 has_invalidation_pending = true; |
| 303 } | 323 } |
| 304 if (!tracker.IsThrottled() && tracker.HasRefreshRequestPending()) { | 324 if (!tracker.IsBlocked() && tracker.HasRefreshRequestPending()) { |
| 305 has_refresh_request_pending = true; | 325 has_refresh_request_pending = true; |
| 306 } | 326 } |
| 307 if (!tracker.IsThrottled() && tracker.HasLocalChangePending()) { | 327 if (!tracker.IsBlocked() && tracker.HasLocalChangePending()) { |
| 308 has_commit_pending = true; | 328 has_commit_pending = true; |
| 309 } | 329 } |
| 310 if (!tracker.IsThrottled() && tracker.IsInitialSyncRequired()) { | 330 if (!tracker.IsBlocked() && tracker.IsInitialSyncRequired()) { |
| 311 is_initial_sync_required = true; | 331 is_initial_sync_required = true; |
| 312 } | 332 } |
| 313 } | 333 } |
| 314 | 334 |
| 315 if (has_invalidation_pending) { | 335 if (has_invalidation_pending) { |
| 316 return sync_pb::GetUpdatesCallerInfo::NOTIFICATION; | 336 return sync_pb::GetUpdatesCallerInfo::NOTIFICATION; |
| 317 } else if (has_refresh_request_pending) { | 337 } else if (has_refresh_request_pending) { |
| 318 return sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH; | 338 return sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH; |
| 319 } else if (is_initial_sync_required) { | 339 } else if (is_initial_sync_required) { |
| 320 // Not quite accurate, but good enough for our purposes. This setting of | 340 // Not quite accurate, but good enough for our purposes. This setting of |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 GetDefaultDelayForType(type, minimum_local_nudge_delay_)); | 412 GetDefaultDelayForType(type, minimum_local_nudge_delay_)); |
| 393 } | 413 } |
| 394 } | 414 } |
| 395 } | 415 } |
| 396 | 416 |
| 397 void NudgeTracker::SetDefaultNudgeDelay(base::TimeDelta nudge_delay) { | 417 void NudgeTracker::SetDefaultNudgeDelay(base::TimeDelta nudge_delay) { |
| 398 minimum_local_nudge_delay_ = nudge_delay; | 418 minimum_local_nudge_delay_ = nudge_delay; |
| 399 } | 419 } |
| 400 | 420 |
| 401 } // namespace syncer | 421 } // namespace syncer |
| OLD | NEW |