| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_quality_estimator.h" | 5 #include "net/base/network_quality_estimator.h" |
| 6 | 6 |
| 7 #include <float.h> | 7 #include <float.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 false, | 226 false, |
| 227 false) {} | 227 false) {} |
| 228 | 228 |
| 229 NetworkQualityEstimator::NetworkQualityEstimator( | 229 NetworkQualityEstimator::NetworkQualityEstimator( |
| 230 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | 230 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
| 231 const std::map<std::string, std::string>& variation_params, | 231 const std::map<std::string, std::string>& variation_params, |
| 232 bool allow_local_host_requests_for_tests, | 232 bool allow_local_host_requests_for_tests, |
| 233 bool allow_smaller_responses_for_tests) | 233 bool allow_smaller_responses_for_tests) |
| 234 : allow_localhost_requests_(allow_local_host_requests_for_tests), | 234 : allow_localhost_requests_(allow_local_host_requests_for_tests), |
| 235 allow_small_responses_(allow_smaller_responses_for_tests), | 235 allow_small_responses_(allow_smaller_responses_for_tests), |
| 236 weight_multiplier_per_second_( |
| 237 GetWeightMultiplierPerSecond(variation_params)), |
| 236 last_connection_change_(base::TimeTicks::Now()), | 238 last_connection_change_(base::TimeTicks::Now()), |
| 237 current_network_id_( | 239 current_network_id_( |
| 238 NetworkID(NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, | 240 NetworkID(NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, |
| 239 std::string())), | 241 std::string())), |
| 240 downstream_throughput_kbps_observations_( | 242 downstream_throughput_kbps_observations_(weight_multiplier_per_second_), |
| 241 GetWeightMultiplierPerSecond(variation_params)), | 243 rtt_observations_(weight_multiplier_per_second_), |
| 242 rtt_observations_(GetWeightMultiplierPerSecond(variation_params)), | |
| 243 external_estimate_provider_(std::move(external_estimates_provider)), | 244 external_estimate_provider_(std::move(external_estimates_provider)), |
| 244 weak_ptr_factory_(this) { | 245 weak_ptr_factory_(this) { |
| 245 static_assert(kMinRequestDurationMicroseconds > 0, | 246 static_assert(kMinRequestDurationMicroseconds > 0, |
| 246 "Minimum request duration must be > 0"); | 247 "Minimum request duration must be > 0"); |
| 247 static_assert(kDefaultHalfLifeSeconds > 0, | 248 static_assert(kDefaultHalfLifeSeconds > 0, |
| 248 "Default half life duration must be > 0"); | 249 "Default half life duration must be > 0"); |
| 249 static_assert(kMaximumNetworkQualityCacheSize > 0, | 250 static_assert(kMaximumNetworkQualityCacheSize > 0, |
| 250 "Size of the network quality cache must be > 0"); | 251 "Size of the network quality cache must be > 0"); |
| 251 // This limit should not be increased unless the logic for removing the | 252 // This limit should not be increased unless the logic for removing the |
| 252 // oldest cache entry is rewritten to use a doubly-linked-list LRU queue. | 253 // oldest cache entry is rewritten to use a doubly-linked-list LRU queue. |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 } | 422 } |
| 422 | 423 |
| 423 // Time when the resource was requested. | 424 // Time when the resource was requested. |
| 424 base::TimeTicks request_start_time = load_timing_info.send_start; | 425 base::TimeTicks request_start_time = load_timing_info.send_start; |
| 425 | 426 |
| 426 // Time when the headers were received. | 427 // Time when the headers were received. |
| 427 base::TimeTicks headers_received_time = load_timing_info.receive_headers_end; | 428 base::TimeTicks headers_received_time = load_timing_info.receive_headers_end; |
| 428 | 429 |
| 429 // Duration between when the resource was requested and when response | 430 // Duration between when the resource was requested and when response |
| 430 // headers were received. | 431 // headers were received. |
| 431 base::TimeDelta observed_rtt = headers_received_time - request_start_time; | 432 base::TimeDelta observed_rtt = headers_received_time - request_start_time; |
| 432 DCHECK_GE(observed_rtt, base::TimeDelta()); | 433 DCHECK_GE(observed_rtt, base::TimeDelta()); |
| 433 if (observed_rtt < peak_network_quality_.rtt()) { | 434 if (observed_rtt < peak_network_quality_.rtt()) { |
| 434 peak_network_quality_ = NetworkQuality( | 435 peak_network_quality_ = NetworkQuality( |
| 435 observed_rtt, peak_network_quality_.downstream_throughput_kbps()); | 436 observed_rtt, peak_network_quality_.downstream_throughput_kbps()); |
| 436 } | 437 } |
| 437 | 438 |
| 438 RttObservation rtt_observation(observed_rtt, now, URL_REQUEST); | 439 RttObservation rtt_observation(observed_rtt, now, URL_REQUEST); |
| 439 rtt_observations_.AddObservation(rtt_observation); | 440 rtt_observations_.AddObservation(rtt_observation); |
| 440 NotifyObserversOfRTT(rtt_observation); | 441 NotifyObserversOfRTT(rtt_observation); |
| 441 | 442 |
| 442 // Compare the RTT observation with the estimated value and record it. | 443 // Compare the RTT observation with the estimated value and record it. |
| 443 if (estimated_median_network_quality_.rtt() != InvalidRTT()) { | 444 if (estimated_median_network_quality_.rtt() != InvalidRTT()) { |
| 444 RecordRTTUMA(estimated_median_network_quality_.rtt().InMilliseconds(), | 445 RecordRTTUMA(estimated_median_network_quality_.rtt().InMilliseconds(), |
| 445 observed_rtt.InMilliseconds()); | 446 observed_rtt.InMilliseconds()); |
| 446 } | 447 } |
| 447 } | 448 } |
| 448 | 449 |
| 449 void NetworkQualityEstimator::NotifyRequestCompleted( | 450 void NetworkQualityEstimator::NotifyRequestCompleted( |
| 450 const URLRequest& request) { | 451 const URLRequest& request) { |
| 451 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), | 452 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), |
| 452 "NetworkQualityEstimator::NotifyRequestCompleted"); | 453 "NetworkQualityEstimator::NotifyRequestCompleted"); |
| 453 DCHECK(thread_checker_.CalledOnValidThread()); | 454 DCHECK(thread_checker_.CalledOnValidThread()); |
| 454 | 455 |
| 455 if (!RequestProvidesUsefulObservations(request)) | 456 if (!RequestProvidesUsefulObservations(request)) |
| 456 return; | 457 return; |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1213 | 1214 |
| 1214 NetworkQualityEstimator::NetworkQuality& | 1215 NetworkQualityEstimator::NetworkQuality& |
| 1215 NetworkQualityEstimator::NetworkQuality:: | 1216 NetworkQualityEstimator::NetworkQuality:: |
| 1216 operator=(const NetworkQuality& other) { | 1217 operator=(const NetworkQuality& other) { |
| 1217 rtt_ = other.rtt_; | 1218 rtt_ = other.rtt_; |
| 1218 downstream_throughput_kbps_ = other.downstream_throughput_kbps_; | 1219 downstream_throughput_kbps_ = other.downstream_throughput_kbps_; |
| 1219 return *this; | 1220 return *this; |
| 1220 } | 1221 } |
| 1221 | 1222 |
| 1222 } // namespace net | 1223 } // namespace net |
| OLD | NEW |