blob: 8e0cb68a51af80d0b59625579a1a59d7002b5c1c [file] [log] [blame]
tbansalb67539d2016-05-16 17:54:131// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "net/nqe/network_quality.h"
6
7namespace net {
tbansalb67539d2016-05-16 17:54:138namespace nqe {
tbansalb67539d2016-05-16 17:54:139namespace internal {
10
11base::TimeDelta InvalidRTT() {
Peter Kastinge5a38ed2021-10-02 03:06:3512 return base::Milliseconds(INVALID_RTT_THROUGHPUT);
tbansalb67539d2016-05-16 17:54:1313}
14
15NetworkQuality::NetworkQuality()
Tarun Bansaldf224ab2018-01-03 17:27:3716 : NetworkQuality(InvalidRTT(), InvalidRTT(), INVALID_RTT_THROUGHPUT) {
17 VerifyValueCorrectness();
18 DETACH_FROM_SEQUENCE(sequence_checker_);
19}
tbansalb67539d2016-05-16 17:54:1320
tbansal805892c2016-05-26 16:46:5921NetworkQuality::NetworkQuality(const base::TimeDelta& http_rtt,
22 const base::TimeDelta& transport_rtt,
tbansalb67539d2016-05-16 17:54:1323 int32_t downstream_throughput_kbps)
tbansal805892c2016-05-26 16:46:5924 : http_rtt_(http_rtt),
25 transport_rtt_(transport_rtt),
26 downstream_throughput_kbps_(downstream_throughput_kbps) {
Tarun Bansaldf224ab2018-01-03 17:27:3727 VerifyValueCorrectness();
28 DETACH_FROM_SEQUENCE(sequence_checker_);
tbansalb67539d2016-05-16 17:54:1329}
30
31NetworkQuality::NetworkQuality(const NetworkQuality& other)
tbansal805892c2016-05-26 16:46:5932 : NetworkQuality(other.http_rtt_,
33 other.transport_rtt_,
Tarun Bansaldf224ab2018-01-03 17:27:3734 other.downstream_throughput_kbps_) {
35 VerifyValueCorrectness();
36 DETACH_FROM_SEQUENCE(sequence_checker_);
37}
tbansalb67539d2016-05-16 17:54:1338
Chris Watkinsf3c65a62017-12-01 02:06:4139NetworkQuality::~NetworkQuality() = default;
tbansalb67539d2016-05-16 17:54:1340
41NetworkQuality& NetworkQuality::operator=(const NetworkQuality& other) {
tbansal805892c2016-05-26 16:46:5942 http_rtt_ = other.http_rtt_;
43 transport_rtt_ = other.transport_rtt_;
tbansalb67539d2016-05-16 17:54:1344 downstream_throughput_kbps_ = other.downstream_throughput_kbps_;
Tarun Bansaldf224ab2018-01-03 17:27:3745 VerifyValueCorrectness();
46 DETACH_FROM_SEQUENCE(sequence_checker_);
tbansalb67539d2016-05-16 17:54:1347 return *this;
48}
49
tbansalbff2aec2016-07-25 18:28:5450bool NetworkQuality::operator==(const NetworkQuality& other) const {
Tarun Bansaldf224ab2018-01-03 17:27:3751 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
tbansalbff2aec2016-07-25 18:28:5452 return http_rtt_ == other.http_rtt_ &&
53 transport_rtt_ == other.transport_rtt_ &&
54 downstream_throughput_kbps_ == other.downstream_throughput_kbps_;
55}
56
tbansal2739868c2016-07-27 00:44:2057bool NetworkQuality::IsFaster(const NetworkQuality& other) const {
Tarun Bansaldf224ab2018-01-03 17:27:3758 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
tbansal2739868c2016-07-27 00:44:2059 return (http_rtt() == InvalidRTT() || other.http_rtt() == InvalidRTT() ||
60 http_rtt() <= other.http_rtt()) &&
61 (transport_rtt() == InvalidRTT() ||
62 other.transport_rtt() == InvalidRTT() ||
63 transport_rtt() <= other.transport_rtt()) &&
zhuoyu.qiand80590e52017-10-30 10:23:5164 (downstream_throughput_kbps() == INVALID_RTT_THROUGHPUT ||
65 other.downstream_throughput_kbps() == INVALID_RTT_THROUGHPUT ||
tbansal2739868c2016-07-27 00:44:2066 downstream_throughput_kbps() >= other.downstream_throughput_kbps());
67}
68
Tarun Bansaldf224ab2018-01-03 17:27:3769void NetworkQuality::VerifyValueCorrectness() const {
70 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
71 DCHECK_LE(INVALID_RTT_THROUGHPUT, http_rtt_.InMilliseconds());
72 DCHECK_LE(INVALID_RTT_THROUGHPUT, transport_rtt_.InMilliseconds());
73 DCHECK_LE(INVALID_RTT_THROUGHPUT, downstream_throughput_kbps_);
74}
75
tbansalb67539d2016-05-16 17:54:1376} // namespace internal
tbansalb67539d2016-05-16 17:54:1377} // namespace nqe
bnc3698b0a02016-12-09 23:36:5078} // namespace net