OLD | NEW |
---|---|
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> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/metrics/histogram_base.h" | 16 #include "base/metrics/histogram_base.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/thread_task_runner_handle.h" | |
Ryan Sleevi
2016/03/25 01:45:34
It seems like a bug that you removed this, given l
| |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
20 #include "net/base/load_timing_info.h" | 21 #include "net/base/load_timing_info.h" |
21 #include "net/base/network_interfaces.h" | 22 #include "net/base/network_interfaces.h" |
22 #include "net/base/url_util.h" | 23 #include "net/base/url_util.h" |
23 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
25 | 26 |
26 #if defined(OS_ANDROID) | 27 #if defined(OS_ANDROID) |
27 #include "net/android/network_library.h" | 28 #include "net/android/network_library.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 bool allow_smaller_responses_for_tests) | 135 bool allow_smaller_responses_for_tests) |
135 : allow_localhost_requests_(allow_local_host_requests_for_tests), | 136 : allow_localhost_requests_(allow_local_host_requests_for_tests), |
136 allow_small_responses_(allow_smaller_responses_for_tests), | 137 allow_small_responses_(allow_smaller_responses_for_tests), |
137 last_connection_change_(base::TimeTicks::Now()), | 138 last_connection_change_(base::TimeTicks::Now()), |
138 current_network_id_( | 139 current_network_id_( |
139 NetworkID(NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, | 140 NetworkID(NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, |
140 std::string())), | 141 std::string())), |
141 downstream_throughput_kbps_observations_( | 142 downstream_throughput_kbps_observations_( |
142 GetWeightMultiplierPerSecond(variation_params)), | 143 GetWeightMultiplierPerSecond(variation_params)), |
143 rtt_msec_observations_(GetWeightMultiplierPerSecond(variation_params)), | 144 rtt_msec_observations_(GetWeightMultiplierPerSecond(variation_params)), |
144 external_estimate_provider_(std::move(external_estimates_provider)) { | 145 external_estimate_provider_(std::move(external_estimates_provider)), |
146 weak_ptr_factory_(this) { | |
145 static_assert(kMinRequestDurationMicroseconds > 0, | 147 static_assert(kMinRequestDurationMicroseconds > 0, |
146 "Minimum request duration must be > 0"); | 148 "Minimum request duration must be > 0"); |
147 static_assert(kDefaultHalfLifeSeconds > 0, | 149 static_assert(kDefaultHalfLifeSeconds > 0, |
148 "Default half life duration must be > 0"); | 150 "Default half life duration must be > 0"); |
149 static_assert(kMaximumNetworkQualityCacheSize > 0, | 151 static_assert(kMaximumNetworkQualityCacheSize > 0, |
150 "Size of the network quality cache must be > 0"); | 152 "Size of the network quality cache must be > 0"); |
151 // This limit should not be increased unless the logic for removing the | 153 // This limit should not be increased unless the logic for removing the |
152 // oldest cache entry is rewritten to use a doubly-linked-list LRU queue. | 154 // oldest cache entry is rewritten to use a doubly-linked-list LRU queue. |
153 static_assert(kMaximumNetworkQualityCacheSize <= 10, | 155 static_assert(kMaximumNetworkQualityCacheSize <= 10, |
154 "Size of the network quality cache must <= 10"); | 156 "Size of the network quality cache must <= 10"); |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
884 current_network_id_, CachedNetworkQuality(network_quality))); | 886 current_network_id_, CachedNetworkQuality(network_quality))); |
885 DCHECK_LE(cached_network_qualities_.size(), | 887 DCHECK_LE(cached_network_qualities_.size(), |
886 static_cast<size_t>(kMaximumNetworkQualityCacheSize)); | 888 static_cast<size_t>(kMaximumNetworkQualityCacheSize)); |
887 } | 889 } |
888 | 890 |
889 scoped_ptr<SocketPerformanceWatcher> | 891 scoped_ptr<SocketPerformanceWatcher> |
890 NetworkQualityEstimator::CreateSocketPerformanceWatcher( | 892 NetworkQualityEstimator::CreateSocketPerformanceWatcher( |
891 const Protocol protocol) { | 893 const Protocol protocol) { |
892 DCHECK(thread_checker_.CalledOnValidThread()); | 894 DCHECK(thread_checker_.CalledOnValidThread()); |
893 | 895 |
894 return scoped_ptr<SocketPerformanceWatcher>( | 896 return scoped_ptr<SocketPerformanceWatcher>(new SocketPerformanceWatcher( |
895 new SocketPerformanceWatcher(protocol, this)); | 897 protocol, GetWeakPtr(), base::ThreadTaskRunnerHandle::Get())); |
896 } | 898 } |
897 | 899 |
898 void NetworkQualityEstimator::OnUpdatedRTTAvailable( | 900 void NetworkQualityEstimator::OnUpdatedRTTAvailable( |
899 const Protocol protocol, | 901 const Protocol protocol, |
900 const base::TimeDelta& rtt) { | 902 const base::TimeDelta& rtt) { |
901 DCHECK(thread_checker_.CalledOnValidThread()); | 903 DCHECK(thread_checker_.CalledOnValidThread()); |
902 | 904 |
903 switch (protocol) { | 905 switch (protocol) { |
904 case PROTOCOL_TCP: | 906 case PROTOCOL_TCP: |
905 NotifyObserversOfRTT(RttObservation(rtt, base::TimeTicks::Now(), TCP)); | 907 NotifyObserversOfRTT(RttObservation(rtt, base::TimeTicks::Now(), TCP)); |
906 return; | 908 return; |
907 case PROTOCOL_QUIC: | 909 case PROTOCOL_QUIC: |
908 NotifyObserversOfRTT(RttObservation(rtt, base::TimeTicks::Now(), QUIC)); | 910 NotifyObserversOfRTT(RttObservation(rtt, base::TimeTicks::Now(), QUIC)); |
909 return; | 911 return; |
910 default: | 912 default: |
911 NOTREACHED(); | 913 NOTREACHED(); |
912 } | 914 } |
913 } | 915 } |
914 | 916 |
917 void NetworkQualityEstimator::OnWatcherReset() { | |
918 DCHECK(thread_checker_.CalledOnValidThread()); | |
919 // Nothing needs to be done for RTT observations since NetworkQualityEstimator | |
920 // does not maintain any watcher-specific state. | |
921 } | |
922 | |
915 void NetworkQualityEstimator::NotifyObserversOfRTT( | 923 void NetworkQualityEstimator::NotifyObserversOfRTT( |
916 const RttObservation& observation) { | 924 const RttObservation& observation) { |
917 FOR_EACH_OBSERVER( | 925 FOR_EACH_OBSERVER( |
918 RTTObserver, rtt_observer_list_, | 926 RTTObserver, rtt_observer_list_, |
919 OnRTTObservation(observation.value.InMilliseconds(), | 927 OnRTTObservation(observation.value.InMilliseconds(), |
920 observation.timestamp, observation.source)); | 928 observation.timestamp, observation.source)); |
921 } | 929 } |
922 | 930 |
923 void NetworkQualityEstimator::NotifyObserversOfThroughput( | 931 void NetworkQualityEstimator::NotifyObserversOfThroughput( |
924 const ThroughputObservation& observation) { | 932 const ThroughputObservation& observation) { |
925 FOR_EACH_OBSERVER( | 933 FOR_EACH_OBSERVER( |
926 ThroughputObserver, throughput_observer_list_, | 934 ThroughputObserver, throughput_observer_list_, |
927 OnThroughputObservation(observation.value, observation.timestamp, | 935 OnThroughputObservation(observation.value, observation.timestamp, |
928 observation.source)); | 936 observation.source)); |
929 } | 937 } |
930 | 938 |
939 base::WeakPtr<NetworkQualityEstimator> NetworkQualityEstimator::GetWeakPtr() { | |
940 DCHECK(thread_checker_.CalledOnValidThread()); | |
941 | |
942 return weak_ptr_factory_.GetWeakPtr(); | |
943 } | |
944 | |
931 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality( | 945 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality( |
932 const NetworkQuality& network_quality) | 946 const NetworkQuality& network_quality) |
933 : last_update_time_(base::TimeTicks::Now()), | 947 : last_update_time_(base::TimeTicks::Now()), |
934 network_quality_(network_quality) { | 948 network_quality_(network_quality) { |
935 } | 949 } |
936 | 950 |
937 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality( | 951 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality( |
938 const CachedNetworkQuality& other) | 952 const CachedNetworkQuality& other) |
939 : last_update_time_(other.last_update_time_), | 953 : last_update_time_(other.last_update_time_), |
940 network_quality_(other.network_quality_) { | 954 network_quality_(other.network_quality_) { |
(...skipping 27 matching lines...) Expand all Loading... | |
968 | 982 |
969 NetworkQualityEstimator::NetworkQuality& | 983 NetworkQualityEstimator::NetworkQuality& |
970 NetworkQualityEstimator::NetworkQuality:: | 984 NetworkQualityEstimator::NetworkQuality:: |
971 operator=(const NetworkQuality& other) { | 985 operator=(const NetworkQuality& other) { |
972 rtt_ = other.rtt_; | 986 rtt_ = other.rtt_; |
973 downstream_throughput_kbps_ = other.downstream_throughput_kbps_; | 987 downstream_throughput_kbps_ = other.downstream_throughput_kbps_; |
974 return *this; | 988 return *this; |
975 } | 989 } |
976 | 990 |
977 } // namespace net | 991 } // namespace net |
OLD | NEW |