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

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

Issue 1162293004: Use request start time for estimating network quality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 5 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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"
11 #include "net/base/load_timing_info.h"
11 #include "net/base/net_util.h" 12 #include "net/base/net_util.h"
12 #include "net/base/network_quality.h" 13 #include "net/base/network_quality.h"
13 #include "net/url_request/url_request.h" 14 #include "net/url_request/url_request.h"
14 #include "url/gurl.h" 15 #include "url/gurl.h"
15 16
16 namespace net { 17 namespace net {
17 18
18 NetworkQualityEstimator::NetworkQualityEstimator() 19 NetworkQualityEstimator::NetworkQualityEstimator()
19 : NetworkQualityEstimator(false) { 20 : NetworkQualityEstimator(false) {
20 } 21 }
(...skipping 24 matching lines...) Expand all
45 (!allow_localhost_requests_ && IsLocalhost(request.url().host())) || 46 (!allow_localhost_requests_ && IsLocalhost(request.url().host())) ||
46 !request.url().SchemeIsHTTPOrHTTPS() || 47 !request.url().SchemeIsHTTPOrHTTPS() ||
47 // Verify that response headers are received, so it can be ensured that 48 // Verify that response headers are received, so it can be ensured that
48 // response is not cached. 49 // response is not cached.
49 request.response_info().response_time.is_null() || request.was_cached() || 50 request.response_info().response_time.is_null() || request.was_cached() ||
50 request.creation_time() < last_connection_change_) { 51 request.creation_time() < last_connection_change_) {
51 return; 52 return;
52 } 53 }
53 54
54 base::TimeTicks now = base::TimeTicks::Now(); 55 base::TimeTicks now = base::TimeTicks::Now();
55 base::TimeDelta request_duration = now - request.creation_time(); 56
56 DCHECK_GE(request_duration, base::TimeDelta()); 57 LoadTimingInfo load_timing_info;
58 request.GetLoadTimingInfo(&load_timing_info);
59
60 // Time when the resource was requested. Use the timings from LoadTimingInfo,
61 // if it is available since it is recorded after DNS is resolved and secure
bengr 2015/06/11 00:22:58 secure -> a secure
tbansal1 2015/06/11 03:01:36 Done.
62 // connection is established.
63 base::TimeTicks request_start_time = !load_timing_info.send_start.is_null()
64 ? load_timing_info.send_start
65 : request.creation_time();
66 DCHECK(!request_start_time.is_null());
67
68 // Time when the headers were received. Use timings from LoadTimingInfo, if
bengr 2015/06/11 00:22:58 Are they available at this point? When wouldn't th
tbansal1 2015/06/11 03:01:35 I think they are MOSTLY available, except for one
69 // available.
70 base::TimeTicks headers_received_time =
71 !load_timing_info.receive_headers_end.is_null()
72 ? load_timing_info.receive_headers_end
73 : now;
74 DCHECK(!headers_received_time.is_null());
75
76 // Duration between when the resource was requested and when response headers
77 // were received.
78 base::TimeDelta observed_rtt = headers_received_time - request_start_time;
79 DCHECK_GE(observed_rtt, base::TimeDelta());
80
81 // Time since the resource was requested.
82 base::TimeDelta since_request_start = now - request_start_time;
83 DCHECK_GE(since_request_start, base::TimeDelta());
84
57 if (!bytes_read_since_last_connection_change_) 85 if (!bytes_read_since_last_connection_change_)
58 fastest_RTT_since_last_connection_change_ = request_duration; 86 fastest_RTT_since_last_connection_change_ = observed_rtt;
59 87
60 bytes_read_since_last_connection_change_ = true; 88 bytes_read_since_last_connection_change_ = true;
61 if (request_duration < fastest_RTT_since_last_connection_change_) 89 if (observed_rtt < fastest_RTT_since_last_connection_change_)
62 fastest_RTT_since_last_connection_change_ = request_duration; 90 fastest_RTT_since_last_connection_change_ = observed_rtt;
63 91
64 // Ignore tiny transfers which will not produce accurate rates. 92 // Ignore tiny transfers which will not produce accurate rates.
65 // Ignore short duration transfers. 93 // Ignore short duration transfers.
66 if (prefilter_bytes_read >= kMinTransferSizeInBytes && 94 if (prefilter_bytes_read >= kMinTransferSizeInBytes &&
67 request_duration >= 95 since_request_start >=
68 base::TimeDelta::FromMicroseconds(kMinRequestDurationMicroseconds)) { 96 base::TimeDelta::FromMicroseconds(kMinRequestDurationMicroseconds)) {
69 uint64_t kbps = static_cast<uint64_t>(prefilter_bytes_read * 8 * 1000 / 97 uint64_t kbps = static_cast<uint64_t>(prefilter_bytes_read * 8 * 1000 /
70 request_duration.InMicroseconds()); 98 since_request_start.InMicroseconds());
71 if (kbps > peak_kbps_since_last_connection_change_) 99 if (kbps > peak_kbps_since_last_connection_change_)
72 peak_kbps_since_last_connection_change_ = kbps; 100 peak_kbps_since_last_connection_change_ = kbps;
73 } 101 }
74 } 102 }
75 103
76 void NetworkQualityEstimator::OnConnectionTypeChanged( 104 void NetworkQualityEstimator::OnConnectionTypeChanged(
77 NetworkChangeNotifier::ConnectionType type) { 105 NetworkChangeNotifier::ConnectionType type) {
78 DCHECK(thread_checker_.CalledOnValidThread()); 106 DCHECK(thread_checker_.CalledOnValidThread());
79 if (bytes_read_since_last_connection_change_) { 107 if (bytes_read_since_last_connection_change_) {
80 switch (current_connection_type_) { 108 switch (current_connection_type_) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 199 }
172 if (!peak_kbps_since_last_connection_change_) { 200 if (!peak_kbps_since_last_connection_change_) {
173 return NetworkQuality(fastest_RTT_since_last_connection_change_, 0.1, 201 return NetworkQuality(fastest_RTT_since_last_connection_change_, 0.1,
174 peak_kbps_since_last_connection_change_, 0); 202 peak_kbps_since_last_connection_change_, 0);
175 } 203 }
176 return NetworkQuality(fastest_RTT_since_last_connection_change_, 0.1, 204 return NetworkQuality(fastest_RTT_since_last_connection_change_, 0.1,
177 peak_kbps_since_last_connection_change_, 0.1); 205 peak_kbps_since_last_connection_change_, 0.1);
178 } 206 }
179 207
180 } // namespace net 208 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698