Pull the new r369476 of base library from Chromium
The merge was done against r369476 which corresponds to git commit
0471d0e2e2ef4a544a63481a389e1df33ea7c00a of Jan 14, 2016
Change-Id: Ie6894cf65424cc5ad115110faccd51602b2d1234
Reviewed-on: https://weave-review.googlesource.com/2225
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
diff --git a/third_party/chromium/base/time/time.cc b/third_party/chromium/base/time/time.cc
index 7006407..0dc892a 100644
--- a/third_party/chromium/base/time/time.cc
+++ b/third_party/chromium/base/time/time.cc
@@ -11,6 +11,7 @@
#include <sstream>
#include "base/logging.h"
+#include "base/macros.h"
#include "base/strings/stringprintf.h"
namespace base {
@@ -19,7 +20,7 @@
// static
TimeDelta TimeDelta::Max() {
- return TimeDelta(std::numeric_limits<int64>::max());
+ return TimeDelta(std::numeric_limits<int64_t>::max());
}
int TimeDelta::InDays() const {
@@ -54,10 +55,10 @@
return static_cast<double>(delta_) / Time::kMicrosecondsPerSecond;
}
-int64 TimeDelta::InSeconds() const {
+int64_t TimeDelta::InSeconds() const {
if (is_max()) {
// Preserve max to prevent overflow.
- return std::numeric_limits<int64>::max();
+ return std::numeric_limits<int64_t>::max();
}
return delta_ / Time::kMicrosecondsPerSecond;
}
@@ -70,46 +71,46 @@
return static_cast<double>(delta_) / Time::kMicrosecondsPerMillisecond;
}
-int64 TimeDelta::InMilliseconds() const {
+int64_t TimeDelta::InMilliseconds() const {
if (is_max()) {
// Preserve max to prevent overflow.
- return std::numeric_limits<int64>::max();
+ return std::numeric_limits<int64_t>::max();
}
return delta_ / Time::kMicrosecondsPerMillisecond;
}
-int64 TimeDelta::InMillisecondsRoundedUp() const {
+int64_t TimeDelta::InMillisecondsRoundedUp() const {
if (is_max()) {
// Preserve max to prevent overflow.
- return std::numeric_limits<int64>::max();
+ return std::numeric_limits<int64_t>::max();
}
return (delta_ + Time::kMicrosecondsPerMillisecond - 1) /
Time::kMicrosecondsPerMillisecond;
}
-int64 TimeDelta::InMicroseconds() const {
+int64_t TimeDelta::InMicroseconds() const {
if (is_max()) {
// Preserve max to prevent overflow.
- return std::numeric_limits<int64>::max();
+ return std::numeric_limits<int64_t>::max();
}
return delta_;
}
namespace time_internal {
-int64 SaturatedAdd(TimeDelta delta, int64 value) {
- CheckedNumeric<int64> rv(delta.delta_);
+int64_t SaturatedAdd(TimeDelta delta, int64_t value) {
+ CheckedNumeric<int64_t> rv(delta.delta_);
rv += value;
return FromCheckedNumeric(rv);
}
-int64 SaturatedSub(TimeDelta delta, int64 value) {
- CheckedNumeric<int64> rv(delta.delta_);
+int64_t SaturatedSub(TimeDelta delta, int64_t value) {
+ CheckedNumeric<int64_t> rv(delta.delta_);
rv -= value;
return FromCheckedNumeric(rv);
}
-int64 FromCheckedNumeric(const CheckedNumeric<int64> value) {
+int64_t FromCheckedNumeric(const CheckedNumeric<int64_t> value) {
if (value.IsValid())
return value.ValueUnsafe();
@@ -117,7 +118,7 @@
// is. Instead, return max/(-max), which is something that clients can reason
// about.
// TODO(rvargas) crbug.com/332611: don't use internal values.
- int64 limit = std::numeric_limits<int64>::max();
+ int64_t limit = std::numeric_limits<int64_t>::max();
if (value.validity() == internal::RANGE_UNDERFLOW)
limit = -limit;
return value.ValueOrDefault(limit);
@@ -133,7 +134,7 @@
// static
Time Time::Max() {
- return Time(std::numeric_limits<int64>::max());
+ return Time(std::numeric_limits<int64_t>::max());
}
// static
@@ -142,7 +143,7 @@
return Time(); // Preserve 0 so we can tell it doesn't exist.
if (tt == std::numeric_limits<time_t>::max())
return Max();
- return Time((tt * kMicrosecondsPerSecond) + kTimeTToMicrosecondsOffset);
+ return Time(kTimeTToMicrosecondsOffset) + TimeDelta::FromSeconds(tt);
}
time_t Time::ToTimeT() const {
@@ -152,7 +153,7 @@
// Preserve max without offset to prevent overflow.
return std::numeric_limits<time_t>::max();
}
- if (std::numeric_limits<int64>::max() - kTimeTToMicrosecondsOffset <= us_) {
+ if (std::numeric_limits<int64_t>::max() - kTimeTToMicrosecondsOffset <= us_) {
DLOG(WARNING) << "Overflow when converting base::Time with internal " <<
"value " << us_ << " to time_t.";
return std::numeric_limits<time_t>::max();
@@ -164,11 +165,7 @@
Time Time::FromDoubleT(double dt) {
if (dt == 0 || std::isnan(dt))
return Time(); // Preserve 0 so we can tell it doesn't exist.
- if (dt == std::numeric_limits<double>::infinity())
- return Max();
- return Time(static_cast<int64>((dt *
- static_cast<double>(kMicrosecondsPerSecond)) +
- kTimeTToMicrosecondsOffset));
+ return Time(kTimeTToMicrosecondsOffset) + TimeDelta::FromSecondsD(dt);
}
double Time::ToDoubleT() const {
@@ -195,10 +192,8 @@
Time Time::FromJsTime(double ms_since_epoch) {
// The epoch is a valid time, so this constructor doesn't interpret
// 0 as the null time.
- if (ms_since_epoch == std::numeric_limits<double>::infinity())
- return Max();
- return Time(static_cast<int64>(ms_since_epoch * kMicrosecondsPerMillisecond) +
- kTimeTToMicrosecondsOffset);
+ return Time(kTimeTToMicrosecondsOffset) +
+ TimeDelta::FromMillisecondsD(ms_since_epoch);
}
double Time::ToJsTime() const {
@@ -214,14 +209,14 @@
kMicrosecondsPerMillisecond);
}
-int64 Time::ToJavaTime() const {
+int64_t Time::ToJavaTime() const {
if (is_null()) {
// Preserve 0 so the invalid result doesn't depend on the platform.
return 0;
}
if (is_max()) {
// Preserve max without offset to prevent overflow.
- return std::numeric_limits<int64>::max();
+ return std::numeric_limits<int64_t>::max();
}
return ((us_ - kTimeTToMicrosecondsOffset) /
kMicrosecondsPerMillisecond);
@@ -301,11 +296,6 @@
return os << as_time_delta.InMicroseconds() << " bogo-thread-microseconds";
}
-std::ostream& operator<<(std::ostream& os, TraceTicks trace_ticks) {
- const TimeDelta as_time_delta = trace_ticks - TraceTicks();
- return os << as_time_delta.InMicroseconds() << " bogo-trace-microseconds";
-}
-
// Time::Exploded -------------------------------------------------------------
inline bool is_in_range(int value, int lo, int hi) {
diff --git a/third_party/chromium/base/time/time.h b/third_party/chromium/base/time/time.h
index 1fe1b85..9456cc7 100644
--- a/third_party/chromium/base/time/time.h
+++ b/third_party/chromium/base/time/time.h
@@ -13,13 +13,13 @@
// TimeDelta represents a duration of time, internally represented in
// microseconds.
//
-// TimeTicks, ThreadTicks, and TraceTicks represent an abstract time that is
-// most of the time incrementing, for use in measuring time durations.
-// Internally, they are represented in microseconds. They can not be converted
-// to a human-readable time, but are guaranteed not to decrease (unlike the Time
-// class). Note that TimeTicks may "stand still" (e.g., if the computer is
-// suspended), and ThreadTicks will "stand still" whenever the thread has been
-// de-scheduled by the operating system.
+// TimeTicks and ThreadTicks represent an abstract time that is most of the time
+// incrementing, for use in measuring time durations. Internally, they are
+// represented in microseconds. They can not be converted to a human-readable
+// time, but are guaranteed not to decrease (unlike the Time class). Note that
+// TimeTicks may "stand still" (e.g., if the computer is suspended), and
+// ThreadTicks will "stand still" whenever the thread has been de-scheduled by
+// the operating system.
//
// All time classes are copyable, assignable, and occupy 64-bits per
// instance. Thus, they can be efficiently passed by-value (as opposed to
@@ -45,22 +45,17 @@
//
// ThreadTicks: Benchmarking how long the current thread has been doing actual
// work.
-//
-// TraceTicks: This is only meant to be used by the event tracing
-// infrastructure, and by outside code modules in special
-// circumstances. Please be sure to consult a
-// base/trace_event/OWNER before committing any new code that
-// uses this.
#ifndef BASE_TIME_TIME_H_
#define BASE_TIME_TIME_H_
+#include <stdint.h>
#include <time.h>
#include <iosfwd>
+#include <limits>
#include "base/base_export.h"
-#include "base/basictypes.h"
#include "base/numerics/safe_math.h"
#include "build/build_config.h"
@@ -79,9 +74,9 @@
// For FILETIME in FromFileTime, until it moves to a new converter class.
// See TODO(iyengar) below.
#include <windows.h>
-#endif
-#include <limits>
+#include "base/gtest_prod_util.h"
+#endif
namespace base {
@@ -92,14 +87,14 @@
// time classes instead.
namespace time_internal {
-// Add or subtract |value| from a TimeDelta. The int64 argument and return value
-// are in terms of a microsecond timebase.
-BASE_EXPORT int64 SaturatedAdd(TimeDelta delta, int64 value);
-BASE_EXPORT int64 SaturatedSub(TimeDelta delta, int64 value);
+// Add or subtract |value| from a TimeDelta. The int64_t argument and return
+// value are in terms of a microsecond timebase.
+BASE_EXPORT int64_t SaturatedAdd(TimeDelta delta, int64_t value);
+BASE_EXPORT int64_t SaturatedSub(TimeDelta delta, int64_t value);
-// Clamp |value| on overflow and underflow conditions. The int64 argument and
+// Clamp |value| on overflow and underflow conditions. The int64_t argument and
// return value are in terms of a microsecond timebase.
-BASE_EXPORT int64 FromCheckedNumeric(const CheckedNumeric<int64> value);
+BASE_EXPORT int64_t FromCheckedNumeric(const CheckedNumeric<int64_t> value);
} // namespace time_internal
@@ -114,11 +109,11 @@
static TimeDelta FromDays(int days);
static TimeDelta FromHours(int hours);
static TimeDelta FromMinutes(int minutes);
- static TimeDelta FromSeconds(int64 secs);
- static TimeDelta FromMilliseconds(int64 ms);
+ static TimeDelta FromSeconds(int64_t secs);
+ static TimeDelta FromMilliseconds(int64_t ms);
static TimeDelta FromSecondsD(double secs);
static TimeDelta FromMillisecondsD(double ms);
- static TimeDelta FromMicroseconds(int64 us);
+ static TimeDelta FromMicroseconds(int64_t us);
#if defined(OS_WIN)
static TimeDelta FromQPCValue(LONGLONG qpc_value);
#endif
@@ -127,9 +122,7 @@
// when deserializing a |TimeDelta| structure, using a value known to be
// compatible. It is not provided as a constructor because the integer type
// may be unclear from the perspective of a caller.
- static TimeDelta FromInternalValue(int64 delta) {
- return TimeDelta(delta);
- }
+ static TimeDelta FromInternalValue(int64_t delta) { return TimeDelta(delta); }
// Returns the maximum time delta, which should be greater than any reasonable
// time delta we might compare it to. Adding or subtracting the maximum time
@@ -140,16 +133,14 @@
// use this and do arithmetic on it, as it is more error prone than using the
// provided operators.
// For serializing, use FromInternalValue to reconstitute.
- int64 ToInternalValue() const {
- return delta_;
- }
+ int64_t ToInternalValue() const { return delta_; }
// Returns the magnitude (absolute value) of this TimeDelta.
TimeDelta magnitude() const {
// Some toolchains provide an incomplete C++11 implementation and lack an
- // int64 overload for std::abs(). The following is a simple branchless
+ // int64_t overload for std::abs(). The following is a simple branchless
// implementation:
- const int64 mask = delta_ >> (sizeof(delta_) * 8 - 1);
+ const int64_t mask = delta_ >> (sizeof(delta_) * 8 - 1);
return TimeDelta((delta_ + mask) ^ mask);
}
@@ -159,9 +150,7 @@
}
// Returns true if the time delta is the maximum time delta.
- bool is_max() const {
- return delta_ == std::numeric_limits<int64>::max();
- }
+ bool is_max() const { return delta_ == std::numeric_limits<int64_t>::max(); }
#if defined(OS_POSIX)
struct timespec ToTimeSpec() const;
@@ -176,11 +165,11 @@
int InHours() const;
int InMinutes() const;
double InSecondsF() const;
- int64 InSeconds() const;
+ int64_t InSeconds() const;
double InMillisecondsF() const;
- int64 InMilliseconds() const;
- int64 InMillisecondsRoundedUp() const;
- int64 InMicroseconds() const;
+ int64_t InMilliseconds() const;
+ int64_t InMillisecondsRoundedUp() const;
+ int64_t InMicroseconds() const;
TimeDelta& operator=(TimeDelta other) {
delta_ = other.delta_;
@@ -208,13 +197,13 @@
// Computations with numeric types.
template<typename T>
TimeDelta operator*(T a) const {
- CheckedNumeric<int64> rv(delta_);
+ CheckedNumeric<int64_t> rv(delta_);
rv *= a;
return TimeDelta(time_internal::FromCheckedNumeric(rv));
}
template<typename T>
TimeDelta operator/(T a) const {
- CheckedNumeric<int64> rv(delta_);
+ CheckedNumeric<int64_t> rv(delta_);
rv /= a;
return TimeDelta(time_internal::FromCheckedNumeric(rv));
}
@@ -227,9 +216,7 @@
return *this = (*this / a);
}
- int64 operator/(TimeDelta a) const {
- return delta_ / a.delta_;
- }
+ int64_t operator/(TimeDelta a) const { return delta_ / a.delta_; }
TimeDelta operator%(TimeDelta a) const {
return TimeDelta(delta_ % a.delta_);
}
@@ -255,17 +242,19 @@
}
private:
- friend int64 time_internal::SaturatedAdd(TimeDelta delta, int64 value);
- friend int64 time_internal::SaturatedSub(TimeDelta delta, int64 value);
+ friend int64_t time_internal::SaturatedAdd(TimeDelta delta, int64_t value);
+ friend int64_t time_internal::SaturatedSub(TimeDelta delta, int64_t value);
// Constructs a delta given the duration in microseconds. This is private
// to avoid confusion by callers with an integer constructor. Use
// FromSeconds, FromMilliseconds, etc. instead.
- explicit TimeDelta(int64 delta_us) : delta_(delta_us) {
- }
+ explicit TimeDelta(int64_t delta_us) : delta_(delta_us) {}
+
+ // Private method to build a delta from a double.
+ static TimeDelta FromDouble(double value);
// Delta in microseconds.
- int64 delta_;
+ int64_t delta_;
};
template<typename T>
@@ -290,20 +279,21 @@
template<class TimeClass>
class TimeBase {
public:
- static const int64 kHoursPerDay = 24;
- static const int64 kMillisecondsPerSecond = 1000;
- static const int64 kMillisecondsPerDay = kMillisecondsPerSecond * 60 * 60 *
- kHoursPerDay;
- static const int64 kMicrosecondsPerMillisecond = 1000;
- static const int64 kMicrosecondsPerSecond = kMicrosecondsPerMillisecond *
- kMillisecondsPerSecond;
- static const int64 kMicrosecondsPerMinute = kMicrosecondsPerSecond * 60;
- static const int64 kMicrosecondsPerHour = kMicrosecondsPerMinute * 60;
- static const int64 kMicrosecondsPerDay = kMicrosecondsPerHour * kHoursPerDay;
- static const int64 kMicrosecondsPerWeek = kMicrosecondsPerDay * 7;
- static const int64 kNanosecondsPerMicrosecond = 1000;
- static const int64 kNanosecondsPerSecond = kNanosecondsPerMicrosecond *
- kMicrosecondsPerSecond;
+ static const int64_t kHoursPerDay = 24;
+ static const int64_t kMillisecondsPerSecond = 1000;
+ static const int64_t kMillisecondsPerDay =
+ kMillisecondsPerSecond * 60 * 60 * kHoursPerDay;
+ static const int64_t kMicrosecondsPerMillisecond = 1000;
+ static const int64_t kMicrosecondsPerSecond =
+ kMicrosecondsPerMillisecond * kMillisecondsPerSecond;
+ static const int64_t kMicrosecondsPerMinute = kMicrosecondsPerSecond * 60;
+ static const int64_t kMicrosecondsPerHour = kMicrosecondsPerMinute * 60;
+ static const int64_t kMicrosecondsPerDay =
+ kMicrosecondsPerHour * kHoursPerDay;
+ static const int64_t kMicrosecondsPerWeek = kMicrosecondsPerDay * 7;
+ static const int64_t kNanosecondsPerMicrosecond = 1000;
+ static const int64_t kNanosecondsPerSecond =
+ kNanosecondsPerMicrosecond * kMicrosecondsPerSecond;
// Returns true if this object has not been initialized.
//
@@ -315,16 +305,12 @@
}
// Returns true if this object represents the maximum time.
- bool is_max() const {
- return us_ == std::numeric_limits<int64>::max();
- }
+ bool is_max() const { return us_ == std::numeric_limits<int64_t>::max(); }
// For serializing only. Use FromInternalValue() to reconstitute. Please don't
// use this and do arithmetic on it, as it is more error prone than using the
// provided operators.
- int64 ToInternalValue() const {
- return us_;
- }
+ int64_t ToInternalValue() const { return us_; }
TimeClass& operator=(TimeClass other) {
us_ = other.us_;
@@ -376,16 +362,13 @@
// when deserializing a |TimeClass| structure, using a value known to be
// compatible. It is not provided as a constructor because the integer type
// may be unclear from the perspective of a caller.
- static TimeClass FromInternalValue(int64 us) {
- return TimeClass(us);
- }
+ static TimeClass FromInternalValue(int64_t us) { return TimeClass(us); }
protected:
- explicit TimeBase(int64 us) : us_(us) {
- }
+ explicit TimeBase(int64_t us) : us_(us) {}
// Time value in a microsecond timebase.
- int64 us_;
+ int64_t us_;
};
} // namespace time_internal
@@ -403,7 +386,7 @@
public:
// The representation of Jan 1, 1970 UTC in microseconds since the
// platform-dependent epoch.
- static const int64 kTimeTToMicrosecondsOffset;
+ static const int64_t kTimeTToMicrosecondsOffset;
#if !defined(OS_WIN)
// On Mac & Linux, this value is the delta from the Windows epoch of 1601 to
@@ -411,12 +394,12 @@
// 1970-based epochs to the new 1601-based ones. It should be removed from
// this global header and put in the platform-specific ones when we remove the
// migration code.
- static const int64 kWindowsEpochDeltaMicroseconds;
+ static const int64_t kWindowsEpochDeltaMicroseconds;
#else
// To avoid overflow in QPC to Microseconds calculations, since we multiply
// by kMicrosecondsPerSecond, then the QPC value should not exceed
// (2^63 - 1) / 1E6. If it exceeds that threshold, we divide then multiply.
- static const int64 kQPCOverflowThreshold = 0x8637BD05AF7;
+ enum : int64_t{kQPCOverflowThreshold = 0x8637BD05AF7};
#endif
// Represents an exploded time that can be formatted nicely. This is kind of
@@ -491,7 +474,7 @@
// Converts to Java convention for times, a number of
// milliseconds since the epoch.
- int64 ToJavaTime() const;
+ int64_t ToJavaTime() const;
#if defined(OS_POSIX)
static Time FromTimeVal(struct timeval t);
@@ -555,8 +538,7 @@
private:
friend class time_internal::TimeBase<Time>;
- explicit Time(int64 us) : TimeBase(us) {
- }
+ explicit Time(int64_t us) : TimeBase(us) {}
// Explodes the given time to either local time |is_local = true| or UTC
// |is_local = false|.
@@ -571,7 +553,6 @@
// static
inline TimeDelta TimeDelta::FromDays(int days) {
- // Preserve max to prevent overflow.
if (days == std::numeric_limits<int>::max())
return Max();
return TimeDelta(days * Time::kMicrosecondsPerDay);
@@ -579,7 +560,6 @@
// static
inline TimeDelta TimeDelta::FromHours(int hours) {
- // Preserve max to prevent overflow.
if (hours == std::numeric_limits<int>::max())
return Max();
return TimeDelta(hours * Time::kMicrosecondsPerHour);
@@ -587,52 +567,47 @@
// static
inline TimeDelta TimeDelta::FromMinutes(int minutes) {
- // Preserve max to prevent overflow.
if (minutes == std::numeric_limits<int>::max())
return Max();
return TimeDelta(minutes * Time::kMicrosecondsPerMinute);
}
// static
-inline TimeDelta TimeDelta::FromSeconds(int64 secs) {
- // Preserve max to prevent overflow.
- if (secs == std::numeric_limits<int64>::max())
- return Max();
- return TimeDelta(secs * Time::kMicrosecondsPerSecond);
+inline TimeDelta TimeDelta::FromSeconds(int64_t secs) {
+ return TimeDelta(secs) * Time::kMicrosecondsPerSecond;
}
// static
-inline TimeDelta TimeDelta::FromMilliseconds(int64 ms) {
- // Preserve max to prevent overflow.
- if (ms == std::numeric_limits<int64>::max())
- return Max();
- return TimeDelta(ms * Time::kMicrosecondsPerMillisecond);
+inline TimeDelta TimeDelta::FromMilliseconds(int64_t ms) {
+ return TimeDelta(ms) * Time::kMicrosecondsPerMillisecond;
}
// static
inline TimeDelta TimeDelta::FromSecondsD(double secs) {
- // Preserve max to prevent overflow.
- if (secs == std::numeric_limits<double>::infinity())
- return Max();
- return TimeDelta(static_cast<int64>(secs * Time::kMicrosecondsPerSecond));
+ return FromDouble(secs * Time::kMicrosecondsPerSecond);
}
// static
inline TimeDelta TimeDelta::FromMillisecondsD(double ms) {
- // Preserve max to prevent overflow.
- if (ms == std::numeric_limits<double>::infinity())
- return Max();
- return TimeDelta(static_cast<int64>(ms * Time::kMicrosecondsPerMillisecond));
+ return FromDouble(ms * Time::kMicrosecondsPerMillisecond);
}
// static
-inline TimeDelta TimeDelta::FromMicroseconds(int64 us) {
- // Preserve max to prevent overflow.
- if (us == std::numeric_limits<int64>::max())
- return Max();
+inline TimeDelta TimeDelta::FromMicroseconds(int64_t us) {
return TimeDelta(us);
}
+// static
+inline TimeDelta TimeDelta::FromDouble(double value) {
+ double max_magnitude = std::numeric_limits<int64_t>::max();
+ TimeDelta delta = TimeDelta(static_cast<int64_t>(value));
+ if (value > max_magnitude)
+ delta = Max();
+ else if (value < -max_magnitude)
+ delta = -Max();
+ return delta;
+}
+
// For logging use only.
BASE_EXPORT std::ostream& operator<<(std::ostream& os, Time time);
@@ -663,12 +638,14 @@
static TimeTicks FromQPCValue(LONGLONG qpc_value);
#endif
- // Get the TimeTick value at the time of the UnixEpoch. This is useful when
- // you need to relate the value of TimeTicks to a real time and date.
- // Note: Upon first invocation, this function takes a snapshot of the realtime
- // clock to establish a reference point. This function will return the same
- // value for the duration of the application, but will be different in future
- // application runs.
+ // Get an estimate of the TimeTick value at the time of the UnixEpoch. Because
+ // Time and TimeTicks respond differently to user-set time and NTP
+ // adjustments, this number is only an estimate. Nevertheless, this can be
+ // useful when you need to relate the value of TimeTicks to a real time and
+ // date. Note: Upon first invocation, this function takes a snapshot of the
+ // realtime clock to establish a reference point. This function will return
+ // the same value for the duration of the application, but will be different
+ // in future application runs.
static TimeTicks UnixEpoch();
// Returns |this| snapped to the next tick, given a |tick_phase| and
@@ -688,8 +665,7 @@
// Please use Now() to create a new object. This is for internal use
// and testing.
- explicit TimeTicks(int64 us) : TimeBase(us) {
- }
+ explicit TimeTicks(int64_t us) : TimeBase(us) {}
};
// For logging use only.
@@ -709,16 +685,28 @@
#if (defined(_POSIX_THREAD_CPUTIME) && (_POSIX_THREAD_CPUTIME >= 0)) || \
(defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_ANDROID)
return true;
+#elif defined(OS_WIN)
+ return IsSupportedWin();
#else
return false;
#endif
}
+ // Waits until the initialization is completed. Needs to be guarded with a
+ // call to IsSupported().
+ static void WaitUntilInitialized() {
+#if defined(OS_WIN)
+ WaitUntilInitializedWin();
+#endif
+ }
+
// Returns thread-specific CPU-time on systems that support this feature.
// Needs to be guarded with a call to IsSupported(). Use this timer
// to (approximately) measure how much time the calling thread spent doing
// actual work vs. being de-scheduled. May return bogus results if the thread
- // migrates to another CPU between two calls.
+ // migrates to another CPU between two calls. Returns an empty ThreadTicks
+ // object until the initialization is completed. If a clock reading is
+ // absolutely needed, call WaitUntilInitialized() before this method.
static ThreadTicks Now();
private:
@@ -726,59 +714,13 @@
// Please use Now() to create a new object. This is for internal use
// and testing.
- explicit ThreadTicks(int64 us) : TimeBase(us) {
- }
+ explicit ThreadTicks(int64_t us) : TimeBase(us) {}
+
};
// For logging use only.
std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks);
-// TraceTicks ----------------------------------------------------------------
-
-// Represents high-resolution system trace clock time.
-class TraceTicks : public time_internal::TimeBase<TraceTicks> {
- public:
- // We define this even without OS_CHROMEOS for seccomp sandbox testing.
-#if defined(OS_LINUX)
- // Force definition of the system trace clock; it is a chromeos-only api
- // at the moment and surfacing it in the right place requires mucking
- // with glibc et al.
- static const clockid_t kClockSystemTrace = 11;
-#endif
-
- TraceTicks() : TimeBase(0) {
- }
-
- // Returns the current system trace time or, if not available on this
- // platform, a high-resolution time value; or a low-resolution time value if
- // neither are avalable. On systems where a global trace clock is defined,
- // timestamping TraceEvents's with this value guarantees synchronization
- // between events collected inside chrome and events collected outside
- // (e.g. kernel, X server).
- //
- // On some platforms, the clock source used for tracing can vary depending on
- // hardware and/or kernel support. Do not make any assumptions without
- // consulting the documentation for this functionality in the time_win.cc,
- // time_posix.cc, etc. files.
- //
- // NOTE: This is only meant to be used by the event tracing infrastructure,
- // and by outside code modules in special circumstances. Please be sure to
- // consult a base/trace_event/OWNER before committing any new code that uses
- // this.
- static TraceTicks Now();
-
- private:
- friend class time_internal::TimeBase<TraceTicks>;
-
- // Please use Now() to create a new object. This is for internal use
- // and testing.
- explicit TraceTicks(int64 us) : TimeBase(us) {
- }
-};
-
-// For logging use only.
-std::ostream& operator<<(std::ostream& os, TraceTicks time_ticks);
-
} // namespace base
#endif // BASE_TIME_TIME_H_
diff --git a/third_party/chromium/base/time/time_posix.cc b/third_party/chromium/base/time/time_posix.cc
index e8e56c2..4b37b4a 100644
--- a/third_party/chromium/base/time/time_posix.cc
+++ b/third_party/chromium/base/time/time_posix.cc
@@ -15,7 +15,6 @@
#include <limits>
#include <ostream>
-#include "base/basictypes.h"
#include "base/logging.h"
#include "build/build_config.h"
@@ -60,8 +59,8 @@
}
#endif // OS_ANDROID
-int64 ConvertTimespecToMicros(const struct timespec& ts) {
- base::CheckedNumeric<int64> result(ts.tv_sec);
+int64_t ConvertTimespecToMicros(const struct timespec& ts) {
+ base::CheckedNumeric<int64_t> result(ts.tv_sec);
result *= base::Time::kMicrosecondsPerSecond;
result += (ts.tv_nsec / base::Time::kNanosecondsPerMicrosecond);
return result.ValueOrDie();
@@ -74,7 +73,7 @@
#if (defined(OS_POSIX) && \
defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0) || \
defined(OS_BSD) || defined(OS_ANDROID)
-int64 ClockNow(clockid_t clk_id) {
+int64_t ClockNow(clockid_t clk_id) {
struct timespec ts;
if (clock_gettime(clk_id, &ts) != 0) {
NOTREACHED() << "clock_gettime(" << clk_id << ") failed.";
@@ -92,7 +91,7 @@
namespace base {
struct timespec TimeDelta::ToTimeSpec() const {
- int64 microseconds = InMicroseconds();
+ int64_t microseconds = InMicroseconds();
time_t seconds = 0;
if (microseconds >= Time::kMicrosecondsPerSecond) {
seconds = InSeconds();
@@ -117,16 +116,16 @@
// => Thu Jan 01 00:00:00 UTC 1970
// irb(main):011:0> Time.at(-11644473600).getutc()
// => Mon Jan 01 00:00:00 UTC 1601
-static const int64 kWindowsEpochDeltaSeconds = 11644473600ll;
+static const int64_t kWindowsEpochDeltaSeconds = 11644473600ll;
// static
-const int64 Time::kWindowsEpochDeltaMicroseconds =
+const int64_t Time::kWindowsEpochDeltaMicroseconds =
kWindowsEpochDeltaSeconds * Time::kMicrosecondsPerSecond;
// Some functions in time.cc use time_t directly, so we provide an offset
// to convert from time_t (Unix epoch) and internal (Windows epoch).
// static
-const int64 Time::kTimeTToMicrosecondsOffset = kWindowsEpochDeltaMicroseconds;
+const int64_t Time::kTimeTToMicrosecondsOffset = kWindowsEpochDeltaMicroseconds;
// static
Time Time::Now() {
@@ -156,9 +155,9 @@
// Time stores times with microsecond resolution, but Exploded only carries
// millisecond resolution, so begin by being lossy. Adjust from Windows
// epoch (1601) to Unix epoch (1970);
- int64 microseconds = us_ - kWindowsEpochDeltaMicroseconds;
+ int64_t microseconds = us_ - kWindowsEpochDeltaMicroseconds;
// The following values are all rounded towards -infinity.
- int64 milliseconds; // Milliseconds since epoch.
+ int64_t milliseconds; // Milliseconds since epoch.
SysTime seconds; // Seconds since epoch.
int millisecond; // Exploded millisecond value (0-999).
if (microseconds >= 0) {
@@ -208,8 +207,7 @@
timestruct.tm_zone = NULL; // not a POSIX field, so mktime/timegm ignore
#endif
-
- int64 milliseconds;
+ int64_t milliseconds;
SysTime seconds;
// Certain exploded dates do not really exist due to daylight saving times,
@@ -227,11 +225,11 @@
// to UTC 00:00:00 that isn't -1.
timestruct = timestruct0;
timestruct.tm_isdst = 0;
- int64 seconds_isdst0 = SysTimeFromTimeStruct(×truct, is_local);
+ int64_t seconds_isdst0 = SysTimeFromTimeStruct(×truct, is_local);
timestruct = timestruct0;
timestruct.tm_isdst = 1;
- int64 seconds_isdst1 = SysTimeFromTimeStruct(×truct, is_local);
+ int64_t seconds_isdst1 = SysTimeFromTimeStruct(×truct, is_local);
// seconds_isdst0 or seconds_isdst1 can be -1 for some timezones.
// E.g. "CLST" (Chile Summer Time) returns -1 for 'tm_isdt == 1'.
@@ -264,14 +262,14 @@
// 999ms to avoid the time being less than any other possible value that
// this function can return.
- // On Android, SysTime is int64, special care must be taken to avoid
+ // On Android, SysTime is int64_t, special care must be taken to avoid
// overflows.
- const int64 min_seconds = (sizeof(SysTime) < sizeof(int64))
- ? std::numeric_limits<SysTime>::min()
- : std::numeric_limits<int32_t>::min();
- const int64 max_seconds = (sizeof(SysTime) < sizeof(int64))
- ? std::numeric_limits<SysTime>::max()
- : std::numeric_limits<int32_t>::max();
+ const int64_t min_seconds = (sizeof(SysTime) < sizeof(int64_t))
+ ? std::numeric_limits<SysTime>::min()
+ : std::numeric_limits<int32_t>::min();
+ const int64_t max_seconds = (sizeof(SysTime) < sizeof(int64_t))
+ ? std::numeric_limits<SysTime>::max()
+ : std::numeric_limits<int32_t>::max();
if (exploded.year < 1969) {
milliseconds = min_seconds * kMillisecondsPerSecond;
} else {
@@ -309,27 +307,6 @@
#endif
}
-// Use the Chrome OS specific system-wide clock.
-#if defined(OS_CHROMEOS)
-// static
-TraceTicks TraceTicks::Now() {
- struct timespec ts;
- if (clock_gettime(kClockSystemTrace, &ts) != 0) {
- // NB: fall-back for a chrome os build running on linux
- return TraceTicks(ClockNow(CLOCK_MONOTONIC));
- }
- return TraceTicks(ConvertTimespecToMicros(ts));
-}
-
-#else // !defined(OS_CHROMEOS)
-
-// static
-TraceTicks TraceTicks::Now() {
- return TraceTicks(ClockNow(CLOCK_MONOTONIC));
-}
-
-#endif // defined(OS_CHROMEOS)
-
#endif // !OS_MACOSX
// static
@@ -341,10 +318,8 @@
if (t.tv_usec == static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1 &&
t.tv_sec == std::numeric_limits<time_t>::max())
return Max();
- return Time(
- (static_cast<int64>(t.tv_sec) * Time::kMicrosecondsPerSecond) +
- t.tv_usec +
- kTimeTToMicrosecondsOffset);
+ return Time((static_cast<int64_t>(t.tv_sec) * Time::kMicrosecondsPerSecond) +
+ t.tv_usec + kTimeTToMicrosecondsOffset);
}
struct timeval Time::ToTimeVal() const {
@@ -359,7 +334,7 @@
result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1;
return result;
}
- int64 us = us_ - kTimeTToMicrosecondsOffset;
+ int64_t us = us_ - kTimeTToMicrosecondsOffset;
result.tv_sec = us / Time::kMicrosecondsPerSecond;
result.tv_usec = us % Time::kMicrosecondsPerSecond;
return result;
diff --git a/third_party/chromium/base/time/time_unittest.cc b/third_party/chromium/base/time/time_unittest.cc
index 737796c..c471a76 100644
--- a/third_party/chromium/base/time/time_unittest.cc
+++ b/third_party/chromium/base/time/time_unittest.cc
@@ -13,6 +13,7 @@
#include "base/compiler_specific.h"
#include "base/logging.h"
+#include "base/macros.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
@@ -289,52 +290,6 @@
EXPECT_EQ(1, exploded.millisecond);
}
-TEST_F(TimeTest, TimeDeltaMax) {
- TimeDelta max = TimeDelta::Max();
- EXPECT_TRUE(max.is_max());
- EXPECT_EQ(max, TimeDelta::Max());
- EXPECT_GT(max, TimeDelta::FromDays(100 * 365));
- EXPECT_GT(max, TimeDelta());
-}
-
-TEST_F(TimeTest, TimeDeltaMaxConversions) {
- TimeDelta t = TimeDelta::Max();
- EXPECT_EQ(std::numeric_limits<int64>::max(), t.ToInternalValue());
-
- EXPECT_EQ(std::numeric_limits<int>::max(), t.InDays());
- EXPECT_EQ(std::numeric_limits<int>::max(), t.InHours());
- EXPECT_EQ(std::numeric_limits<int>::max(), t.InMinutes());
- EXPECT_EQ(std::numeric_limits<double>::infinity(), t.InSecondsF());
- EXPECT_EQ(std::numeric_limits<int64>::max(), t.InSeconds());
- EXPECT_EQ(std::numeric_limits<double>::infinity(), t.InMillisecondsF());
- EXPECT_EQ(std::numeric_limits<int64>::max(), t.InMilliseconds());
- EXPECT_EQ(std::numeric_limits<int64>::max(), t.InMillisecondsRoundedUp());
-
- t = TimeDelta::FromDays(std::numeric_limits<int>::max());
- EXPECT_TRUE(t.is_max());
-
- t = TimeDelta::FromHours(std::numeric_limits<int>::max());
- EXPECT_TRUE(t.is_max());
-
- t = TimeDelta::FromMinutes(std::numeric_limits<int>::max());
- EXPECT_TRUE(t.is_max());
-
- t = TimeDelta::FromSeconds(std::numeric_limits<int64>::max());
- EXPECT_TRUE(t.is_max());
-
- t = TimeDelta::FromMilliseconds(std::numeric_limits<int64>::max());
- EXPECT_TRUE(t.is_max());
-
- t = TimeDelta::FromSecondsD(std::numeric_limits<double>::infinity());
- EXPECT_TRUE(t.is_max());
-
- t = TimeDelta::FromMillisecondsD(std::numeric_limits<double>::infinity());
- EXPECT_TRUE(t.is_max());
-
- t = TimeDelta::FromMicroseconds(std::numeric_limits<int64>::max());
- EXPECT_TRUE(t.is_max());
-}
-
TEST_F(TimeTest, Max) {
Time max = Time::Max();
EXPECT_TRUE(max.is_max());
@@ -345,7 +300,7 @@
TEST_F(TimeTest, MaxConversions) {
Time t = Time::Max();
- EXPECT_EQ(std::numeric_limits<int64>::max(), t.ToInternalValue());
+ EXPECT_EQ(std::numeric_limits<int64_t>::max(), t.ToInternalValue());
t = Time::FromDoubleT(std::numeric_limits<double>::infinity());
EXPECT_TRUE(t.is_max());
@@ -392,7 +347,7 @@
#if defined(OS_MACOSX)
TEST_F(TimeTest, TimeTOverflow) {
- Time t = Time::FromInternalValue(std::numeric_limits<int64>::max() - 1);
+ Time t = Time::FromInternalValue(std::numeric_limits<int64_t>::max() - 1);
EXPECT_FALSE(t.is_max());
EXPECT_EQ(std::numeric_limits<time_t>::max(), t.ToTimeT());
}
@@ -461,12 +416,6 @@
HighResClockTest(&TimeTicks::Now);
}
-TEST(TraceTicks, NowFromSystemTraceTime) {
- // Re-use HighRes test for now since clock properties are identical.
- using NowFunction = TimeTicks (*)(void);
- HighResClockTest(reinterpret_cast<NowFunction>(&TraceTicks::Now));
-}
-
TEST(TimeTicks, SnappedToNextTickBasic) {
base::TimeTicks phase = base::TimeTicks::FromInternalValue(4000);
base::TimeDelta interval = base::TimeDelta::FromMicroseconds(1000);
@@ -546,6 +495,7 @@
EXPECT_EQ(13, TimeDelta::FromMillisecondsD(13.3).InMilliseconds());
EXPECT_EQ(13.3, TimeDelta::FromMillisecondsD(13.3).InMillisecondsF());
EXPECT_EQ(13, TimeDelta::FromMicroseconds(13).InMicroseconds());
+ EXPECT_EQ(3.456, TimeDelta::FromMillisecondsD(3.45678).InMillisecondsF());
}
#if defined(OS_POSIX)
@@ -600,25 +550,102 @@
}
TEST(TimeDelta, Magnitude) {
- const int64 zero = 0;
+ const int64_t zero = 0;
EXPECT_EQ(TimeDelta::FromMicroseconds(zero),
TimeDelta::FromMicroseconds(zero).magnitude());
- const int64 one = 1;
- const int64 negative_one = -1;
+ const int64_t one = 1;
+ const int64_t negative_one = -1;
EXPECT_EQ(TimeDelta::FromMicroseconds(one),
TimeDelta::FromMicroseconds(one).magnitude());
EXPECT_EQ(TimeDelta::FromMicroseconds(one),
TimeDelta::FromMicroseconds(negative_one).magnitude());
- const int64 max_int64_minus_one = std::numeric_limits<int64>::max() - 1;
- const int64 min_int64_plus_two = std::numeric_limits<int64>::min() + 2;
+ const int64_t max_int64_minus_one = std::numeric_limits<int64_t>::max() - 1;
+ const int64_t min_int64_plus_two = std::numeric_limits<int64_t>::min() + 2;
EXPECT_EQ(TimeDelta::FromMicroseconds(max_int64_minus_one),
TimeDelta::FromMicroseconds(max_int64_minus_one).magnitude());
EXPECT_EQ(TimeDelta::FromMicroseconds(max_int64_minus_one),
TimeDelta::FromMicroseconds(min_int64_plus_two).magnitude());
}
+TEST(TimeDelta, Max) {
+ TimeDelta max = TimeDelta::Max();
+ EXPECT_TRUE(max.is_max());
+ EXPECT_EQ(max, TimeDelta::Max());
+ EXPECT_GT(max, TimeDelta::FromDays(100 * 365));
+ EXPECT_GT(max, TimeDelta());
+}
+
+bool IsMin(TimeDelta delta) {
+ return (-delta).is_max();
+}
+
+TEST(TimeDelta, MaxConversions) {
+ TimeDelta t = TimeDelta::Max();
+ EXPECT_EQ(std::numeric_limits<int64_t>::max(), t.ToInternalValue());
+
+ EXPECT_EQ(std::numeric_limits<int>::max(), t.InDays());
+ EXPECT_EQ(std::numeric_limits<int>::max(), t.InHours());
+ EXPECT_EQ(std::numeric_limits<int>::max(), t.InMinutes());
+ EXPECT_EQ(std::numeric_limits<double>::infinity(), t.InSecondsF());
+ EXPECT_EQ(std::numeric_limits<int64_t>::max(), t.InSeconds());
+ EXPECT_EQ(std::numeric_limits<double>::infinity(), t.InMillisecondsF());
+ EXPECT_EQ(std::numeric_limits<int64_t>::max(), t.InMilliseconds());
+ EXPECT_EQ(std::numeric_limits<int64_t>::max(), t.InMillisecondsRoundedUp());
+
+ t = TimeDelta::FromDays(std::numeric_limits<int>::max());
+ EXPECT_TRUE(t.is_max());
+
+ t = TimeDelta::FromHours(std::numeric_limits<int>::max());
+ EXPECT_TRUE(t.is_max());
+
+ t = TimeDelta::FromMinutes(std::numeric_limits<int>::max());
+ EXPECT_TRUE(t.is_max());
+
+ int64_t max_int = std::numeric_limits<int64_t>::max();
+
+ t = TimeDelta::FromSeconds(max_int / Time::kMicrosecondsPerSecond + 1);
+ EXPECT_TRUE(t.is_max());
+
+ t = TimeDelta::FromMilliseconds(max_int / Time::kMillisecondsPerSecond + 1);
+ EXPECT_TRUE(t.is_max());
+
+ t = TimeDelta::FromMicroseconds(max_int);
+ EXPECT_TRUE(t.is_max());
+
+ t = TimeDelta::FromSeconds(-max_int / Time::kMicrosecondsPerSecond - 1);
+ EXPECT_TRUE(IsMin(t));
+
+ t = TimeDelta::FromMilliseconds(-max_int / Time::kMillisecondsPerSecond - 1);
+ EXPECT_TRUE(IsMin(t));
+
+ t = TimeDelta::FromMicroseconds(-max_int);
+ EXPECT_TRUE(IsMin(t));
+
+ t = -TimeDelta::FromMicroseconds(std::numeric_limits<int64_t>::min());
+ EXPECT_FALSE(IsMin(t));
+
+ t = TimeDelta::FromSecondsD(std::numeric_limits<double>::infinity());
+ EXPECT_TRUE(t.is_max());
+
+ double max_d = max_int;
+
+ t = TimeDelta::FromSecondsD(max_d / Time::kMicrosecondsPerSecond + 1);
+ EXPECT_TRUE(t.is_max());
+
+ t = TimeDelta::FromMillisecondsD(std::numeric_limits<double>::infinity());
+ EXPECT_TRUE(t.is_max());
+
+ t = TimeDelta::FromMillisecondsD(max_d / Time::kMillisecondsPerSecond * 2);
+ EXPECT_TRUE(t.is_max());
+
+ t = TimeDelta::FromSecondsD(-max_d / Time::kMicrosecondsPerSecond - 1);
+ EXPECT_TRUE(IsMin(t));
+
+ t = TimeDelta::FromMillisecondsD(-max_d / Time::kMillisecondsPerSecond * 2);
+ EXPECT_TRUE(IsMin(t));
+}
TEST(TimeDelta, NumericOperators) {
double d = 0.5;
@@ -645,7 +672,6 @@
EXPECT_EQ(TimeDelta::FromMilliseconds(500),
f * TimeDelta::FromMilliseconds(1000));
-
int i = 2;
EXPECT_EQ(TimeDelta::FromMilliseconds(2000),
TimeDelta::FromMilliseconds(1000) * i);
@@ -670,7 +696,6 @@
EXPECT_EQ(TimeDelta::FromMilliseconds(2000),
i64 * TimeDelta::FromMilliseconds(1000));
-
EXPECT_EQ(TimeDelta::FromMilliseconds(500),
TimeDelta::FromMilliseconds(1000) * 0.5);
EXPECT_EQ(TimeDelta::FromMilliseconds(2000),
@@ -694,10 +719,6 @@
2 * TimeDelta::FromMilliseconds(1000));
}
-bool IsMin(TimeDelta delta) {
- return (-delta).is_max();
-}
-
TEST(TimeDelta, Overflows) {
// Some sanity checks.
EXPECT_TRUE(TimeDelta::Max().is_max());