| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "net/base/network_throttle_manager_impl.h" | 5 #include "net/base/network_throttle_manager_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "base/time/default_tick_clock.h" | 10 #include "base/time/default_tick_clock.h" |
| 12 | 11 |
| 13 namespace net { | 12 namespace net { |
| 14 | 13 |
| 15 const size_t NetworkThrottleManagerImpl::kActiveRequestThrottlingLimit = 2; | 14 const size_t NetworkThrottleManagerImpl::kActiveRequestThrottlingLimit = 2; |
| 16 const int NetworkThrottleManagerImpl::kMedianLifetimeMultiple = 5; | 15 const int NetworkThrottleManagerImpl::kMedianLifetimeMultiple = 5; |
| 17 | 16 |
| 18 // Initial estimate based on the median in the | 17 // Initial estimate based on the median in the |
| 19 // Net.RequestTime2.Success histogram, excluding cached results by eye. | 18 // Net.RequestTime2.Success histogram, excluding cached results by eye. |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 outstanding_throttles_.erase(throttle->queue_pointer()); | 233 outstanding_throttles_.erase(throttle->queue_pointer()); |
| 235 // Fall through | 234 // Fall through |
| 236 case ThrottleImpl::State::AGED: | 235 case ThrottleImpl::State::AGED: |
| 237 DCHECK(!throttle->start_time().is_null()); | 236 DCHECK(!throttle->start_time().is_null()); |
| 238 lifetime_median_estimate_.AddSample( | 237 lifetime_median_estimate_.AddSample( |
| 239 (tick_clock_->NowTicks() - throttle->start_time()) | 238 (tick_clock_->NowTicks() - throttle->start_time()) |
| 240 .InMillisecondsRoundedUp()); | 239 .InMillisecondsRoundedUp()); |
| 241 break; | 240 break; |
| 242 } | 241 } |
| 243 | 242 |
| 244 DCHECK(std::find(blocked_throttles_.begin(), blocked_throttles_.end(), | 243 DCHECK(!base::ContainsValue(blocked_throttles_, throttle)); |
| 245 throttle) == blocked_throttles_.end()); | 244 DCHECK(!base::ContainsValue(outstanding_throttles_, throttle)); |
| 246 DCHECK(std::find(outstanding_throttles_.begin(), outstanding_throttles_.end(), | |
| 247 throttle) == outstanding_throttles_.end()); | |
| 248 | 245 |
| 249 // Unblock the throttles if there's some chance there's a throttle to | 246 // Unblock the throttles if there's some chance there's a throttle to |
| 250 // unblock. | 247 // unblock. |
| 251 if (outstanding_throttles_.size() < kActiveRequestThrottlingLimit && | 248 if (outstanding_throttles_.size() < kActiveRequestThrottlingLimit && |
| 252 !blocked_throttles_.empty()) { | 249 !blocked_throttles_.empty()) { |
| 253 // Via PostTask so there aren't upcalls from within destructors. | 250 // Via PostTask so there aren't upcalls from within destructors. |
| 254 base::ThreadTaskRunnerHandle::Get()->PostTask( | 251 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 255 FROM_HERE, | 252 FROM_HERE, |
| 256 base::Bind(&NetworkThrottleManagerImpl::MaybeUnblockThrottles, | 253 base::Bind(&NetworkThrottleManagerImpl::MaybeUnblockThrottles, |
| 257 weak_ptr_factory_.GetWeakPtr())); | 254 weak_ptr_factory_.GetWeakPtr())); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 while (outstanding_throttles_.size() < kActiveRequestThrottlingLimit && | 314 while (outstanding_throttles_.size() < kActiveRequestThrottlingLimit && |
| 318 !blocked_throttles_.empty()) { | 315 !blocked_throttles_.empty()) { |
| 319 // NOTE: This call may result in reentrant calls into | 316 // NOTE: This call may result in reentrant calls into |
| 320 // NetworkThrottleManagerImpl; no state should be assumed to be | 317 // NetworkThrottleManagerImpl; no state should be assumed to be |
| 321 // persistent across this call. | 318 // persistent across this call. |
| 322 UnblockThrottle(blocked_throttles_.front()); | 319 UnblockThrottle(blocked_throttles_.front()); |
| 323 } | 320 } |
| 324 } | 321 } |
| 325 | 322 |
| 326 } // namespace net | 323 } // namespace net |
| OLD | NEW |