Chromium Code Reviews| Index: net/nqe/network_quality_estimator.cc |
| diff --git a/net/nqe/network_quality_estimator.cc b/net/nqe/network_quality_estimator.cc |
| index fc6ed937aeb11eee266a16b302954de116f77aea..bb894ea98992c3efd309f1e9f7fae5a40c1f6580 100644 |
| --- a/net/nqe/network_quality_estimator.cc |
| +++ b/net/nqe/network_quality_estimator.cc |
| @@ -389,9 +389,6 @@ NetworkQualityEstimator::NetworkQualityEstimator( |
| base::TimeDelta::FromSeconds(10)), |
| rtt_observations_size_at_last_ect_computation_(0), |
| throughput_observations_size_at_last_ect_computation_(0), |
| - http_rtt_(nqe::internal::InvalidRTT()), |
| - transport_rtt_(nqe::internal::InvalidRTT()), |
| - downstream_throughput_kbps_(nqe::internal::kInvalidThroughput), |
| effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), |
| min_signal_strength_since_connection_change_(INT32_MAX), |
| max_signal_strength_since_connection_change_(INT32_MIN), |
| @@ -761,10 +758,13 @@ void NetworkQualityEstimator::RecordAccuracyAfterMainFrame( |
| if (last_main_frame_request_ <= last_connection_change_) |
| return; |
| - base::TimeDelta recent_http_rtt; |
| + base::TimeDelta recent_http_rtt = nqe::internal::InvalidRTT(); |
|
RyanSturm
2016/10/31 19:22:10
nit: Is this part necessary? If GetRecentHttpRTT r
tbansal1
2016/10/31 21:34:51
Done.
|
| + if (!GetRecentHttpRTT(last_main_frame_request_, &recent_http_rtt)) |
| + recent_http_rtt = nqe::internal::InvalidRTT(); |
| + |
| if (estimated_quality_at_last_main_frame_.http_rtt() != |
| nqe::internal::InvalidRTT() && |
| - GetRecentHttpRTT(last_main_frame_request_, &recent_http_rtt)) { |
| + recent_http_rtt != nqe::internal::InvalidRTT()) { |
| const int estimated_observed_diff_milliseconds = |
| estimated_quality_at_last_main_frame_.http_rtt().InMilliseconds() - |
| recent_http_rtt.InMilliseconds(); |
| @@ -1027,10 +1027,9 @@ void NetworkQualityEstimator::OnConnectionTypeChanged( |
| // Write the estimates of the previous network to the cache. |
| network_quality_store_->Add( |
| - current_network_id_, |
| - nqe::internal::CachedNetworkQuality( |
| - last_effective_connection_type_computation_, |
| - estimated_quality_at_last_main_frame_, effective_connection_type_)); |
| + current_network_id_, nqe::internal::CachedNetworkQuality( |
| + last_effective_connection_type_computation_, |
| + network_quality_, effective_connection_type_)); |
| // Clear the local state. |
| last_connection_change_ = tick_clock_->NowTicks(); |
| @@ -1048,10 +1047,7 @@ void NetworkQualityEstimator::OnConnectionTypeChanged( |
| #endif // OS_ANDROID |
| min_signal_strength_since_connection_change_ = INT32_MAX; |
| max_signal_strength_since_connection_change_ = INT32_MIN; |
| - estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality(); |
| - http_rtt_ = nqe::internal::InvalidRTT(); |
| - transport_rtt_ = nqe::internal::InvalidRTT(); |
| - downstream_throughput_kbps_ = nqe::internal::kInvalidThroughput; |
| + network_quality_ = nqe::internal::NetworkQuality(); |
| effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
| effective_connection_type_at_last_main_frame_ = |
| EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
| @@ -1238,10 +1234,18 @@ void NetworkQualityEstimator::ComputeEffectiveConnectionType() { |
| const EffectiveConnectionType past_type = effective_connection_type_; |
| last_effective_connection_type_computation_ = now; |
| + base::TimeDelta http_rtt = nqe::internal::InvalidRTT(); |
| + base::TimeDelta transport_rtt = nqe::internal::InvalidRTT(); |
| + int32_t downstream_throughput_kbps = nqe::internal::kInvalidThroughput; |
| + |
| effective_connection_type_ = |
| GetRecentEffectiveConnectionTypeAndNetworkQuality( |
| - base::TimeTicks(), &http_rtt_, &transport_rtt_, |
| - &downstream_throughput_kbps_); |
| + base::TimeTicks(), &http_rtt, &transport_rtt, |
| + &downstream_throughput_kbps); |
| + |
| + network_quality_ = nqe::internal::NetworkQuality(http_rtt, transport_rtt, |
| + downstream_throughput_kbps); |
| + |
| NotifyObserversOfRTTOrThroughputComputed(); |
| if (past_type != effective_connection_type_) |
| @@ -1263,9 +1267,9 @@ NetworkQualityEstimator::GetRecentEffectiveConnectionType( |
| const base::TimeTicks& start_time) const { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - base::TimeDelta http_rtt; |
| - base::TimeDelta transport_rtt; |
| - int32_t downstream_throughput_kbps; |
| + base::TimeDelta http_rtt = nqe::internal::InvalidRTT(); |
| + base::TimeDelta transport_rtt = nqe::internal::InvalidRTT(); |
| + int32_t downstream_throughput_kbps = nqe::internal::kInvalidThroughput; |
| return GetRecentEffectiveConnectionTypeAndNetworkQuality( |
| start_time, &http_rtt, &transport_rtt, &downstream_throughput_kbps); |
| @@ -1598,10 +1602,7 @@ bool NetworkQualityEstimator::ReadCachedNetworkQualityEstimate() { |
| if (effective_connection_type_ == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { |
| // Read the effective connection type from the cached estimate. |
| last_effective_connection_type_computation_ = now; |
| - http_rtt_ = cached_network_quality.network_quality().http_rtt(); |
| - transport_rtt_ = cached_network_quality.network_quality().transport_rtt(); |
| - downstream_throughput_kbps_ = |
| - cached_network_quality.network_quality().downstream_throughput_kbps(); |
| + network_quality_ = cached_network_quality.network_quality(); |
| effective_connection_type_ = |
| cached_network_quality.effective_connection_type(); |
| @@ -1779,11 +1780,10 @@ void NetworkQualityEstimator:: |
| // Add the estimates of the current network to the cache store. |
| if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { |
| - network_quality_store_->Add( |
| - current_network_id_, |
| - nqe::internal::CachedNetworkQuality( |
| - tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_, |
| - effective_connection_type_)); |
| + network_quality_store_->Add(current_network_id_, |
| + nqe::internal::CachedNetworkQuality( |
| + tick_clock_->NowTicks(), network_quality_, |
| + effective_connection_type_)); |
| } |
| } |
| @@ -1792,8 +1792,9 @@ void NetworkQualityEstimator::NotifyObserversOfRTTOrThroughputComputed() const { |
| // TODO(tbansal): Add hysteresis in the notification. |
| for (auto& observer : rtt_and_throughput_estimates_observer_list_) { |
| - observer.OnRTTOrThroughputEstimatesComputed(http_rtt_, transport_rtt_, |
| - downstream_throughput_kbps_); |
| + observer.OnRTTOrThroughputEstimatesComputed( |
| + network_quality_.http_rtt(), network_quality_.transport_rtt(), |
| + network_quality_.downstream_throughput_kbps()); |
| } |
| } |