Commit c462cafe authored by mkwst@chromium.org's avatar mkwst@chromium.org

Add 'base::Time::Max()' to explicitly refer to the end of time.

BrowingDataRemover (and, I imagine, other systems) recognized ranges bounded by null Time objects ('base::Time()') as referring to "everything". That introduces easily-forgotten complexity, which leads to avoidable mistakes in logic. This CL provides a mechanism for avoiding this sort of confusion in the future by adding the ability to explicitly refer to the end of time via 'base::Time::Max()'.

It simply returns a Time object whose internal counter is set to the maximum int64, which means that simple comparisons like 'time <= end' will do The Right Thing.

BUG=144972


Review URL: https://chromiumcodereview.appspot.com/10883061

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153514 0039d316-1c4b-4281-b951-d872f2087c98
parent fd9ba17a
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <float.h> #include <float.h>
#endif #endif
#include <limits>
#include "base/sys_string_conversions.h" #include "base/sys_string_conversions.h"
#include "base/third_party/nspr/prtime.h" #include "base/third_party/nspr/prtime.h"
...@@ -63,6 +65,11 @@ int64 TimeDelta::InMicroseconds() const { ...@@ -63,6 +65,11 @@ int64 TimeDelta::InMicroseconds() const {
// Time ----------------------------------------------------------------------- // Time -----------------------------------------------------------------------
// static
Time Time::Max() {
return Time(std::numeric_limits<int64>::max());
}
// static // static
Time Time::FromTimeT(time_t tt) { Time Time::FromTimeT(time_t tt) {
if (tt == 0) if (tt == 0)
......
...@@ -254,6 +254,10 @@ class BASE_EXPORT Time { ...@@ -254,6 +254,10 @@ class BASE_EXPORT Time {
// times are increasing, or that two calls to Now() won't be the same. // times are increasing, or that two calls to Now() won't be the same.
static Time Now(); static Time Now();
// Returns the maximum time, which should be greater than any reasonable time
// with which we might compare it.
static Time Max();
// Returns the current time. Same as Now() except that this function always // Returns the current time. Same as Now() except that this function always
// uses system time so that there are no discrepancies between the returned // uses system time so that there are no discrepancies between the returned
// time and system time even on virtual environments including our test bot. // time and system time even on virtual environments including our test bot.
......
...@@ -479,6 +479,12 @@ TEST_F(TimeTest, ExplodeBeforeUnixEpoch) { ...@@ -479,6 +479,12 @@ TEST_F(TimeTest, ExplodeBeforeUnixEpoch) {
EXPECT_EQ(1, exploded.millisecond); EXPECT_EQ(1, exploded.millisecond);
} }
TEST_F(TimeTest, Max) {
EXPECT_EQ(base::Time::Max(), base::Time::Max());
EXPECT_GT(base::Time::Max(), base::Time::Now());
EXPECT_GT(base::Time::Max(), base::Time());
}
TEST(TimeTicks, Deltas) { TEST(TimeTicks, Deltas) {
for (int index = 0; index < 50; index++) { for (int index = 0; index < 50; index++) {
TimeTicks ticks_start = TimeTicks::Now(); TimeTicks ticks_start = TimeTicks::Now();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment