Chromium Code Reviews| 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/nqe/network_quality_estimator.h" | 5 #include "net/nqe/network_quality_estimator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 DCHECK_GT(max_limit, kLowerLimit); | 137 DCHECK_GT(max_limit, kLowerLimit); |
| 138 const size_t kBucketCount = 50; | 138 const size_t kBucketCount = 50; |
| 139 | 139 |
| 140 // Prefix of network quality estimator histograms. | 140 // Prefix of network quality estimator histograms. |
| 141 const char prefix[] = "NQE."; | 141 const char prefix[] = "NQE."; |
| 142 return base::Histogram::FactoryGet( | 142 return base::Histogram::FactoryGet( |
| 143 prefix + statistic_name + GetNameForConnectionType(type), kLowerLimit, | 143 prefix + statistic_name + GetNameForConnectionType(type), kLowerLimit, |
| 144 max_limit, kBucketCount, base::HistogramBase::kUmaTargetedHistogramFlag); | 144 max_limit, kBucketCount, base::HistogramBase::kUmaTargetedHistogramFlag); |
| 145 } | 145 } |
| 146 | 146 |
| 147 bool GetValueForVariationParam( | 147 // Sets |variations_value| to the value of |parameter_name| read from |
| 148 // |variation_params|. If the value is unavailable from |variation_params|, then | |
| 149 // |variations_value| is set to |default_value|. | |
| 150 void GetValueForVariationParam( | |
| 148 const std::map<std::string, std::string>& variation_params, | 151 const std::map<std::string, std::string>& variation_params, |
| 149 const std::string& parameter_name, | 152 const std::string& parameter_name, |
| 150 int32_t* variations_value) { | 153 int64_t default_value, |
| 154 int64_t* variations_value) { | |
| 151 const auto it = variation_params.find(parameter_name); | 155 const auto it = variation_params.find(parameter_name); |
| 152 return it != variation_params.end() && | 156 if (it != variation_params.end() && |
| 153 base::StringToInt(it->second, variations_value); | 157 base::StringToInt64(it->second, variations_value)) { |
| 158 return; | |
| 159 } | |
| 160 *variations_value = default_value; | |
| 154 } | 161 } |
| 155 | 162 |
| 156 // Returns the variation value for |parameter_name|. If the value is | 163 // Returns the variation value for |parameter_name|. If the value is |
| 157 // unavailable, |default_value| is returned. | 164 // unavailable, |default_value| is returned. |
| 158 double GetDoubleValueForVariationParamWithDefaultValue( | 165 double GetDoubleValueForVariationParamWithDefaultValue( |
| 159 const std::map<std::string, std::string>& variation_params, | 166 const std::map<std::string, std::string>& variation_params, |
| 160 const std::string& parameter_name, | 167 const std::string& parameter_name, |
| 161 double default_value) { | 168 double default_value) { |
| 162 const auto it = variation_params.find(parameter_name); | 169 const auto it = variation_params.find(parameter_name); |
| 163 if (it == variation_params.end()) | 170 if (it == variation_params.end()) |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 default_observations_[i].http_rtt(), | 420 default_observations_[i].http_rtt(), |
| 414 default_observations_[i].transport_rtt(), variations_value); | 421 default_observations_[i].transport_rtt(), variations_value); |
| 415 } | 422 } |
| 416 } | 423 } |
| 417 } | 424 } |
| 418 | 425 |
| 419 void NetworkQualityEstimator::ObtainEffectiveConnectionTypeModelParams( | 426 void NetworkQualityEstimator::ObtainEffectiveConnectionTypeModelParams( |
| 420 const std::map<std::string, std::string>& variation_params) { | 427 const std::map<std::string, std::string>& variation_params) { |
| 421 DCHECK(thread_checker_.CalledOnValidThread()); | 428 DCHECK(thread_checker_.CalledOnValidThread()); |
| 422 | 429 |
| 430 default_effective_connection_type_thresholds_ | |
| 431 [EFFECTIVE_CONNECTION_TYPE_SLOW_2G] = nqe::internal::NetworkQuality( | |
| 432 // Set to 2010 milliseconds which corresponds to the 33rd percentile | |
|
bengr
2016/07/26 23:14:51
nit: milliseconds, which
everywhere.
tbansal1
2016/07/26 23:42:24
Done.
| |
| 433 // of 2G HTTP RTT observations on Android. | |
| 434 base::TimeDelta::FromMilliseconds(2010), | |
| 435 // Set to 1870 milliseconds which corresponds to the 33rd percentile | |
| 436 // of 2G transport RTT observations on Android. | |
| 437 base::TimeDelta::FromMilliseconds(1870), | |
| 438 nqe::internal::kInvalidThroughput); | |
| 439 | |
| 440 default_effective_connection_type_thresholds_[EFFECTIVE_CONNECTION_TYPE_2G] = | |
| 441 nqe::internal::NetworkQuality( | |
| 442 // Set to 1420 milliseconds which corresponds to 50th percentile of 2G | |
| 443 // HTTP RTT observations on Android. | |
| 444 base::TimeDelta::FromMilliseconds(1420), | |
| 445 // Set to 1280 milliseconds which corresponds to 50th percentile of 2G | |
| 446 // transport RTT observations on Android. | |
| 447 base::TimeDelta::FromMilliseconds(1280), | |
| 448 nqe::internal::kInvalidThroughput); | |
| 449 | |
| 423 for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) { | 450 for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) { |
| 424 EffectiveConnectionType effective_connection_type = | 451 EffectiveConnectionType effective_connection_type = |
| 425 static_cast<EffectiveConnectionType>(i); | 452 static_cast<EffectiveConnectionType>(i); |
| 426 DCHECK_EQ(nqe::internal::InvalidRTT(), | 453 DCHECK_EQ(nqe::internal::InvalidRTT(), |
| 427 connection_thresholds_[i].http_rtt()); | 454 connection_thresholds_[i].http_rtt()); |
| 428 DCHECK_EQ(nqe::internal::InvalidRTT(), | 455 DCHECK_EQ(nqe::internal::InvalidRTT(), |
| 429 connection_thresholds_[i].transport_rtt()); | 456 connection_thresholds_[i].transport_rtt()); |
| 430 DCHECK_EQ(nqe::internal::kInvalidThroughput, | 457 DCHECK_EQ(nqe::internal::kInvalidThroughput, |
| 431 connection_thresholds_[i].downstream_throughput_kbps()); | 458 connection_thresholds_[i].downstream_throughput_kbps()); |
| 432 if (effective_connection_type == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) | 459 if (effective_connection_type == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) |
| 433 continue; | 460 continue; |
| 434 | 461 |
| 435 std::string connection_type_name = std::string( | 462 std::string connection_type_name = std::string( |
| 436 GetNameForEffectiveConnectionType(effective_connection_type)); | 463 GetNameForEffectiveConnectionType(effective_connection_type)); |
| 437 | 464 |
| 438 int32_t variations_value = kMinimumRTTVariationParameterMsec - 1; | 465 int64_t variations_value; |
| 439 if (GetValueForVariationParam( | 466 GetValueForVariationParam(variation_params, |
| 440 variation_params, connection_type_name + kThresholdURLRTTMsecSuffix, | 467 connection_type_name + kThresholdURLRTTMsecSuffix, |
| 441 &variations_value) && | 468 default_effective_connection_type_thresholds_[i] |
| 442 variations_value >= kMinimumRTTVariationParameterMsec) { | 469 .http_rtt() |
| 443 connection_thresholds_[i].set_http_rtt( | 470 .InMilliseconds(), |
| 444 base::TimeDelta(base::TimeDelta::FromMilliseconds(variations_value))); | 471 &variations_value); |
| 472 connection_thresholds_[i].set_http_rtt( | |
| 473 base::TimeDelta::FromMilliseconds(variations_value)); | |
| 474 // Verify that the RTT values are in decreasing order as the network | |
| 475 // quality improves. | |
| 476 DCHECK(i == 0 || | |
| 477 connection_thresholds_[i].http_rtt() == | |
|
bengr
2016/07/26 23:14:51
It might be clearer and reduce redundancy if you h
tbansal1
2016/07/26 23:42:23
Done.
| |
| 478 nqe::internal::InvalidRTT() || | |
| 479 connection_thresholds_[i - 1].http_rtt() == | |
| 480 nqe::internal::InvalidRTT() || | |
| 481 connection_thresholds_[i].http_rtt() <= | |
| 482 connection_thresholds_[i - 1].http_rtt()); | |
| 445 | 483 |
| 446 // Verify that the RTT values are in decreasing order as the network | 484 GetValueForVariationParam( |
| 447 // quality improves. | 485 variation_params, |
| 448 DCHECK(i == 0 || | 486 connection_type_name + kThresholdTransportRTTMsecSuffix, |
| 449 connection_thresholds_[i - 1].http_rtt() == | 487 default_effective_connection_type_thresholds_[i] |
| 450 nqe::internal::InvalidRTT() || | 488 .transport_rtt() |
| 451 connection_thresholds_[i].http_rtt() <= | 489 .InMilliseconds(), |
| 452 connection_thresholds_[i - 1].http_rtt()); | 490 &variations_value); |
| 453 } | 491 connection_thresholds_[i].set_transport_rtt( |
| 492 base::TimeDelta::FromMilliseconds(variations_value)); | |
| 493 // Verify that the transport RTT values are in decreasing order as the | |
| 494 // network quality improves. | |
| 495 DCHECK(i == 0 || | |
| 496 connection_thresholds_[i].transport_rtt() == | |
| 497 nqe::internal::InvalidRTT() || | |
| 498 connection_thresholds_[i - 1].transport_rtt() == | |
| 499 nqe::internal::InvalidRTT() || | |
| 500 connection_thresholds_[i].transport_rtt() <= | |
| 501 connection_thresholds_[i - 1].transport_rtt()); | |
| 454 | 502 |
| 455 variations_value = kMinimumRTTVariationParameterMsec - 1; | 503 GetValueForVariationParam(variation_params, |
| 456 if (GetValueForVariationParam( | 504 connection_type_name + kThresholdKbpsSuffix, |
| 457 variation_params, | 505 default_effective_connection_type_thresholds_[i] |
| 458 connection_type_name + kThresholdTransportRTTMsecSuffix, | 506 .downstream_throughput_kbps(), |
| 459 &variations_value) && | 507 &variations_value); |
| 460 variations_value >= kMinimumRTTVariationParameterMsec) { | 508 connection_thresholds_[i].set_downstream_throughput_kbps(variations_value); |
| 461 connection_thresholds_[i].set_transport_rtt( | 509 // Verify that the throughput values are in increasing order as the |
| 462 base::TimeDelta(base::TimeDelta::FromMilliseconds(variations_value))); | 510 // network quality improves. |
| 463 | 511 DCHECK(i == 0 || |
| 464 // Verify that the transport RTT values are in decreasing order as the | 512 connection_thresholds_[i].downstream_throughput_kbps() == |
| 465 // network quality improves. | 513 kMinimumThroughputVariationParameterKbps || |
| 466 DCHECK(i == 0 || | 514 connection_thresholds_[i - 1].downstream_throughput_kbps() == |
| 467 connection_thresholds_[i - 1].transport_rtt() == | 515 kMinimumThroughputVariationParameterKbps || |
| 468 nqe::internal::InvalidRTT() || | 516 connection_thresholds_[i].downstream_throughput_kbps() >= |
| 469 connection_thresholds_[i].transport_rtt() <= | 517 connection_thresholds_[i - 1].downstream_throughput_kbps()); |
| 470 connection_thresholds_[i - 1].transport_rtt()); | |
| 471 } | |
| 472 | |
| 473 variations_value = kMinimumThroughputVariationParameterKbps - 1; | |
| 474 if (GetValueForVariationParam(variation_params, | |
| 475 connection_type_name + kThresholdKbpsSuffix, | |
| 476 &variations_value) && | |
| 477 variations_value >= kMinimumThroughputVariationParameterKbps) { | |
| 478 connection_thresholds_[i].set_downstream_throughput_kbps( | |
| 479 variations_value); | |
| 480 | |
| 481 // Verify that the throughput values are in increasing order as the | |
| 482 // network quality improves. | |
| 483 DCHECK(i == 0 || | |
| 484 connection_thresholds_[i - 1].downstream_throughput_kbps() == | |
| 485 kMinimumThroughputVariationParameterKbps || | |
| 486 connection_thresholds_[i].downstream_throughput_kbps() >= | |
| 487 connection_thresholds_[i - 1].downstream_throughput_kbps()); | |
| 488 } | |
| 489 } | 518 } |
| 490 } | 519 } |
| 491 | 520 |
| 492 void NetworkQualityEstimator::AddDefaultEstimates() { | 521 void NetworkQualityEstimator::AddDefaultEstimates() { |
| 493 DCHECK(thread_checker_.CalledOnValidThread()); | 522 DCHECK(thread_checker_.CalledOnValidThread()); |
| 494 | 523 |
| 495 if (default_observations_[current_network_id_.type].http_rtt() != | 524 if (default_observations_[current_network_id_.type].http_rtt() != |
| 496 nqe::internal::InvalidRTT()) { | 525 nqe::internal::InvalidRTT()) { |
| 497 RttObservation rtt_observation( | 526 RttObservation rtt_observation( |
| 498 default_observations_[current_network_id_.type].http_rtt(), | 527 default_observations_[current_network_id_.type].http_rtt(), |
| (...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1612 NotifyObserversOfEffectiveConnectionTypeChanged() { | 1641 NotifyObserversOfEffectiveConnectionTypeChanged() { |
| 1613 DCHECK(thread_checker_.CalledOnValidThread()); | 1642 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1614 | 1643 |
| 1615 // TODO(tbansal): Add hysteresis in the notification. | 1644 // TODO(tbansal): Add hysteresis in the notification. |
| 1616 FOR_EACH_OBSERVER( | 1645 FOR_EACH_OBSERVER( |
| 1617 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, | 1646 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, |
| 1618 OnEffectiveConnectionTypeChanged(effective_connection_type_)); | 1647 OnEffectiveConnectionTypeChanged(effective_connection_type_)); |
| 1619 } | 1648 } |
| 1620 | 1649 |
| 1621 } // namespace net | 1650 } // namespace net |
| OLD | NEW |