summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/time/time.cc41
-rw-r--r--base/time/time.h40
-rw-r--r--base/time/time_unittest.cc40
-rw-r--r--cc/debug/rasterize_and_record_benchmark.cc3
-rw-r--r--cc/debug/rasterize_and_record_benchmark_impl.cc3
-rw-r--r--cc/resources/picture_pile.cc3
-rw-r--r--cc/resources/picture_pile_impl.cc3
-rw-r--r--content/renderer/media/websourcebuffer_impl.cc2
-rw-r--r--media/base/buffers.h2
-rw-r--r--media/filters/chunk_demuxer.cc1
-rw-r--r--net/http/http_response_headers.cc2
-rw-r--r--net/spdy/spdy_session.cc4
-rw-r--r--sync/sessions/nudge_tracker.cc6
13 files changed, 23 insertions, 127 deletions
diff --git a/base/time/time.cc b/base/time/time.cc
index 2c63886..4605d56 100644
--- a/base/time/time.cc
+++ b/base/time/time.cc
@@ -17,81 +17,40 @@ namespace base {
// TimeDelta ------------------------------------------------------------------
-// static
-TimeDelta TimeDelta::Max() {
- return TimeDelta(std::numeric_limits<int64>::max());
-}
-
int TimeDelta::InDays() const {
- if (is_max()) {
- // Preserve max to prevent overflow.
- return std::numeric_limits<int>::max();
- }
return static_cast<int>(delta_ / Time::kMicrosecondsPerDay);
}
int TimeDelta::InHours() const {
- if (is_max()) {
- // Preserve max to prevent overflow.
- return std::numeric_limits<int>::max();
- }
return static_cast<int>(delta_ / Time::kMicrosecondsPerHour);
}
int TimeDelta::InMinutes() const {
- if (is_max()) {
- // Preserve max to prevent overflow.
- return std::numeric_limits<int>::max();
- }
return static_cast<int>(delta_ / Time::kMicrosecondsPerMinute);
}
double TimeDelta::InSecondsF() const {
- if (is_max()) {
- // Preserve max to prevent overflow.
- return std::numeric_limits<double>::infinity();
- }
return static_cast<double>(delta_) / Time::kMicrosecondsPerSecond;
}
int64 TimeDelta::InSeconds() const {
- if (is_max()) {
- // Preserve max to prevent overflow.
- return std::numeric_limits<int64>::max();
- }
return delta_ / Time::kMicrosecondsPerSecond;
}
double TimeDelta::InMillisecondsF() const {
- if (is_max()) {
- // Preserve max to prevent overflow.
- return std::numeric_limits<double>::infinity();
- }
return static_cast<double>(delta_) / Time::kMicrosecondsPerMillisecond;
}
int64 TimeDelta::InMilliseconds() const {
- if (is_max()) {
- // Preserve max to prevent overflow.
- return std::numeric_limits<int64>::max();
- }
return delta_ / Time::kMicrosecondsPerMillisecond;
}
int64 TimeDelta::InMillisecondsRoundedUp() const {
- if (is_max()) {
- // Preserve max to prevent overflow.
- return std::numeric_limits<int64>::max();
- }
return (delta_ + Time::kMicrosecondsPerMillisecond - 1) /
Time::kMicrosecondsPerMillisecond;
}
int64 TimeDelta::InMicroseconds() const {
- if (is_max()) {
- // Preserve max to prevent overflow.
- return std::numeric_limits<int64>::max();
- }
return delta_;
}
diff --git a/base/time/time.h b/base/time/time.h
index 69a1324..40566b9 100644
--- a/base/time/time.h
+++ b/base/time/time.h
@@ -61,9 +61,9 @@ class BASE_EXPORT TimeDelta {
}
// Converts units of time to TimeDeltas.
- static TimeDelta FromDays(int days);
- static TimeDelta FromHours(int hours);
- static TimeDelta FromMinutes(int minutes);
+ static TimeDelta FromDays(int64 days);
+ static TimeDelta FromHours(int64 hours);
+ static TimeDelta FromMinutes(int64 minutes);
static TimeDelta FromSeconds(int64 secs);
static TimeDelta FromMilliseconds(int64 ms);
static TimeDelta FromMicroseconds(int64 us);
@@ -79,11 +79,6 @@ class BASE_EXPORT TimeDelta {
return TimeDelta(delta);
}
- // Returns the maximum time delta, which should be greater than any reasonable
- // time delta we might compare it to. Adding or subtracting the maximum time
- // delta to a time or another time delta has an undefined result.
- static TimeDelta Max();
-
// Returns the internal numeric value of the TimeDelta object. Please don't
// use this and do arithmetic on it, as it is more error prone than using the
// provided operators.
@@ -92,11 +87,6 @@ class BASE_EXPORT TimeDelta {
return delta_;
}
- // Returns true if the time delta is the maximum time delta.
- bool is_max() const {
- return delta_ == std::numeric_limits<int64>::max();
- }
-
#if defined(OS_POSIX)
struct timespec ToTimeSpec() const;
#endif
@@ -503,50 +493,32 @@ class BASE_EXPORT Time {
// Inline the TimeDelta factory methods, for fast TimeDelta construction.
// static
-inline TimeDelta TimeDelta::FromDays(int days) {
- // Preserve max to prevent overflow.
- if (days == std::numeric_limits<int>::max())
- return Max();
+inline TimeDelta TimeDelta::FromDays(int64 days) {
return TimeDelta(days * Time::kMicrosecondsPerDay);
}
// static
-inline TimeDelta TimeDelta::FromHours(int hours) {
- // Preserve max to prevent overflow.
- if (hours == std::numeric_limits<int>::max())
- return Max();
+inline TimeDelta TimeDelta::FromHours(int64 hours) {
return TimeDelta(hours * Time::kMicrosecondsPerHour);
}
// static
-inline TimeDelta TimeDelta::FromMinutes(int minutes) {
- // Preserve max to prevent overflow.
- if (minutes == std::numeric_limits<int>::max())
- return Max();
+inline TimeDelta TimeDelta::FromMinutes(int64 minutes) {
return TimeDelta(minutes * Time::kMicrosecondsPerMinute);
}
// static
inline TimeDelta TimeDelta::FromSeconds(int64 secs) {
- // Preserve max to prevent overflow.
- if (secs == std::numeric_limits<int64>::max())
- return Max();
return TimeDelta(secs * Time::kMicrosecondsPerSecond);
}
// static
inline TimeDelta TimeDelta::FromMilliseconds(int64 ms) {
- // Preserve max to prevent overflow.
- if (ms == std::numeric_limits<int64>::max())
- return Max();
return TimeDelta(ms * Time::kMicrosecondsPerMillisecond);
}
// static
inline TimeDelta TimeDelta::FromMicroseconds(int64 us) {
- // Preserve max to prevent overflow.
- if (us == std::numeric_limits<int64>::max())
- return Max();
return TimeDelta(us);
}
diff --git a/base/time/time_unittest.cc b/base/time/time_unittest.cc
index 40d7bd4..b5d2493 100644
--- a/base/time/time_unittest.cc
+++ b/base/time/time_unittest.cc
@@ -481,46 +481,6 @@ TEST_F(TimeTest, ExplodeBeforeUnixEpoch) {
EXPECT_EQ(1, exploded.millisecond);
}
-TEST_F(TimeTest, TimeDeltaMax) {
- TimeDelta max = TimeDelta::Max();
- EXPECT_TRUE(max.is_max());
- EXPECT_EQ(max, TimeDelta::Max());
- EXPECT_GT(max, TimeDelta::FromDays(100 * 365));
- EXPECT_GT(max, TimeDelta());
-}
-
-TEST_F(TimeTest, TimeDeltaMaxConversions) {
- TimeDelta t = TimeDelta::Max();
- EXPECT_EQ(std::numeric_limits<int64>::max(), t.ToInternalValue());
-
- EXPECT_EQ(std::numeric_limits<int>::max(), t.InDays());
- EXPECT_EQ(std::numeric_limits<int>::max(), t.InHours());
- EXPECT_EQ(std::numeric_limits<int>::max(), t.InMinutes());
- EXPECT_EQ(std::numeric_limits<double>::infinity(), t.InSecondsF());
- EXPECT_EQ(std::numeric_limits<int64>::max(), t.InSeconds());
- EXPECT_EQ(std::numeric_limits<double>::infinity(), t.InMillisecondsF());
- EXPECT_EQ(std::numeric_limits<int64>::max(), t.InMilliseconds());
- EXPECT_EQ(std::numeric_limits<int64>::max(), t.InMillisecondsRoundedUp());
-
- t = TimeDelta::FromDays(std::numeric_limits<int>::max());
- EXPECT_TRUE(t.is_max());
-
- t = TimeDelta::FromHours(std::numeric_limits<int>::max());
- EXPECT_TRUE(t.is_max());
-
- t = TimeDelta::FromMinutes(std::numeric_limits<int>::max());
- EXPECT_TRUE(t.is_max());
-
- t = TimeDelta::FromSeconds(std::numeric_limits<int64>::max());
- EXPECT_TRUE(t.is_max());
-
- t = TimeDelta::FromMilliseconds(std::numeric_limits<int64>::max());
- EXPECT_TRUE(t.is_max());
-
- t = TimeDelta::FromMicroseconds(std::numeric_limits<int64>::max());
- EXPECT_TRUE(t.is_max());
-}
-
TEST_F(TimeTest, Max) {
Time max = Time::Max();
EXPECT_TRUE(max.is_max());
diff --git a/cc/debug/rasterize_and_record_benchmark.cc b/cc/debug/rasterize_and_record_benchmark.cc
index ab8d1cb..55f5677 100644
--- a/cc/debug/rasterize_and_record_benchmark.cc
+++ b/cc/debug/rasterize_and_record_benchmark.cc
@@ -108,7 +108,8 @@ void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) {
return;
- base::TimeDelta min_time = base::TimeDelta::Max();
+ base::TimeDelta min_time =
+ base::TimeDelta::FromInternalValue(std::numeric_limits<int64>::max());
for (int i = 0; i < record_repeat_count_; ++i) {
base::TimeTicks start = Now();
scoped_refptr<Picture> picture = Picture::Create(
diff --git a/cc/debug/rasterize_and_record_benchmark_impl.cc b/cc/debug/rasterize_and_record_benchmark_impl.cc
index fd0b7bd..15cfd7a 100644
--- a/cc/debug/rasterize_and_record_benchmark_impl.cc
+++ b/cc/debug/rasterize_and_record_benchmark_impl.cc
@@ -104,7 +104,8 @@ void RasterizeAndRecordBenchmarkImpl::RunOnLayer(PictureLayerImpl* layer) {
int tile_size = content_rect.width() * content_rect.height();
- base::TimeDelta min_time = base::TimeDelta::Max();
+ base::TimeDelta min_time =
+ base::TimeDelta::FromInternalValue(std::numeric_limits<int64>::max());
bool is_solid_color = false;
for (int i = 0; i < rasterize_repeat_count_; ++i) {
diff --git a/cc/resources/picture_pile.cc b/cc/resources/picture_pile.cc
index 43b13c5..7e5a822 100644
--- a/cc/resources/picture_pile.cc
+++ b/cc/resources/picture_pile.cc
@@ -228,7 +228,8 @@ bool PicturePile::Update(
bool gather_pixel_refs = num_raster_threads > 1;
{
- base::TimeDelta best_duration = base::TimeDelta::Max();
+ base::TimeDelta best_duration = base::TimeDelta::FromInternalValue(
+ std::numeric_limits<int64>::max());
for (int i = 0; i < repeat_count; i++) {
base::TimeTicks start_time = stats_instrumentation->StartRecording();
picture = Picture::Create(record_rect,
diff --git a/cc/resources/picture_pile_impl.cc b/cc/resources/picture_pile_impl.cc
index 1254f13..b88a439 100644
--- a/cc/resources/picture_pile_impl.cc
+++ b/cc/resources/picture_pile_impl.cc
@@ -247,7 +247,8 @@ void PicturePileImpl::RasterCommon(
total_clip.Union(positive_clip);
#endif // NDEBUG
- base::TimeDelta best_duration = base::TimeDelta::Max();
+ base::TimeDelta best_duration =
+ base::TimeDelta::FromInternalValue(std::numeric_limits<int64>::max());
int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_);
int rasterized_pixel_count = 0;
diff --git a/content/renderer/media/websourcebuffer_impl.cc b/content/renderer/media/websourcebuffer_impl.cc
index de55d41..a7d8d8a 100644
--- a/content/renderer/media/websourcebuffer_impl.cc
+++ b/content/renderer/media/websourcebuffer_impl.cc
@@ -15,8 +15,6 @@ static base::TimeDelta DoubleToTimeDelta(double time) {
if (time == std::numeric_limits<double>::infinity())
return media::kInfiniteDuration();
- // Don't use base::TimeDelta::Max() here, as we want the largest finite time
- // delta.
base::TimeDelta max_time = base::TimeDelta::FromInternalValue(kint64max - 1);
double max_time_in_seconds = max_time.InSecondsF();
diff --git a/media/base/buffers.h b/media/base/buffers.h
index 5c5c47b..6a6c730 100644
--- a/media/base/buffers.h
+++ b/media/base/buffers.h
@@ -37,7 +37,7 @@ MEDIA_EXPORT extern inline base::TimeDelta kNoTimestamp() {
// Represents an infinite stream duration.
MEDIA_EXPORT extern inline base::TimeDelta kInfiniteDuration() {
- return base::TimeDelta::Max();
+ return base::TimeDelta::FromMicroseconds(kint64max);
}
} // namespace media
diff --git a/media/filters/chunk_demuxer.cc b/media/filters/chunk_demuxer.cc
index 3f8618a..b7244b9 100644
--- a/media/filters/chunk_demuxer.cc
+++ b/media/filters/chunk_demuxer.cc
@@ -1523,7 +1523,6 @@ void ChunkDemuxer::SetDuration(double duration) {
// This can be different if the value of |duration| doesn't fit the range or
// precision of TimeDelta.
TimeDelta min_duration = TimeDelta::FromInternalValue(1);
- // Don't use TimeDelta::Max() here, as we want the largest finite time delta.
TimeDelta max_duration = TimeDelta::FromInternalValue(kint64max - 1);
double min_duration_in_seconds = min_duration.InSecondsF();
double max_duration_in_seconds = max_duration.InSecondsF();
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc
index f26292a..0072976 100644
--- a/net/http/http_response_headers.cc
+++ b/net/http/http_response_headers.cc
@@ -1009,7 +1009,7 @@ TimeDelta HttpResponseHeaders::GetFreshnessLifetime(
// These responses are implicitly fresh (unless otherwise overruled):
if (response_code_ == 300 || response_code_ == 301 || response_code_ == 410)
- return TimeDelta::Max();
+ return TimeDelta::FromMicroseconds(kint64max);
return TimeDelta(); // not fresh
}
diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc
index 8e6a55a..a6f29c5 100644
--- a/net/spdy/spdy_session.cc
+++ b/net/spdy/spdy_session.cc
@@ -2723,7 +2723,9 @@ void SpdySession::CheckPingStatus(base::TimeTicks last_check_time) {
if (delay.InMilliseconds() < 0 || last_activity_time_ < last_check_time) {
// Track all failed PING messages in a separate bucket.
- RecordPingRTTHistogram(base::TimeDelta::Max());
+ const base::TimeDelta kFailedPing =
+ base::TimeDelta::FromInternalValue(INT_MAX);
+ RecordPingRTTHistogram(kFailedPing);
CloseSessionResult result =
DoCloseSession(ERR_SPDY_PING_FAILED, "Failed ping.");
DCHECK_EQ(result, SESSION_CLOSED_AND_REMOVED);
diff --git a/sync/sessions/nudge_tracker.cc b/sync/sessions/nudge_tracker.cc
index b69d753..212500a 100644
--- a/sync/sessions/nudge_tracker.cc
+++ b/sync/sessions/nudge_tracker.cc
@@ -192,9 +192,11 @@ bool NudgeTracker::IsTypeThrottled(ModelType type) const {
base::TimeDelta NudgeTracker::GetTimeUntilNextUnthrottle(
base::TimeTicks now) const {
DCHECK(IsAnyTypeThrottled()) << "This function requires a pending unthrottle";
+ const base::TimeDelta kMaxTimeDelta =
+ base::TimeDelta::FromInternalValue(kint64max);
// Return min of GetTimeUntilUnthrottle() values for all IsThrottled() types.
- base::TimeDelta time_until_next_unthrottle = base::TimeDelta::Max();
+ base::TimeDelta time_until_next_unthrottle = kMaxTimeDelta;
for (TypeTrackerMap::const_iterator it = type_trackers_.begin();
it != type_trackers_.end(); ++it) {
if (it->second.IsThrottled()) {
@@ -203,7 +205,7 @@ base::TimeDelta NudgeTracker::GetTimeUntilNextUnthrottle(
it->second.GetTimeUntilUnthrottle(now));
}
}
- DCHECK(!time_until_next_unthrottle.is_max());
+ DCHECK(kMaxTimeDelta != time_until_next_unthrottle);
return time_until_next_unthrottle;
}