Chromium Code Reviews| Index: net/nqe/event_creator.cc |
| diff --git a/net/nqe/event_creator.cc b/net/nqe/event_creator.cc |
| index 930e3725c88d8f04167ed40bcd982cd89999cb93..a0db5374d963989357e037c0bbc0f52b4a3086ff 100644 |
| --- a/net/nqe/event_creator.cc |
| +++ b/net/nqe/event_creator.cc |
| @@ -4,6 +4,7 @@ |
| #include "net/nqe/event_creator.h" |
| +#include <stdlib.h> |
| #include <memory> |
| #include <utility> |
| @@ -21,7 +22,15 @@ namespace internal { |
| namespace { |
| -std::unique_ptr<base::Value> EffectiveConnectionTypeChangedNetLogCallback( |
| +// If the difference between the current network quality metric and the value of |
| +// the metric when the net log entry was last created is more than |
| +// |kMinDifferenceInMetrics|, then a new log entry is created. For RTTs, the |
| +// difference in last entry and the current value should be more than |
| +// |kMinDifferenceInMetrics| milliseconds. For throughput, the difference |
| +// must be more than |kMinDifferenceInMetrics| kilobits per second. |
| +static const int kMinDifferenceInMetrics = 100; |
|
RyanSturm
2017/03/03 22:10:21
This is fine, but you might consider having the di
tbansal1
2017/03/03 23:06:35
Yeah, percentage difference is one way but then we
|
| + |
| +std::unique_ptr<base::Value> NetworkQualityChangedNetLogCallback( |
| base::TimeDelta http_rtt, |
| base::TimeDelta transport_rtt, |
| int32_t downstream_throughput_kbps, |
| @@ -36,6 +45,15 @@ std::unique_ptr<base::Value> EffectiveConnectionTypeChangedNetLogCallback( |
| return std::move(dict); |
| } |
| +bool MetricChangedMeaningfully(int32_t past_value, int32_t current_value) { |
|
RyanSturm
2017/03/03 22:10:21
nit: the behavior is already correct, but adding a
tbansal1
2017/03/03 23:06:35
Done.
|
| + if ((past_value == INVALID_RTT_THROUGHPUT) != |
| + (current_value == INVALID_RTT_THROUGHPUT)) { |
| + return true; |
| + } |
| + |
| + return std::abs(past_value - current_value) >= kMinDifferenceInMetrics; |
| +} |
| + |
| } // namespace |
| EventCreator::EventCreator(NetLogWithSource net_log) |
| @@ -46,7 +64,7 @@ EventCreator::~EventCreator() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| } |
| -void EventCreator::MaybeAddEffectiveConnectionTypeChangedEventToNetLog( |
| +void EventCreator::MaybeAddNetworkQualityChangedEventToNetLog( |
| EffectiveConnectionType effective_connection_type, |
| const NetworkQuality& network_quality) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| @@ -54,15 +72,16 @@ void EventCreator::MaybeAddEffectiveConnectionTypeChangedEventToNetLog( |
| // Check if any of the network quality metrics changed meaningfully. |
| bool effective_connection_type_changed = |
| past_effective_connection_type_ != effective_connection_type; |
| - bool http_rtt_changed = (past_network_quality_.http_rtt() == InvalidRTT()) != |
| - (network_quality.http_rtt() == InvalidRTT()); |
| - bool transport_rtt_changed = |
| - (past_network_quality_.transport_rtt() == InvalidRTT()) != |
| - (network_quality.transport_rtt() == InvalidRTT()); |
| - bool kbps_changed = |
| - (past_network_quality_.downstream_throughput_kbps() == |
| - INVALID_RTT_THROUGHPUT) != |
| - (network_quality.downstream_throughput_kbps() == INVALID_RTT_THROUGHPUT); |
| + bool http_rtt_changed = MetricChangedMeaningfully( |
| + past_network_quality_.http_rtt().InMilliseconds(), |
| + network_quality.http_rtt().InMilliseconds()); |
| + |
| + bool transport_rtt_changed = MetricChangedMeaningfully( |
| + past_network_quality_.transport_rtt().InMilliseconds(), |
| + network_quality.transport_rtt().InMilliseconds()); |
| + bool kbps_changed = MetricChangedMeaningfully( |
| + past_network_quality_.downstream_throughput_kbps(), |
| + network_quality.downstream_throughput_kbps()); |
| if (!effective_connection_type_changed && !http_rtt_changed && |
| !transport_rtt_changed && !kbps_changed) { |
| @@ -75,7 +94,7 @@ void EventCreator::MaybeAddEffectiveConnectionTypeChangedEventToNetLog( |
| net_log_.AddEvent( |
| NetLogEventType::NETWORK_QUALITY_CHANGED, |
| - base::Bind(&EffectiveConnectionTypeChangedNetLogCallback, |
| + base::Bind(&NetworkQualityChangedNetLogCallback, |
| network_quality.http_rtt(), network_quality.transport_rtt(), |
| network_quality.downstream_throughput_kbps(), |
| effective_connection_type)); |