| 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 // 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 <stdint.h> | 14 #include <stdint.h> |
| 15 | 15 |
| 16 #include <cmath> |
| 16 #include <ostream> | 17 #include <ostream> |
| 17 | 18 |
| 18 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
| 19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 20 #include "net/base/net_export.h" | 21 #include "net/base/net_export.h" |
| 21 | 22 |
| 22 #define QUICTIME_CONSTEXPR inline | 23 #define QUICTIME_CONSTEXPR inline |
| 23 | 24 |
| 24 namespace net { | 25 namespace net { |
| 25 | 26 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 inline QuicTime::Delta operator+(QuicTime::Delta lhs, QuicTime::Delta rhs) { | 241 inline QuicTime::Delta operator+(QuicTime::Delta lhs, QuicTime::Delta rhs) { |
| 241 return QuicTime::Delta(lhs.time_offset_ + rhs.time_offset_); | 242 return QuicTime::Delta(lhs.time_offset_ + rhs.time_offset_); |
| 242 } | 243 } |
| 243 inline QuicTime::Delta operator-(QuicTime::Delta lhs, QuicTime::Delta rhs) { | 244 inline QuicTime::Delta operator-(QuicTime::Delta lhs, QuicTime::Delta rhs) { |
| 244 return QuicTime::Delta(lhs.time_offset_ - rhs.time_offset_); | 245 return QuicTime::Delta(lhs.time_offset_ - rhs.time_offset_); |
| 245 } | 246 } |
| 246 inline QuicTime::Delta operator*(QuicTime::Delta lhs, int rhs) { | 247 inline QuicTime::Delta operator*(QuicTime::Delta lhs, int rhs) { |
| 247 return QuicTime::Delta(lhs.time_offset_ * rhs); | 248 return QuicTime::Delta(lhs.time_offset_ * rhs); |
| 248 } | 249 } |
| 249 inline QuicTime::Delta operator*(QuicTime::Delta lhs, double rhs) { | 250 inline QuicTime::Delta operator*(QuicTime::Delta lhs, double rhs) { |
| 250 return QuicTime::Delta(lhs.time_offset_ * rhs); | 251 return QuicTime::Delta( |
| 252 static_cast<int64_t>(std::llround(lhs.time_offset_ * rhs))); |
| 251 } | 253 } |
| 252 inline QuicTime::Delta operator*(int lhs, QuicTime::Delta rhs) { | 254 inline QuicTime::Delta operator*(int lhs, QuicTime::Delta rhs) { |
| 253 return rhs * lhs; | 255 return rhs * lhs; |
| 254 } | 256 } |
| 255 inline QuicTime::Delta operator*(double lhs, QuicTime::Delta rhs) { | 257 inline QuicTime::Delta operator*(double lhs, QuicTime::Delta rhs) { |
| 256 return rhs * lhs; | 258 return rhs * lhs; |
| 257 } | 259 } |
| 258 | 260 |
| 259 // Non-member arithmetic operators for QuicTime and QuicTime::Delta. | 261 // Non-member arithmetic operators for QuicTime and QuicTime::Delta. |
| 260 inline QuicTime operator+(QuicTime lhs, QuicTime::Delta rhs) { | 262 inline QuicTime operator+(QuicTime lhs, QuicTime::Delta rhs) { |
| 261 return QuicTime(lhs.time_ + rhs.time_offset_); | 263 return QuicTime(lhs.time_ + rhs.time_offset_); |
| 262 } | 264 } |
| 263 inline QuicTime operator-(QuicTime lhs, QuicTime::Delta rhs) { | 265 inline QuicTime operator-(QuicTime lhs, QuicTime::Delta rhs) { |
| 264 return QuicTime(lhs.time_ - rhs.time_offset_); | 266 return QuicTime(lhs.time_ - rhs.time_offset_); |
| 265 } | 267 } |
| 266 inline QuicTime::Delta operator-(QuicTime lhs, QuicTime rhs) { | 268 inline QuicTime::Delta operator-(QuicTime lhs, QuicTime rhs) { |
| 267 return QuicTime::Delta(lhs.time_ - rhs.time_); | 269 return QuicTime::Delta(lhs.time_ - rhs.time_); |
| 268 } | 270 } |
| 269 | 271 |
| 270 // Override stream output operator for gtest. | 272 // Override stream output operator for gtest. |
| 271 inline std::ostream& operator<<(std::ostream& output, | 273 inline std::ostream& operator<<(std::ostream& output, |
| 272 const QuicTime::Delta delta) { | 274 const QuicTime::Delta delta) { |
| 273 output << delta.ToDebugValue(); | 275 output << delta.ToDebugValue(); |
| 274 return output; | 276 return output; |
| 275 } | 277 } |
| 276 } // namespace net | 278 } // namespace net |
| 277 | 279 |
| 278 #endif // NET_QUIC_QUIC_TIME_H_ | 280 #endif // NET_QUIC_QUIC_TIME_H_ |
| OLD | NEW |