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 #include "net/quic/quic_time.h" | 5 #include "net/quic/quic_time.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 | 12 |
13 uint64 QuicWallTime::ToUNIXSeconds() const { | 13 uint64 QuicWallTime::ToUNIXSeconds() const { |
14 return seconds_; | 14 return microseconds_ / 1000000; |
| 15 } |
| 16 |
| 17 uint64 QuicWallTime::ToUNIXMicroseconds() const { |
| 18 return microseconds_; |
15 } | 19 } |
16 | 20 |
17 bool QuicWallTime::IsAfter(QuicWallTime other) const { | 21 bool QuicWallTime::IsAfter(QuicWallTime other) const { |
18 return seconds_ > other.seconds_; | 22 return microseconds_ > other.microseconds_; |
19 } | 23 } |
20 | 24 |
21 bool QuicWallTime::IsBefore(QuicWallTime other) const { | 25 bool QuicWallTime::IsBefore(QuicWallTime other) const { |
22 return seconds_ < other.seconds_; | 26 return microseconds_ < other.microseconds_; |
23 } | 27 } |
24 | 28 |
25 bool QuicWallTime::IsZero() const { | 29 bool QuicWallTime::IsZero() const { |
26 return seconds_ == 0; | 30 return microseconds_ == 0; |
27 } | 31 } |
28 | 32 |
29 QuicTime::Delta QuicWallTime::AbsoluteDifference(QuicWallTime other) const { | 33 QuicTime::Delta QuicWallTime::AbsoluteDifference(QuicWallTime other) const { |
30 uint64 d; | 34 uint64 d; |
31 | 35 |
32 if (seconds_ > other.seconds_) { | 36 if (microseconds_ > other.microseconds_) { |
33 d = seconds_ - other.seconds_; | 37 d = microseconds_ - other.microseconds_; |
34 } else { | 38 } else { |
35 d = other.seconds_ - seconds_; | 39 d = other.microseconds_ - microseconds_; |
36 } | 40 } |
37 | 41 |
38 if (d > static_cast<uint64>(kint64max)) { | 42 if (d > static_cast<uint64>(kint64max)) { |
39 d = kint64max; | 43 d = kint64max; |
40 } | 44 } |
41 return QuicTime::Delta::FromSeconds(d); | 45 return QuicTime::Delta::FromMicroseconds(d); |
42 } | 46 } |
43 | 47 |
44 QuicWallTime QuicWallTime::Add(QuicTime::Delta delta) const { | 48 QuicWallTime QuicWallTime::Add(QuicTime::Delta delta) const { |
45 uint64 seconds = seconds_ + delta.ToSeconds(); | 49 uint64 microseconds = microseconds_ + delta.ToMicroseconds(); |
46 if (seconds < seconds_) { | 50 if (microseconds < microseconds_) { |
47 seconds = kuint64max; | 51 microseconds = kuint64max; |
48 } | 52 } |
49 return QuicWallTime(seconds); | 53 return QuicWallTime(microseconds); |
50 } | 54 } |
51 | 55 |
52 // TODO(ianswett) Test this. | 56 // TODO(ianswett) Test this. |
53 QuicWallTime QuicWallTime::Subtract(QuicTime::Delta delta) const { | 57 QuicWallTime QuicWallTime::Subtract(QuicTime::Delta delta) const { |
54 uint64 seconds = seconds_ - delta.ToSeconds(); | 58 uint64 microseconds = microseconds_ - delta.ToMicroseconds(); |
55 if (seconds > seconds_) { | 59 if (microseconds > microseconds_) { |
56 seconds = 0; | 60 microseconds = 0; |
57 } | 61 } |
58 return QuicWallTime(seconds); | 62 return QuicWallTime(microseconds); |
59 } | 63 } |
60 | 64 |
61 } // namespace net | 65 } // namespace net |
OLD | NEW |