Index: base/time/time.h |
diff --git a/base/time/time.h b/base/time/time.h |
index 18de085e341714b85efe6e10a988835601bf998e..0cb729aaceb20e46ed9b4f27c687e3bb825fe0bf 100644 |
--- a/base/time/time.h |
+++ b/base/time/time.h |
@@ -75,6 +75,7 @@ class BASE_EXPORT TimeDelta { |
static TimeDelta FromSecondsD(double secs); |
static TimeDelta FromMillisecondsD(double ms); |
static TimeDelta FromMicroseconds(int64 us); |
+ static TimeDelta FromNanoseconds(int64 ns); |
#if defined(OS_WIN) |
static TimeDelta FromQPCValue(LONGLONG qpc_value); |
#endif |
@@ -575,6 +576,14 @@ inline TimeDelta TimeDelta::FromMicroseconds(int64 us) { |
return TimeDelta(us); |
} |
+// static |
+inline TimeDelta TimeDelta::FromNanoseconds(int64 ns) { |
+ // Preserve max to prevent overflow. |
+ if (ns == std::numeric_limits<int64>::max()) |
+ return Max(); |
+ return TimeDelta(ns / Time::kNanosecondsPerMicrosecond); |
+} |
+ |
inline Time TimeDelta::operator+(Time t) const { |
return Time(t.us_ + delta_); |
} |