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

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: Addressed bengr comments Created 4 years, 5 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/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/stringprintf.h"
20 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
21 #include "base/time/default_tick_clock.h" 22 #include "base/time/default_tick_clock.h"
22 #include "base/trace_event/trace_event.h" 23 #include "base/trace_event/trace_event.h"
23 #include "build/build_config.h" 24 #include "build/build_config.h"
24 #include "net/base/load_flags.h" 25 #include "net/base/load_flags.h"
25 #include "net/base/load_timing_info.h" 26 #include "net/base/load_timing_info.h"
26 #include "net/base/network_interfaces.h" 27 #include "net/base/network_interfaces.h"
27 #include "net/base/url_util.h" 28 #include "net/base/url_util.h"
28 #include "net/nqe/socket_watcher_factory.h" 29 #include "net/nqe/socket_watcher_factory.h"
29 #include "net/nqe/throughput_analyzer.h" 30 #include "net/nqe/throughput_analyzer.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 174 }
174 175
175 // Returns true if the scheme of the |request| is either HTTP or HTTPS. 176 // Returns true if the scheme of the |request| is either HTTP or HTTPS.
176 bool RequestSchemeIsHTTPOrHTTPS(const net::URLRequest& request) { 177 bool RequestSchemeIsHTTPOrHTTPS(const net::URLRequest& request) {
177 return request.url().is_valid() && request.url().SchemeIsHTTPOrHTTPS(); 178 return request.url().is_valid() && request.url().SchemeIsHTTPOrHTTPS();
178 } 179 }
179 180
180 // Returns the suffix of the histogram that should be used for recording the 181 // Returns the suffix of the histogram that should be used for recording the
181 // accuracy when the observed RTT is |observed_rtt|. The width of the intervals 182 // accuracy when the observed RTT is |observed_rtt|. The width of the intervals
182 // are in exponentially increasing order. 183 // are in exponentially increasing order.
183 std::string GetHistogramSuffixObservedRTT(const base::TimeDelta& observed_rtt) { 184 const char* GetHistogramSuffixObservedRTT(const base::TimeDelta& observed_rtt) {
184 const float rtt_milliseconds = observed_rtt.InMillisecondsF(); 185 const float rtt_milliseconds = observed_rtt.InMillisecondsF();
185 DCHECK_GE(rtt_milliseconds, 0); 186 DCHECK_GE(rtt_milliseconds, 0);
186 187
187 // The values here should remain synchronized with the suffixes specified in 188 // The values here should remain synchronized with the suffixes specified in
188 // histograms.xml. 189 // histograms.xml.
189 static const char* const kSuffixes[] = { 190 static const char* const kSuffixes[] = {
190 "0_20", "20_60", "60_140", "140_300", "300_620", 191 "0_20", "20_60", "60_140", "140_300", "300_620",
191 "620_1260", "1260_2540", "2540_5100", "5100_Infinity"}; 192 "620_1260", "1260_2540", "2540_5100", "5100_Infinity"};
192 for (size_t i = 0; i < arraysize(kSuffixes) - 1; ++i) { 193 for (size_t i = 0; i < arraysize(kSuffixes) - 1; ++i) {
193 if (rtt_milliseconds <= static_cast<float>((20 * (2 << i) - 20))) 194 if (rtt_milliseconds <= static_cast<float>((20 * (2 << i) - 20)))
194 return kSuffixes[i]; 195 return kSuffixes[i];
195 } 196 }
196 return kSuffixes[arraysize(kSuffixes) - 1]; 197 return kSuffixes[arraysize(kSuffixes) - 1];
197 } 198 }
198 199
199 // Returns the suffix of the histogram that should be used for recording the 200 // Returns the suffix of the histogram that should be used for recording the
200 // accuracy when the observed throughput in kilobits per second is 201 // accuracy when the observed throughput in kilobits per second is
201 // |observed_throughput_kbps|. The width of the intervals are in exponentially 202 // |observed_throughput_kbps|. The width of the intervals are in exponentially
202 // increasing order. 203 // increasing order.
203 std::string GetHistogramSuffixObservedThroughput( 204 const char* GetHistogramSuffixObservedThroughput(
204 const int32_t& observed_throughput_kbps) { 205 const int32_t& observed_throughput_kbps) {
205 DCHECK_GE(observed_throughput_kbps, 0); 206 DCHECK_GE(observed_throughput_kbps, 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 (observed_throughput_kbps <= static_cast<float>((20 * (2 << i) - 20))) 214 if (observed_throughput_kbps <= 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
220 void RecordAccuracyRTT(const char* prefix,
bengr 2016/07/22 17:32:57 I would switch the wording of all of these to put
tbansal1 2016/07/22 21:47:45 Done.
221 int32_t metric,
222 base::TimeDelta measuring_duration,
223 base::TimeDelta observed_rtt) {
224 const std::string histogram_name =
225 base::StringPrintf("%s.EstimatedObservedDiff.%s.%d.%s", prefix,
226 metric >= 0 ? "Positive" : "Negative",
227 static_cast<int32_t>(measuring_duration.InSeconds()),
228 GetHistogramSuffixObservedRTT(observed_rtt));
229
230 base::HistogramBase* histogram = base::Histogram::FactoryGet(
231 histogram_name, 1, 10 * 1000 /* 10 seconds */, 50 /* Number of buckets */,
232 base::HistogramBase::kUmaTargetedHistogramFlag);
233 histogram->Add(std::abs(metric));
234 }
235
236 void RecordAccuracyThroughput(const char* prefix,
237 int32_t metric,
238 base::TimeDelta measuring_duration,
239 int32_t observed_throughput_kbps) {
240 const std::string histogram_name = base::StringPrintf(
241 "%s.EstimatedObservedDiff.%s.%d.%s", prefix,
242 metric >= 0 ? "Positive" : "Negative",
243 static_cast<int32_t>(measuring_duration.InSeconds()),
244 GetHistogramSuffixObservedThroughput(observed_throughput_kbps));
245
246 base::HistogramBase* histogram = base::Histogram::FactoryGet(
247 histogram_name, 1, 1000 * 1000 /* 1 Gbps */, 50 /* Number of buckets */,
248 base::HistogramBase::kUmaTargetedHistogramFlag);
249 histogram->Add(std::abs(metric));
250 }
251
252 void RecordAccuracyEffectiveConnectionType(
253 const char* prefix,
254 int32_t metric,
255 base::TimeDelta measuring_duration,
256 net::NetworkQualityEstimator::EffectiveConnectionType
257 observed_effective_connection_type) {
258 const std::string histogram_name = base::StringPrintf(
259 "%s.EstimatedObservedDiff.%s.%d.%s", prefix,
260 metric >= 0 ? "Positive" : "Negative",
261 static_cast<int32_t>(measuring_duration.InSeconds()),
262 net::NetworkQualityEstimator::GetNameForEffectiveConnectionType(
263 observed_effective_connection_type));
264
265 base::HistogramBase* histogram = base::Histogram::FactoryGet(
266 histogram_name, 0,
267 net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_LAST,
268 net::NetworkQualityEstimator::
269 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */,
270 base::HistogramBase::kUmaTargetedHistogramFlag);
271 histogram->Add(std::abs(metric));
272 }
273
219 } // namespace 274 } // namespace
220 275
221 namespace net { 276 namespace net {
222 277
223 NetworkQualityEstimator::NetworkQualityEstimator( 278 NetworkQualityEstimator::NetworkQualityEstimator(
224 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, 279 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
225 const std::map<std::string, std::string>& variation_params) 280 const std::map<std::string, std::string>& variation_params)
226 : NetworkQualityEstimator(std::move(external_estimates_provider), 281 : NetworkQualityEstimator(std::move(external_estimates_provider),
227 variation_params, 282 variation_params,
228 false, 283 false,
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 if (!GetDownlinkThroughputKbpsEstimate(&downstream_throughput_kbps)) 565 if (!GetDownlinkThroughputKbpsEstimate(&downstream_throughput_kbps))
511 downstream_throughput_kbps = nqe::internal::kInvalidThroughput; 566 downstream_throughput_kbps = nqe::internal::kInvalidThroughput;
512 567
513 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality( 568 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality(
514 estimated_http_rtt, estimated_transport_rtt, 569 estimated_http_rtt, estimated_transport_rtt,
515 downstream_throughput_kbps); 570 downstream_throughput_kbps);
516 effective_connection_type_at_last_main_frame_ = 571 effective_connection_type_at_last_main_frame_ =
517 GetEffectiveConnectionType(); 572 GetEffectiveConnectionType();
518 573
519 RecordMetricsOnMainFrameRequest(); 574 RecordMetricsOnMainFrameRequest();
575 MaybeQueryExternalEstimateProvider();
520 576
521 // Post the tasks which will run in the future and record the estimation 577 // Post the tasks which will run in the future and record the estimation
522 // accuracy based on the observations received between now and the time of 578 // accuracy based on the observations received between now and the time of
523 // task execution. Posting the task at different intervals makes it 579 // task execution. Posting the task at different intervals makes it
524 // possible to measure the accuracy by comparing the estimate with the 580 // possible to measure the accuracy by comparing the estimate with the
525 // observations received over intervals of varying durations. 581 // observations received over intervals of varying durations.
526 for (const base::TimeDelta& measuring_delay : 582 for (const base::TimeDelta& measuring_delay :
527 GetAccuracyRecordingIntervals()) { 583 GetAccuracyRecordingIntervals()) {
528 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 584 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
529 FROM_HERE, 585 FROM_HERE,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 return; 644 return;
589 645
590 base::TimeDelta recent_http_rtt; 646 base::TimeDelta recent_http_rtt;
591 if (estimated_quality_at_last_main_frame_.http_rtt() != 647 if (estimated_quality_at_last_main_frame_.http_rtt() !=
592 nqe::internal::InvalidRTT() && 648 nqe::internal::InvalidRTT() &&
593 GetRecentHttpRTTMedian(last_main_frame_request_, &recent_http_rtt)) { 649 GetRecentHttpRTTMedian(last_main_frame_request_, &recent_http_rtt)) {
594 const int estimated_observed_diff_milliseconds = 650 const int estimated_observed_diff_milliseconds =
595 estimated_quality_at_last_main_frame_.http_rtt().InMilliseconds() - 651 estimated_quality_at_last_main_frame_.http_rtt().InMilliseconds() -
596 recent_http_rtt.InMilliseconds(); 652 recent_http_rtt.InMilliseconds();
597 653
598 const std::string sign_suffix = 654 RecordAccuracyRTT("NQE.Accuracy.HttpRTT",
599 estimated_observed_diff_milliseconds >= 0 ? "Positive." : "Negative."; 655 estimated_observed_diff_milliseconds, measuring_duration,
600 656 recent_http_rtt);
601 base::HistogramBase* histogram = base::Histogram::FactoryGet(
602 "NQE.Accuracy.HttpRTT.EstimatedObservedDiff." + sign_suffix +
603 base::IntToString(measuring_duration.InSeconds()) + "." +
604 GetHistogramSuffixObservedRTT(recent_http_rtt),
605 1, 10 * 1000 /* 10 seconds */, 50 /* Number of buckets */,
606 base::HistogramBase::kUmaTargetedHistogramFlag);
607 histogram->Add(std::abs(estimated_observed_diff_milliseconds));
608 } 657 }
609 658
610 base::TimeDelta recent_transport_rtt; 659 base::TimeDelta recent_transport_rtt;
611 if (estimated_quality_at_last_main_frame_.transport_rtt() != 660 if (estimated_quality_at_last_main_frame_.transport_rtt() !=
612 nqe::internal::InvalidRTT() && 661 nqe::internal::InvalidRTT() &&
613 GetRecentTransportRTTMedian(last_main_frame_request_, 662 GetRecentTransportRTTMedian(last_main_frame_request_,
614 &recent_transport_rtt)) { 663 &recent_transport_rtt)) {
615 const int estimated_observed_diff_milliseconds = 664 const int estimated_observed_diff_milliseconds =
616 estimated_quality_at_last_main_frame_.transport_rtt().InMilliseconds() - 665 estimated_quality_at_last_main_frame_.transport_rtt().InMilliseconds() -
617 recent_transport_rtt.InMilliseconds(); 666 recent_transport_rtt.InMilliseconds();
618 667
619 const std::string sign_suffix = 668 RecordAccuracyRTT("NQE.Accuracy.TransportRTT",
620 estimated_observed_diff_milliseconds >= 0 ? "Positive." : "Negative."; 669 estimated_observed_diff_milliseconds, measuring_duration,
621 670 recent_transport_rtt);
622 base::HistogramBase* histogram = base::Histogram::FactoryGet(
623 "NQE.Accuracy.TransportRTT.EstimatedObservedDiff." + sign_suffix +
624 base::IntToString(measuring_duration.InSeconds()) + "." +
625 GetHistogramSuffixObservedRTT(recent_transport_rtt),
626 1, 10 * 1000 /* 10 seconds */, 50 /* Number of buckets */,
627 base::HistogramBase::kUmaTargetedHistogramFlag);
628 histogram->Add(std::abs(estimated_observed_diff_milliseconds));
629 } 671 }
630 672
631 int32_t recent_downstream_throughput_kbps; 673 int32_t recent_downstream_throughput_kbps;
632 if (estimated_quality_at_last_main_frame_.downstream_throughput_kbps() != 674 if (estimated_quality_at_last_main_frame_.downstream_throughput_kbps() !=
633 nqe::internal::kInvalidThroughput && 675 nqe::internal::kInvalidThroughput &&
634 GetRecentMedianDownlinkThroughputKbps( 676 GetRecentMedianDownlinkThroughputKbps(
635 last_main_frame_request_, &recent_downstream_throughput_kbps)) { 677 last_main_frame_request_, &recent_downstream_throughput_kbps)) {
636 const int estimated_observed_diff = 678 const int estimated_observed_diff =
637 estimated_quality_at_last_main_frame_.downstream_throughput_kbps() - 679 estimated_quality_at_last_main_frame_.downstream_throughput_kbps() -
638 recent_downstream_throughput_kbps; 680 recent_downstream_throughput_kbps;
639 681
640 const std::string sign_suffix = 682 RecordAccuracyThroughput("NQE.Accuracy.DownstreamThroughputKbps",
641 estimated_observed_diff >= 0 ? "Positive." : "Negative."; 683 estimated_observed_diff, measuring_duration,
642 684 recent_downstream_throughput_kbps);
643 base::HistogramBase* histogram = base::Histogram::FactoryGet(
644 "NQE.Accuracy.DownstreamThroughputKbps.EstimatedObservedDiff." +
645 sign_suffix + base::IntToString(measuring_duration.InSeconds()) +
646 "." + GetHistogramSuffixObservedThroughput(
647 recent_downstream_throughput_kbps),
648 1, 1000 * 1000 /* 1 Gbps */, 50 /* Number of buckets */,
649 base::HistogramBase::kUmaTargetedHistogramFlag);
650 histogram->Add(std::abs(estimated_observed_diff));
651 } 685 }
652 686
653 EffectiveConnectionType recent_effective_connection_type = 687 EffectiveConnectionType recent_effective_connection_type =
654 GetRecentEffectiveConnectionType(last_main_frame_request_); 688 GetRecentEffectiveConnectionType(last_main_frame_request_);
655 if (effective_connection_type_at_last_main_frame_ != 689 if (effective_connection_type_at_last_main_frame_ !=
656 EFFECTIVE_CONNECTION_TYPE_UNKNOWN && 690 EFFECTIVE_CONNECTION_TYPE_UNKNOWN &&
657 recent_effective_connection_type != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 691 recent_effective_connection_type != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
658 const int estimated_observed_diff = 692 const int estimated_observed_diff =
659 static_cast<int>(effective_connection_type_at_last_main_frame_) - 693 static_cast<int>(effective_connection_type_at_last_main_frame_) -
660 static_cast<int>(recent_effective_connection_type); 694 static_cast<int>(recent_effective_connection_type);
661 695
662 const std::string sign_suffix = 696 RecordAccuracyEffectiveConnectionType(
663 estimated_observed_diff >= 0 ? "Positive." : "Negative."; 697 "NQE.Accuracy.EffectiveConnectionType", estimated_observed_diff,
698 measuring_duration, recent_effective_connection_type);
699 }
664 700
665 base::HistogramBase* histogram = base::Histogram::FactoryGet( 701 // Add histogram to evaluate the accuracy of the external estimate provider.
666 "NQE.Accuracy.EffectiveConnectionType.EstimatedObservedDiff." + 702 if (external_estimate_provider_quality_.http_rtt() !=
667 sign_suffix + base::IntToString(measuring_duration.InSeconds()) + 703 nqe::internal::InvalidRTT() &&
668 "." + 704 recent_http_rtt != nqe::internal::InvalidRTT()) {
669 GetNameForEffectiveConnectionType(recent_effective_connection_type), 705 const int estimated_observed_diff_milliseconds =
670 0, EFFECTIVE_CONNECTION_TYPE_LAST, 706 external_estimate_provider_quality_.http_rtt().InMilliseconds() -
671 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, 707 recent_http_rtt.InMilliseconds();
672 base::HistogramBase::kUmaTargetedHistogramFlag); 708
673 histogram->Add(std::abs(estimated_observed_diff)); 709 RecordAccuracyRTT("NQE.ExternalEstimateProvider.RTT.Accuracy",
710 estimated_observed_diff_milliseconds, measuring_duration,
711 recent_http_rtt);
674 } 712 }
675 } 713 }
676 714
677 void NetworkQualityEstimator::NotifyRequestCompleted( 715 void NetworkQualityEstimator::NotifyRequestCompleted(
678 const URLRequest& request) { 716 const URLRequest& request) {
679 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), 717 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"),
680 "NetworkQualityEstimator::NotifyRequestCompleted"); 718 "NetworkQualityEstimator::NotifyRequestCompleted");
681 DCHECK(thread_checker_.CalledOnValidThread()); 719 DCHECK(thread_checker_.CalledOnValidThread());
682 720
683 if (!RequestSchemeIsHTTPOrHTTPS(request)) 721 if (!RequestSchemeIsHTTPOrHTTPS(request))
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 "NQE.CellularSignalStrengthAvailable", 814 "NQE.CellularSignalStrengthAvailable",
777 min_signal_strength_since_connection_change_ != INT32_MAX && 815 min_signal_strength_since_connection_change_ != INT32_MAX &&
778 max_signal_strength_since_connection_change_ != INT32_MIN); 816 max_signal_strength_since_connection_change_ != INT32_MIN);
779 } 817 }
780 #endif // OS_ANDROID 818 #endif // OS_ANDROID
781 min_signal_strength_since_connection_change_ = INT32_MAX; 819 min_signal_strength_since_connection_change_ = INT32_MAX;
782 max_signal_strength_since_connection_change_ = INT32_MIN; 820 max_signal_strength_since_connection_change_ = INT32_MIN;
783 821
784 current_network_id_ = GetCurrentNetworkID(); 822 current_network_id_ = GetCurrentNetworkID();
785 823
824 MaybeQueryExternalEstimateProvider();
825
826 // Read any cached estimates for the new network. If cached estimates are
827 // unavailable, add the default estimates.
828 if (!ReadCachedNetworkQualityEstimate())
829 AddDefaultEstimates();
830 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality();
831 throughput_analyzer_->OnConnectionTypeChanged();
832 MaybeRecomputeEffectiveConnectionType();
833 UpdateSignalStrength();
834 }
835
836 void NetworkQualityEstimator::MaybeQueryExternalEstimateProvider() const {
786 // Query the external estimate provider on certain connection types. Once the 837 // Query the external estimate provider on certain connection types. Once the
787 // updated estimates are available, OnUpdatedEstimateAvailable will be called 838 // updated estimates are available, OnUpdatedEstimateAvailable will be called
788 // by |external_estimate_provider_| with updated estimates. 839 // by |external_estimate_provider_| with updated estimates.
789 if (external_estimate_provider_ && 840 if (external_estimate_provider_ &&
790 current_network_id_.type != NetworkChangeNotifier::CONNECTION_NONE && 841 current_network_id_.type != NetworkChangeNotifier::CONNECTION_NONE &&
791 current_network_id_.type != NetworkChangeNotifier::CONNECTION_UNKNOWN && 842 current_network_id_.type != NetworkChangeNotifier::CONNECTION_UNKNOWN &&
792 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET && 843 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET &&
793 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) { 844 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) {
794 RecordExternalEstimateProviderMetrics( 845 RecordExternalEstimateProviderMetrics(
795 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED); 846 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED);
796 external_estimate_provider_->Update(); 847 external_estimate_provider_->Update();
797 } 848 }
798
799 // Read any cached estimates for the new network. If cached estimates are
800 // unavailable, add the default estimates.
801 if (!ReadCachedNetworkQualityEstimate())
802 AddDefaultEstimates();
803 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality();
804 throughput_analyzer_->OnConnectionTypeChanged();
805 MaybeRecomputeEffectiveConnectionType();
806 UpdateSignalStrength();
807 } 849 }
808 850
809 void NetworkQualityEstimator::UpdateSignalStrength() { 851 void NetworkQualityEstimator::UpdateSignalStrength() {
810 #if defined(OS_ANDROID) 852 #if defined(OS_ANDROID)
811 int32_t signal_strength_dbm; 853 int32_t signal_strength_dbm;
812 if (!android::cellular_signal_strength::GetSignalStrengthDbm( 854 if (!android::cellular_signal_strength::GetSignalStrengthDbm(
813 &signal_strength_dbm)) { 855 &signal_strength_dbm)) {
814 return; 856 return;
815 } 857 }
816 min_signal_strength_since_connection_change_ = std::min( 858 min_signal_strength_since_connection_change_ = std::min(
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 void NetworkQualityEstimator::OnUpdatedEstimateAvailable( 1298 void NetworkQualityEstimator::OnUpdatedEstimateAvailable(
1257 const base::TimeDelta& rtt, 1299 const base::TimeDelta& rtt,
1258 int32_t downstream_throughput_kbps, 1300 int32_t downstream_throughput_kbps,
1259 int32_t upstream_throughput_kbps) { 1301 int32_t upstream_throughput_kbps) {
1260 DCHECK(thread_checker_.CalledOnValidThread()); 1302 DCHECK(thread_checker_.CalledOnValidThread());
1261 DCHECK(external_estimate_provider_); 1303 DCHECK(external_estimate_provider_);
1262 1304
1263 RecordExternalEstimateProviderMetrics( 1305 RecordExternalEstimateProviderMetrics(
1264 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK); 1306 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK);
1265 1307
1308 external_estimate_provider_quality_ = nqe::internal::NetworkQuality();
1309
1266 if (rtt > base::TimeDelta()) { 1310 if (rtt > base::TimeDelta()) {
1267 RecordExternalEstimateProviderMetrics( 1311 RecordExternalEstimateProviderMetrics(
1268 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE); 1312 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE);
1269 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt); 1313 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt);
1270 rtt_observations_.AddObservation( 1314 rtt_observations_.AddObservation(
1271 RttObservation(rtt, tick_clock_->NowTicks(), 1315 RttObservation(rtt, tick_clock_->NowTicks(),
1272 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE)); 1316 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE));
1317 external_estimate_provider_quality_.set_http_rtt(rtt);
1273 } 1318 }
1274 1319
1275 if (downstream_throughput_kbps > 0) { 1320 if (downstream_throughput_kbps > 0) {
1276 RecordExternalEstimateProviderMetrics( 1321 RecordExternalEstimateProviderMetrics(
1277 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE); 1322 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE);
1278 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth", 1323 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth",
1279 downstream_throughput_kbps); 1324 downstream_throughput_kbps);
1280 downstream_throughput_kbps_observations_.AddObservation( 1325 downstream_throughput_kbps_observations_.AddObservation(
1281 ThroughputObservation( 1326 ThroughputObservation(
1282 downstream_throughput_kbps, tick_clock_->NowTicks(), 1327 downstream_throughput_kbps, tick_clock_->NowTicks(),
1283 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE)); 1328 NETWORK_QUALITY_OBSERVATION_SOURCE_EXTERNAL_ESTIMATE));
1329 external_estimate_provider_quality_.set_downstream_throughput_kbps(
1330 downstream_throughput_kbps);
1284 } 1331 }
1285 } 1332 }
1286 1333
1287 // static 1334 // static
1288 const char* NetworkQualityEstimator::GetNameForEffectiveConnectionType( 1335 const char* NetworkQualityEstimator::GetNameForEffectiveConnectionType(
1289 EffectiveConnectionType type) { 1336 EffectiveConnectionType type) {
1290 switch (type) { 1337 switch (type) {
1291 case EFFECTIVE_CONNECTION_TYPE_UNKNOWN: 1338 case EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
1292 return "Unknown"; 1339 return "Unknown";
1293 case EFFECTIVE_CONNECTION_TYPE_OFFLINE: 1340 case EFFECTIVE_CONNECTION_TYPE_OFFLINE:
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 NotifyObserversOfEffectiveConnectionTypeChanged() { 1519 NotifyObserversOfEffectiveConnectionTypeChanged() {
1473 DCHECK(thread_checker_.CalledOnValidThread()); 1520 DCHECK(thread_checker_.CalledOnValidThread());
1474 1521
1475 // TODO(tbansal): Add hysteresis in the notification. 1522 // TODO(tbansal): Add hysteresis in the notification.
1476 FOR_EACH_OBSERVER( 1523 FOR_EACH_OBSERVER(
1477 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, 1524 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_,
1478 OnEffectiveConnectionTypeChanged(effective_connection_type_)); 1525 OnEffectiveConnectionTypeChanged(effective_connection_type_));
1479 } 1526 }
1480 1527
1481 } // namespace net 1528 } // 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