| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 
|  | 2 // Use of this source code is governed by a BSD-style license that can be | 
|  | 3 // found in the LICENSE file. | 
|  | 4 | 
|  | 5 #ifndef WTF_Time_h | 
|  | 6 #define WTF_Time_h | 
|  | 7 | 
|  | 8 #include "base/time/time.h" | 
|  | 9 #include "wtf/CurrentTime.h" | 
|  | 10 | 
|  | 11 namespace WTF { | 
|  | 12 // Provides thin wrappers around the following basic time types from | 
|  | 13 // base/time package: | 
|  | 14 // | 
|  | 15 //  - WTF::TimeDelta is an alias for base::TimeDelta and represents a duration | 
|  | 16 //    of time. | 
|  | 17 //  - WTF::TimeTicks wraps base::TimeTicks and represents a monotonic time | 
|  | 18 //    value. | 
|  | 19 //  - WTF::Time wraps base::Time and represents a wall time value. | 
|  | 20 // | 
|  | 21 // For usage guideline please see the documentation in base/time/time.h | 
|  | 22 | 
|  | 23 using TimeDelta = base::TimeDelta; | 
|  | 24 | 
|  | 25 namespace internal { | 
|  | 26 | 
|  | 27 template <class WrappedTimeType> | 
|  | 28 class TimeWrapper { | 
|  | 29  public: | 
|  | 30   TimeWrapper() {} | 
|  | 31 | 
|  | 32   bool isNull() const { return m_value.is_null(); } | 
|  | 33 | 
|  | 34   static TimeWrapper Now() { | 
|  | 35     if (WTF::getTimeFunctionForTesting()) { | 
|  | 36       double seconds = (WTF::getTimeFunctionForTesting())(); | 
|  | 37       return TimeWrapper() + TimeDelta::FromSecondsD(seconds); | 
|  | 38     } | 
|  | 39     return TimeWrapper(WrappedTimeType::Now()); | 
|  | 40   } | 
|  | 41 | 
|  | 42   int64_t ToInternalValueForTesting() const { | 
|  | 43     return m_value.ToInternalValue(); | 
|  | 44   } | 
|  | 45 | 
|  | 46   TimeWrapper& operator=(TimeWrapper other) { | 
|  | 47     m_value = other.m_value; | 
|  | 48     return *this; | 
|  | 49   } | 
|  | 50 | 
|  | 51   TimeDelta operator-(TimeWrapper other) const { | 
|  | 52     return m_value - other.m_value; | 
|  | 53   } | 
|  | 54 | 
|  | 55   TimeWrapper operator+(TimeDelta delta) const { | 
|  | 56     return TimeWrapper(m_value + delta); | 
|  | 57   } | 
|  | 58   TimeWrapper operator-(TimeDelta delta) const { | 
|  | 59     return TimeWrapper(m_value - delta); | 
|  | 60   } | 
|  | 61 | 
|  | 62   TimeWrapper& operator+=(TimeDelta delta) { | 
|  | 63     m_value += delta; | 
|  | 64     return *this; | 
|  | 65   } | 
|  | 66   TimeWrapper& operator-=(TimeDelta delta) { | 
|  | 67     m_value -= delta; | 
|  | 68     return *this; | 
|  | 69   } | 
|  | 70 | 
|  | 71   bool operator==(TimeWrapper other) const { return m_value == other.m_value; } | 
|  | 72   bool operator!=(TimeWrapper other) const { return m_value != other.m_value; } | 
|  | 73   bool operator<(TimeWrapper other) const { return m_value < other.m_value; } | 
|  | 74   bool operator<=(TimeWrapper other) const { return m_value <= other.m_value; } | 
|  | 75   bool operator>(TimeWrapper other) const { return m_value > other.m_value; } | 
|  | 76   bool operator>=(TimeWrapper other) const { return m_value >= other.m_value; } | 
|  | 77 | 
|  | 78  private: | 
|  | 79   WrappedTimeType m_value; | 
|  | 80   TimeWrapper(WrappedTimeType value) : m_value(value) {} | 
|  | 81 }; | 
|  | 82 | 
|  | 83 }  // namespace internal | 
|  | 84 | 
|  | 85 using Time = internal::TimeWrapper<base::Time>; | 
|  | 86 using TimeTicks = internal::TimeWrapper<base::TimeTicks>; | 
|  | 87 | 
|  | 88 }  // namespace WTF | 
|  | 89 | 
|  | 90 using WTF::Time; | 
|  | 91 using WTF::TimeDelta; | 
|  | 92 using WTF::TimeTicks; | 
|  | 93 | 
|  | 94 #endif  // Time_h | 
| OLD | NEW | 
|---|