blob: aa7a6cc28511b85c0150120a9547b9750ce86c7d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// QuicBandwidth represents a bandwidth, stored in bits per second resolution.
#ifndef NET_QUIC_QUIC_BANDWIDTH_H_
#define NET_QUIC_QUIC_BANDWIDTH_H_
#include "base/basictypes.h"
#include "net/quic/quic_time.h"
namespace net {
typedef uint64 QuicByteCount;
typedef uint64 QuicPacketCount;
class NET_EXPORT_PRIVATE QuicBandwidth {
public:
// Creates a new QuicBandwidth with an internal value of 0.
static QuicBandwidth Zero();
// Create a new QuicBandwidth holding the bits per second.
static QuicBandwidth FromBitsPerSecond(int64 bits_per_second);
// Create a new QuicBandwidth holding the kilo bits per second.
static QuicBandwidth FromKBitsPerSecond(int64 k_bits_per_second);
// Create a new QuicBandwidth holding the bytes per second.
static QuicBandwidth FromBytesPerSecond(int64 bytes_per_second);
// Create a new QuicBandwidth holding the kilo bytes per second.
static QuicBandwidth FromKBytesPerSecond(int64 k_bytes_per_second);
// Create a new QuicBandwidth based on the bytes per the elapsed delta.
static QuicBandwidth FromBytesAndTimeDelta(QuicByteCount bytes,
QuicTime::Delta delta);
int64 ToBitsPerSecond() const;
int64 ToKBitsPerSecond() const;
int64 ToBytesPerSecond() const;
int64 ToKBytesPerSecond() const;
QuicByteCount ToBytesPerPeriod(QuicTime::Delta time_period) const;
int64 ToKBytesPerPeriod(QuicTime::Delta time_period) const;
bool IsZero() const;
QuicBandwidth Add(const QuicBandwidth& delta) const;
QuicBandwidth Subtract(const QuicBandwidth& delta) const;
QuicBandwidth Scale(float scale_factor) const;
QuicTime::Delta TransferTime(QuicByteCount bytes) const;
private:
explicit QuicBandwidth(int64 bits_per_second);
int64 bits_per_second_;
};
// Non-member relational operators for QuicBandwidth.
inline bool operator==(QuicBandwidth lhs, QuicBandwidth rhs) {
return lhs.ToBitsPerSecond() == rhs.ToBitsPerSecond();
}
inline bool operator!=(QuicBandwidth lhs, QuicBandwidth rhs) {
return !(lhs == rhs);
}
inline bool operator<(QuicBandwidth lhs, QuicBandwidth rhs) {
return lhs.ToBitsPerSecond() < rhs.ToBitsPerSecond();
}
inline bool operator>(QuicBandwidth lhs, QuicBandwidth rhs) {
return rhs < lhs;
}
inline bool operator<=(QuicBandwidth lhs, QuicBandwidth rhs) {
return !(rhs < lhs);
}
inline bool operator>=(QuicBandwidth lhs, QuicBandwidth rhs) {
return !(lhs < rhs);
}
} // namespace net
#endif // NET_QUIC_QUIC_BANDWIDTH_H_
|