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/nqe/network_quality_estimator.h" | 5 #include "net/nqe/network_quality_estimator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <utility> | 10 #include <utility> |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 NetworkID(NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, | 258 NetworkID(NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, |
259 std::string())), | 259 std::string())), |
260 downstream_throughput_kbps_observations_(weight_multiplier_per_second_), | 260 downstream_throughput_kbps_observations_(weight_multiplier_per_second_), |
261 rtt_observations_(weight_multiplier_per_second_), | 261 rtt_observations_(weight_multiplier_per_second_), |
262 effective_connection_type_at_last_main_frame_( | 262 effective_connection_type_at_last_main_frame_( |
263 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), | 263 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), |
264 external_estimate_provider_(std::move(external_estimates_provider)), | 264 external_estimate_provider_(std::move(external_estimates_provider)), |
265 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), | 265 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), |
266 min_signal_strength_since_connection_change_(INT32_MAX), | 266 min_signal_strength_since_connection_change_(INT32_MAX), |
267 max_signal_strength_since_connection_change_(INT32_MIN), | 267 max_signal_strength_since_connection_change_(INT32_MIN), |
268 stop_reporting_effective_connection_type_(false), | |
268 weak_ptr_factory_(this) { | 269 weak_ptr_factory_(this) { |
269 static_assert(kDefaultHalfLifeSeconds > 0, | 270 static_assert(kDefaultHalfLifeSeconds > 0, |
270 "Default half life duration must be > 0"); | 271 "Default half life duration must be > 0"); |
271 static_assert(kMaximumNetworkQualityCacheSize > 0, | 272 static_assert(kMaximumNetworkQualityCacheSize > 0, |
272 "Size of the network quality cache must be > 0"); | 273 "Size of the network quality cache must be > 0"); |
273 // This limit should not be increased unless the logic for removing the | 274 // This limit should not be increased unless the logic for removing the |
274 // oldest cache entry is rewritten to use a doubly-linked-list LRU queue. | 275 // oldest cache entry is rewritten to use a doubly-linked-list LRU queue. |
275 static_assert(kMaximumNetworkQualityCacheSize <= 10, | 276 static_assert(kMaximumNetworkQualityCacheSize <= 10, |
276 "Size of the network quality cache must <= 10"); | 277 "Size of the network quality cache must <= 10"); |
277 // None of the algorithms can have an empty name. | 278 // None of the algorithms can have an empty name. |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
730 use_localhost_requests_); | 731 use_localhost_requests_); |
731 } | 732 } |
732 | 733 |
733 void NetworkQualityEstimator::SetUseSmallResponsesForTesting( | 734 void NetworkQualityEstimator::SetUseSmallResponsesForTesting( |
734 bool use_small_responses) { | 735 bool use_small_responses) { |
735 DCHECK(thread_checker_.CalledOnValidThread()); | 736 DCHECK(thread_checker_.CalledOnValidThread()); |
736 use_small_responses_ = use_small_responses; | 737 use_small_responses_ = use_small_responses; |
737 throughput_analyzer_->SetUseSmallResponsesForTesting(use_small_responses_); | 738 throughput_analyzer_->SetUseSmallResponsesForTesting(use_small_responses_); |
738 } | 739 } |
739 | 740 |
741 void NetworkQualityEstimator::StopReportingEffectiveConnectionTypeForTesting( | |
742 bool stop_reporting_effective_connection_type) { | |
743 stop_reporting_effective_connection_type_ = | |
tbansal1
2016/07/19 23:05:22
Add thread checker.
RyanSturm
2016/07/19 23:31:02
Done.
| |
744 stop_reporting_effective_connection_type; | |
745 } | |
746 | |
747 void NetworkQualityEstimator::ReportEffectiveConnectionTypeForTesting( | |
748 EffectiveConnectionType effective_connection_type) { | |
749 FOR_EACH_OBSERVER( | |
tbansal1
2016/07/19 23:05:22
Add thread checker.
RyanSturm
2016/07/19 23:31:02
Done.
| |
750 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, | |
751 OnEffectiveConnectionTypeChanged(effective_connection_type)); | |
752 } | |
753 | |
740 bool NetworkQualityEstimator::RequestProvidesRTTObservation( | 754 bool NetworkQualityEstimator::RequestProvidesRTTObservation( |
741 const URLRequest& request) const { | 755 const URLRequest& request) const { |
742 DCHECK(thread_checker_.CalledOnValidThread()); | 756 DCHECK(thread_checker_.CalledOnValidThread()); |
743 | 757 |
744 return (use_localhost_requests_ || !IsLocalhost(request.url().host())) && | 758 return (use_localhost_requests_ || !IsLocalhost(request.url().host())) && |
745 // Verify that response headers are received, so it can be ensured that | 759 // Verify that response headers are received, so it can be ensured that |
746 // response is not cached. | 760 // response is not cached. |
747 !request.response_info().response_time.is_null() && | 761 !request.response_info().response_time.is_null() && |
748 !request.was_cached() && | 762 !request.was_cached() && |
749 request.creation_time() >= last_connection_change_; | 763 request.creation_time() >= last_connection_change_; |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1464 last_effective_connection_type_computation_ = now; | 1478 last_effective_connection_type_computation_ = now; |
1465 effective_connection_type_ = GetEffectiveConnectionType(); | 1479 effective_connection_type_ = GetEffectiveConnectionType(); |
1466 | 1480 |
1467 if (past_type != effective_connection_type_) | 1481 if (past_type != effective_connection_type_) |
1468 NotifyObserversOfEffectiveConnectionTypeChanged(); | 1482 NotifyObserversOfEffectiveConnectionTypeChanged(); |
1469 } | 1483 } |
1470 | 1484 |
1471 void NetworkQualityEstimator:: | 1485 void NetworkQualityEstimator:: |
1472 NotifyObserversOfEffectiveConnectionTypeChanged() { | 1486 NotifyObserversOfEffectiveConnectionTypeChanged() { |
1473 DCHECK(thread_checker_.CalledOnValidThread()); | 1487 DCHECK(thread_checker_.CalledOnValidThread()); |
1474 | 1488 if (stop_reporting_effective_connection_type_) |
1489 return; | |
1475 // TODO(tbansal): Add hysteresis in the notification. | 1490 // TODO(tbansal): Add hysteresis in the notification. |
1476 FOR_EACH_OBSERVER( | 1491 FOR_EACH_OBSERVER( |
1477 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, | 1492 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, |
1478 OnEffectiveConnectionTypeChanged(effective_connection_type_)); | 1493 OnEffectiveConnectionTypeChanged(effective_connection_type_)); |
1479 } | 1494 } |
1480 | 1495 |
1481 } // namespace net | 1496 } // namespace net |
OLD | NEW |