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

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

Issue 1672513002: Expose packet loss counts from QUIC to NetworkQualityEstimator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed bengr comments, Rebased 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 #ifndef NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ 5 #ifndef NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_
6 #define NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ 6 #define NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <deque> 11 #include <deque>
12 #include <map> 12 #include <map>
13 #include <string> 13 #include <string>
14 #include <tuple> 14 #include <tuple>
15 15
16 #include "base/compiler_specific.h"
16 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
17 #include "base/macros.h" 18 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
20 #include "base/observer_list.h" 21 #include "base/observer_list.h"
21 #include "base/threading/thread_checker.h" 22 #include "base/threading/thread_checker.h"
22 #include "base/time/time.h" 23 #include "base/time/time.h"
23 #include "net/base/external_estimate_provider.h" 24 #include "net/base/external_estimate_provider.h"
24 #include "net/base/net_export.h" 25 #include "net/base/net_export.h"
25 #include "net/base/network_change_notifier.h" 26 #include "net/base/network_change_notifier.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // by the platform. For example, typical RTT and throughput values are used 63 // by the platform. For example, typical RTT and throughput values are used
63 // for a given type of network connection. 64 // for a given type of network connection.
64 DEFAULT_FROM_PLATFORM, 65 DEFAULT_FROM_PLATFORM,
65 // The observation came from a Chromium-external source. 66 // The observation came from a Chromium-external source.
66 EXTERNAL_ESTIMATE 67 EXTERNAL_ESTIMATE
67 }; 68 };
68 69
69 // Observes measurements of round trip time. 70 // Observes measurements of round trip time.
70 class NET_EXPORT_PRIVATE RTTObserver { 71 class NET_EXPORT_PRIVATE RTTObserver {
71 public: 72 public:
72 // Will be called when a new RTT observation is available. The round trip 73 // OnRTTObservation will be called when a new RTT observation is available.
73 // time is specified in milliseconds. The time when the observation was 74 // The round trip time is specified in milliseconds. The time when the
74 // taken and the source of the observation are provided. 75 // observation was taken and the source of the observation are provided.
75 virtual void OnRTTObservation(int32_t rtt_ms, 76 virtual void OnRTTObservation(int32_t rtt_ms,
76 const base::TimeTicks& timestamp, 77 const base::TimeTicks& timestamp,
77 ObservationSource source) = 0; 78 ObservationSource source) = 0;
78 79
79 protected: 80 protected:
80 RTTObserver() {} 81 RTTObserver() {}
81 virtual ~RTTObserver() {} 82 virtual ~RTTObserver() {}
82 83
83 private: 84 private:
84 DISALLOW_COPY_AND_ASSIGN(RTTObserver); 85 DISALLOW_COPY_AND_ASSIGN(RTTObserver);
85 }; 86 };
86 87
87 // Observes measurements of throughput. 88 // Observes measurements of throughput.
88 class NET_EXPORT_PRIVATE ThroughputObserver { 89 class NET_EXPORT_PRIVATE ThroughputObserver {
89 public: 90 public:
90 // Will be called when a new throughput observation is available. 91 // Will be called when a new throughput observation is available.
91 // Throughput is specified in kilobits per second. 92 // Throughput is specified in kilobits per second.
92 virtual void OnThroughputObservation(int32_t throughput_kbps, 93 virtual void OnThroughputObservation(int32_t throughput_kbps,
93 const base::TimeTicks& timestamp, 94 const base::TimeTicks& timestamp,
94 ObservationSource source) = 0; 95 ObservationSource source) = 0;
95 96
96 protected: 97 protected:
97 ThroughputObserver() {} 98 ThroughputObserver() {}
98 virtual ~ThroughputObserver() {} 99 virtual ~ThroughputObserver() {}
99 100
100 private: 101 private:
101 DISALLOW_COPY_AND_ASSIGN(ThroughputObserver); 102 DISALLOW_COPY_AND_ASSIGN(ThroughputObserver);
102 }; 103 };
103 104
105 // Observes measurements of packet loss.
106 class NET_EXPORT_PRIVATE PacketLossObserver {
107 public:
108 // OnPacketLossObservation will be called when a new packet loss
109 // observation is available. |packets_lost| is the number of packets
110 // lost. |packets_received_in_order| is the number of packets received
111 // in order. |packets_received_out_of_order| is the number of packets
112 // received out of order.
113
114 // An example:
115 // Last observation after packet #1. Packets #5 and #6 are received:
116 // lost = 3, in_order = 2, out_of_order = 0.
117
118 // Last observation after packet #6. Packet #3 received:
119 // lost = 0, in_order = 0, out_of_order = 1.
120 virtual void OnPacketLossObservation(size_t packets_lost,
121 size_t packets_received_in_order,
122 size_t packets_received_out_of_order,
123 const base::TimeTicks& timestamp,
124 ObservationSource source) = 0;
125
126 protected:
127 PacketLossObserver() {}
128 virtual ~PacketLossObserver() {}
129
130 private:
131 DISALLOW_COPY_AND_ASSIGN(PacketLossObserver);
132 };
133
104 // Creates a new NetworkQualityEstimator. 134 // Creates a new NetworkQualityEstimator.
105 // |variation_params| is the map containing all field trial parameters 135 // |variation_params| is the map containing all field trial parameters
106 // related to NetworkQualityEstimator field trial. 136 // related to NetworkQualityEstimator field trial.
107 // |external_estimates_provider| may be NULL. 137 // |external_estimates_provider| may be NULL.
108 NetworkQualityEstimator( 138 NetworkQualityEstimator(
109 scoped_ptr<ExternalEstimateProvider> external_estimates_provider, 139 scoped_ptr<ExternalEstimateProvider> external_estimates_provider,
110 const std::map<std::string, std::string>& variation_params); 140 const std::map<std::string, std::string>& variation_params);
111 141
112 // Construct a NetworkQualityEstimator instance allowing for test 142 // Construct a NetworkQualityEstimator instance allowing for test
113 // configuration. Registers for network type change notifications so estimates 143 // configuration. Registers for network type change notifications so estimates
(...skipping 10 matching lines...) Expand all
124 // estimation. 154 // estimation.
125 NetworkQualityEstimator( 155 NetworkQualityEstimator(
126 scoped_ptr<ExternalEstimateProvider> external_estimates_provider, 156 scoped_ptr<ExternalEstimateProvider> external_estimates_provider,
127 const std::map<std::string, std::string>& variation_params, 157 const std::map<std::string, std::string>& variation_params,
128 bool allow_local_host_requests_for_tests, 158 bool allow_local_host_requests_for_tests,
129 bool allow_smaller_responses_for_tests); 159 bool allow_smaller_responses_for_tests);
130 160
131 ~NetworkQualityEstimator() override; 161 ~NetworkQualityEstimator() override;
132 162
133 // Returns true if RTT is available and sets |rtt| to estimated RTT. 163 // Returns true if RTT is available and sets |rtt| to estimated RTT.
134 // Virtualized for testing. |rtt| should not be null. 164 // Virtualized for testing. |rtt| must not be null.
135 virtual bool GetRTTEstimate(base::TimeDelta* rtt) const; 165 virtual bool GetRTTEstimate(base::TimeDelta* rtt) const WARN_UNUSED_RESULT;
136 166
137 // Returns true if downlink throughput is available and sets |kbps| to 167 // Returns true if downlink throughput is available and sets |kbps| to
138 // estimated downlink throughput (in kilobits per second). 168 // estimated downlink throughput (in kilobits per second).
139 // Virtualized for testing. |kbps| should not be null. 169 // Virtualized for testing. |kbps| must not be null.
140 virtual bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps) const; 170 virtual bool GetDownlinkThroughputKbpsEstimate(int32_t* kbps) const
171 WARN_UNUSED_RESULT;
172
173 // Returns true if the estimated packet loss rate is available and sets
174 // |packet_loss_rate_estimate| to the estimated packet loss rate. Virtualized
175 // for testing. |packet_loss_rate_estimate| must not be NULL.
176 // |packet_loss_rate_estimate| is always between 0.0 and 1.0 (both inclusive)
177 // with a higher value indicating higher packet loss rate.
178 virtual bool GetPacketLossRateEstimate(float* packet_loss_rate_estimate) const
179 WARN_UNUSED_RESULT;
141 180
142 // Notifies NetworkQualityEstimator that the response header of |request| has 181 // Notifies NetworkQualityEstimator that the response header of |request| has
143 // been received. 182 // been received.
144 void NotifyHeadersReceived(const URLRequest& request); 183 void NotifyHeadersReceived(const URLRequest& request);
145 184
146 // Notifies NetworkQualityEstimator that the response body of |request| has 185 // Notifies NetworkQualityEstimator that the response body of |request| has
147 // been received. 186 // been received.
148 void NotifyRequestCompleted(const URLRequest& request); 187 void NotifyRequestCompleted(const URLRequest& request);
149 188
150 // Returns true if median RTT is available and sets |rtt| to the median of 189 // Returns true if median RTT is available and sets |rtt| to the median of
151 // RTT observations since |begin_timestamp|. 190 // RTT observations since |begin_timestamp|.
152 // Virtualized for testing. |rtt| should not be null. 191 // Virtualized for testing. |rtt| must not be null.
153 virtual bool GetRecentMedianRTT(const base::TimeTicks& begin_timestamp, 192 virtual bool GetRecentMedianRTT(const base::TimeTicks& begin_timestamp,
154 base::TimeDelta* rtt) const; 193 base::TimeDelta* rtt) const
194 WARN_UNUSED_RESULT;
155 195
156 // Returns true if median downstream throughput is available and sets |kbps| 196 // Returns true if median downstream throughput is available and sets |kbps|
157 // to the median of downstream throughput (in kilobits per second) 197 // to the median of downstream throughput (in kilobits per second)
158 // observations since |begin_timestamp|. Virtualized for testing. |kbps| 198 // observations since |begin_timestamp|. Virtualized for testing. |kbps|
159 // should not be null. 199 // must not be null.
160 virtual bool GetRecentMedianDownlinkThroughputKbps( 200 virtual bool GetRecentMedianDownlinkThroughputKbps(
161 const base::TimeTicks& begin_timestamp, 201 const base::TimeTicks& begin_timestamp,
162 int32_t* kbps) const; 202 int32_t* kbps) const WARN_UNUSED_RESULT;
163 203
164 // SocketPerformanceWatcherFactory implementation: 204 // SocketPerformanceWatcherFactory implementation:
165 scoped_ptr<SocketPerformanceWatcher> CreateSocketPerformanceWatcher( 205 scoped_ptr<SocketPerformanceWatcher> CreateSocketPerformanceWatcher(
166 const Protocol protocol) override; 206 const Protocol protocol) override;
167 void OnUpdatedRTTAvailable(const Protocol protocol, 207 void OnUpdatedRTTAvailable(const Protocol protocol,
168 const base::TimeDelta& rtt) override; 208 const base::TimeDelta& rtt) override;
209 void OnUpdatedPacketCountAvailable(
210 Protocol protocol,
211 size_t packets_lost,
212 size_t packets_received_in_order,
213 size_t packets_received_out_of_order) override;
169 214
170 // Adds |rtt_observer| to the list of round trip time observers. Must be 215 // Adds |rtt_observer| to the list of round trip time observers. Must be
171 // called on the IO thread. 216 // called on the IO thread.
172 void AddRTTObserver(RTTObserver* rtt_observer); 217 void AddRTTObserver(RTTObserver* rtt_observer);
173 218
174 // Removes |rtt_observer| from the list of round trip time observers if it 219 // Removes |rtt_observer| from the list of round trip time observers if it
175 // is on the list of observers. Must be called on the IO thread. 220 // is on the list of observers. Must be called on the IO thread.
176 void RemoveRTTObserver(RTTObserver* rtt_observer); 221 void RemoveRTTObserver(RTTObserver* rtt_observer);
177 222
178 // Adds |throughput_observer| to the list of throughput observers. Must be 223 // Adds |throughput_observer| to the list of throughput observers. Must be
179 // called on the IO thread. 224 // called on the IO thread.
180 void AddThroughputObserver(ThroughputObserver* throughput_observer); 225 void AddThroughputObserver(ThroughputObserver* throughput_observer);
181 226
182 // Removes |throughput_observer| from the list of throughput observers if it 227 // Removes |throughput_observer| from the list of throughput observers if it
183 // is on the list of observers. Must be called on the IO thread. 228 // is on the list of observers. Must be called on the IO thread.
184 void RemoveThroughputObserver(ThroughputObserver* throughput_observer); 229 void RemoveThroughputObserver(ThroughputObserver* throughput_observer);
185 230
231 // Adds |packet_loss_observer| to the list of packet loss observers. Must be
232 // called on the IO thread.
233 void AddPacketLossObserver(PacketLossObserver* packet_loss_observer);
234
235 // Removes |packet_loss_observer| from the list of packet loss observers if it
236 // is on the list of observers. Must be called on the IO thread.
237 void RemovePacketLossObserver(PacketLossObserver* packet_loss_observer);
238
186 protected: 239 protected:
187 // NetworkID is used to uniquely identify a network. 240 // NetworkID is used to uniquely identify a network.
188 // For the purpose of network quality estimation and caching, a network is 241 // For the purpose of network quality estimation and caching, a network is
189 // uniquely identified by a combination of |type| and 242 // uniquely identified by a combination of |type| and
190 // |id|. This approach is unable to distinguish networks with 243 // |id|. This approach is unable to distinguish networks with
191 // same name (e.g., different Wi-Fi networks with same SSID). 244 // same name (e.g., different Wi-Fi networks with same SSID).
192 // This is a protected member to expose it to tests. 245 // This is a protected member to expose it to tests.
193 struct NET_EXPORT_PRIVATE NetworkID { 246 struct NET_EXPORT_PRIVATE NetworkID {
194 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id) 247 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id)
195 : type(type), id(id) {} 248 : type(type), id(id) {}
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 // NetworkChangeNotifier::ConnectionTypeObserver implementation: 280 // NetworkChangeNotifier::ConnectionTypeObserver implementation:
228 void OnConnectionTypeChanged( 281 void OnConnectionTypeChanged(
229 NetworkChangeNotifier::ConnectionType type) override; 282 NetworkChangeNotifier::ConnectionType type) override;
230 283
231 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. 284 // ExternalEstimateProvider::UpdatedEstimateObserver implementation.
232 void OnUpdatedEstimateAvailable() override; 285 void OnUpdatedEstimateAvailable() override;
233 286
234 private: 287 private:
235 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); 288 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations);
236 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestKbpsRTTUpdates); 289 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestKbpsRTTUpdates);
290 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
291 TestPacketLossRateUpdates);
237 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); 292 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation);
238 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); 293 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams);
239 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); 294 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam);
240 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); 295 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator);
241 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, 296 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
242 PercentileSameTimestamps); 297 PercentileSameTimestamps);
243 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, 298 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
244 PercentileDifferentTimestamps); 299 PercentileDifferentTimestamps);
245 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); 300 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles);
246 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); 301 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 } 437 }
383 438
384 // Returns the number of observations in this buffer. 439 // Returns the number of observations in this buffer.
385 size_t Size() const { return observations_.size(); } 440 size_t Size() const { return observations_.size(); }
386 441
387 // Clears the observations stored in this buffer. 442 // Clears the observations stored in this buffer.
388 void Clear() { observations_.clear(); } 443 void Clear() { observations_.clear(); }
389 444
390 // Returns true iff the |percentile| value of the observations in this 445 // Returns true iff the |percentile| value of the observations in this
391 // buffer is available. Sets |result| to the computed |percentile| 446 // buffer is available. Sets |result| to the computed |percentile|
392 // value among all observations since |begin_timestamp|. If the value is 447 // value among all observations since |begin_timestamp| (inclusive). If the
393 // unavailable, false is returned and |result| is not modified. Percentile 448 // value is unavailable, false is returned and |result| is not modified.
394 // value is unavailable if all the values in observation buffer are older 449 // Percentile value is unavailable if all the values in observation buffer
395 // than |begin_timestamp|. 450 // are older than |begin_timestamp|. |result| must not be null.
396 // |result| must not be null.
397 bool GetPercentile(const base::TimeTicks& begin_timestamp, 451 bool GetPercentile(const base::TimeTicks& begin_timestamp,
398 ValueType* result, 452 ValueType* result,
399 int percentile) const; 453 int percentile) const;
400 454
455 // Returns true iff the weighted average value of the observations in this
456 // buffer is available. Sets |result| to the computed average
457 // value of all observations since |begin_timestamp| (inclusive). If the
458 // value is unavailable, false is returned and |result| is not modified.
459 // The average value is unavailable if all of the values in the observation
460 // buffer are older than |begin_timestamp|. |result| must not be NULL.
461 bool GetWeightedAverage(const base::TimeTicks& begin_timestamp,
462 ValueType* result) const WARN_UNUSED_RESULT;
463
401 private: 464 private:
402 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); 465 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations);
403 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, 466 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
404 ObtainOperatingParams); 467 ObtainOperatingParams);
405 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); 468 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam);
406 469
407 // Computes the weighted observations and stores them in 470 // Computes the weighted observations and stores them in
408 // |weighted_observations| sorted by ascending |WeightedObservation.value|. 471 // |weighted_observations| sorted by ascending |WeightedObservation.value|.
409 // Only the observations with timestamp later than |begin_timestamp| are 472 // Only the observations with timestamp later than |begin_timestamp| are
410 // considered. Also, sets |total_weight| to the total weight of all 473 // considered. Also, sets |total_weight| to the total weight of all
(...skipping 23 matching lines...) Expand all
434 RttObservation; 497 RttObservation;
435 typedef net::NetworkQualityEstimator::ObservationBuffer<base::TimeDelta> 498 typedef net::NetworkQualityEstimator::ObservationBuffer<base::TimeDelta>
436 RttObservationBuffer; 499 RttObservationBuffer;
437 500
438 // Value of throughput observations is in kilobits per second. 501 // Value of throughput observations is in kilobits per second.
439 typedef net::NetworkQualityEstimator::Observation<int32_t> 502 typedef net::NetworkQualityEstimator::Observation<int32_t>
440 ThroughputObservation; 503 ThroughputObservation;
441 typedef net::NetworkQualityEstimator::ObservationBuffer<int32_t> 504 typedef net::NetworkQualityEstimator::ObservationBuffer<int32_t>
442 ThroughputObservationBuffer; 505 ThroughputObservationBuffer;
443 506
507 // Value of a packet loss observation. A value of 0.0 indicates all packets
508 // during the observation period were received successfully in-order, while a
509 // value of 1.0 indicates all packets during the observation period were
510 // lost. Currently, the observation period is set to one packet.
511 typedef net::NetworkQualityEstimator::Observation<float>
512 PacketLossRateObservation;
513 typedef net::NetworkQualityEstimator::ObservationBuffer<float>
514 PacketLossRateObservationBuffer;
515
444 // This does not use a unordered_map or hash_map for code simplicity (key just 516 // This does not use a unordered_map or hash_map for code simplicity (key just
445 // implements operator<, rather than hash and equality) and because the map is 517 // implements operator<, rather than hash and equality) and because the map is
446 // tiny. 518 // tiny.
447 typedef std::map<NetworkID, CachedNetworkQuality> CachedNetworkQualities; 519 typedef std::map<NetworkID, CachedNetworkQuality> CachedNetworkQualities;
448 520
449 // Throughput is set to |kInvalidThroughput| if a valid value is 521 // Throughput is set to |kInvalidThroughput| if a valid value is
450 // unavailable. Readers should discard throughput value if it is set to 522 // unavailable. Readers should discard throughput value if it is set to
451 // |kInvalidThroughput|. 523 // |kInvalidThroughput|.
452 static const int32_t kInvalidThroughput; 524 static const int32_t kInvalidThroughput;
453 525
526 // Packet loss rate is set to a value strictly lower than
527 // |kMinimumValidPacketLossRate| if a valid value is unavailable. Readers
528 // should discard the packet loss rate value if it is set to a value strictly
529 // lower than |kMinimumValidPacketLossRate|.
530 static const float kMinimumValidPacketLossRate;
531
454 // Tiny transfer sizes may give inaccurate throughput results. 532 // Tiny transfer sizes may give inaccurate throughput results.
455 // Minimum size of the transfer over which the throughput is computed. 533 // Minimum size of the transfer over which the throughput is computed.
456 static const int kMinTransferSizeInBytes = 10000; 534 static const int kMinTransferSizeInBytes = 10000;
457 535
458 // Minimum duration (in microseconds) of the transfer over which the 536 // Minimum duration (in microseconds) of the transfer over which the
459 // throughput is computed. 537 // throughput is computed.
460 static const int kMinRequestDurationMicroseconds = 1000; 538 static const int kMinRequestDurationMicroseconds = 1000;
461 539
462 // Minimum valid value of the variation parameter that holds RTT (in 540 // Minimum valid value of the variation parameter that holds RTT (in
463 // milliseconds) values. 541 // milliseconds) values.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 void AddDefaultEstimates(); 575 void AddDefaultEstimates();
498 576
499 // Returns an estimate of network quality at the specified |percentile|. 577 // Returns an estimate of network quality at the specified |percentile|.
500 // Only the observations later than |begin_timestamp| are taken into account. 578 // Only the observations later than |begin_timestamp| are taken into account.
501 // |percentile| must be between 0 and 100 (both inclusive) with higher 579 // |percentile| must be between 0 and 100 (both inclusive) with higher
502 // percentiles indicating less performant networks. For example, if 580 // percentiles indicating less performant networks. For example, if
503 // |percentile| is 90, then the network is expected to be faster than the 581 // |percentile| is 90, then the network is expected to be faster than the
504 // returned estimate with 0.9 probability. Similarly, network is expected to 582 // returned estimate with 0.9 probability. Similarly, network is expected to
505 // be slower than the returned estimate with 0.1 probability. 583 // be slower than the returned estimate with 0.1 probability.
506 base::TimeDelta GetRTTEstimateInternal(const base::TimeTicks& begin_timestamp, 584 base::TimeDelta GetRTTEstimateInternal(const base::TimeTicks& begin_timestamp,
507 int percentile) const; 585 int percentile) const
586 WARN_UNUSED_RESULT;
508 int32_t GetDownlinkThroughputKbpsEstimateInternal( 587 int32_t GetDownlinkThroughputKbpsEstimateInternal(
509 const base::TimeTicks& begin_timestamp, 588 const base::TimeTicks& begin_timestamp,
510 int percentile) const; 589 int percentile) const WARN_UNUSED_RESULT;
590
591 // Returns an estimate of the packet loss rate. Only the observations later
592 // than |begin_timestamp| are taken into account.
593 float GetPacketLossRateEstimateInternal(
594 const base::TimeTicks& begin_timestamp) const WARN_UNUSED_RESULT;
511 595
512 // Returns the current network ID checking by calling the platform APIs. 596 // Returns the current network ID checking by calling the platform APIs.
513 // Virtualized for testing. 597 // Virtualized for testing.
514 virtual NetworkID GetCurrentNetworkID() const; 598 virtual NetworkID GetCurrentNetworkID() const;
515 599
516 // Writes the estimated quality of the current network to the cache. 600 // Writes the estimated quality of the current network to the cache.
517 void CacheNetworkQualityEstimate(); 601 void CacheNetworkQualityEstimate();
518 602
519 void NotifyObserversOfRTT(const RttObservation& observation); 603 void NotifyObserversOfRTT(const RttObservation& observation);
520 604
521 void NotifyObserversOfThroughput(const ThroughputObservation& observation); 605 void NotifyObserversOfThroughput(const ThroughputObservation& observation);
522 606
607 void NotifyObserversOfPacketLoss(size_t packets_lost,
608 size_t packets_received_in_order,
609 size_t packets_received_out_of_order,
610 const base::TimeTicks& timestamp,
611 ObservationSource source);
612
523 // Records the UMA related to RTT. 613 // Records the UMA related to RTT.
524 void RecordRTTUMA(int32_t estimated_value_msec, 614 void RecordRTTUMA(int32_t estimated_value_msec,
525 int32_t actual_value_msec) const; 615 int32_t actual_value_msec) const;
526 616
527 // Returns true only if |request| can be used for network quality estimation. 617 // Returns true only if |request| can be used for network quality estimation.
528 // Only the requests that go over network are considered to provide useful 618 // Only the requests that go over network are considered to provide useful
529 // observations. 619 // observations.
530 bool RequestProvidesUsefulObservations(const URLRequest& request) const; 620 bool RequestProvidesUsefulObservations(const URLRequest& request) const;
531 621
532 // Values of external estimate provider status. This enum must remain 622 // Values of external estimate provider status. This enum must remain
533 // synchronized with the enum of the same name in 623 // synchronized with the enum of the same name in
534 // metrics/histograms/histograms.xml. 624 // metrics/histograms/histograms.xml.
535 enum NQEExternalEstimateProviderStatus { 625 enum NQEExternalEstimateProviderStatus {
536 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, 626 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE,
537 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, 627 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE,
538 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, 628 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED,
539 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, 629 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL,
540 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, 630 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK,
541 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY 631 EXTERNAL_ESTIMATE_PROVIDER_STATUS_BOUNDARY
542 }; 632 };
543 633
544 // Records the metrics related to external estimate provider. 634 // Records the metrics related to external estimate provider.
545 void RecordExternalEstimateProviderMetrics( 635 void RecordExternalEstimateProviderMetrics(
546 NQEExternalEstimateProviderStatus status) const; 636 NQEExternalEstimateProviderStatus status) const;
547 637
638 // Gets the ObservationSource that corresponds to the given |protocol|,
639 // updates |observation_source| and returns true. If the corresponding
640 // ObservationSource is unknown, false is returned and |observation_source| is
641 // not modified.
642 bool GetObservationSourceForProtocol(
643 Protocol protocol,
644 ObservationSource* observation_source) const;
645
548 // Determines if the requests to local host can be used in estimating the 646 // Determines if the requests to local host can be used in estimating the
549 // network quality. Set to true only for tests. 647 // network quality. Set to true only for tests.
550 const bool allow_localhost_requests_; 648 const bool allow_localhost_requests_;
551 649
552 // Determines if the responses smaller than |kMinTransferSizeInBytes| 650 // Determines if the responses smaller than |kMinTransferSizeInBytes|
553 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the 651 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the
554 // network quality. Set to true only for tests. 652 // network quality. Set to true only for tests.
555 const bool allow_small_responses_; 653 const bool allow_small_responses_;
556 654
557 // Time when last connection change was observed. 655 // Time when last connection change was observed.
(...skipping 13 matching lines...) Expand all
571 // Cache that stores quality of previously seen networks. 669 // Cache that stores quality of previously seen networks.
572 CachedNetworkQualities cached_network_qualities_; 670 CachedNetworkQualities cached_network_qualities_;
573 671
574 // Buffer that holds throughput observations (in kilobits per second) sorted 672 // Buffer that holds throughput observations (in kilobits per second) sorted
575 // by timestamp. 673 // by timestamp.
576 ThroughputObservationBuffer downstream_throughput_kbps_observations_; 674 ThroughputObservationBuffer downstream_throughput_kbps_observations_;
577 675
578 // Buffer that holds RTT observations sorted by timestamp. 676 // Buffer that holds RTT observations sorted by timestamp.
579 RttObservationBuffer rtt_msec_observations_; 677 RttObservationBuffer rtt_msec_observations_;
580 678
679 // Buffer that holds packet loss observations sorted by timestamp.
680 PacketLossRateObservationBuffer packet_loss_rate_observations_;
681
581 // Default network quality observations obtained from the network quality 682 // Default network quality observations obtained from the network quality
582 // estimator field trial parameters. The observations are indexed by 683 // estimator field trial parameters. The observations are indexed by
583 // ConnectionType. 684 // ConnectionType.
584 NetworkQuality 685 NetworkQuality
585 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1]; 686 default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1];
586 687
587 // Estimated network quality. Updated on mainframe requests. 688 // Estimated network quality. Updated on mainframe requests.
588 NetworkQuality estimated_median_network_quality_; 689 NetworkQuality estimated_median_network_quality_;
589 690
590 // ExternalEstimateProvider that provides network quality using operating 691 // ExternalEstimateProvider that provides network quality using operating
591 // system APIs. May be NULL. 692 // system APIs. May be NULL.
592 const scoped_ptr<ExternalEstimateProvider> external_estimate_provider_; 693 const scoped_ptr<ExternalEstimateProvider> external_estimate_provider_;
593 694
594 // Observer lists for round trip times and throughput measurements. 695 // Observer lists for round trip times, throughput and packet loss
696 // measurements.
595 base::ObserverList<RTTObserver> rtt_observer_list_; 697 base::ObserverList<RTTObserver> rtt_observer_list_;
596 base::ObserverList<ThroughputObserver> throughput_observer_list_; 698 base::ObserverList<ThroughputObserver> throughput_observer_list_;
699 base::ObserverList<PacketLossObserver> packet_loss_observer_list_;
597 700
598 base::ThreadChecker thread_checker_; 701 base::ThreadChecker thread_checker_;
599 702
600 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); 703 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator);
601 }; 704 };
602 705
603 } // namespace net 706 } // namespace net
604 707
605 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ 708 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/network_quality_estimator.cc » ('j') | net/quic/quic_connection_logger.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698