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

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: Addressed rch comments 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 }
455 NOTREACHED();
456 return false;
457 }
458
432 void NetworkQualityEstimator::OnConnectionTypeChanged( 459 void NetworkQualityEstimator::OnConnectionTypeChanged(
433 NetworkChangeNotifier::ConnectionType type) { 460 NetworkChangeNotifier::ConnectionType type) {
434 DCHECK(thread_checker_.CalledOnValidThread()); 461 DCHECK(thread_checker_.CalledOnValidThread());
435 if (peak_network_quality_.rtt() != InvalidRTT()) { 462 if (peak_network_quality_.rtt() != InvalidRTT()) {
436 switch (current_network_id_.type) { 463 switch (current_network_id_.type) {
437 case NetworkChangeNotifier::CONNECTION_UNKNOWN: 464 case NetworkChangeNotifier::CONNECTION_UNKNOWN:
438 UMA_HISTOGRAM_TIMES("NQE.FastestRTT.Unknown", 465 UMA_HISTOGRAM_TIMES("NQE.FastestRTT.Unknown",
439 peak_network_quality_.rtt()); 466 peak_network_quality_.rtt());
440 break; 467 break;
441 case NetworkChangeNotifier::CONNECTION_ETHERNET: 468 case NetworkChangeNotifier::CONNECTION_ETHERNET:
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 920
894 return scoped_ptr<SocketPerformanceWatcher>( 921 return scoped_ptr<SocketPerformanceWatcher>(
895 new SocketPerformanceWatcher(protocol, this)); 922 new SocketPerformanceWatcher(protocol, this));
896 } 923 }
897 924
898 void NetworkQualityEstimator::OnUpdatedRTTAvailable( 925 void NetworkQualityEstimator::OnUpdatedRTTAvailable(
899 const Protocol protocol, 926 const Protocol protocol,
900 const base::TimeDelta& rtt) { 927 const base::TimeDelta& rtt) {
901 DCHECK(thread_checker_.CalledOnValidThread()); 928 DCHECK(thread_checker_.CalledOnValidThread());
902 929
903 switch (protocol) { 930 ObservationSource observation_source;
904 case PROTOCOL_TCP: 931 if (!GetObservationSourceForProtocol(protocol, &observation_source))
905 NotifyObserversOfRTT(RttObservation(rtt, base::TimeTicks::Now(), TCP)); 932 return;
906 return; 933
907 case PROTOCOL_QUIC: 934 NotifyObserversOfRTT(
908 NotifyObserversOfRTT(RttObservation(rtt, base::TimeTicks::Now(), QUIC)); 935 RttObservation(rtt, base::TimeTicks::Now(), observation_source));
909 return; 936 }
910 default: 937
911 NOTREACHED(); 938 void NetworkQualityEstimator::OnIncrementalPacketCountAvailable(
912 } 939 Protocol protocol,
940 size_t packets_missing,
941 size_t packets_received_in_order,
942 size_t packets_received_out_of_order) {
943 DCHECK(thread_checker_.CalledOnValidThread());
944
945 ObservationSource observation_source;
946 if (!GetObservationSourceForProtocol(protocol, &observation_source))
947 return;
948
949 // Consider it as a packet loss only if at least 3 packets are received after
950 // the missing packets.
951 // TODO(tbansal): Maintain a watcher specific buffer that keeps track of
952 // missing, and at most last N-1 in-order packets. If N (=3) packets with
953 // sequence number higher than the sequence number of a missing packet are
954 // received, then the missing packet should be marked as lost, and removed
955 // from the watcher specific buffer. If an out-of-order packet is received,
956 // then the state of the missing packet with lowest sequence number should be
957 // changed to received. This simple approach does not require going back in
958 // time, and changing the previously taken observations.
959 NotifyObserversOfIncrementalPacketCount(
960 packets_missing, packets_received_in_order, packets_received_out_of_order,
961 base::TimeTicks::Now(), observation_source);
913 } 962 }
914 963
915 void NetworkQualityEstimator::NotifyObserversOfRTT( 964 void NetworkQualityEstimator::NotifyObserversOfRTT(
916 const RttObservation& observation) { 965 const RttObservation& observation) {
966 DCHECK(thread_checker_.CalledOnValidThread());
967 DCHECK_NE(EXTERNAL_ESTIMATE, observation.source);
968
917 FOR_EACH_OBSERVER( 969 FOR_EACH_OBSERVER(
918 RTTObserver, rtt_observer_list_, 970 RTTObserver, rtt_observer_list_,
919 OnRTTObservation(observation.value.InMilliseconds(), 971 OnRTTObservation(observation.value.InMilliseconds(),
920 observation.timestamp, observation.source)); 972 observation.timestamp, observation.source));
921 } 973 }
922 974
923 void NetworkQualityEstimator::NotifyObserversOfThroughput( 975 void NetworkQualityEstimator::NotifyObserversOfThroughput(
924 const ThroughputObservation& observation) { 976 const ThroughputObservation& observation) {
977 DCHECK(thread_checker_.CalledOnValidThread());
978 DCHECK_NE(EXTERNAL_ESTIMATE, observation.source);
979
925 FOR_EACH_OBSERVER( 980 FOR_EACH_OBSERVER(
926 ThroughputObserver, throughput_observer_list_, 981 ThroughputObserver, throughput_observer_list_,
927 OnThroughputObservation(observation.value, observation.timestamp, 982 OnThroughputObservation(observation.value, observation.timestamp,
928 observation.source)); 983 observation.source));
929 } 984 }
930 985
986 void NetworkQualityEstimator::NotifyObserversOfIncrementalPacketCount(
987 size_t packets_missing,
988 size_t packets_received_in_order,
989 size_t packets_received_out_of_order,
990 const base::TimeTicks& timestamp,
991 ObservationSource source) {
992 DCHECK(thread_checker_.CalledOnValidThread());
993 DCHECK_NE(EXTERNAL_ESTIMATE, source);
994
995 FOR_EACH_OBSERVER(PacketCountObserver, packet_count_observer_list_,
996 OnIncrementalPacketCountObservation(
997 packets_missing, packets_received_in_order,
998 packets_received_out_of_order, timestamp, source));
999 }
1000
931 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality( 1001 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality(
932 const NetworkQuality& network_quality) 1002 const NetworkQuality& network_quality)
933 : last_update_time_(base::TimeTicks::Now()), 1003 : last_update_time_(base::TimeTicks::Now()),
934 network_quality_(network_quality) { 1004 network_quality_(network_quality) {
935 } 1005 }
936 1006
937 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality( 1007 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality(
938 const CachedNetworkQuality& other) 1008 const CachedNetworkQuality& other)
939 : last_update_time_(other.last_update_time_), 1009 : last_update_time_(other.last_update_time_),
940 network_quality_(other.network_quality_) { 1010 network_quality_(other.network_quality_) {
(...skipping 27 matching lines...) Expand all
968 1038
969 NetworkQualityEstimator::NetworkQuality& 1039 NetworkQualityEstimator::NetworkQuality&
970 NetworkQualityEstimator::NetworkQuality:: 1040 NetworkQualityEstimator::NetworkQuality::
971 operator=(const NetworkQuality& other) { 1041 operator=(const NetworkQuality& other) {
972 rtt_ = other.rtt_; 1042 rtt_ = other.rtt_;
973 downstream_throughput_kbps_ = other.downstream_throughput_kbps_; 1043 downstream_throughput_kbps_ = other.downstream_throughput_kbps_;
974 return *this; 1044 return *this;
975 } 1045 }
976 1046
977 } // namespace net 1047 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698