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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 if (!request.url().is_valid() || | 44 if (!request.url().is_valid() || |
45 (!allow_localhost_requests_ && IsLocalhost(request.url().host())) || | 45 (!allow_localhost_requests_ && IsLocalhost(request.url().host())) || |
46 !request.url().SchemeIsHTTPOrHTTPS() || | 46 !request.url().SchemeIsHTTPOrHTTPS() || |
47 // Verify that response headers are received, so it can be ensured that | 47 // Verify that response headers are received, so it can be ensured that |
48 // response is not cached. | 48 // response is not cached. |
49 request.response_info().response_time.is_null() || request.was_cached() || | 49 request.response_info().response_time.is_null() || request.was_cached() || |
50 request.creation_time() < last_connection_change_) { | 50 request.creation_time() < last_connection_change_) { |
51 return; | 51 return; |
52 } | 52 } |
53 | 53 |
54 base::TimeTicks now = base::TimeTicks::Now(); | 54 base::Time now = base::Time::Now(); |
55 base::TimeDelta request_duration = now - request.creation_time(); | 55 |
56 DCHECK_GE(request_duration, base::TimeDelta()); | 56 // Time when the resource was requested. |
bengr
2015/06/09 00:18:49
Please add a comment to explain this logic.
tbansal1
2015/06/10 18:20:11
Done.
| |
57 base::Time request_start_time = !request.request_time().is_null() | |
58 ? request.request_time() | |
59 : request.creation_time(); | |
60 | |
61 // Difference of when the response headers were received and when the resource | |
bengr
2015/06/09 00:18:49
// Duration between when the resource was requeste
tbansal1
2015/06/10 18:20:11
Done.
| |
62 // was requested. | |
63 base::TimeDelta estimated_rtt = | |
bengr
2015/06/09 00:18:49
Maybe rename this as observed_rtt? It would be goo
tbansal1
2015/06/10 18:20:11
Done.
| |
64 request.response_info().response_time - request_start_time; | |
bengr
2015/06/09 00:18:49
Can response_time be null?
tbansal1
2015/06/10 18:20:11
No, there is a check above in the "if" condition:
| |
65 DCHECK_GE(estimated_rtt, base::TimeDelta()); | |
66 | |
67 // Time since the resource was requested. | |
68 base::TimeDelta since_request_start = now - request_start_time; | |
69 DCHECK_GE(since_request_start, base::TimeDelta()); | |
70 | |
57 if (!bytes_read_since_last_connection_change_) | 71 if (!bytes_read_since_last_connection_change_) |
58 fastest_RTT_since_last_connection_change_ = request_duration; | 72 fastest_RTT_since_last_connection_change_ = estimated_rtt; |
59 | 73 |
60 bytes_read_since_last_connection_change_ = true; | 74 bytes_read_since_last_connection_change_ = true; |
61 if (request_duration < fastest_RTT_since_last_connection_change_) | 75 if (estimated_rtt < fastest_RTT_since_last_connection_change_) |
62 fastest_RTT_since_last_connection_change_ = request_duration; | 76 fastest_RTT_since_last_connection_change_ = estimated_rtt; |
63 | 77 |
64 // Ignore tiny transfers which will not produce accurate rates. | 78 // Ignore tiny transfers which will not produce accurate rates. |
65 // Ignore short duration transfers. | 79 // Ignore short duration transfers. |
66 if (prefilter_bytes_read >= kMinTransferSizeInBytes && | 80 if (prefilter_bytes_read >= kMinTransferSizeInBytes && |
67 request_duration >= | 81 since_request_start >= |
68 base::TimeDelta::FromMicroseconds(kMinRequestDurationMicroseconds)) { | 82 base::TimeDelta::FromMicroseconds(kMinRequestDurationMicroseconds)) { |
69 uint64_t kbps = static_cast<uint64_t>(prefilter_bytes_read * 8 * 1000 / | 83 uint64_t kbps = static_cast<uint64_t>(prefilter_bytes_read * 8 * 1000 / |
70 request_duration.InMicroseconds()); | 84 since_request_start.InMicroseconds()); |
71 if (kbps > peak_kbps_since_last_connection_change_) | 85 if (kbps > peak_kbps_since_last_connection_change_) |
72 peak_kbps_since_last_connection_change_ = kbps; | 86 peak_kbps_since_last_connection_change_ = kbps; |
73 } | 87 } |
74 } | 88 } |
75 | 89 |
76 void NetworkQualityEstimator::OnConnectionTypeChanged( | 90 void NetworkQualityEstimator::OnConnectionTypeChanged( |
77 NetworkChangeNotifier::ConnectionType type) { | 91 NetworkChangeNotifier::ConnectionType type) { |
78 DCHECK(thread_checker_.CalledOnValidThread()); | 92 DCHECK(thread_checker_.CalledOnValidThread()); |
79 if (bytes_read_since_last_connection_change_) { | 93 if (bytes_read_since_last_connection_change_) { |
80 switch (current_connection_type_) { | 94 switch (current_connection_type_) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 } | 185 } |
172 if (!peak_kbps_since_last_connection_change_) { | 186 if (!peak_kbps_since_last_connection_change_) { |
173 return NetworkQuality(fastest_RTT_since_last_connection_change_, 0.1, | 187 return NetworkQuality(fastest_RTT_since_last_connection_change_, 0.1, |
174 peak_kbps_since_last_connection_change_, 0); | 188 peak_kbps_since_last_connection_change_, 0); |
175 } | 189 } |
176 return NetworkQuality(fastest_RTT_since_last_connection_change_, 0.1, | 190 return NetworkQuality(fastest_RTT_since_last_connection_change_, 0.1, |
177 peak_kbps_since_last_connection_change_, 0.1); | 191 peak_kbps_since_last_connection_change_, 0.1); |
178 } | 192 } |
179 | 193 |
180 } // namespace net | 194 } // namespace net |
OLD | NEW |