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 <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "net/base/load_timing_info.h" | |
12 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" |
13 #include "net/base/network_quality.h" | 14 #include "net/base/network_quality.h" |
14 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Maximum number of observations that can be held in the ObservationBuffer. | 20 // Maximum number of observations that can be held in the ObservationBuffer. |
20 const size_t kMaximumObservationsBufferSize = 500; | 21 const size_t kMaximumObservationsBufferSize = 500; |
21 | 22 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 (!allow_localhost_requests_ && IsLocalhost(request.url().host())) || | 57 (!allow_localhost_requests_ && IsLocalhost(request.url().host())) || |
57 !request.url().SchemeIsHTTPOrHTTPS() || | 58 !request.url().SchemeIsHTTPOrHTTPS() || |
58 // Verify that response headers are received, so it can be ensured that | 59 // Verify that response headers are received, so it can be ensured that |
59 // response is not cached. | 60 // response is not cached. |
60 request.response_info().response_time.is_null() || request.was_cached() || | 61 request.response_info().response_time.is_null() || request.was_cached() || |
61 request.creation_time() < last_connection_change_) { | 62 request.creation_time() < last_connection_change_) { |
62 return; | 63 return; |
63 } | 64 } |
64 | 65 |
65 base::TimeTicks now = base::TimeTicks::Now(); | 66 base::TimeTicks now = base::TimeTicks::Now(); |
66 base::TimeDelta request_duration = now - request.creation_time(); | 67 LoadTimingInfo load_timing_info; |
67 DCHECK_GE(request_duration, base::TimeDelta()); | 68 request.GetLoadTimingInfo(&load_timing_info); |
69 | |
70 // Time when the resource was requested. Use the timings from LoadTimingInfo, | |
71 // if it is available since it is recorded after DNS is resolved and a secure | |
72 // connection is established. | |
73 base::TimeTicks request_start_time = !load_timing_info.send_start.is_null() | |
mmenke
2015/06/15 17:21:00
Hrm...If load_timing_info.send_start or load_timin
tbansal1
2015/06/15 18:57:11
QUIC still has these 2 values populated. I checked
| |
74 ? load_timing_info.send_start | |
75 : request.creation_time(); | |
76 DCHECK(!request_start_time.is_null()); | |
77 | |
78 // Time when the headers were received. Use timings from LoadTimingInfo, if | |
79 // available. | |
80 base::TimeTicks headers_received_time = | |
81 !load_timing_info.receive_headers_end.is_null() | |
82 ? load_timing_info.receive_headers_end | |
83 : now; | |
84 DCHECK(!headers_received_time.is_null()); | |
85 | |
86 // Duration between when the resource was requested and when response headers | |
87 // were received. | |
88 base::TimeDelta observed_rtt = headers_received_time - request_start_time; | |
89 DCHECK_GE(observed_rtt, base::TimeDelta()); | |
mmenke
2015/06/15 17:21:00
This is only used in the body of the next if state
tbansal1
2015/06/15 18:57:11
Done.
| |
90 | |
91 // Time since the resource was requested. | |
92 base::TimeDelta since_request_start = now - request_start_time; | |
93 DCHECK_GE(since_request_start, base::TimeDelta()); | |
68 | 94 |
69 // Only add RTT observation if this is the first read for this response. | 95 // Only add RTT observation if this is the first read for this response. |
70 if (cumulative_prefilter_bytes_read == prefiltered_bytes_read) { | 96 if (cumulative_prefilter_bytes_read == prefiltered_bytes_read) { |
71 if (request_duration < fastest_rtt_since_last_connection_change_) | 97 if (observed_rtt < fastest_rtt_since_last_connection_change_) |
72 fastest_rtt_since_last_connection_change_ = request_duration; | 98 fastest_rtt_since_last_connection_change_ = observed_rtt; |
73 | 99 |
74 rtt_msec_observations_.AddObservation( | 100 rtt_msec_observations_.AddObservation( |
75 Observation(request_duration.InMilliseconds(), now)); | 101 Observation(observed_rtt.InMilliseconds(), now)); |
76 } | 102 } |
77 | 103 |
78 // Ignore tiny transfers which will not produce accurate rates. | 104 // Ignore tiny transfers which will not produce accurate rates. |
79 // Ignore short duration transfers. | 105 // Ignore short duration transfers. |
80 if (cumulative_prefilter_bytes_read >= kMinTransferSizeInBytes && | 106 if (cumulative_prefilter_bytes_read >= kMinTransferSizeInBytes && |
81 request_duration >= | 107 since_request_start >= |
82 base::TimeDelta::FromMicroseconds(kMinRequestDurationMicroseconds)) { | 108 base::TimeDelta::FromMicroseconds(kMinRequestDurationMicroseconds)) { |
83 double kbps_f = cumulative_prefilter_bytes_read * 8.0 / 1000.0 / | 109 double kbps_f = cumulative_prefilter_bytes_read * 8.0 / 1000.0 / |
84 request_duration.InSecondsF(); | 110 since_request_start.InSecondsF(); |
85 DCHECK_GE(kbps_f, 0.0); | 111 DCHECK_GE(kbps_f, 0.0); |
86 | 112 |
87 // Check overflow errors. This may happen if the kbpsF is more than | 113 // Check overflow errors. This may happen if the kbpsF is more than |
88 // 2 * 10^9 (= 2000 Gbps). | 114 // 2 * 10^9 (= 2000 Gbps). |
89 if (kbps_f >= std::numeric_limits<int32_t>::max()) | 115 if (kbps_f >= std::numeric_limits<int32_t>::max()) |
90 kbps_f = std::numeric_limits<int32_t>::max() - 1; | 116 kbps_f = std::numeric_limits<int32_t>::max() - 1; |
91 | 117 |
92 int32_t kbps = static_cast<int32_t>(kbps_f); | 118 int32_t kbps = static_cast<int32_t>(kbps_f); |
93 | 119 |
94 if (kbps > 0) { | 120 if (kbps > 0) { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 size_t NetworkQualityEstimator::ObservationBuffer::Size() const { | 267 size_t NetworkQualityEstimator::ObservationBuffer::Size() const { |
242 return observations_.size(); | 268 return observations_.size(); |
243 } | 269 } |
244 | 270 |
245 void NetworkQualityEstimator::ObservationBuffer::Clear() { | 271 void NetworkQualityEstimator::ObservationBuffer::Clear() { |
246 observations_.clear(); | 272 observations_.clear(); |
247 DCHECK(observations_.empty()); | 273 DCHECK(observations_.empty()); |
248 } | 274 } |
249 | 275 |
250 } // namespace net | 276 } // namespace net |
OLD | NEW |