Chromium Code Reviews| 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/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "net/base/load_timing_info.h" | |
| 10 #include "net/base/net_util.h" | 11 #include "net/base/net_util.h" |
| 11 #include "net/base/network_quality.h" | 12 #include "net/base/network_quality.h" |
| 12 #include "net/url_request/url_request.h" | 13 #include "net/url_request/url_request.h" |
| 13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 17 NetworkQualityEstimator::NetworkQualityEstimator() | 18 NetworkQualityEstimator::NetworkQualityEstimator() |
| 18 : NetworkQualityEstimator(false) { | 19 : NetworkQualityEstimator(false) { |
| 19 } | 20 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 42 | 43 |
| 43 if (!request.url().is_valid() || | 44 if (!request.url().is_valid() || |
| 44 (!allow_localhost_requests_ && IsLocalhost(request.url().host())) || | 45 (!allow_localhost_requests_ && IsLocalhost(request.url().host())) || |
| 45 !request.url().SchemeIsHTTPOrHTTPS() || | 46 !request.url().SchemeIsHTTPOrHTTPS() || |
| 46 // 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 |
| 47 // response is not cached. | 48 // response is not cached. |
| 48 request.response_info().response_time.is_null() || request.was_cached()) | 49 request.response_info().response_time.is_null() || request.was_cached()) |
| 49 return; | 50 return; |
| 50 | 51 |
| 51 base::TimeTicks now = base::TimeTicks::Now(); | 52 base::TimeTicks now = base::TimeTicks::Now(); |
| 52 base::TimeDelta request_duration = now - request.creation_time(); | 53 |
| 54 LoadTimingInfo load_timing_info; | |
| 55 request.GetLoadTimingInfo(&load_timing_info); | |
| 56 DCHECK_NE(load_timing_info.request_start, base::TimeTicks()); | |
|
bengr
2015/06/01 23:23:34
Do all requests have load timing info?
tbansal1
2015/06/01 23:53:36
Seems like yes. request_start is populated in
URLR
| |
| 57 | |
| 58 base::TimeDelta request_duration = now - load_timing_info.request_start; | |
| 53 DCHECK_GE(request_duration, base::TimeDelta()); | 59 DCHECK_GE(request_duration, base::TimeDelta()); |
| 54 if (!bytes_read_since_last_connection_change_) | 60 if (!bytes_read_since_last_connection_change_) |
| 55 fastest_RTT_since_last_connection_change_ = request_duration; | 61 fastest_RTT_since_last_connection_change_ = request_duration; |
| 56 | 62 |
| 57 bytes_read_since_last_connection_change_ = true; | 63 bytes_read_since_last_connection_change_ = true; |
| 58 if (request_duration < fastest_RTT_since_last_connection_change_) | 64 if (request_duration < fastest_RTT_since_last_connection_change_) |
| 59 fastest_RTT_since_last_connection_change_ = request_duration; | 65 fastest_RTT_since_last_connection_change_ = request_duration; |
| 60 | 66 |
| 61 // Ignore tiny transfers which will not produce accurate rates. | 67 // Ignore tiny transfers which will not produce accurate rates. |
| 62 // Ignore short duration transfers. | 68 // Ignore short duration transfers. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 } | 175 } |
| 170 if (!peak_kbps_since_last_connection_change_) { | 176 if (!peak_kbps_since_last_connection_change_) { |
| 171 return NetworkQuality(fastest_RTT_since_last_connection_change_, 0.1, | 177 return NetworkQuality(fastest_RTT_since_last_connection_change_, 0.1, |
| 172 peak_kbps_since_last_connection_change_, 0); | 178 peak_kbps_since_last_connection_change_, 0); |
| 173 } | 179 } |
| 174 return NetworkQuality(fastest_RTT_since_last_connection_change_, 0.1, | 180 return NetworkQuality(fastest_RTT_since_last_connection_change_, 0.1, |
| 175 peak_kbps_since_last_connection_change_, 0.1); | 181 peak_kbps_since_last_connection_change_, 0.1); |
| 176 } | 182 } |
| 177 | 183 |
| 178 } // namespace net | 184 } // namespace net |
| OLD | NEW |