blob: ee660175268e808699414ded735f0fa997e553ad [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
Tsuyoshi Horo4f516be2022-06-14 11:53:137namespace net::nqe::internal {
tbansalb67539d2016-05-16 17:54:138
9base::TimeDelta InvalidRTT() {
Peter Kastinge5a38ed2021-10-02 03:06:3510 return base::Milliseconds(INVALID_RTT_THROUGHPUT);
tbansalb67539d2016-05-16 17:54:1311}
12
13NetworkQuality::NetworkQuality()
Tarun Bansaldf224ab2018-01-03 17:27:3714 : NetworkQuality(InvalidRTT(), InvalidRTT(), INVALID_RTT_THROUGHPUT) {
15 VerifyValueCorrectness();
16 DETACH_FROM_SEQUENCE(sequence_checker_);
17}
tbansalb67539d2016-05-16 17:54:1318
tbansal805892c2016-05-26 16:46:5919NetworkQuality::NetworkQuality(const base::TimeDelta& http_rtt,
20 const base::TimeDelta& transport_rtt,
tbansalb67539d2016-05-16 17:54:1321 int32_t downstream_throughput_kbps)
tbansal805892c2016-05-26 16:46:5922 : http_rtt_(http_rtt),
23 transport_rtt_(transport_rtt),
24 downstream_throughput_kbps_(downstream_throughput_kbps) {
Tarun Bansaldf224ab2018-01-03 17:27:3725 VerifyValueCorrectness();
26 DETACH_FROM_SEQUENCE(sequence_checker_);
tbansalb67539d2016-05-16 17:54:1327}
28
29NetworkQuality::NetworkQuality(const NetworkQuality& other)
tbansal805892c2016-05-26 16:46:5930 : NetworkQuality(other.http_rtt_,
31 other.transport_rtt_,
Tarun Bansaldf224ab2018-01-03 17:27:3732 other.downstream_throughput_kbps_) {
33 VerifyValueCorrectness();
34 DETACH_FROM_SEQUENCE(sequence_checker_);
35}
tbansalb67539d2016-05-16 17:54:1336
Chris Watkinsf3c65a62017-12-01 02:06:4137NetworkQuality::~NetworkQuality() = default;
tbansalb67539d2016-05-16 17:54:1338
39NetworkQuality& NetworkQuality::operator=(const NetworkQuality& other) {
tbansal805892c2016-05-26 16:46:5940 http_rtt_ = other.http_rtt_;
41 transport_rtt_ = other.transport_rtt_;
tbansalb67539d2016-05-16 17:54:1342 downstream_throughput_kbps_ = other.downstream_throughput_kbps_;
Tarun Bansaldf224ab2018-01-03 17:27:3743 VerifyValueCorrectness();
44 DETACH_FROM_SEQUENCE(sequence_checker_);
tbansalb67539d2016-05-16 17:54:1345 return *this;
46}
47
tbansalbff2aec2016-07-25 18:28:5448bool NetworkQuality::operator==(const NetworkQuality& other) const {
Tarun Bansaldf224ab2018-01-03 17:27:3749 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
tbansalbff2aec2016-07-25 18:28:5450 return http_rtt_ == other.http_rtt_ &&
51 transport_rtt_ == other.transport_rtt_ &&
52 downstream_throughput_kbps_ == other.downstream_throughput_kbps_;
53}
54
tbansal2739868c2016-07-27 00:44:2055bool NetworkQuality::IsFaster(const NetworkQuality& other) const {
Tarun Bansaldf224ab2018-01-03 17:27:3756 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
tbansal2739868c2016-07-27 00:44:2057 return (http_rtt() == InvalidRTT() || other.http_rtt() == InvalidRTT() ||
58 http_rtt() <= other.http_rtt()) &&
59 (transport_rtt() == InvalidRTT() ||
60 other.transport_rtt() == InvalidRTT() ||
61 transport_rtt() <= other.transport_rtt()) &&
zhuoyu.qiand80590e52017-10-30 10:23:5162 (downstream_throughput_kbps() == INVALID_RTT_THROUGHPUT ||
63 other.downstream_throughput_kbps() == INVALID_RTT_THROUGHPUT ||
tbansal2739868c2016-07-27 00:44:2064 downstream_throughput_kbps() >= other.downstream_throughput_kbps());
65}
66
Tarun Bansaldf224ab2018-01-03 17:27:3767void NetworkQuality::VerifyValueCorrectness() const {
68 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
69 DCHECK_LE(INVALID_RTT_THROUGHPUT, http_rtt_.InMilliseconds());
70 DCHECK_LE(INVALID_RTT_THROUGHPUT, transport_rtt_.InMilliseconds());
71 DCHECK_LE(INVALID_RTT_THROUGHPUT, downstream_throughput_kbps_);
72}
73
Tsuyoshi Horo4f516be2022-06-14 11:53:1374} // namespace net::nqe::internal