Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(670)

Side by Side Diff: net/nqe/network_quality_estimator.cc

Issue 2145613003: NQE: Add accuracy histogram for external estimate provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/metrics/histogram_base.h" 17 #include "base/metrics/histogram_base.h"
18 #include "base/metrics/sparse_histogram.h" 18 #include "base/metrics/sparse_histogram.h"
19 #include "base/rand_util.h" 19 #include "base/rand_util.h"
20 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/stringprintf.h"
22 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/time/default_tick_clock.h" 24 #include "base/time/default_tick_clock.h"
24 #include "base/trace_event/trace_event.h" 25 #include "base/trace_event/trace_event.h"
25 #include "build/build_config.h" 26 #include "build/build_config.h"
26 #include "net/base/load_flags.h" 27 #include "net/base/load_flags.h"
27 #include "net/base/load_timing_info.h" 28 #include "net/base/load_timing_info.h"
28 #include "net/base/network_interfaces.h" 29 #include "net/base/network_interfaces.h"
29 #include "net/base/url_util.h" 30 #include "net/base/url_util.h"
30 #include "net/http/http_status_code.h" 31 #include "net/http/http_status_code.h"
31 #include "net/nqe/socket_watcher_factory.h" 32 #include "net/nqe/socket_watcher_factory.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 194 }
194 195
195 // Returns true if the scheme of the |request| is either HTTP or HTTPS. 196 // Returns true if the scheme of the |request| is either HTTP or HTTPS.
196 bool RequestSchemeIsHTTPOrHTTPS(const net::URLRequest& request) { 197 bool RequestSchemeIsHTTPOrHTTPS(const net::URLRequest& request) {
197 return request.url().is_valid() && request.url().SchemeIsHTTPOrHTTPS(); 198 return request.url().is_valid() && request.url().SchemeIsHTTPOrHTTPS();
198 } 199 }
199 200
200 // Returns the suffix of the histogram that should be used for recording the 201 // Returns the suffix of the histogram that should be used for recording the
201 // accuracy when the observed RTT is |observed_rtt|. The width of the intervals 202 // accuracy when the observed RTT is |observed_rtt|. The width of the intervals
202 // are in exponentially increasing order. 203 // are in exponentially increasing order.
203 std::string GetHistogramSuffixObservedRTT(const base::TimeDelta& observed_rtt) { 204 const char* GetHistogramSuffixObservedRTT(const base::TimeDelta& observed_rtt) {
204 const float rtt_milliseconds = observed_rtt.InMillisecondsF(); 205 const float rtt_milliseconds = observed_rtt.InMillisecondsF();
205 DCHECK_GE(rtt_milliseconds, 0); 206 DCHECK_GE(rtt_milliseconds, 0);
206 207
207 // The values here should remain synchronized with the suffixes specified in 208 // The values here should remain synchronized with the suffixes specified in
208 // histograms.xml. 209 // histograms.xml.
209 static const char* const kSuffixes[] = { 210 static const char* const kSuffixes[] = {
210 "0_20", "20_60", "60_140", "140_300", "300_620", 211 "0_20", "20_60", "60_140", "140_300", "300_620",
211 "620_1260", "1260_2540", "2540_5100", "5100_Infinity"}; 212 "620_1260", "1260_2540", "2540_5100", "5100_Infinity"};
212 for (size_t i = 0; i < arraysize(kSuffixes) - 1; ++i) { 213 for (size_t i = 0; i < arraysize(kSuffixes) - 1; ++i) {
213 if (rtt_milliseconds <= static_cast<float>((20 * (2 << i) - 20))) 214 if (rtt_milliseconds <= static_cast<float>((20 * (2 << i) - 20)))
214 return kSuffixes[i]; 215 return kSuffixes[i];
215 } 216 }
216 return kSuffixes[arraysize(kSuffixes) - 1]; 217 return kSuffixes[arraysize(kSuffixes) - 1];
217 } 218 }
218 219
219 // Returns the suffix of the histogram that should be used for recording the 220 // Returns the suffix of the histogram that should be used for recording the
220 // accuracy when the observed throughput in kilobits per second is 221 // accuracy when the observed throughput in kilobits per second is
221 // |observed_throughput_kbps|. The width of the intervals are in exponentially 222 // |observed_throughput_kbps|. The width of the intervals are in exponentially
222 // increasing order. 223 // increasing order.
223 std::string GetHistogramSuffixObservedThroughput( 224 const char* GetHistogramSuffixObservedThroughput(
224 const int32_t& observed_throughput_kbps) { 225 const int32_t& observed_throughput_kbps) {
225 DCHECK_GE(observed_throughput_kbps, 0); 226 DCHECK_GE(observed_throughput_kbps, 0);
226 227
227 // The values here should remain synchronized with the suffixes specified in 228 // The values here should remain synchronized with the suffixes specified in
228 // histograms.xml. 229 // histograms.xml.
229 static const char* const kSuffixes[] = { 230 static const char* const kSuffixes[] = {
230 "0_20", "20_60", "60_140", "140_300", "300_620", 231 "0_20", "20_60", "60_140", "140_300", "300_620",
231 "620_1260", "1260_2540", "2540_5100", "5100_Infinity"}; 232 "620_1260", "1260_2540", "2540_5100", "5100_Infinity"};
232 for (size_t i = 0; i < arraysize(kSuffixes) - 1; ++i) { 233 for (size_t i = 0; i < arraysize(kSuffixes) - 1; ++i) {
233 if (observed_throughput_kbps <= static_cast<float>((20 * (2 << i) - 20))) 234 if (observed_throughput_kbps <= static_cast<float>((20 * (2 << i) - 20)))
(...skipping 28 matching lines...) Expand all
262 // kBitsPerMetric. 263 // kBitsPerMetric.
263 static const int32_t kLargestValuePossible = (1 << kBitsPerMetric) - 1; 264 static const int32_t kLargestValuePossible = (1 << kBitsPerMetric) - 1;
264 if (metric > kLargestValuePossible) { 265 if (metric > kLargestValuePossible) {
265 // Fit |metric| in kBitsPerMetric by clamping it down. 266 // Fit |metric| in kBitsPerMetric by clamping it down.
266 metric = kLargestValuePossible; 267 metric = kLargestValuePossible;
267 } 268 }
268 DCHECK_EQ(0, metric >> kBitsPerMetric); 269 DCHECK_EQ(0, metric >> kBitsPerMetric);
269 return metric; 270 return metric;
270 } 271 }
271 272
273 void RecordRTTAccuracy(const char* prefix,
274 int32_t metric,
275 base::TimeDelta measuring_duration,
276 base::TimeDelta observed_rtt) {
277 const std::string histogram_name =
278 base::StringPrintf("%s.EstimatedObservedDiff.%s.%d.%s", prefix,
279 metric >= 0 ? "Positive" : "Negative",
280 static_cast<int32_t>(measuring_duration.InSeconds()),
281 GetHistogramSuffixObservedRTT(observed_rtt));
282
283 base::HistogramBase* histogram = base::Histogram::FactoryGet(
284 histogram_name, 1, 10 * 1000 /* 10 seconds */, 50 /* Number of buckets */,
285 base::HistogramBase::kUmaTargetedHistogramFlag);
286 histogram->Add(std::abs(metric));
287 }
288
289 void RecordThroughputAccuracy(const char* prefix,
290 int32_t metric,
291 base::TimeDelta measuring_duration,
292 int32_t observed_throughput_kbps) {
293 const std::string histogram_name = base::StringPrintf(
294 "%s.EstimatedObservedDiff.%s.%d.%s", prefix,
295 metric >= 0 ? "Positive" : "Negative",
296 static_cast<int32_t>(measuring_duration.InSeconds()),
297 GetHistogramSuffixObservedThroughput(observed_throughput_kbps));
298
299 base::HistogramBase* histogram = base::Histogram::FactoryGet(
300 histogram_name, 1, 1000 * 1000 /* 1 Gbps */, 50 /* Number of buckets */,
301 base::HistogramBase::kUmaTargetedHistogramFlag);
302 histogram->Add(std::abs(metric));
303 }
304
305 void RecordEffectiveConnectionTypeAccuracy(
306 const char* prefix,
307 int32_t metric,
308 base::TimeDelta measuring_duration,
309 net::NetworkQualityEstimator::EffectiveConnectionType
310 observed_effective_connection_type) {
311 const std::string histogram_name = base::StringPrintf(
312 "%s.EstimatedObservedDiff.%s.%d.%s", prefix,
313 metric >= 0 ? "Positive" : "Negative",
314 static_cast<int32_t>(measuring_duration.InSeconds()),
315 net::NetworkQualityEstimator::GetNameForEffectiveConnectionType(
316 observed_effective_connection_type));
317
318 base::HistogramBase* histogram = base::Histogram::FactoryGet(
319 histogram_name, 0,
320 net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_LAST,
321 net::NetworkQualityEstimator::
322 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */,
323 base::HistogramBase::kUmaTargetedHistogramFlag);
324 histogram->Add(std::abs(metric));
325 }
326
272 } // namespace 327 } // namespace
273 328
274 namespace net { 329 namespace net {
275 330
276 NetworkQualityEstimator::NetworkQualityEstimator( 331 NetworkQualityEstimator::NetworkQualityEstimator(
277 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, 332 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
278 const std::map<std::string, std::string>& variation_params) 333 const std::map<std::string, std::string>& variation_params)
279 : NetworkQualityEstimator(std::move(external_estimates_provider), 334 : NetworkQualityEstimator(std::move(external_estimates_provider),
280 variation_params, 335 variation_params,
281 false, 336 false,
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 if (!GetDownlinkThroughputKbpsEstimate(&downstream_throughput_kbps)) 619 if (!GetDownlinkThroughputKbpsEstimate(&downstream_throughput_kbps))
565 downstream_throughput_kbps = nqe::internal::kInvalidThroughput; 620 downstream_throughput_kbps = nqe::internal::kInvalidThroughput;
566 621
567 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality( 622 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality(
568 estimated_http_rtt, estimated_transport_rtt, 623 estimated_http_rtt, estimated_transport_rtt,
569 downstream_throughput_kbps); 624 downstream_throughput_kbps);
570 effective_connection_type_at_last_main_frame_ = 625 effective_connection_type_at_last_main_frame_ =
571 GetEffectiveConnectionType(); 626 GetEffectiveConnectionType();
572 627
573 RecordMetricsOnMainFrameRequest(); 628 RecordMetricsOnMainFrameRequest();
629 MaybeQueryExternalEstimateProvider();
574 630
575 // Post the tasks which will run in the future and record the estimation 631 // Post the tasks which will run in the future and record the estimation
576 // accuracy based on the observations received between now and the time of 632 // accuracy based on the observations received between now and the time of
577 // task execution. Posting the task at different intervals makes it 633 // task execution. Posting the task at different intervals makes it
578 // possible to measure the accuracy by comparing the estimate with the 634 // possible to measure the accuracy by comparing the estimate with the
579 // observations received over intervals of varying durations. 635 // observations received over intervals of varying durations.
580 for (const base::TimeDelta& measuring_delay : 636 for (const base::TimeDelta& measuring_delay :
581 GetAccuracyRecordingIntervals()) { 637 GetAccuracyRecordingIntervals()) {
582 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 638 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
583 FROM_HERE, 639 FROM_HERE,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 return; 699 return;
644 700
645 base::TimeDelta recent_http_rtt; 701 base::TimeDelta recent_http_rtt;
646 if (estimated_quality_at_last_main_frame_.http_rtt() != 702 if (estimated_quality_at_last_main_frame_.http_rtt() !=
647 nqe::internal::InvalidRTT() && 703 nqe::internal::InvalidRTT() &&
648 GetRecentHttpRTTMedian(last_main_frame_request_, &recent_http_rtt)) { 704 GetRecentHttpRTTMedian(last_main_frame_request_, &recent_http_rtt)) {
649 const int estimated_observed_diff_milliseconds = 705 const int estimated_observed_diff_milliseconds =
650 estimated_quality_at_last_main_frame_.http_rtt().InMilliseconds() - 706 estimated_quality_at_last_main_frame_.http_rtt().InMilliseconds() -
651 recent_http_rtt.InMilliseconds(); 707 recent_http_rtt.InMilliseconds();
652 708
653 const std::string sign_suffix = 709 RecordRTTAccuracy("NQE.Accuracy.HttpRTT",
654 estimated_observed_diff_milliseconds >= 0 ? "Positive." : "Negative."; 710 estimated_observed_diff_milliseconds, measuring_duration,
655 711 recent_http_rtt);
656 base::HistogramBase* histogram = base::Histogram::FactoryGet(
657 "NQE.Accuracy.HttpRTT.EstimatedObservedDiff." + sign_suffix +
658 base::IntToString(measuring_duration.InSeconds()) + "." +
659 GetHistogramSuffixObservedRTT(recent_http_rtt),
660 1, 10 * 1000 /* 10 seconds */, 50 /* Number of buckets */,
661 base::HistogramBase::kUmaTargetedHistogramFlag);
662 histogram->Add(std::abs(estimated_observed_diff_milliseconds));
663 } 712 }
664 713
665 base::TimeDelta recent_transport_rtt; 714 base::TimeDelta recent_transport_rtt;
666 if (estimated_quality_at_last_main_frame_.transport_rtt() != 715 if (estimated_quality_at_last_main_frame_.transport_rtt() !=
667 nqe::internal::InvalidRTT() && 716 nqe::internal::InvalidRTT() &&
668 GetRecentTransportRTTMedian(last_main_frame_request_, 717 GetRecentTransportRTTMedian(last_main_frame_request_,
669 &recent_transport_rtt)) { 718 &recent_transport_rtt)) {
670 const int estimated_observed_diff_milliseconds = 719 const int estimated_observed_diff_milliseconds =
671 estimated_quality_at_last_main_frame_.transport_rtt().InMilliseconds() - 720 estimated_quality_at_last_main_frame_.transport_rtt().InMilliseconds() -
672 recent_transport_rtt.InMilliseconds(); 721 recent_transport_rtt.InMilliseconds();
673 722
674 const std::string sign_suffix = 723 RecordRTTAccuracy("NQE.Accuracy.TransportRTT",
675 estimated_observed_diff_milliseconds >= 0 ? "Positive." : "Negative."; 724 estimated_observed_diff_milliseconds, measuring_duration,
676 725 recent_transport_rtt);
677 base::HistogramBase* histogram = base::Histogram::FactoryGet(
678 "NQE.Accuracy.TransportRTT.EstimatedObservedDiff." + sign_suffix +
679 base::IntToString(measuring_duration.InSeconds()) + "." +
680 GetHistogramSuffixObservedRTT(recent_transport_rtt),
681 1, 10 * 1000 /* 10 seconds */, 50 /* Number of buckets */,
682 base::HistogramBase::kUmaTargetedHistogramFlag);
683 histogram->Add(std::abs(estimated_observed_diff_milliseconds));
684 } 726 }
685 727
686 int32_t recent_downstream_throughput_kbps; 728 int32_t recent_downstream_throughput_kbps;
687 if (estimated_quality_at_last_main_frame_.downstream_throughput_kbps() != 729 if (estimated_quality_at_last_main_frame_.downstream_throughput_kbps() !=
688 nqe::internal::kInvalidThroughput && 730 nqe::internal::kInvalidThroughput &&
689 GetRecentMedianDownlinkThroughputKbps( 731 GetRecentMedianDownlinkThroughputKbps(
690 last_main_frame_request_, &recent_downstream_throughput_kbps)) { 732 last_main_frame_request_, &recent_downstream_throughput_kbps)) {
691 const int estimated_observed_diff = 733 const int estimated_observed_diff =
692 estimated_quality_at_last_main_frame_.downstream_throughput_kbps() - 734 estimated_quality_at_last_main_frame_.downstream_throughput_kbps() -
693 recent_downstream_throughput_kbps; 735 recent_downstream_throughput_kbps;
694 736
695 const std::string sign_suffix = 737 RecordThroughputAccuracy("NQE.Accuracy.DownstreamThroughputKbps",
696 estimated_observed_diff >= 0 ? "Positive." : "Negative."; 738 estimated_observed_diff, measuring_duration,
697 739 recent_downstream_throughput_kbps);
698 base::HistogramBase* histogram = base::Histogram::FactoryGet(
699 "NQE.Accuracy.DownstreamThroughputKbps.EstimatedObservedDiff." +
700 sign_suffix + base::IntToString(measuring_duration.InSeconds()) +
701 "." + GetHistogramSuffixObservedThroughput(
702 recent_downstream_throughput_kbps),
703 1, 1000 * 1000 /* 1 Gbps */, 50 /* Number of buckets */,
704 base::HistogramBase::kUmaTargetedHistogramFlag);
705 histogram->Add(std::abs(estimated_observed_diff));
706 } 740 }
707 741
708 EffectiveConnectionType recent_effective_connection_type = 742 EffectiveConnectionType recent_effective_connection_type =
709 GetRecentEffectiveConnectionType(last_main_frame_request_); 743 GetRecentEffectiveConnectionType(last_main_frame_request_);
710 if (effective_connection_type_at_last_main_frame_ != 744 if (effective_connection_type_at_last_main_frame_ !=
711 EFFECTIVE_CONNECTION_TYPE_UNKNOWN && 745 EFFECTIVE_CONNECTION_TYPE_UNKNOWN &&
712 recent_effective_connection_type != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 746 recent_effective_connection_type != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
713 const int estimated_observed_diff = 747 const int estimated_observed_diff =
714 static_cast<int>(effective_connection_type_at_last_main_frame_) - 748 static_cast<int>(effective_connection_type_at_last_main_frame_) -
715 static_cast<int>(recent_effective_connection_type); 749 static_cast<int>(recent_effective_connection_type);
716 750
717 const std::string sign_suffix = 751 RecordEffectiveConnectionTypeAccuracy(
718 estimated_observed_diff >= 0 ? "Positive." : "Negative."; 752 "NQE.Accuracy.EffectiveConnectionType", estimated_observed_diff,
753 measuring_duration, recent_effective_connection_type);
754 }
719 755
720 base::HistogramBase* histogram = base::Histogram::FactoryGet( 756 // Add histogram to evaluate the accuracy of the external estimate provider.
721 "NQE.Accuracy.EffectiveConnectionType.EstimatedObservedDiff." + 757 if (external_estimate_provider_quality_.http_rtt() !=
722 sign_suffix + base::IntToString(measuring_duration.InSeconds()) + 758 nqe::internal::InvalidRTT() &&
723 "." + 759 recent_http_rtt != nqe::internal::InvalidRTT()) {
724 GetNameForEffectiveConnectionType(recent_effective_connection_type), 760 const int estimated_observed_diff_milliseconds =
725 0, EFFECTIVE_CONNECTION_TYPE_LAST, 761 external_estimate_provider_quality_.http_rtt().InMilliseconds() -
726 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, 762 recent_http_rtt.InMilliseconds();
727 base::HistogramBase::kUmaTargetedHistogramFlag); 763
728 histogram->Add(std::abs(estimated_observed_diff)); 764 RecordRTTAccuracy("NQE.ExternalEstimateProvider.RTT.Accuracy",
765 estimated_observed_diff_milliseconds, measuring_duration,
766 recent_http_rtt);
729 } 767 }
730 } 768 }
731 769
732 void NetworkQualityEstimator::NotifyRequestCompleted( 770 void NetworkQualityEstimator::NotifyRequestCompleted(
733 const URLRequest& request) { 771 const URLRequest& request) {
734 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), 772 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"),
735 "NetworkQualityEstimator::NotifyRequestCompleted"); 773 "NetworkQualityEstimator::NotifyRequestCompleted");
736 DCHECK(thread_checker_.CalledOnValidThread()); 774 DCHECK(thread_checker_.CalledOnValidThread());
737 775
738 if (!RequestSchemeIsHTTPOrHTTPS(request)) 776 if (!RequestSchemeIsHTTPOrHTTPS(request))
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 max_signal_strength_since_connection_change_ != INT32_MIN); 974 max_signal_strength_since_connection_change_ != INT32_MIN);
937 } 975 }
938 #endif // OS_ANDROID 976 #endif // OS_ANDROID
939 min_signal_strength_since_connection_change_ = INT32_MAX; 977 min_signal_strength_since_connection_change_ = INT32_MAX;
940 max_signal_strength_since_connection_change_ = INT32_MIN; 978 max_signal_strength_since_connection_change_ = INT32_MIN;
941 979
942 // Update the local state as part of preparation for the new connection. 980 // Update the local state as part of preparation for the new connection.
943 current_network_id_ = GetCurrentNetworkID(); 981 current_network_id_ = GetCurrentNetworkID();
944 RecordNetworkIDAvailability(); 982 RecordNetworkIDAvailability();
945 983
984 MaybeQueryExternalEstimateProvider();
985
986 // Read any cached estimates for the new network. If cached estimates are
987 // unavailable, add the default estimates.
988 if (!ReadCachedNetworkQualityEstimate())
989 AddDefaultEstimates();
990 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality();
991 throughput_analyzer_->OnConnectionTypeChanged();
992 MaybeRecomputeEffectiveConnectionType();
993 UpdateSignalStrength();
994 }
995
996 void NetworkQualityEstimator::MaybeQueryExternalEstimateProvider() const {
946 // Query the external estimate provider on certain connection types. Once the 997 // Query the external estimate provider on certain connection types. Once the
947 // updated estimates are available, OnUpdatedEstimateAvailable will be called 998 // updated estimates are available, OnUpdatedEstimateAvailable will be called
948 // by |external_estimate_provider_| with updated estimates. 999 // by |external_estimate_provider_| with updated estimates.
949 if (external_estimate_provider_ && 1000 if (external_estimate_provider_ &&
950 current_network_id_.type != NetworkChangeNotifier::CONNECTION_NONE && 1001 current_network_id_.type != NetworkChangeNotifier::CONNECTION_NONE &&
951 current_network_id_.type != NetworkChangeNotifier::CONNECTION_UNKNOWN && 1002 current_network_id_.type != NetworkChangeNotifier::CONNECTION_UNKNOWN &&
952 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET && 1003 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET &&
953 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) { 1004 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) {
954 RecordExternalEstimateProviderMetrics( 1005 RecordExternalEstimateProviderMetrics(
955 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED); 1006 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED);
956 external_estimate_provider_->Update(); 1007 external_estimate_provider_->Update();
957 } 1008 }
958
959 // Read any cached estimates for the new network. If cached estimates are
960 // unavailable, add the default estimates.
961 if (!ReadCachedNetworkQualityEstimate())
962 AddDefaultEstimates();
963 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality();
964 throughput_analyzer_->OnConnectionTypeChanged();
965 MaybeRecomputeEffectiveConnectionType();
966 UpdateSignalStrength();
967 } 1009 }
968 1010
969 void NetworkQualityEstimator::UpdateSignalStrength() { 1011 void NetworkQualityEstimator::UpdateSignalStrength() {
970 #if defined(OS_ANDROID) 1012 #if defined(OS_ANDROID)
971 int32_t signal_strength_dbm; 1013 int32_t signal_strength_dbm;
972 if (!android::cellular_signal_strength::GetSignalStrengthDbm( 1014 if (!android::cellular_signal_strength::GetSignalStrengthDbm(
973 &signal_strength_dbm)) { 1015 &signal_strength_dbm)) {
974 return; 1016 return;
975 } 1017 }
976 min_signal_strength_since_connection_change_ = std::min( 1018 min_signal_strength_since_connection_change_ = std::min(
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 void NetworkQualityEstimator::OnUpdatedEstimateAvailable( 1479 void NetworkQualityEstimator::OnUpdatedEstimateAvailable(
1438 const base::TimeDelta& rtt, 1480 const base::TimeDelta& rtt,
1439 int32_t downstream_throughput_kbps, 1481 int32_t downstream_throughput_kbps,
1440 int32_t upstream_throughput_kbps) { 1482 int32_t upstream_throughput_kbps) {
1441 DCHECK(thread_checker_.CalledOnValidThread()); 1483 DCHECK(thread_checker_.CalledOnValidThread());
1442 DCHECK(external_estimate_provider_); 1484 DCHECK(external_estimate_provider_);
1443 1485
1444 RecordExternalEstimateProviderMetrics( 1486 RecordExternalEstimateProviderMetrics(
1445 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK); 1487 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK);
1446 1488
1489 external_estimate_provider_quality_ = nqe::internal::NetworkQuality();
1490
1447 if (rtt > base::TimeDelta()) { 1491 if (rtt > base::TimeDelta()) {
1448 RecordExternalEstimateProviderMetrics( 1492 RecordExternalEstimateProviderMetrics(
1449 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE); 1493 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE);
1450 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt); 1494 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt);
1451 rtt_observations_.AddObservation( 1495 rtt_observations_.AddObservation(
1452 RttObservation(rtt, tick_clock_->NowTicks(), 1496 RttObservation(rtt, tick_clock_->NowTicks(),
1453 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE)); 1497 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE));
1498 external_estimate_provider_quality_.set_http_rtt(rtt);
1454 } 1499 }
1455 1500
1456 if (downstream_throughput_kbps > 0) { 1501 if (downstream_throughput_kbps > 0) {
1457 RecordExternalEstimateProviderMetrics( 1502 RecordExternalEstimateProviderMetrics(
1458 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE); 1503 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE);
1459 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth", 1504 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth",
1460 downstream_throughput_kbps); 1505 downstream_throughput_kbps);
1461 downstream_throughput_kbps_observations_.AddObservation( 1506 downstream_throughput_kbps_observations_.AddObservation(
1462 ThroughputObservation( 1507 ThroughputObservation(
1463 downstream_throughput_kbps, tick_clock_->NowTicks(), 1508 downstream_throughput_kbps, tick_clock_->NowTicks(),
1464 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE)); 1509 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE));
1510 external_estimate_provider_quality_.set_downstream_throughput_kbps(
1511 downstream_throughput_kbps);
1465 } 1512 }
1466 } 1513 }
1467 1514
1468 // static 1515 // static
1469 const char* NetworkQualityEstimator::GetNameForEffectiveConnectionType( 1516 const char* NetworkQualityEstimator::GetNameForEffectiveConnectionType(
1470 EffectiveConnectionType type) { 1517 EffectiveConnectionType type) {
1471 switch (type) { 1518 switch (type) {
1472 case EFFECTIVE_CONNECTION_TYPE_UNKNOWN: 1519 case EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
1473 return "Unknown"; 1520 return "Unknown";
1474 case EFFECTIVE_CONNECTION_TYPE_OFFLINE: 1521 case EFFECTIVE_CONNECTION_TYPE_OFFLINE:
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 NotifyObserversOfEffectiveConnectionTypeChanged() { 1659 NotifyObserversOfEffectiveConnectionTypeChanged() {
1613 DCHECK(thread_checker_.CalledOnValidThread()); 1660 DCHECK(thread_checker_.CalledOnValidThread());
1614 1661
1615 // TODO(tbansal): Add hysteresis in the notification. 1662 // TODO(tbansal): Add hysteresis in the notification.
1616 FOR_EACH_OBSERVER( 1663 FOR_EACH_OBSERVER(
1617 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, 1664 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_,
1618 OnEffectiveConnectionTypeChanged(effective_connection_type_)); 1665 OnEffectiveConnectionTypeChanged(effective_connection_type_));
1619 } 1666 }
1620 1667
1621 } // namespace net 1668 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator.h ('k') | net/nqe/network_quality_estimator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698