0

Enable reading of cached network quality from WiFi networks

Bug: 490870
Change-Id: I05d1878ce164f1907b304c9e222c36d26365d402
Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester
Reviewed-on: https://chromium-review.googlesource.com/567665
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: Ryan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#489748}
This commit is contained in:
Tarun Bansal
2017-07-26 20:45:56 +00:00
committed by Commit Bot
parent 05dabf99bb
commit ae2022fb0b
3 changed files with 26 additions and 13 deletions

@ -1483,6 +1483,12 @@ bool NetworkQualityEstimator::ReadCachedNetworkQualityEstimate() {
if (!params_->persistent_cache_reading_enabled())
return false;
if (current_network_id_.type !=
NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI &&
!disable_offline_check_) {
return false;
}
nqe::internal::CachedNetworkQuality cached_network_quality;
const bool cached_estimate_available = network_quality_store_->GetById(
@ -1820,6 +1826,11 @@ void NetworkQualityEstimator::MaybeUpdateNetworkQualityFromCache(
return;
if (network_id != current_network_id_)
return;
if (network_id.type !=
NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI &&
!disable_offline_check_) {
return;
}
// Since the cached network quality is for the current network, add it to
// the current observations.

@ -86,7 +86,7 @@ double GetWeightMultiplierPerSecond(
bool GetPersistentCacheReadingEnabled(
const std::map<std::string, std::string>& params) {
if (GetStringValueForVariationParamWithDefaultValue(
params, "persistent_cache_reading_enabled", "false") != "true") {
params, "persistent_cache_reading_enabled", "true") != "true") {
return false;
}
return true;

@ -195,13 +195,11 @@ TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) {
base::HistogramTester histogram_tester;
// Enable requests to local host to be used for network quality estimation.
std::map<std::string, std::string> variation_params;
variation_params["persistent_cache_reading_enabled"] = "true";
TestNetworkQualityEstimator estimator(variation_params);
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test");
histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable",
false, 1);
histogram_tester.ExpectTotalCount("NQE.CachedNetworkQualityAvailable", 0);
base::TimeDelta rtt;
int32_t kbps;
@ -290,7 +288,7 @@ TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) {
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1");
histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable",
false, 2);
false, 1);
histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1);
histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1);
@ -325,7 +323,7 @@ TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) {
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, std::string());
histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable",
false, 2);
false, 1);
histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1);
histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1);
@ -357,8 +355,6 @@ TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) {
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test");
histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", false,
2);
histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", true,
1);
}
@ -367,11 +363,10 @@ TEST(NetworkQualityEstimatorTest, TestKbpsRTTUpdates) {
TEST(NetworkQualityEstimatorTest, Caching) {
base::HistogramTester histogram_tester;
std::map<std::string, std::string> variation_params;
variation_params["persistent_cache_reading_enabled"] = "true";
TestNetworkQualityEstimator estimator(variation_params);
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test");
NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test");
histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable",
false, 1);
@ -431,7 +426,7 @@ TEST(NetworkQualityEstimatorTest, Caching) {
EXPECT_LE(2, num_net_log_entries);
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test");
NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test");
histogram_tester.ExpectBucketCount(
"NQE.RTT.ObservationSource",
NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE, 1);
@ -478,10 +473,11 @@ TEST(NetworkQualityEstimatorTest, CachingDisabled) {
base::HistogramTester histogram_tester;
std::map<std::string, std::string> variation_params;
// Do not set |persistent_cache_reading_enabled| variation param.
variation_params["persistent_cache_reading_enabled"] = "false";
TestNetworkQualityEstimator estimator(variation_params);
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test");
NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test");
histogram_tester.ExpectTotalCount("NQE.CachedNetworkQualityAvailable", 0);
base::TimeDelta rtt;
@ -2233,6 +2229,12 @@ TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) {
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test");
histogram_tester.ExpectBucketCount(
"NQE.RTT.ObservationSource",
NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE, 0);
estimator.SimulateNetworkChange(
NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1");
histogram_tester.ExpectBucketCount(
"NQE.RTT.ObservationSource",
NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE, 1);
@ -3006,7 +3008,7 @@ TEST(NetworkQualityEstimatorTest, OnPrefsReadWithReadingDisabled) {
std::map<std::string, std::string> variation_params;
variation_params["effective_connection_type_algorithm"] =
"TransportRTTOrDownstreamThroughput";
// |persistent_cache_reading_enabled| variation param is not set.
variation_params["persistent_cache_reading_enabled"] = "false";
// Disable default platform values so that the effect of cached estimates
// at the time of startup can be studied in isolation.