Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4649)

Unified Diff: base/time/time.cc

Issue 34623008: Change to calculate the real NTP in TimeTicks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed flaky test Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/time/time.h ('k') | media/cast/audio_receiver/audio_receiver_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « base/time/time.h ('k') | media/cast/audio_receiver/audio_receiver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698