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

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

Issue 1421853006: Landing Recent QUIC changes until: Fri Oct 30 22:23:58 2015 +0000 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comments Created 5 years, 1 month 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_stream_sequencer_test.cc ('k') | net/quic/quic_time.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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 friend inline bool operator==(QuicTime lhs, QuicTime rhs); 152 friend inline bool operator==(QuicTime lhs, QuicTime rhs);
153 friend inline bool operator<(QuicTime lhs, QuicTime rhs); 153 friend inline bool operator<(QuicTime lhs, QuicTime rhs);
154 friend class QuicClock; 154 friend class QuicClock;
155 friend class QuicClockTest; 155 friend class QuicClockTest;
156 156
157 explicit QUICTIME_CONSTEXPR QuicTime(int64 time) : time_(time) {} 157 explicit QUICTIME_CONSTEXPR QuicTime(int64 time) : time_(time) {}
158 158
159 int64 time_; 159 int64 time_;
160 }; 160 };
161 161
162 // A QuicWallTime represents an absolute time that is globally consistent. It 162 // A QuicWallTime represents an absolute time that is globally consistent. In
163 // provides, at most, one second granularity and, in practice, clock-skew means 163 // practice, clock-skew means that comparing values from different machines
164 // that you shouldn't even depend on that. 164 // requires some flexibility in interpretation.
165 class NET_EXPORT_PRIVATE QuicWallTime { 165 class NET_EXPORT_PRIVATE QuicWallTime {
166 public: 166 public:
167 // FromUNIXSeconds constructs a QuicWallTime from a count of the seconds 167 // FromUNIXSeconds constructs a QuicWallTime from a count of the seconds
168 // since the UNIX epoch. 168 // since the UNIX epoch.
169 static QUICTIME_CONSTEXPR QuicWallTime FromUNIXSeconds(uint64 seconds) { 169 static QUICTIME_CONSTEXPR QuicWallTime FromUNIXSeconds(uint64 seconds) {
170 return QuicWallTime(seconds); 170 return QuicWallTime(seconds * 1000000);
171 }
172
173 static QUICTIME_CONSTEXPR QuicWallTime
174 FromUNIXMicroseconds(uint64 microseconds) {
175 return QuicWallTime(microseconds);
171 } 176 }
172 177
173 // Zero returns a QuicWallTime set to zero. IsZero will return true for this 178 // Zero returns a QuicWallTime set to zero. IsZero will return true for this
174 // value. 179 // value.
175 static QUICTIME_CONSTEXPR QuicWallTime Zero() { return QuicWallTime(0); } 180 static QUICTIME_CONSTEXPR QuicWallTime Zero() { return QuicWallTime(0); }
176 181
177 // ToUNIXSeconds converts a QuicWallTime into a count of seconds since the 182 // Returns the number of seconds since the UNIX epoch.
178 // UNIX epoch.
179 uint64 ToUNIXSeconds() const; 183 uint64 ToUNIXSeconds() const;
184 // Returns the number of microseconds since the UNIX epoch.
185 uint64 ToUNIXMicroseconds() const;
180 186
181 bool IsAfter(QuicWallTime other) const; 187 bool IsAfter(QuicWallTime other) const;
182 bool IsBefore(QuicWallTime other) const; 188 bool IsBefore(QuicWallTime other) const;
183 189
184 // IsZero returns true if this object is the result of calling |Zero|. 190 // IsZero returns true if this object is the result of calling |Zero|.
185 bool IsZero() const; 191 bool IsZero() const;
186 192
187 // AbsoluteDifference returns the absolute value of the time difference 193 // AbsoluteDifference returns the absolute value of the time difference
188 // between |this| and |other|. 194 // between |this| and |other|.
189 QuicTime::Delta AbsoluteDifference(QuicWallTime other) const; 195 QuicTime::Delta AbsoluteDifference(QuicWallTime other) const;
190 196
191 // Add returns a new QuicWallTime that represents the time of |this| plus 197 // Add returns a new QuicWallTime that represents the time of |this| plus
192 // |delta|. 198 // |delta|.
193 QuicWallTime Add(QuicTime::Delta delta) const WARN_UNUSED_RESULT; 199 QuicWallTime Add(QuicTime::Delta delta) const WARN_UNUSED_RESULT;
194 200
195 // Subtract returns a new QuicWallTime that represents the time of |this| 201 // Subtract returns a new QuicWallTime that represents the time of |this|
196 // minus |delta|. 202 // minus |delta|.
197 QuicWallTime Subtract(QuicTime::Delta delta) const WARN_UNUSED_RESULT; 203 QuicWallTime Subtract(QuicTime::Delta delta) const WARN_UNUSED_RESULT;
198 204
199 private: 205 private:
200 explicit QUICTIME_CONSTEXPR QuicWallTime(uint64 seconds) 206 explicit QUICTIME_CONSTEXPR QuicWallTime(uint64 microseconds)
201 : seconds_(seconds) {} 207 : microseconds_(microseconds) {}
202 208
203 uint64 seconds_; 209 uint64 microseconds_;
204 }; 210 };
205 211
206 // Non-member relational operators for QuicTime::Delta. 212 // Non-member relational operators for QuicTime::Delta.
207 inline bool operator==(QuicTime::Delta lhs, QuicTime::Delta rhs) { 213 inline bool operator==(QuicTime::Delta lhs, QuicTime::Delta rhs) {
208 return lhs.time_offset_ == rhs.time_offset_; 214 return lhs.time_offset_ == rhs.time_offset_;
209 } 215 }
210 inline bool operator!=(QuicTime::Delta lhs, QuicTime::Delta rhs) { 216 inline bool operator!=(QuicTime::Delta lhs, QuicTime::Delta rhs) {
211 return !(lhs == rhs); 217 return !(lhs == rhs);
212 } 218 }
213 inline bool operator<(QuicTime::Delta lhs, QuicTime::Delta rhs) { 219 inline bool operator<(QuicTime::Delta lhs, QuicTime::Delta rhs) {
(...skipping 24 matching lines...) Expand all
238 inline bool operator<=(QuicTime lhs, QuicTime rhs) { 244 inline bool operator<=(QuicTime lhs, QuicTime rhs) {
239 return !(rhs < lhs); 245 return !(rhs < lhs);
240 } 246 }
241 inline bool operator>=(QuicTime lhs, QuicTime rhs) { 247 inline bool operator>=(QuicTime lhs, QuicTime rhs) {
242 return !(lhs < rhs); 248 return !(lhs < rhs);
243 } 249 }
244 250
245 } // namespace net 251 } // namespace net
246 252
247 #endif // NET_QUIC_QUIC_TIME_H_ 253 #endif // NET_QUIC_QUIC_TIME_H_
OLDNEW
« no previous file with comments | « net/quic/quic_stream_sequencer_test.cc ('k') | net/quic/quic_time.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698