Index: base/time/time.cc |
diff --git a/base/time/time.cc b/base/time/time.cc |
index a9e4b1cf90aa61c031feaa05f52a01111090f431..9f3c53d6695b1e8b4960dc4911c761dff3b7aa56 100644 |
--- a/base/time/time.cc |
+++ b/base/time/time.cc |
@@ -8,6 +8,7 @@ |
#include <ostream> |
#include "base/float_util.h" |
+#include "base/lazy_instance.h" |
#include "base/logging.h" |
#include "base/third_party/nspr/prtime.h" |
#include "base/third_party/nspr/prtypes.h" |
@@ -189,6 +190,29 @@ bool Time::FromStringInternal(const char* time_string, |
return true; |
} |
+// Local helper class to hold the conversion from Time to TickTime at the |
+// time of the Unix epoch. |
+class UnixEpochSingleton { |
+ public: |
+ UnixEpochSingleton() |
+ : unix_epoch_(TimeTicks::Now() - (Time::Now() - Time::UnixEpoch())) {} |
+ |
+ TimeTicks unix_epoch() const { return unix_epoch_; } |
+ |
+ private: |
+ const TimeTicks unix_epoch_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(UnixEpochSingleton); |
+}; |
+ |
+static LazyInstance<UnixEpochSingleton>::Leaky |
+ leaky_unix_epoch_singleton_instance = LAZY_INSTANCE_INITIALIZER; |
+ |
+// Static |
+TimeTicks TimeTicks::UnixEpoch() { |
+ return leaky_unix_epoch_singleton_instance.Get().unix_epoch(); |
+} |
+ |
// Time::Exploded ------------------------------------------------------------- |
inline bool is_in_range(int value, int lo, int hi) { |