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

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

Issue 1273173002: Added Network Quality Estimator Real-time interface to Cronet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed remaining comments Created 5 years, 3 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 | « net/base/network_quality_estimator.h ('k') | net/base/network_quality_estimator_unittest.cc » ('j') | 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 <float.h> 7 #include <float.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <cmath> 9 #include <cmath>
10 #include <limits> 10 #include <limits>
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 variations_value >= kMinimumThroughputVariationParameterKbps) { 236 variations_value >= kMinimumThroughputVariationParameterKbps) {
237 default_observations_[i] = 237 default_observations_[i] =
238 NetworkQuality(default_observations_[i].rtt(), variations_value); 238 NetworkQuality(default_observations_[i].rtt(), variations_value);
239 } 239 }
240 } 240 }
241 } 241 }
242 242
243 void NetworkQualityEstimator::AddDefaultEstimates() { 243 void NetworkQualityEstimator::AddDefaultEstimates() {
244 DCHECK(thread_checker_.CalledOnValidThread()); 244 DCHECK(thread_checker_.CalledOnValidThread());
245 if (default_observations_[current_network_id_.type].rtt() != InvalidRTT()) { 245 if (default_observations_[current_network_id_.type].rtt() != InvalidRTT()) {
246 rtt_msec_observations_.AddObservation(Observation( 246 Observation rtt_observation(
247 default_observations_[current_network_id_.type].rtt().InMilliseconds(), 247 default_observations_[current_network_id_.type].rtt().InMilliseconds(),
248 base::TimeTicks::Now())); 248 base::TimeTicks::Now(), OBSERVATION_SOURCE_DEFAULT_FROM_PLATFORM);
249 rtt_msec_observations_.AddObservation(rtt_observation);
250 NotifyObserversOfRTT(rtt_observation);
249 } 251 }
250 if (default_observations_[current_network_id_.type] 252 if (default_observations_[current_network_id_.type]
251 .downstream_throughput_kbps() != kInvalidThroughput) { 253 .downstream_throughput_kbps() != kInvalidThroughput) {
254 Observation throughput_observation(
255 default_observations_[current_network_id_.type]
256 .downstream_throughput_kbps(),
257 base::TimeTicks::Now(), OBSERVATION_SOURCE_DEFAULT_FROM_PLATFORM);
252 downstream_throughput_kbps_observations_.AddObservation( 258 downstream_throughput_kbps_observations_.AddObservation(
253 Observation(default_observations_[current_network_id_.type] 259 throughput_observation);
254 .downstream_throughput_kbps(), 260 NotifyObserversOfThroughput(throughput_observation);
255 base::TimeTicks::Now()));
256 } 261 }
257 } 262 }
258 263
259 NetworkQualityEstimator::~NetworkQualityEstimator() { 264 NetworkQualityEstimator::~NetworkQualityEstimator() {
260 DCHECK(thread_checker_.CalledOnValidThread()); 265 DCHECK(thread_checker_.CalledOnValidThread());
261 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 266 NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
262 } 267 }
263 268
264 void NetworkQualityEstimator::NotifyHeadersReceived(const URLRequest& request) { 269 void NetworkQualityEstimator::NotifyHeadersReceived(const URLRequest& request) {
265 DCHECK(thread_checker_.CalledOnValidThread()); 270 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 27 matching lines...) Expand all
293 298
294 // Duration between when the resource was requested and when response 299 // Duration between when the resource was requested and when response
295 // headers were received. 300 // headers were received.
296 base::TimeDelta observed_rtt = headers_received_time - request_start_time; 301 base::TimeDelta observed_rtt = headers_received_time - request_start_time;
297 DCHECK_GE(observed_rtt, base::TimeDelta()); 302 DCHECK_GE(observed_rtt, base::TimeDelta());
298 if (observed_rtt < peak_network_quality_.rtt()) { 303 if (observed_rtt < peak_network_quality_.rtt()) {
299 peak_network_quality_ = NetworkQuality( 304 peak_network_quality_ = NetworkQuality(
300 observed_rtt, peak_network_quality_.downstream_throughput_kbps()); 305 observed_rtt, peak_network_quality_.downstream_throughput_kbps());
301 } 306 }
302 307
303 rtt_msec_observations_.AddObservation( 308 Observation rtt_observation(observed_rtt.InMilliseconds(), now,
304 Observation(observed_rtt.InMilliseconds(), now)); 309 OBSERVATION_SOURCE_URL_REQUEST);
310 rtt_msec_observations_.AddObservation(rtt_observation);
311 NotifyObserversOfRTT(rtt_observation);
305 312
306 // Compare the RTT observation with the estimated value and record it. 313 // Compare the RTT observation with the estimated value and record it.
307 if (estimated_median_network_quality_.rtt() != InvalidRTT()) { 314 if (estimated_median_network_quality_.rtt() != InvalidRTT()) {
308 RecordRTTUMA(estimated_median_network_quality_.rtt().InMilliseconds(), 315 RecordRTTUMA(estimated_median_network_quality_.rtt().InMilliseconds(),
309 observed_rtt.InMilliseconds()); 316 observed_rtt.InMilliseconds());
310 } 317 }
311 } 318 }
312 319
313 void NetworkQualityEstimator::NotifyRequestCompleted( 320 void NetworkQualityEstimator::NotifyRequestCompleted(
314 const URLRequest& request) { 321 const URLRequest& request) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 // connection. 368 // connection.
362 if (downstream_kbps - downstream_kbps_as_integer > 0) 369 if (downstream_kbps - downstream_kbps_as_integer > 0)
363 downstream_kbps_as_integer++; 370 downstream_kbps_as_integer++;
364 371
365 DCHECK_GT(downstream_kbps_as_integer, 0.0); 372 DCHECK_GT(downstream_kbps_as_integer, 0.0);
366 if (downstream_kbps_as_integer > 373 if (downstream_kbps_as_integer >
367 peak_network_quality_.downstream_throughput_kbps()) 374 peak_network_quality_.downstream_throughput_kbps())
368 peak_network_quality_ = 375 peak_network_quality_ =
369 NetworkQuality(peak_network_quality_.rtt(), downstream_kbps_as_integer); 376 NetworkQuality(peak_network_quality_.rtt(), downstream_kbps_as_integer);
370 377
378 Observation throughput_observation(downstream_kbps_as_integer, now,
379 OBSERVATION_SOURCE_URL_REQUEST);
371 downstream_throughput_kbps_observations_.AddObservation( 380 downstream_throughput_kbps_observations_.AddObservation(
372 Observation(downstream_kbps_as_integer, now)); 381 throughput_observation);
382 NotifyObserversOfThroughput(throughput_observation);
383 }
384
385 void NetworkQualityEstimator::AddRTTObserver(RTTObserver* rtt_observer) {
386 DCHECK(thread_checker_.CalledOnValidThread());
387 rtt_observer_list_.AddObserver(rtt_observer);
388 }
389
390 void NetworkQualityEstimator::RemoveRTTObserver(RTTObserver* rtt_observer) {
391 DCHECK(thread_checker_.CalledOnValidThread());
392 rtt_observer_list_.RemoveObserver(rtt_observer);
393 }
394
395 void NetworkQualityEstimator::AddThroughputObserver(
396 ThroughputObserver* throughput_observer) {
397 DCHECK(thread_checker_.CalledOnValidThread());
398 throughput_observer_list_.AddObserver(throughput_observer);
399 }
400
401 void NetworkQualityEstimator::RemoveThroughputObserver(
402 ThroughputObserver* throughput_observer) {
403 DCHECK(thread_checker_.CalledOnValidThread());
404 throughput_observer_list_.RemoveObserver(throughput_observer);
405 }
406
407 void NetworkQualityEstimator::ConfigureForTests(bool allow_local_host_requests,
408 bool allow_smaller_responses) {
409 allow_localhost_requests_ = allow_local_host_requests,
410 allow_small_responses_ = allow_smaller_responses;
373 } 411 }
374 412
375 void NetworkQualityEstimator::RecordRTTUMA(int32_t estimated_value_msec, 413 void NetworkQualityEstimator::RecordRTTUMA(int32_t estimated_value_msec,
376 int32_t actual_value_msec) const { 414 int32_t actual_value_msec) const {
377 DCHECK(thread_checker_.CalledOnValidThread()); 415 DCHECK(thread_checker_.CalledOnValidThread());
378 416
379 // Record the difference between the actual and the estimated value. 417 // Record the difference between the actual and the estimated value.
380 if (estimated_value_msec >= actual_value_msec) { 418 if (estimated_value_msec >= actual_value_msec) {
381 base::HistogramBase* difference_rtt = 419 base::HistogramBase* difference_rtt =
382 GetHistogram("DifferenceRTTEstimatedAndActual.", 420 GetHistogram("DifferenceRTTEstimatedAndActual.",
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 bool NetworkQualityEstimator::GetRecentMedianDownlinkThroughputKbps( 618 bool NetworkQualityEstimator::GetRecentMedianDownlinkThroughputKbps(
581 const base::TimeTicks& begin_timestamp, 619 const base::TimeTicks& begin_timestamp,
582 int32_t* kbps) const { 620 int32_t* kbps) const {
583 DCHECK(thread_checker_.CalledOnValidThread()); 621 DCHECK(thread_checker_.CalledOnValidThread());
584 DCHECK(kbps); 622 DCHECK(kbps);
585 *kbps = GetDownlinkThroughputKbpsEstimateInternal(begin_timestamp, 50); 623 *kbps = GetDownlinkThroughputKbpsEstimateInternal(begin_timestamp, 50);
586 return (*kbps != kInvalidThroughput); 624 return (*kbps != kInvalidThroughput);
587 } 625 }
588 626
589 NetworkQualityEstimator::Observation::Observation(int32_t value, 627 NetworkQualityEstimator::Observation::Observation(int32_t value,
590 base::TimeTicks timestamp) 628 base::TimeTicks timestamp,
591 : value(value), timestamp(timestamp) { 629 ObservationSource source)
630 : value(value), timestamp(timestamp), source(source) {
592 DCHECK_GE(value, 0); 631 DCHECK_GE(value, 0);
593 DCHECK(!timestamp.is_null()); 632 DCHECK(!timestamp.is_null());
594 } 633 }
595 634
596 NetworkQualityEstimator::Observation::~Observation() { 635 NetworkQualityEstimator::Observation::~Observation() {
597 } 636 }
598 637
599 NetworkQualityEstimator::ObservationBuffer::ObservationBuffer( 638 NetworkQualityEstimator::ObservationBuffer::ObservationBuffer(
600 double weight_multiplier_per_second) 639 double weight_multiplier_per_second)
601 : weight_multiplier_per_second_(weight_multiplier_per_second) { 640 : weight_multiplier_per_second_(weight_multiplier_per_second) {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 cached_network_qualities_.find(current_network_id_); 835 cached_network_qualities_.find(current_network_id_);
797 836
798 if (it == cached_network_qualities_.end()) 837 if (it == cached_network_qualities_.end())
799 return false; 838 return false;
800 839
801 NetworkQuality network_quality(it->second.network_quality()); 840 NetworkQuality network_quality(it->second.network_quality());
802 841
803 DCHECK_NE(InvalidRTT(), network_quality.rtt()); 842 DCHECK_NE(InvalidRTT(), network_quality.rtt());
804 DCHECK_NE(kInvalidThroughput, network_quality.downstream_throughput_kbps()); 843 DCHECK_NE(kInvalidThroughput, network_quality.downstream_throughput_kbps());
805 844
806 downstream_throughput_kbps_observations_.AddObservation(Observation( 845 Observation througphput_observation(
807 network_quality.downstream_throughput_kbps(), base::TimeTicks::Now())); 846 network_quality.downstream_throughput_kbps(), base::TimeTicks::Now(),
808 rtt_msec_observations_.AddObservation(Observation( 847 OBSERVATION_SOURCE_CACHED_ESTIMATE);
809 network_quality.rtt().InMilliseconds(), base::TimeTicks::Now())); 848 downstream_throughput_kbps_observations_.AddObservation(
849 througphput_observation);
850 NotifyObserversOfThroughput(througphput_observation);
851
852 Observation rtt_observation(network_quality.rtt().InMilliseconds(),
853 base::TimeTicks::Now(),
854 OBSERVATION_SOURCE_CACHED_ESTIMATE);
855 rtt_msec_observations_.AddObservation(rtt_observation);
856 NotifyObserversOfRTT(rtt_observation);
857
810 return true; 858 return true;
811 } 859 }
812 860
813 void NetworkQualityEstimator::OnUpdatedEstimateAvailable() { 861 void NetworkQualityEstimator::OnUpdatedEstimateAvailable() {
814 DCHECK(thread_checker_.CalledOnValidThread()); 862 DCHECK(thread_checker_.CalledOnValidThread());
815 DCHECK(external_estimates_provider_); 863 DCHECK(external_estimates_provider_);
816 // TODO(tbansal): Query provider for the recent value. 864 // TODO(tbansal): Query provider for the recent value.
817 } 865 }
818 866
819 void NetworkQualityEstimator::CacheNetworkQualityEstimate() { 867 void NetworkQualityEstimator::CacheNetworkQualityEstimate() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 new SocketPerformanceWatcherTCP()); 910 new SocketPerformanceWatcherTCP());
863 } 911 }
864 912
865 scoped_ptr<SocketPerformanceWatcher> 913 scoped_ptr<SocketPerformanceWatcher>
866 NetworkQualityEstimator::CreateUDPSocketPerformanceWatcher() const { 914 NetworkQualityEstimator::CreateUDPSocketPerformanceWatcher() const {
867 DCHECK(thread_checker_.CalledOnValidThread()); 915 DCHECK(thread_checker_.CalledOnValidThread());
868 return scoped_ptr<SocketPerformanceWatcher>( 916 return scoped_ptr<SocketPerformanceWatcher>(
869 new SocketPerformanceWatcherUDP()); 917 new SocketPerformanceWatcherUDP());
870 } 918 }
871 919
920 void NetworkQualityEstimator::NotifyObserversOfRTT(
921 const Observation& observation) {
922 FOR_EACH_OBSERVER(RTTObserver, rtt_observer_list_,
923 OnRTTObservation(observation.value, observation.timestamp,
924 observation.source));
925 }
926
927 void NetworkQualityEstimator::NotifyObserversOfThroughput(
928 const Observation& observation) {
929 FOR_EACH_OBSERVER(
930 ThroughputObserver, throughput_observer_list_,
931 OnThroughputObservation(observation.value, observation.timestamp,
932 observation.source));
933 }
934
872 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality( 935 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality(
873 const NetworkQuality& network_quality) 936 const NetworkQuality& network_quality)
874 : last_update_time_(base::TimeTicks::Now()), 937 : last_update_time_(base::TimeTicks::Now()),
875 network_quality_(network_quality) { 938 network_quality_(network_quality) {
876 } 939 }
877 940
878 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality( 941 NetworkQualityEstimator::CachedNetworkQuality::CachedNetworkQuality(
879 const CachedNetworkQuality& other) 942 const CachedNetworkQuality& other)
880 : last_update_time_(other.last_update_time_), 943 : last_update_time_(other.last_update_time_),
881 network_quality_(other.network_quality_) { 944 network_quality_(other.network_quality_) {
(...skipping 27 matching lines...) Expand all
909 972
910 NetworkQualityEstimator::NetworkQuality& 973 NetworkQualityEstimator::NetworkQuality&
911 NetworkQualityEstimator::NetworkQuality:: 974 NetworkQualityEstimator::NetworkQuality::
912 operator=(const NetworkQuality& other) { 975 operator=(const NetworkQuality& other) {
913 rtt_ = other.rtt_; 976 rtt_ = other.rtt_;
914 downstream_throughput_kbps_ = other.downstream_throughput_kbps_; 977 downstream_throughput_kbps_ = other.downstream_throughput_kbps_;
915 return *this; 978 return *this;
916 } 979 }
917 980
918 } // namespace net 981 } // namespace net
OLDNEW
« no previous file with comments | « net/base/network_quality_estimator.h ('k') | net/base/network_quality_estimator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698