Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Unified Diff: net/quic/core/quic_bandwidth.h

Issue 2916033003: Landing Recent QUIC changes until 03:18 AM, May 28, UTC (Closed)
Patch Set: A few more EXPORTs. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/core/frames/quic_frames_test.cc ('k') | net/quic/core/quic_bandwidth.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/core/quic_bandwidth.h
diff --git a/net/quic/core/quic_bandwidth.h b/net/quic/core/quic_bandwidth.h
index 4e11d5f88aa9190934bde7974fa3acc290fc376b..e710b2edb301788f2074595fbf6b3a3bb37cfb19 100644
--- a/net/quic/core/quic_bandwidth.h
+++ b/net/quic/core/quic_bandwidth.h
@@ -9,9 +9,11 @@
#include <cmath>
#include <cstdint>
+#include <limits>
#include <ostream>
#include "base/compiler_specific.h"
+#include "net/quic/core/quic_constants.h"
#include "net/quic/core/quic_time.h"
#include "net/quic/core/quic_types.h"
#include "net/quic/platform/api/quic_export.h"
@@ -21,47 +23,75 @@ namespace net {
class QUIC_EXPORT_PRIVATE QuicBandwidth {
public:
// Creates a new QuicBandwidth with an internal value of 0.
- static QuicBandwidth Zero();
+ static constexpr QuicBandwidth Zero() { return QuicBandwidth(0); }
// Creates a new QuicBandwidth with an internal value of INT64_MAX.
- static QuicBandwidth Infinite();
+ static constexpr QuicBandwidth Infinite() {
+ return QuicBandwidth(std::numeric_limits<int64_t>::max());
+ }
// Create a new QuicBandwidth holding the bits per second.
- static QuicBandwidth FromBitsPerSecond(int64_t bits_per_second);
+ static constexpr QuicBandwidth FromBitsPerSecond(int64_t bits_per_second) {
+ return QuicBandwidth(bits_per_second);
+ }
// Create a new QuicBandwidth holding the kilo bits per second.
- static QuicBandwidth FromKBitsPerSecond(int64_t k_bits_per_second);
+ static constexpr QuicBandwidth FromKBitsPerSecond(int64_t k_bits_per_second) {
+ return QuicBandwidth(k_bits_per_second * 1000);
+ }
// Create a new QuicBandwidth holding the bytes per second.
- static QuicBandwidth FromBytesPerSecond(int64_t bytes_per_second);
+ static constexpr QuicBandwidth FromBytesPerSecond(int64_t bytes_per_second) {
+ return QuicBandwidth(bytes_per_second * 8);
+ }
// Create a new QuicBandwidth holding the kilo bytes per second.
- static QuicBandwidth FromKBytesPerSecond(int64_t k_bytes_per_second);
+ static constexpr QuicBandwidth FromKBytesPerSecond(
+ int64_t k_bytes_per_second) {
+ return QuicBandwidth(k_bytes_per_second * 8000);
+ }
// Create a new QuicBandwidth based on the bytes per the elapsed delta.
- static QuicBandwidth FromBytesAndTimeDelta(QuicByteCount bytes,
- QuicTime::Delta delta);
+ static inline QuicBandwidth FromBytesAndTimeDelta(QuicByteCount bytes,
+ QuicTime::Delta delta) {
+ return QuicBandwidth((bytes * kNumMicrosPerSecond) /
+ delta.ToMicroseconds() * 8);
+ }
- int64_t ToBitsPerSecond() const;
+ inline int64_t ToBitsPerSecond() const { return bits_per_second_; }
- int64_t ToKBitsPerSecond() const;
+ inline int64_t ToKBitsPerSecond() const { return bits_per_second_ / 1000; }
- int64_t ToBytesPerSecond() const;
+ inline int64_t ToBytesPerSecond() const { return bits_per_second_ / 8; }
- int64_t ToKBytesPerSecond() const;
+ inline int64_t ToKBytesPerSecond() const { return bits_per_second_ / 8000; }
- QuicByteCount ToBytesPerPeriod(QuicTime::Delta time_period) const;
+ inline QuicByteCount ToBytesPerPeriod(QuicTime::Delta time_period) const {
+ return ToBytesPerSecond() * time_period.ToMicroseconds() /
+ kNumMicrosPerSecond;
+ }
- int64_t ToKBytesPerPeriod(QuicTime::Delta time_period) const;
+ inline int64_t ToKBytesPerPeriod(QuicTime::Delta time_period) const {
+ return ToKBytesPerSecond() * time_period.ToMicroseconds() /
+ kNumMicrosPerSecond;
+ }
- bool IsZero() const;
+ inline bool IsZero() const { return bits_per_second_ == 0; }
- QuicTime::Delta TransferTime(QuicByteCount bytes) const;
+ inline QuicTime::Delta TransferTime(QuicByteCount bytes) const {
+ if (bits_per_second_ == 0) {
+ return QuicTime::Delta::Zero();
+ }
+ return QuicTime::Delta::FromMicroseconds(bytes * 8 * kNumMicrosPerSecond /
+ bits_per_second_);
+ }
std::string ToDebugValue() const;
private:
- explicit QuicBandwidth(int64_t bits_per_second);
+ explicit constexpr QuicBandwidth(int64_t bits_per_second)
+ : bits_per_second_(bits_per_second >= 0 ? bits_per_second : 0) {}
+
int64_t bits_per_second_;
friend QuicBandwidth operator+(QuicBandwidth lhs, QuicBandwidth rhs);
« no previous file with comments | « net/quic/core/frames/quic_frames_test.cc ('k') | net/quic/core/quic_bandwidth.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698