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

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

Issue 1672513002: Expose packet loss counts from QUIC to NetworkQualityEstimator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: \ Created 4 years, 9 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
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/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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 DCHECK(thread_checker_.CalledOnValidThread()); 369 DCHECK(thread_checker_.CalledOnValidThread());
370 throughput_observer_list_.AddObserver(throughput_observer); 370 throughput_observer_list_.AddObserver(throughput_observer);
371 } 371 }
372 372
373 void NetworkQualityEstimator::RemoveThroughputObserver( 373 void NetworkQualityEstimator::RemoveThroughputObserver(
374 ThroughputObserver* throughput_observer) { 374 ThroughputObserver* throughput_observer) {
375 DCHECK(thread_checker_.CalledOnValidThread()); 375 DCHECK(thread_checker_.CalledOnValidThread());
376 throughput_observer_list_.RemoveObserver(throughput_observer); 376 throughput_observer_list_.RemoveObserver(throughput_observer);
377 } 377 }
378 378
379 void NetworkQualityEstimator::AddPacketCountObserver(
380 PacketCountObserver* packet_count_observer) {
381 DCHECK(thread_checker_.CalledOnValidThread());
382 packet_count_observer_list_.AddObserver(packet_count_observer);
383 }
384
385 void NetworkQualityEstimator::RemovePacketCountObserver(
386 PacketCountObserver* packet_count_observer) {
387 DCHECK(thread_checker_.CalledOnValidThread());
388 packet_count_observer_list_.RemoveObserver(packet_count_observer);
389 }
390
379 void NetworkQualityEstimator::RecordRTTUMA(int32_t estimated_value_msec, 391 void NetworkQualityEstimator::RecordRTTUMA(int32_t estimated_value_msec,
380 int32_t actual_value_msec) const { 392 int32_t actual_value_msec) const {
381 DCHECK(thread_checker_.CalledOnValidThread()); 393 DCHECK(thread_checker_.CalledOnValidThread());
382 394
383 // Record the difference between the actual and the estimated value. 395 // Record the difference between the actual and the estimated value.
384 if (estimated_value_msec >= actual_value_msec) { 396 if (estimated_value_msec >= actual_value_msec) {
385 base::HistogramBase* difference_rtt = 397 base::HistogramBase* difference_rtt =
386 GetHistogram("DifferenceRTTEstimatedAndActual.", 398 GetHistogram("DifferenceRTTEstimatedAndActual.",
387 current_network_id_.type, 10 * 1000); // 10 seconds 399 current_network_id_.type, 10 * 1000); // 10 seconds
388 difference_rtt->Add(estimated_value_msec - actual_value_msec); 400 difference_rtt->Add(estimated_value_msec - actual_value_msec);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 !request.was_cached() && 434 !request.was_cached() &&
423 request.creation_time() >= last_connection_change_; 435 request.creation_time() >= last_connection_change_;
424 } 436 }
425 437
426 void NetworkQualityEstimator::RecordExternalEstimateProviderMetrics( 438 void NetworkQualityEstimator::RecordExternalEstimateProviderMetrics(
427 NQEExternalEstimateProviderStatus status) const { 439 NQEExternalEstimateProviderStatus status) const {
428 UMA_HISTOGRAM_ENUMERATION("NQE.ExternalEstimateProviderStatus", status, 440 UMA_HISTOGRAM_ENUMERATION("NQE.ExternalEstimateProviderStatus", status,
429 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY); 441 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY);
430 } 442 }
431 443
444 bool NetworkQualityEstimator::GetObservationSourceForProtocol(
445 Protocol protocol,
446 NetworkQualityEstimator::ObservationSource* observation_source) const {
447 switch (protocol) {
448 case PROTOCOL_TCP:
449 *observation_source = TCP;
450 return true;
451 case PROTOCOL_QUIC:
452 *observation_source = QUIC;
453 return true;
454 default:
Ryan Hamilton 2016/03/10 00:29:53 nit: If there are only two value, you can omit the
tbansal1 2016/03/10 03:37:21 Done.
455 NOTREACHED();
456 return false;
457 }
458 }
459
432 void NetworkQualityEstimator::OnConnectionTypeChanged( 460 void NetworkQualityEstimator::OnConnectionTypeChanged(
433 NetworkChangeNotifier::ConnectionType type) { 461 NetworkChangeNotifier::ConnectionType type) {
434 DCHECK(thread_checker_.CalledOnValidThread()); 462 DCHECK(thread_checker_.CalledOnValidThread());
435 if (peak_network_quality_.rtt() != InvalidRTT()) { 463 if (peak_network_quality_.rtt() != InvalidRTT()) {
436 switch (current_network_id_.type) { 464 switch (current_network_id_.type) {
437 case NetworkChangeNotifier::CONNECTION_UNKNOWN: 465 case NetworkChangeNotifier::CONNECTION_UNKNOWN:
438 UMA_HISTOGRAM_TIMES("NQE.FastestRTT.Unknown", 466 UMA_HISTOGRAM_TIMES("NQE.FastestRTT.Unknown",
439 peak_network_quality_.rtt()); 467 peak_network_quality_.rtt());
440 break; 468 break;
441 case NetworkChangeNotifier::CONNECTION_ETHERNET: 469 case NetworkChangeNotifier::CONNECTION_ETHERNET:
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 921
894 return scoped_ptr<SocketPerformanceWatcher>( 922 return scoped_ptr<SocketPerformanceWatcher>(
895 new SocketPerformanceWatcher(protocol, this)); 923 new SocketPerformanceWatcher(protocol, this));
896 } 924 }
897 925
898 void NetworkQualityEstimator::OnUpdatedRTTAvailable( 926 void NetworkQualityEstimator::OnUpdatedRTTAvailable(
899 const Protocol protocol, 927 const Protocol protocol,
900 const base::TimeDelta& rtt) { 928 const base::TimeDelta& rtt) {
901 DCHECK(thread_checker_.CalledOnValidThread()); 929 DCHECK(thread_checker_.CalledOnValidThread());
902 930
903 switch (protocol) { 931 ObservationSource observation_source;
904 case PROTOCOL_TCP: 932 if (!GetObservationSourceForProtocol(protocol, &observation_source))
905 NotifyObserversOfRTT(RttObservation(rtt, base::TimeTicks::Now(), TCP)); 933 return;
906 return; 934
907 case PROTOCOL_QUIC: 935 NotifyObserversOfRTT(
908 NotifyObserversOfRTT(RttObservation(rtt, base::TimeTicks::Now(), QUIC)); 936 RttObservation(rtt, base::TimeTicks::Now(), observation_source));
909 return; 937 }
910 default: 938
911 NOTREACHED(); 939 void NetworkQualityEstimator::OnIncrementalPacketCountAvailable(
912 } 940 Protocol protocol,
941 size_t packets_missing,
942 size_t packets_received_in_order,
943 size_t packets_received_out_of_order) {
944 DCHECK(thread_checker_.CalledOnValidThread());
945
946 ObservationSource observation_source;
947 if (!GetObservationSourceForProtocol(protocol, &observation_source))
948 return;
949
950 // Consider it as a packet loss only if at least 3 packets are received after
951 // the missing packets.
952 // TODO(tbansal): Maintain a watcher specific buffer that keeps track of
953 // missing, and at most last N-1 in-order packets. If N (=3) packets with
954 // sequence number higher than the sequence number of a missing packet are
955 // received, then the missing packet should be marked as lost, and removed
956 // from the watcher specific buffer. If an out-of-order packet is received,
957 // then the state of the missing packet with lowest sequence number should be
958 // changed to received. This simple approach does not require going back in
959 // time, and changing the previously taken observations.
960 NotifyObserversOfIncrementalPacketCount(
961 packets_missing, packets_received_in_order, packets_received_out_of_order,
962 base::TimeTicks::Now(), observation_source);
913 } 963 }
914 964
915 void NetworkQualityEstimator::NotifyObserversOfRTT( 965 void NetworkQualityEstimator::NotifyObserversOfRTT(
916 const RttObservation& observation) { 966 const RttObservation& observation) {
967 DCHECK(thread_checker_.CalledOnValidThread());
968 DCHECK_NE(EXTERNAL_ESTIMATE, observation.source);
969
917 FOR_EACH_OBSERVER( 970 FOR_EACH_OBSERVER(
918 RTTObserver, rtt_observer_list_, 971 RTTObserver, rtt_observer_list_,
919 OnRTTObservation(observation.value.InMilliseconds(), 972 OnRTTObservation(observation.value.InMilliseconds(),
920 observation.timestamp, observation.source)); 973 observation.timestamp, observation.source));
921 } 974 }
922 975
923 void NetworkQualityEstimator::NotifyObserversOfThroughput( 976 void NetworkQualityEstimator::NotifyObserversOfThroughput(
924 const ThroughputObservation& observation) { 977 const ThroughputObservation& observation) {
978 DCHECK(thread_checker_.CalledOnValidThread());
979 DCHECK_NE(EXTERNAL_ESTIMATE, observation.source);
980
925 FOR_EACH_OBSERVER( 981 FOR_EACH_OBSERVER(
926 ThroughputObserver, throughput_observer_list_, 982 ThroughputObserver, throughput_observer_list_,
927 OnThroughputObservation(observation.value, observation.timestamp, 983 OnThroughputObservation(observation.value, observation.timestamp,
928 observation.source)); 984 observation.source));
929 } 985 }
930 986
987 void NetworkQualityEstimator::NotifyObserversOfIncrementalPacketCount(
988 size_t packets_missing,
989 size_t packets_received_in_order,
990 size_t packets_received_out_of_order,
991 const base::TimeTicks& timestamp,
992 ObservationSource source) {
993 DCHECK(thread_checker_.CalledOnValidThread());
994 DCHECK_NE(EXTERNAL_ESTIMATE, source);
995
996 FOR_EACH_OBSERVER(PacketCountObserver, packet_count_observer_list_,
997 OnIncrementalPacketCountObservation(
998 packets_missing, packets_received_in_order,
999 packets_received_out_of_order, timestamp, source));
1000 }
1001
931 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality( 1002 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality(
932 const NetworkQuality& network_quality) 1003 const NetworkQuality& network_quality)
933 : last_update_time_(base::TimeTicks::Now()), 1004 : last_update_time_(base::TimeTicks::Now()),
934 network_quality_(network_quality) { 1005 network_quality_(network_quality) {
935 } 1006 }
936 1007
937 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality( 1008 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality(
938 const CachedNetworkQuality& other) 1009 const CachedNetworkQuality& other)
939 : last_update_time_(other.last_update_time_), 1010 : last_update_time_(other.last_update_time_),
940 network_quality_(other.network_quality_) { 1011 network_quality_(other.network_quality_) {
(...skipping 27 matching lines...) Expand all
968 1039
969 NetworkQualityEstimator::NetworkQuality& 1040 NetworkQualityEstimator::NetworkQuality&
970 NetworkQualityEstimator::NetworkQuality:: 1041 NetworkQualityEstimator::NetworkQuality::
971 operator=(const NetworkQuality& other) { 1042 operator=(const NetworkQuality& other) {
972 rtt_ = other.rtt_; 1043 rtt_ = other.rtt_;
973 downstream_throughput_kbps_ = other.downstream_throughput_kbps_; 1044 downstream_throughput_kbps_ = other.downstream_throughput_kbps_;
974 return *this; 1045 return *this;
975 } 1046 }
976 1047
977 } // namespace net 1048 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698