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

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: Changed to use a LazyInstance instead of a Singleton 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
Index: base/time/time.cc
diff --git a/base/time/time.cc b/base/time/time.cc
index a9e4b1cf90aa61c031feaa05f52a01111090f431..710de88ec173002ef962958003e0da57bf844330 100644
--- a/base/time/time.cc
+++ b/base/time/time.cc
@@ -8,7 +8,9 @@
#include <ostream>
#include "base/float_util.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
+//#include "base/memory/singleton.h"
jar (doing other things) 2013/10/30 20:00:12 nit: delete... not needed.
pwestin 2013/10/30 23:14:30 Done.
#include "base/third_party/nspr/prtime.h"
#include "base/third_party/nspr/prtypes.h"
@@ -189,6 +191,27 @@ 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_;
+};
jar (doing other things) 2013/10/30 20:00:12 nit: DISALLOW_COPY_AND_ASSIGN
pwestin 2013/10/30 23:14:30 Done.
+
+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/cast_defines.h » ('j') | media/cast/cast_defines.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698