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 <float.h> | 7 #include <float.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <cmath> | 9 #include <cmath> |
10 #include <limits> | 10 #include <limits> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/metrics/histogram_base.h" | 16 #include "base/metrics/histogram_base.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/trace_event/trace_event.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
20 #include "net/base/load_timing_info.h" | 21 #include "net/base/load_timing_info.h" |
21 #include "net/base/network_interfaces.h" | 22 #include "net/base/network_interfaces.h" |
22 #include "net/base/url_util.h" | 23 #include "net/base/url_util.h" |
23 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
25 | 26 |
26 #if defined(OS_ANDROID) | 27 #if defined(OS_ANDROID) |
27 #include "net/android/network_library.h" | 28 #include "net/android/network_library.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 NotifyObserversOfThroughput(throughput_observation); | 234 NotifyObserversOfThroughput(throughput_observation); |
234 } | 235 } |
235 } | 236 } |
236 | 237 |
237 NetworkQualityEstimator::~NetworkQualityEstimator() { | 238 NetworkQualityEstimator::~NetworkQualityEstimator() { |
238 DCHECK(thread_checker_.CalledOnValidThread()); | 239 DCHECK(thread_checker_.CalledOnValidThread()); |
239 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 240 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
240 } | 241 } |
241 | 242 |
242 void NetworkQualityEstimator::NotifyHeadersReceived(const URLRequest& request) { | 243 void NetworkQualityEstimator::NotifyHeadersReceived(const URLRequest& request) { |
| 244 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), |
| 245 "NetworkQualityEstimator::NotifyHeadersReceived"); |
243 DCHECK(thread_checker_.CalledOnValidThread()); | 246 DCHECK(thread_checker_.CalledOnValidThread()); |
244 | 247 |
245 if (!RequestProvidesUsefulObservations(request)) | 248 if (!RequestProvidesUsefulObservations(request)) |
246 return; | 249 return; |
247 | 250 |
248 // Update |estimated_median_network_quality_| if this is a main frame request. | 251 // Update |estimated_median_network_quality_| if this is a main frame request. |
249 if (request.load_flags() & LOAD_MAIN_FRAME) { | 252 if (request.load_flags() & LOAD_MAIN_FRAME) { |
250 estimated_median_network_quality_ = NetworkQuality( | 253 estimated_median_network_quality_ = NetworkQuality( |
251 GetRTTEstimateInternal(base::TimeTicks(), 50), | 254 GetRTTEstimateInternal(base::TimeTicks(), 50), |
252 GetDownlinkThroughputKbpsEstimateInternal(base::TimeTicks(), 50)); | 255 GetDownlinkThroughputKbpsEstimateInternal(base::TimeTicks(), 50)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 287 |
285 // Compare the RTT observation with the estimated value and record it. | 288 // Compare the RTT observation with the estimated value and record it. |
286 if (estimated_median_network_quality_.rtt() != InvalidRTT()) { | 289 if (estimated_median_network_quality_.rtt() != InvalidRTT()) { |
287 RecordRTTUMA(estimated_median_network_quality_.rtt().InMilliseconds(), | 290 RecordRTTUMA(estimated_median_network_quality_.rtt().InMilliseconds(), |
288 observed_rtt.InMilliseconds()); | 291 observed_rtt.InMilliseconds()); |
289 } | 292 } |
290 } | 293 } |
291 | 294 |
292 void NetworkQualityEstimator::NotifyRequestCompleted( | 295 void NetworkQualityEstimator::NotifyRequestCompleted( |
293 const URLRequest& request) { | 296 const URLRequest& request) { |
| 297 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("net"), |
| 298 "NetworkQualityEstimator::NotifyRequestCompleted"); |
294 DCHECK(thread_checker_.CalledOnValidThread()); | 299 DCHECK(thread_checker_.CalledOnValidThread()); |
295 | 300 |
296 if (!RequestProvidesUsefulObservations(request)) | 301 if (!RequestProvidesUsefulObservations(request)) |
297 return; | 302 return; |
298 | 303 |
299 base::TimeTicks now = base::TimeTicks::Now(); | 304 base::TimeTicks now = base::TimeTicks::Now(); |
300 LoadTimingInfo load_timing_info; | 305 LoadTimingInfo load_timing_info; |
301 request.GetLoadTimingInfo(&load_timing_info); | 306 request.GetLoadTimingInfo(&load_timing_info); |
302 | 307 |
303 // If the load timing info is unavailable, it probably means that the request | 308 // If the load timing info is unavailable, it probably means that the request |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 | 973 |
969 NetworkQualityEstimator::NetworkQuality& | 974 NetworkQualityEstimator::NetworkQuality& |
970 NetworkQualityEstimator::NetworkQuality:: | 975 NetworkQualityEstimator::NetworkQuality:: |
971 operator=(const NetworkQuality& other) { | 976 operator=(const NetworkQuality& other) { |
972 rtt_ = other.rtt_; | 977 rtt_ = other.rtt_; |
973 downstream_throughput_kbps_ = other.downstream_throughput_kbps_; | 978 downstream_throughput_kbps_ = other.downstream_throughput_kbps_; |
974 return *this; | 979 return *this; |
975 } | 980 } |
976 | 981 |
977 } // namespace net | 982 } // namespace net |
OLD | NEW |