| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 false, | 205 false, |
| 206 false) {} | 206 false) {} |
| 207 | 207 |
| 208 NetworkQualityEstimator::NetworkQualityEstimator( | 208 NetworkQualityEstimator::NetworkQualityEstimator( |
| 209 scoped_ptr<ExternalEstimateProvider> external_estimates_provider, | 209 scoped_ptr<ExternalEstimateProvider> external_estimates_provider, |
| 210 const std::map<std::string, std::string>& variation_params, | 210 const std::map<std::string, std::string>& variation_params, |
| 211 bool allow_local_host_requests_for_tests, | 211 bool allow_local_host_requests_for_tests, |
| 212 bool allow_smaller_responses_for_tests) | 212 bool allow_smaller_responses_for_tests) |
| 213 : allow_localhost_requests_(allow_local_host_requests_for_tests), | 213 : allow_localhost_requests_(allow_local_host_requests_for_tests), |
| 214 allow_small_responses_(allow_smaller_responses_for_tests), | 214 allow_small_responses_(allow_smaller_responses_for_tests), |
| 215 weight_multiplier_per_second_( |
| 216 GetWeightMultiplierPerSecond(variation_params)), |
| 215 last_connection_change_(base::TimeTicks::Now()), | 217 last_connection_change_(base::TimeTicks::Now()), |
| 216 current_network_id_( | 218 current_network_id_( |
| 217 NetworkID(NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, | 219 NetworkID(NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, |
| 218 std::string())), | 220 std::string())), |
| 219 downstream_throughput_kbps_observations_( | 221 downstream_throughput_kbps_observations_(weight_multiplier_per_second_), |
| 220 GetWeightMultiplierPerSecond(variation_params)), | 222 rtt_observations_(weight_multiplier_per_second_), |
| 221 rtt_observations_(GetWeightMultiplierPerSecond(variation_params)), | |
| 222 external_estimate_provider_(std::move(external_estimates_provider)), | 223 external_estimate_provider_(std::move(external_estimates_provider)), |
| 223 weak_ptr_factory_(this) { | 224 weak_ptr_factory_(this) { |
| 224 static_assert(kMinRequestDurationMicroseconds > 0, | 225 static_assert(kMinRequestDurationMicroseconds > 0, |
| 225 "Minimum request duration must be > 0"); | 226 "Minimum request duration must be > 0"); |
| 226 static_assert(kDefaultHalfLifeSeconds > 0, | 227 static_assert(kDefaultHalfLifeSeconds > 0, |
| 227 "Default half life duration must be > 0"); | 228 "Default half life duration must be > 0"); |
| 228 static_assert(kMaximumNetworkQualityCacheSize > 0, | 229 static_assert(kMaximumNetworkQualityCacheSize > 0, |
| 229 "Size of the network quality cache must be > 0"); | 230 "Size of the network quality cache must be > 0"); |
| 230 // This limit should not be increased unless the logic for removing the | 231 // This limit should not be increased unless the logic for removing the |
| 231 // oldest cache entry is rewritten to use a doubly-linked-list LRU queue. | 232 // oldest cache entry is rewritten to use a doubly-linked-list LRU queue. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 } | 349 } |
| 349 | 350 |
| 350 // Time when the resource was requested. | 351 // Time when the resource was requested. |
| 351 base::TimeTicks request_start_time = load_timing_info.send_start; | 352 base::TimeTicks request_start_time = load_timing_info.send_start; |
| 352 | 353 |
| 353 // Time when the headers were received. | 354 // Time when the headers were received. |
| 354 base::TimeTicks headers_received_time = load_timing_info.receive_headers_end; | 355 base::TimeTicks headers_received_time = load_timing_info.receive_headers_end; |
| 355 | 356 |
| 356 // Duration between when the resource was requested and when response | 357 // Duration between when the resource was requested and when response |
| 357 // headers were received. | 358 // headers were received. |
| 358 base::TimeDelta observed_rtt = headers_received_time - request_start_time; | 359 base::TimeDelta observed_rtt = headers_received_time - request_start_time; |
| 359 DCHECK_GE(observed_rtt, base::TimeDelta()); | 360 DCHECK_GE(observed_rtt, base::TimeDelta()); |
| 360 if (observed_rtt < peak_network_quality_.rtt()) { | 361 if (observed_rtt < peak_network_quality_.rtt()) { |
| 361 peak_network_quality_ = NetworkQuality( | 362 peak_network_quality_ = NetworkQuality( |
| 362 observed_rtt, peak_network_quality_.downstream_throughput_kbps()); | 363 observed_rtt, peak_network_quality_.downstream_throughput_kbps()); |
| 363 } | 364 } |
| 364 | 365 |
| 365 RttObservation rtt_observation(observed_rtt, now, URL_REQUEST); | 366 RttObservation rtt_observation(observed_rtt, now, URL_REQUEST); |
| 366 rtt_observations_.AddObservation(rtt_observation); | 367 rtt_observations_.AddObservation(rtt_observation); |
| 367 NotifyObserversOfRTT(rtt_observation); | 368 NotifyObserversOfRTT(rtt_observation); |
| 368 | 369 |
| 369 // Compare the RTT observation with the estimated value and record it. | 370 // Compare the RTT observation with the estimated value and record it. |
| 370 if (estimated_median_network_quality_.rtt() != InvalidRTT()) { | 371 if (estimated_median_network_quality_.rtt() != InvalidRTT()) { |
| 371 RecordRTTUMA(estimated_median_network_quality_.rtt().InMilliseconds(), | 372 RecordRTTUMA(estimated_median_network_quality_.rtt().InMilliseconds(), |
| 372 observed_rtt.InMilliseconds()); | 373 observed_rtt.InMilliseconds()); |
| 373 } | 374 } |
| 374 } | 375 } |
| 375 | 376 |
| 376 void NetworkQualityEstimator::NotifyRequestCompleted( | 377 void NetworkQualityEstimator::NotifyRequestCompleted( |
| 377 const URLRequest& request) { | 378 const URLRequest& request) { |
| 378 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), | 379 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), |
| 379 "NetworkQualityEstimator::NotifyRequestCompleted"); | 380 "NetworkQualityEstimator::NotifyRequestCompleted"); |
| 380 DCHECK(thread_checker_.CalledOnValidThread()); | 381 DCHECK(thread_checker_.CalledOnValidThread()); |
| 381 | 382 |
| 382 if (!RequestProvidesUsefulObservations(request)) | 383 if (!RequestProvidesUsefulObservations(request)) |
| 383 return; | 384 return; |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 | 1071 |
| 1071 NetworkQualityEstimator::NetworkQuality& | 1072 NetworkQualityEstimator::NetworkQuality& |
| 1072 NetworkQualityEstimator::NetworkQuality:: | 1073 NetworkQualityEstimator::NetworkQuality:: |
| 1073 operator=(const NetworkQuality& other) { | 1074 operator=(const NetworkQuality& other) { |
| 1074 rtt_ = other.rtt_; | 1075 rtt_ = other.rtt_; |
| 1075 downstream_throughput_kbps_ = other.downstream_throughput_kbps_; | 1076 downstream_throughput_kbps_ = other.downstream_throughput_kbps_; |
| 1076 return *this; | 1077 return *this; |
| 1077 } | 1078 } |
| 1078 | 1079 |
| 1079 } // namespace net | 1080 } // namespace net |
| OLD | NEW |