summaryrefslogtreecommitdiffstats
path: root/net/quic/quic_time.h
diff options
context:
space:
mode:
authorrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-11 14:48:10 +0000
committerrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-11 14:48:10 +0000
commit2a960e03abbb0c4225a0d2796a7d93db8a8e9343 (patch)
treee64760f33aba6bb7a679a224560d7b3186609b71 /net/quic/quic_time.h
parentffaa2a63665d31ba16ab63c2dc447e7543dc5002 (diff)
downloadchromium_src-2a960e03abbb0c4225a0d2796a7d93db8a8e9343.zip
chromium_src-2a960e03abbb0c4225a0d2796a7d93db8a8e9343.tar.gz
chromium_src-2a960e03abbb0c4225a0d2796a7d93db8a8e9343.tar.bz2
QuicTime integration
Merge internal change: 37669847 Review URL: https://chromiumcodereview.appspot.com/11293161 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167124 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/quic/quic_time.h')
-rw-r--r--net/quic/quic_time.h128
1 files changed, 128 insertions, 0 deletions
diff --git a/net/quic/quic_time.h b/net/quic/quic_time.h
new file mode 100644
index 0000000..becb3b2
--- /dev/null
+++ b/net/quic/quic_time.h
@@ -0,0 +1,128 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// QuicTime represents one point in time, stored in microsecond resolution.
+// This class wrapps the classes DateTimeO and DateTimeOffset.
+
+#ifndef NET_QUIC_QUIC_TIME_H_
+#define NET_QUIC_QUIC_TIME_H_
+
+#include "base/basictypes.h"
+#include "base/time.h"
+#include "net/base/net_export.h"
+
+namespace net {
+
+class NET_EXPORT_PRIVATE QuicTime {
+ public:
+ // A QuicTime::Delta represents the signed difference between two points in
+ // time, stored in microsecond resolution.
+ class NET_EXPORT_PRIVATE Delta {
+ public:
+ // Default constructor initiates to 0.
+ Delta();
+
+ explicit Delta(base::TimeDelta delta);
+
+ // Create a object with infinite offset time.
+ static Delta Infinite();
+
+ // Converts a number of milliseconds to a time offset.
+ static Delta FromMilliseconds(int64 ms);
+
+ // Converts a number of microseconds to a time offset.
+ static Delta FromMicroseconds(int64 us);
+
+ // Converts the time offset to a rounded number of milliseconds.
+ int64 ToMilliseconds() const;
+
+ // Converts the time offset to a rounded number of microseconds.
+ int64 ToMicroseconds() const;
+
+ Delta Add(const Delta& delta) const;
+
+ Delta Subtract(const Delta& delta) const;
+
+ bool IsZero() const;
+
+ bool IsInfinite() const;
+
+ private:
+ base::TimeDelta delta_;
+
+ friend class QuicTime;
+ };
+
+ // Default constructor initiates to 0.
+ QuicTime();
+
+ explicit QuicTime(base::TimeTicks ticks);
+
+ // Create a new QuicTime holding the time_ms.
+ static QuicTime FromMilliseconds(uint64 time_ms);
+
+ // Create a new QuicTime holding the time_us.
+ static QuicTime FromMicroseconds(uint64 time_us);
+
+ uint64 ToMilliseconds() const;
+
+ uint64 ToMicroseconds() const;
+
+ bool IsInitialized() const;
+
+ QuicTime Add(const Delta& delta) const;
+
+ QuicTime Subtract(const Delta& delta) const;
+
+ Delta Subtract(const QuicTime& other) const;
+
+ private:
+ base::TimeTicks ticks_;
+
+ friend class QuicClock;
+ friend class QuicClockTest;
+};
+
+// Non-member relational operators for QuicTime::Delta.
+inline bool operator==(QuicTime::Delta lhs, QuicTime::Delta rhs) {
+ return lhs.ToMicroseconds() == rhs.ToMicroseconds();
+}
+inline bool operator!=(QuicTime::Delta lhs, QuicTime::Delta rhs) {
+ return !(lhs == rhs);
+}
+inline bool operator<(QuicTime::Delta lhs, QuicTime::Delta rhs) {
+ return lhs.ToMicroseconds() < rhs.ToMicroseconds();
+}
+inline bool operator>(QuicTime::Delta lhs, QuicTime::Delta rhs) {
+ return rhs < lhs;
+}
+inline bool operator<=(QuicTime::Delta lhs, QuicTime::Delta rhs) {
+ return !(rhs < lhs);
+}
+inline bool operator>=(QuicTime::Delta lhs, QuicTime::Delta rhs) {
+ return !(lhs < rhs);
+}
+// Non-member relational operators for QuicTime.
+inline bool operator==(QuicTime lhs, QuicTime rhs) {
+ return lhs.ToMicroseconds() == rhs.ToMicroseconds();
+}
+inline bool operator!=(QuicTime lhs, QuicTime rhs) {
+ return !(lhs == rhs);
+}
+inline bool operator<(QuicTime lhs, QuicTime rhs) {
+ return lhs.ToMicroseconds() < rhs.ToMicroseconds();
+}
+inline bool operator>(QuicTime lhs, QuicTime rhs) {
+ return rhs < lhs;
+}
+inline bool operator<=(QuicTime lhs, QuicTime rhs) {
+ return !(rhs < lhs);
+}
+inline bool operator>=(QuicTime lhs, QuicTime rhs) {
+ return !(lhs < rhs);
+}
+
+} // namespace net
+
+#endif // NET_QUIC_QUIC_TIME_H_