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

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

Issue 14816006: Land Recent QUIC changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing NET_PRIVATE_EXPORT to QuicWallTime Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_session.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
11 #ifndef NET_QUIC_QUIC_TIME_H_ 11 #ifndef NET_QUIC_QUIC_TIME_H_
12 #define NET_QUIC_QUIC_TIME_H_ 12 #define NET_QUIC_QUIC_TIME_H_
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "net/base/net_export.h" 16 #include "net/base/net_export.h"
17 17
18 namespace net { 18 namespace net {
19 19
20 static const uint64 kNumMicrosPerSecond = base::Time::kMicrosecondsPerSecond; 20 static const uint64 kNumMicrosPerSecond = base::Time::kMicrosecondsPerSecond;
21 21
22 // A QuicTime is a purely relative time. QuicTime values from different clocks
23 // cannot be compared to each other. If you need an absolute time, see
24 // QuicWallTime, below.
22 class NET_EXPORT_PRIVATE QuicTime { 25 class NET_EXPORT_PRIVATE QuicTime {
23 public: 26 public:
24 // A QuicTime::Delta represents the signed difference between two points in 27 // A QuicTime::Delta represents the signed difference between two points in
25 // time, stored in microsecond resolution. 28 // time, stored in microsecond resolution.
26 class NET_EXPORT_PRIVATE Delta { 29 class NET_EXPORT_PRIVATE Delta {
27 public: 30 public:
28 explicit Delta(base::TimeDelta delta); 31 explicit Delta(base::TimeDelta delta);
29 32
30 // Create a object with an offset of 0. 33 // Create a object with an offset of 0.
31 static Delta Zero(); 34 static Delta Zero();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 private: 92 private:
90 friend bool operator==(QuicTime lhs, QuicTime rhs); 93 friend bool operator==(QuicTime lhs, QuicTime rhs);
91 friend bool operator<(QuicTime lhs, QuicTime rhs); 94 friend bool operator<(QuicTime lhs, QuicTime rhs);
92 95
93 friend class QuicClock; 96 friend class QuicClock;
94 friend class QuicClockTest; 97 friend class QuicClockTest;
95 98
96 base::TimeTicks ticks_; 99 base::TimeTicks ticks_;
97 }; 100 };
98 101
102 // A QuicWallTime represents an absolute time that is globally consistent. It
103 // provides, at most, one second granularity and, in practice, clock-skew means
104 // that you shouldn't even depend on that.
105 class NET_EXPORT_PRIVATE QuicWallTime {
106 public:
107 // FromUNIXSeconds constructs a QuicWallTime from a count of the seconds
108 // since the UNIX epoch.
109 static QuicWallTime FromUNIXSeconds(uint64 seconds);
110
111 // ToUNIXSeconds converts a QuicWallTime into a count of seconds since the
112 // UNIX epoch.
113 uint64 ToUNIXSeconds() const;
114
115 bool IsAfter(QuicWallTime other) const;
116 bool IsBefore(QuicWallTime other) const;
117
118 // AbsoluteDifference returns the absolute value of the time difference
119 // between |this| and |other|.
120 QuicTime::Delta AbsoluteDifference(QuicWallTime other) const;
121
122 // Add returns a new QuicWallTime that represents the time of |this| plus
123 // |delta|.
124 QuicWallTime Add(QuicTime::Delta delta) const;
125
126 // Subtract returns a new QuicWallTime that represents the time of |this|
127 // minus |delta|.
128 QuicWallTime Subtract(QuicTime::Delta delta) const;
129
130 private:
131 explicit QuicWallTime(uint64 seconds);
132
133 uint64 seconds_;
134 };
135
99 // Non-member relational operators for QuicTime::Delta. 136 // Non-member relational operators for QuicTime::Delta.
100 inline bool operator==(QuicTime::Delta lhs, QuicTime::Delta rhs) { 137 inline bool operator==(QuicTime::Delta lhs, QuicTime::Delta rhs) {
101 return lhs.ToMicroseconds() == rhs.ToMicroseconds(); 138 return lhs.ToMicroseconds() == rhs.ToMicroseconds();
102 } 139 }
103 inline bool operator!=(QuicTime::Delta lhs, QuicTime::Delta rhs) { 140 inline bool operator!=(QuicTime::Delta lhs, QuicTime::Delta rhs) {
104 return !(lhs == rhs); 141 return !(lhs == rhs);
105 } 142 }
106 inline bool operator<(QuicTime::Delta lhs, QuicTime::Delta rhs) { 143 inline bool operator<(QuicTime::Delta lhs, QuicTime::Delta rhs) {
107 return lhs.ToMicroseconds() < rhs.ToMicroseconds(); 144 return lhs.ToMicroseconds() < rhs.ToMicroseconds();
108 } 145 }
(...skipping 22 matching lines...) Expand all
131 inline bool operator<=(QuicTime lhs, QuicTime rhs) { 168 inline bool operator<=(QuicTime lhs, QuicTime rhs) {
132 return !(rhs < lhs); 169 return !(rhs < lhs);
133 } 170 }
134 inline bool operator>=(QuicTime lhs, QuicTime rhs) { 171 inline bool operator>=(QuicTime lhs, QuicTime rhs) {
135 return !(lhs < rhs); 172 return !(lhs < rhs);
136 } 173 }
137 174
138 } // namespace net 175 } // namespace net
139 176
140 #endif // NET_QUIC_QUIC_TIME_H_ 177 #endif // NET_QUIC_QUIC_TIME_H_
OLDNEW
« no previous file with comments | « net/quic/quic_session.cc ('k') | net/quic/quic_time.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698