| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/event_creator.h" | 5 #include "net/nqe/event_creator.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 dict->SetInteger("http_rtt_ms", http_rtt.InMilliseconds()); | 31 dict->SetInteger("http_rtt_ms", http_rtt.InMilliseconds()); |
| 32 dict->SetInteger("transport_rtt_ms", transport_rtt.InMilliseconds()); | 32 dict->SetInteger("transport_rtt_ms", transport_rtt.InMilliseconds()); |
| 33 dict->SetInteger("downstream_throughput_kbps", downstream_throughput_kbps); | 33 dict->SetInteger("downstream_throughput_kbps", downstream_throughput_kbps); |
| 34 dict->SetString("effective_connection_type", | 34 dict->SetString("effective_connection_type", |
| 35 GetNameForEffectiveConnectionType(effective_connection_type)); | 35 GetNameForEffectiveConnectionType(effective_connection_type)); |
| 36 return std::move(dict); | 36 return std::move(dict); |
| 37 } | 37 } |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 void AddEffectiveConnectionTypeChangedEventToNetLog( | 41 EventCreator::EventCreator(NetLogWithSource net_log) |
| 42 const NetLogWithSource& net_log, | 42 : net_log_(net_log), |
| 43 base::TimeDelta http_rtt, | 43 past_effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {} |
| 44 base::TimeDelta transport_rtt, | 44 |
| 45 int32_t downstream_throughput_kbps, | 45 EventCreator::~EventCreator() { |
| 46 EffectiveConnectionType effective_connection_type) { | 46 DCHECK(thread_checker_.CalledOnValidThread()); |
| 47 net_log.AddEvent( | 47 } |
| 48 |
| 49 void EventCreator::MaybeAddEffectiveConnectionTypeChangedEventToNetLog( |
| 50 EffectiveConnectionType effective_connection_type, |
| 51 const NetworkQuality& network_quality) { |
| 52 DCHECK(thread_checker_.CalledOnValidThread()); |
| 53 |
| 54 // Check if any of the network quality metrics changed meaningfully. |
| 55 bool effective_connection_type_changed = |
| 56 past_effective_connection_type_ != effective_connection_type; |
| 57 bool http_rtt_changed = (past_network_quality_.http_rtt() == InvalidRTT()) != |
| 58 (network_quality.http_rtt() == InvalidRTT()); |
| 59 bool transport_rtt_changed = |
| 60 (past_network_quality_.transport_rtt() == InvalidRTT()) != |
| 61 (network_quality.transport_rtt() == InvalidRTT()); |
| 62 bool kbps_changed = |
| 63 (past_network_quality_.downstream_throughput_kbps() == |
| 64 INVALID_RTT_THROUGHPUT) != |
| 65 (network_quality.downstream_throughput_kbps() == INVALID_RTT_THROUGHPUT); |
| 66 |
| 67 if (!effective_connection_type_changed && !http_rtt_changed && |
| 68 !transport_rtt_changed && !kbps_changed) { |
| 69 // Return since none of the metrics changed meaningfully. |
| 70 return; |
| 71 } |
| 72 |
| 73 past_effective_connection_type_ = effective_connection_type; |
| 74 past_network_quality_ = network_quality; |
| 75 |
| 76 net_log_.AddEvent( |
| 48 NetLogEventType::NETWORK_QUALITY_CHANGED, | 77 NetLogEventType::NETWORK_QUALITY_CHANGED, |
| 49 base::Bind(&EffectiveConnectionTypeChangedNetLogCallback, http_rtt, | 78 base::Bind(&EffectiveConnectionTypeChangedNetLogCallback, |
| 50 transport_rtt, downstream_throughput_kbps, | 79 network_quality.http_rtt(), network_quality.transport_rtt(), |
| 80 network_quality.downstream_throughput_kbps(), |
| 51 effective_connection_type)); | 81 effective_connection_type)); |
| 52 } | 82 } |
| 53 | 83 |
| 54 } // namespace internal | 84 } // namespace internal |
| 55 | 85 |
| 56 } // namespace nqe | 86 } // namespace nqe |
| 57 | 87 |
| 58 } // namespace net | 88 } // namespace net |
| OLD | NEW |