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