1 // Copyright (c) 2012 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.
5 // QuicBandwidth represents a bandwidth, stored in bits per second resolution.
7 #ifndef NET_QUIC_QUIC_BANDWIDTH_H_
8 #define NET_QUIC_QUIC_BANDWIDTH_H_
10 #include "base/basictypes.h"
11 #include "net/quic/quic_time.h"
15 typedef uint64 QuicByteCount
;
17 class NET_EXPORT_PRIVATE QuicBandwidth
{
19 // Creates a new QuicBandwidth with an internal value of 0.
20 static QuicBandwidth
Zero();
22 // Create a new QuicBandwidth holding the bits per second.
23 static QuicBandwidth
FromBitsPerSecond(int64 bits_per_second
);
25 // Create a new QuicBandwidth holding the kilo bits per second.
26 static QuicBandwidth
FromKBitsPerSecond(int64 k_bits_per_second
);
28 // Create a new QuicBandwidth holding the bytes per second.
29 static QuicBandwidth
FromBytesPerSecond(int64 bytes_per_second
);
31 // Create a new QuicBandwidth holding the kilo bytes per second.
32 static QuicBandwidth
FromKBytesPerSecond(int64 k_bytes_per_second
);
34 // Create a new QuicBandwidth based on the bytes per the elapsed delta.
35 static QuicBandwidth
FromBytesAndTimeDelta(QuicByteCount bytes
,
36 QuicTime::Delta delta
);
38 int64
ToBitsPerSecond() const;
40 int64
ToKBitsPerSecond() const;
42 int64
ToBytesPerSecond() const;
44 int64
ToKBytesPerSecond() const;
46 QuicByteCount
ToBytesPerPeriod(QuicTime::Delta time_period
) const;
48 int64
ToKBytesPerPeriod(QuicTime::Delta time_period
) const;
52 QuicBandwidth
Add(const QuicBandwidth
& delta
) const;
54 QuicBandwidth
Subtract(const QuicBandwidth
& delta
) const;
56 QuicBandwidth
Scale(float scale_factor
) const;
58 QuicTime::Delta
TransferTime(QuicByteCount bytes
) const;
61 explicit QuicBandwidth(int64 bits_per_second
);
62 int64 bits_per_second_
;
65 // Non-member relational operators for QuicBandwidth.
66 inline bool operator==(QuicBandwidth lhs
, QuicBandwidth rhs
) {
67 return lhs
.ToBitsPerSecond() == rhs
.ToBitsPerSecond();
69 inline bool operator!=(QuicBandwidth lhs
, QuicBandwidth rhs
) {
72 inline bool operator<(QuicBandwidth lhs
, QuicBandwidth rhs
) {
73 return lhs
.ToBitsPerSecond() < rhs
.ToBitsPerSecond();
75 inline bool operator>(QuicBandwidth lhs
, QuicBandwidth rhs
) {
78 inline bool operator<=(QuicBandwidth lhs
, QuicBandwidth rhs
) {
81 inline bool operator>=(QuicBandwidth lhs
, QuicBandwidth rhs
) {
86 #endif // NET_QUIC_QUIC_BANDWIDTH_H_