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

Side by Side Diff: net/quic/quic_time.h

Issue 2132623002: Landing Recent QUIC changes until 2016-07-02 02:45 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing comment about RPCs Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « net/quic/quic_sustained_bandwidth_recorder_test.cc ('k') | net/quic/quic_time_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // QuicTime represents one point in time, stored in microsecond resolution. 5 // QuicTime represents one point in time, stored in microsecond resolution.
6 // QuicTime is monotonically increasing, even across system clock adjustments. 6 // QuicTime is monotonically increasing, even across system clock adjustments.
7 // The epoch (time 0) of QuicTime is unspecified. 7 // The epoch (time 0) of QuicTime is unspecified.
8 // 8 //
9 // This implementation wraps the classes base::TimeTicks and base::TimeDelta. 9 // This implementation wraps the classes base::TimeTicks and base::TimeDelta.
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 // Converts the time offset to a rounded number of seconds. 64 // Converts the time offset to a rounded number of seconds.
65 inline int64_t ToSeconds() const { return time_offset_ / 1000 / 1000; } 65 inline int64_t ToSeconds() const { return time_offset_ / 1000 / 1000; }
66 66
67 // Converts the time offset to a rounded number of milliseconds. 67 // Converts the time offset to a rounded number of milliseconds.
68 inline int64_t ToMilliseconds() const { return time_offset_ / 1000; } 68 inline int64_t ToMilliseconds() const { return time_offset_ / 1000; }
69 69
70 // Converts the time offset to a rounded number of microseconds. 70 // Converts the time offset to a rounded number of microseconds.
71 inline int64_t ToMicroseconds() const { return time_offset_; } 71 inline int64_t ToMicroseconds() const { return time_offset_; }
72 72
73 inline Delta Add(Delta delta) const WARN_UNUSED_RESULT {
74 return Delta(time_offset_ + delta.time_offset_);
75 }
76
77 inline Delta Subtract(Delta delta) const WARN_UNUSED_RESULT {
78 return Delta(time_offset_ - delta.time_offset_);
79 }
80
81 inline Delta Multiply(int i) const WARN_UNUSED_RESULT {
82 return Delta(time_offset_ * i);
83 }
84
85 inline Delta Multiply(double d) const WARN_UNUSED_RESULT {
86 return Delta(time_offset_ * d);
87 }
88
89 // Returns the larger delta of time1 and time2. 73 // Returns the larger delta of time1 and time2.
90 static inline Delta Max(Delta delta1, Delta delta2) { 74 static inline Delta Max(Delta delta1, Delta delta2) {
91 return delta1 < delta2 ? delta2 : delta1; 75 return delta1 < delta2 ? delta2 : delta1;
92 } 76 }
93 77
94 // Returns the smaller delta of time1 and time2. 78 // Returns the smaller delta of time1 and time2.
95 static inline Delta Min(Delta delta1, Delta delta2) { 79 static inline Delta Min(Delta delta1, Delta delta2) {
96 return delta1 < delta2 ? delta1 : delta2; 80 return delta1 < delta2 ? delta1 : delta2;
97 } 81 }
98 82
99 inline bool IsZero() const { return time_offset_ == 0; } 83 inline bool IsZero() const { return time_offset_ == 0; }
100 84
101 inline bool IsInfinite() const { 85 inline bool IsInfinite() const {
102 return time_offset_ == kQuicInfiniteTimeUs; 86 return time_offset_ == kQuicInfiniteTimeUs;
103 } 87 }
104 88
105 private: 89 private:
106 base::TimeDelta delta_; 90 base::TimeDelta delta_;
107 friend inline bool operator==(QuicTime::Delta lhs, QuicTime::Delta rhs); 91 friend inline bool operator==(QuicTime::Delta lhs, QuicTime::Delta rhs);
108 friend inline bool operator<(QuicTime::Delta lhs, QuicTime::Delta rhs); 92 friend inline bool operator<(QuicTime::Delta lhs, QuicTime::Delta rhs);
109 friend inline QuicTime::Delta operator<<(QuicTime::Delta lhs, size_t rhs); 93 friend inline QuicTime::Delta operator<<(QuicTime::Delta lhs, size_t rhs);
110 friend inline QuicTime::Delta operator>>(QuicTime::Delta lhs, size_t rhs); 94 friend inline QuicTime::Delta operator>>(QuicTime::Delta lhs, size_t rhs);
111 95
112 // Highest number of microseconds that DateTimeOffset can hold. 96 friend inline QuicTime::Delta operator+(QuicTime::Delta lhs,
113 static const int64_t kQuicInfiniteTimeUs = INT64_C(0x7fffffffffffffff) / 10; 97 QuicTime::Delta rhs);
98 friend inline QuicTime::Delta operator-(QuicTime::Delta lhs,
99 QuicTime::Delta rhs);
100 friend inline QuicTime::Delta operator*(QuicTime::Delta lhs, int rhs);
101 friend inline QuicTime::Delta operator*(QuicTime::Delta lhs, double rhs);
102
103 friend inline QuicTime operator+(QuicTime lhs, QuicTime::Delta rhs);
104 friend inline QuicTime operator-(QuicTime lhs, QuicTime::Delta rhs);
105 friend inline QuicTime::Delta operator-(QuicTime lhs, QuicTime rhs);
106
107 static const int64_t kQuicInfiniteTimeUs =
108 std::numeric_limits<int64_t>::max();
114 109
115 explicit QUICTIME_CONSTEXPR Delta(int64_t time_offset) 110 explicit QUICTIME_CONSTEXPR Delta(int64_t time_offset)
116 : time_offset_(time_offset) {} 111 : time_offset_(time_offset) {}
117 112
118 int64_t time_offset_; 113 int64_t time_offset_;
119 friend class QuicTime; 114 friend class QuicTime;
120 friend class QuicClock; 115 friend class QuicClock;
121 }; 116 };
122 117
123 explicit QuicTime(base::TimeTicks ticks) : time_(ticks.ToInternalValue()) {} 118 explicit QuicTime(base::TimeTicks ticks) : time_(ticks.ToInternalValue()) {}
(...skipping 13 matching lines...) Expand all
137 } 132 }
138 133
139 // Produce the internal value to be used when logging. This value 134 // Produce the internal value to be used when logging. This value
140 // represents the number of microseconds since some epoch. It may 135 // represents the number of microseconds since some epoch. It may
141 // be the UNIX epoch on some platforms. On others, it may 136 // be the UNIX epoch on some platforms. On others, it may
142 // be a CPU ticks based value. 137 // be a CPU ticks based value.
143 inline int64_t ToDebuggingValue() const { return time_; } 138 inline int64_t ToDebuggingValue() const { return time_; }
144 139
145 inline bool IsInitialized() const { return 0 != time_; } 140 inline bool IsInitialized() const { return 0 != time_; }
146 141
147 inline QuicTime Add(Delta delta) const WARN_UNUSED_RESULT {
148 return QuicTime(time_ + delta.time_offset_);
149 }
150
151 inline QuicTime Subtract(Delta delta) const WARN_UNUSED_RESULT {
152 return QuicTime(time_ - delta.time_offset_);
153 }
154
155 inline Delta Subtract(QuicTime other) const WARN_UNUSED_RESULT {
156 return Delta(time_ - other.time_);
157 }
158
159 private: 142 private:
160 friend inline bool operator==(QuicTime lhs, QuicTime rhs); 143 friend inline bool operator==(QuicTime lhs, QuicTime rhs);
161 friend inline bool operator<(QuicTime lhs, QuicTime rhs); 144 friend inline bool operator<(QuicTime lhs, QuicTime rhs);
162 friend class QuicClock; 145 friend inline QuicTime operator+(QuicTime lhs, QuicTime::Delta rhs);
163 friend class QuicClockTest; 146 friend inline QuicTime operator-(QuicTime lhs, QuicTime::Delta rhs);
147 friend inline QuicTime::Delta operator-(QuicTime lhs, QuicTime rhs);
164 148
165 explicit QUICTIME_CONSTEXPR QuicTime(int64_t time) : time_(time) {} 149 explicit QUICTIME_CONSTEXPR QuicTime(int64_t time) : time_(time) {}
166 150
167 int64_t time_; 151 int64_t time_;
168 }; 152 };
169 153
170 // A QuicWallTime represents an absolute time that is globally consistent. In 154 // A QuicWallTime represents an absolute time that is globally consistent. In
171 // practice, clock-skew means that comparing values from different machines 155 // practice, clock-skew means that comparing values from different machines
172 // requires some flexibility in interpretation. 156 // requires some flexibility.
173 class NET_EXPORT_PRIVATE QuicWallTime { 157 class NET_EXPORT_PRIVATE QuicWallTime {
174 public: 158 public:
175 // FromUNIXSeconds constructs a QuicWallTime from a count of the seconds 159 // FromUNIXSeconds constructs a QuicWallTime from a count of the seconds
176 // since the UNIX epoch. 160 // since the UNIX epoch.
177 static QUICTIME_CONSTEXPR QuicWallTime FromUNIXSeconds(uint64_t seconds) { 161 static QUICTIME_CONSTEXPR QuicWallTime FromUNIXSeconds(uint64_t seconds) {
178 return QuicWallTime(seconds * 1000000); 162 return QuicWallTime(seconds * 1000000);
179 } 163 }
180 164
181 static QUICTIME_CONSTEXPR QuicWallTime 165 static QUICTIME_CONSTEXPR QuicWallTime
182 FromUNIXMicroseconds(uint64_t microseconds) { 166 FromUNIXMicroseconds(uint64_t microseconds) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 inline bool operator>(QuicTime lhs, QuicTime rhs) { 240 inline bool operator>(QuicTime lhs, QuicTime rhs) {
257 return rhs < lhs; 241 return rhs < lhs;
258 } 242 }
259 inline bool operator<=(QuicTime lhs, QuicTime rhs) { 243 inline bool operator<=(QuicTime lhs, QuicTime rhs) {
260 return !(rhs < lhs); 244 return !(rhs < lhs);
261 } 245 }
262 inline bool operator>=(QuicTime lhs, QuicTime rhs) { 246 inline bool operator>=(QuicTime lhs, QuicTime rhs) {
263 return !(lhs < rhs); 247 return !(lhs < rhs);
264 } 248 }
265 249
250 // Non-member arithmetic operators for QuicTime::Delta.
251 inline QuicTime::Delta operator+(QuicTime::Delta lhs, QuicTime::Delta rhs) {
252 return QuicTime::Delta(lhs.time_offset_ + rhs.time_offset_);
253 }
254 inline QuicTime::Delta operator-(QuicTime::Delta lhs, QuicTime::Delta rhs) {
255 return QuicTime::Delta(lhs.time_offset_ - rhs.time_offset_);
256 }
257 inline QuicTime::Delta operator*(QuicTime::Delta lhs, int rhs) {
258 return QuicTime::Delta(lhs.time_offset_ * rhs);
259 }
260 inline QuicTime::Delta operator*(QuicTime::Delta lhs, double rhs) {
261 return QuicTime::Delta(lhs.time_offset_ * rhs);
262 }
263 inline QuicTime::Delta operator*(int lhs, QuicTime::Delta rhs) {
264 return rhs * lhs;
265 }
266 inline QuicTime::Delta operator*(double lhs, QuicTime::Delta rhs) {
267 return rhs * lhs;
268 }
269
270 // Non-member arithmetic operators for QuicTime and QuicTime::Delta.
271 inline QuicTime operator+(QuicTime lhs, QuicTime::Delta rhs) {
272 return QuicTime(lhs.time_ + rhs.time_offset_);
273 }
274 inline QuicTime operator-(QuicTime lhs, QuicTime::Delta rhs) {
275 return QuicTime(lhs.time_ - rhs.time_offset_);
276 }
277 inline QuicTime::Delta operator-(QuicTime lhs, QuicTime rhs) {
278 return QuicTime::Delta(lhs.time_ - rhs.time_);
279 }
280
266 } // namespace net 281 } // namespace net
267 282
268 #endif // NET_QUIC_QUIC_TIME_H_ 283 #endif // NET_QUIC_QUIC_TIME_H_
OLDNEW
« no previous file with comments | « net/quic/quic_sustained_bandwidth_recorder_test.cc ('k') | net/quic/quic_time_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698