Commit 874f09c6 authored by François Doray's avatar François Doray Committed by Commit Bot

Revert "Base: Mark TimeDelta::In...() methods as constexpr."

This reverts commit 4d971424.

Reason for revert: Caused a binary size regression on Android. https://crbug.com/883902

TBR=alemate@chromium.org,chili@chromium.org,kouhei@chromium.org

Bug: 883902

Original change's description:
> Base: Mark TimeDelta::In...() methods as constexpr.
>
> This will allow use of these methods in constexpr expressions such as
> https://chromium-review.googlesource.com/c/chromium/src/+/1195852/4/chrome/browser/resource_coordinator/tab_manager_features.h#118
>
> Change-Id: I4407ac72846e7c826e5cf3d920cda5f4b5d5071c
> Reviewed-on: https://chromium-review.googlesource.com/1220446
> Commit-Queue: François Doray <fdoray@chromium.org>
> Reviewed-by: Mark Mentovai <mark@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#590667}

TBR=fdoray@chromium.org,mark@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: Ib3b8ead36933549c238622ea2b6641dc427f65ad
Reviewed-on: https://chromium-review.googlesource.com/c/1226098
Commit-Queue: François Doray <fdoray@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606467}
parent aea3512d
......@@ -37,6 +37,14 @@ ThreadTicksNowFunction g_thread_ticks_now_function =
// TimeDelta ------------------------------------------------------------------
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::InDaysFloored() const {
if (is_max()) {
// Preserve max to prevent overflow.
......@@ -50,6 +58,54 @@ int TimeDelta::InDaysFloored() const {
return result;
}
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_t TimeDelta::InSeconds() const {
if (is_max()) {
// Preserve max to prevent overflow.
return std::numeric_limits<int64_t>::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_t TimeDelta::InMilliseconds() const {
if (is_max()) {
// Preserve max to prevent overflow.
return std::numeric_limits<int64_t>::max();
}
return delta_ / Time::kMicrosecondsPerMillisecond;
}
int64_t TimeDelta::InMillisecondsRoundedUp() const {
if (is_max()) {
// Preserve max to prevent overflow.
......@@ -63,6 +119,22 @@ int64_t TimeDelta::InMillisecondsRoundedUp() const {
return result;
}
double TimeDelta::InMicrosecondsF() const {
if (is_max()) {
// Preserve max to prevent overflow.
return std::numeric_limits<double>::infinity();
}
return static_cast<double>(delta_);
}
int64_t TimeDelta::InNanoseconds() const {
if (is_max()) {
// Preserve max to prevent overflow.
return std::numeric_limits<int64_t>::max();
}
return delta_ * Time::kNanosecondsPerMicrosecond;
}
namespace time_internal {
int64_t SaturatedAdd(TimeDelta delta, int64_t value) {
......
......@@ -186,18 +186,18 @@ class BASE_EXPORT TimeDelta {
// towards zero, std::trunc() behavior). The InXYZFloored() versions round to
// lesser integers (std::floor() behavior). The XYZRoundedUp() versions round
// up to greater integers (std::ceil() behavior).
constexpr int InDays() const;
int InDays() const;
int InDaysFloored() const;
constexpr int InHours() const;
constexpr int InMinutes() const;
constexpr double InSecondsF() const;
constexpr int64_t InSeconds() const;
constexpr double InMillisecondsF() const;
constexpr int64_t InMilliseconds() const;
int InHours() const;
int InMinutes() const;
double InSecondsF() const;
int64_t InSeconds() const;
double InMillisecondsF() const;
int64_t InMilliseconds() const;
int64_t InMillisecondsRoundedUp() const;
constexpr int64_t InMicroseconds() const;
constexpr double InMicrosecondsF() const;
constexpr int64_t InNanoseconds() const;
constexpr int64_t InMicroseconds() const { return delta_; }
double InMicrosecondsF() const;
int64_t InNanoseconds() const;
// Computations with other deltas. Can easily be made constexpr with C++17 but
// hard to do until then per limitations around
......@@ -294,11 +294,6 @@ class BASE_EXPORT TimeDelta {
// and a known-positive value.
static constexpr TimeDelta FromProduct(int64_t value, int64_t positive_value);
// Returns |delta_| (microseconds) divided by |divisor|, or the max value
// representable in T if is_max().
template <typename T>
constexpr T DivideOrMax(int64_t divisor) const;
// Delta in microseconds.
int64_t delta_;
};
......@@ -326,6 +321,8 @@ template<class TimeClass>
class TimeBase {
public:
static constexpr int64_t kHoursPerDay = 24;
static constexpr int64_t kSecondsPerMinute = 60;
static constexpr int64_t kSecondsPerHour = 60 * kSecondsPerMinute;
static constexpr int64_t kMillisecondsPerSecond = 1000;
static constexpr int64_t kMillisecondsPerDay =
kMillisecondsPerSecond * 60 * 60 * kHoursPerDay;
......@@ -784,64 +781,6 @@ constexpr TimeDelta TimeDelta::Min() {
return TimeDelta(std::numeric_limits<int64_t>::min());
}
// Must be defined before use below.
template <typename T>
constexpr T TimeDelta::DivideOrMax(int64_t divisor) const {
return is_max() ? std::numeric_limits<T>::max()
: static_cast<T>(delta_ / divisor);
}
// Must be defined before use below.
template <>
constexpr double TimeDelta::DivideOrMax<double>(int64_t divisor) const {
return is_max() ? std::numeric_limits<double>::infinity()
: static_cast<double>(delta_) / divisor;
}
constexpr int TimeDelta::InDays() const {
return DivideOrMax<int>(Time::kMicrosecondsPerDay);
}
constexpr int TimeDelta::InHours() const {
return DivideOrMax<int>(Time::kMicrosecondsPerHour);
}
constexpr int TimeDelta::InMinutes() const {
return DivideOrMax<int>(Time::kMicrosecondsPerMinute);
}
constexpr double TimeDelta::InSecondsF() const {
return DivideOrMax<double>(Time::kMicrosecondsPerSecond);
}
constexpr int64_t TimeDelta::InSeconds() const {
return DivideOrMax<int64_t>(Time::kMicrosecondsPerSecond);
}
constexpr double TimeDelta::InMillisecondsF() const {
return DivideOrMax<double>(Time::kMicrosecondsPerMillisecond);
}
constexpr int64_t TimeDelta::InMilliseconds() const {
return DivideOrMax<int64_t>(Time::kMicrosecondsPerMillisecond);
}
constexpr int64_t TimeDelta::InMicroseconds() const {
return DivideOrMax<int64_t>(1);
}
constexpr double TimeDelta::InMicrosecondsF() const {
return DivideOrMax<double>(1);
}
constexpr int64_t TimeDelta::InNanoseconds() const {
if (is_max()) {
// Preserve max to prevent overflow.
return std::numeric_limits<int64_t>::max();
}
return delta_ * Time::kNanosecondsPerMicrosecond;
}
// static
constexpr TimeDelta TimeDelta::FromDouble(double value) {
// TODO(crbug.com/612601): Use saturated_cast<int64_t>(value) once we sort out
......
......@@ -65,7 +65,9 @@ class Adapter : public AlsReader::Observer,
// Size of |ambient_light_values_|.
static constexpr int kNumberAmbientValuesToTrack =
kAmbientLightShortHorizon.InSeconds() * AlsReader::kAlsPollFrequency;
(kAmbientLightShortHorizon.InMicroseconds() /
base::Time::kMicrosecondsPerSecond) *
AlsReader::kAlsPollFrequency;
// The values in Params can be overridden by experiment flags.
struct Params {
......
......@@ -111,23 +111,22 @@ struct ProactiveTabFreezeAndDiscardParams {
// exponentially increasing timeouts beyond that.
static constexpr base::FeatureParam<int> kLowOccludedTimeout{
&features::kProactiveTabFreezeAndDiscard, "LowOccludedTimeoutSeconds",
base::TimeDelta::FromHours(6).InSeconds()};
6 * base::Time::kSecondsPerHour};
static constexpr base::FeatureParam<int> kModerateOccludedTimeout{
&features::kProactiveTabFreezeAndDiscard,
"ModerateOccludedTimeoutSeconds",
base::TimeDelta::FromHours(1).InSeconds()};
"ModerateOccludedTimeoutSeconds", 1 * base::Time::kSecondsPerHour};
static constexpr base::FeatureParam<int> kHighOccludedTimeout{
&features::kProactiveTabFreezeAndDiscard, "HighOccludedTimeoutSeconds",
static_cast<int>(base::TimeDelta::FromMinutes(10).InSeconds())};
10 * base::Time::kSecondsPerMinute};
static constexpr base::FeatureParam<int> kFreezeTimeout{
&features::kProactiveTabFreezeAndDiscard, "FreezeTimeout",
base::TimeDelta::FromMinutes(10).InSeconds()};
10 * base::Time::kSecondsPerMinute};
static constexpr base::FeatureParam<int> kUnfreezeTimeout{
&features::kProactiveTabFreezeAndDiscard, "UnfreezeTimeout",
base::TimeDelta::FromMinutes(15).InSeconds()};
15 * base::Time::kSecondsPerMinute};
static constexpr base::FeatureParam<int> kRefreezeTimeout{
&features::kProactiveTabFreezeAndDiscard, "RefreezeTimeout",
base::TimeDelta::FromMinutes(10).InSeconds()};
10 * base::Time::kSecondsPerMinute};
static constexpr base::FeatureParam<bool> kDisableHeuristicsProtections{
&features::kProactiveTabFreezeAndDiscard,
......@@ -198,17 +197,16 @@ struct SiteCharacteristicsDatabaseParams {
// tabs don't use any of these features in this time window.
static constexpr base::FeatureParam<int> kFaviconUpdateObservationWindow{
&features::kSiteCharacteristicsDatabase, "FaviconUpdateObservationWindow",
base::TimeDelta::FromHours(2).InSeconds()};
2 * base::Time::kSecondsPerHour};
static constexpr base::FeatureParam<int> kTitleUpdateObservationWindow{
&features::kSiteCharacteristicsDatabase, "TitleUpdateObservationWindow",
base::TimeDelta::FromHours(2).InSeconds()};
2 * base::Time::kSecondsPerHour};
static constexpr base::FeatureParam<int> kAudioUsageObservationWindow{
&features::kSiteCharacteristicsDatabase, "AudioUsageObservationWindow",
base::TimeDelta::FromHours(2).InSeconds()};
2 * base::Time::kSecondsPerHour};
static constexpr base::FeatureParam<int> kNotificationsUsageObservationWindow{
&features::kSiteCharacteristicsDatabase,
"NotificationsUsageObservationWindow",
base::TimeDelta::FromHours(2).InSeconds()};
"NotificationsUsageObservationWindow", 2 * base::Time::kSecondsPerHour};
static constexpr base::FeatureParam<int> kTitleOrFaviconChangeGracePeriod{
&features::kSiteCharacteristicsDatabase,
"TitleOrFaviconChangeGracePeriod", 20 /* 20 seconds */};
......@@ -264,7 +262,7 @@ struct InfiniteSessionRestoreParams {
// This is the 75th percentile of SessionRestore.RestoredTab.TimeSinceActive.
static constexpr base::FeatureParam<int> kMaxTimeSinceLastUseToRestore{
&features::kInfiniteSessionRestore, "MaxTimeSinceLastUseToRestore",
base::TimeDelta::FromHours(6).InSeconds()};
6 * base::Time::kSecondsPerHour};
// Taken from an informal survey of Googlers on min engagement of things they
// think *must* load. Note that about 25% of session-restore tabs fall above
// this threshold (see SessionRestore.RestoredTab.SiteEngagementScore).
......
......@@ -32,8 +32,8 @@ namespace offline_pages {
namespace {
const bool kUserRequest = true;
const bool kStartOfProcessing = true;
constexpr int kMinDurationSeconds = 1;
constexpr int kMaxDurationSeconds = base::TimeDelta::FromDays(7).InSeconds();
constexpr base::TimeDelta kMinDuration = base::TimeDelta::FromSeconds(1);
constexpr base::TimeDelta kMaxDuration = base::TimeDelta::FromDays(7);
const int kDurationBuckets = 50;
const int kDisabledTaskRecheckSeconds = 5;
......@@ -66,8 +66,8 @@ void RecordOfflinerResultUMA(const ClientId& client_id,
base::TimeDelta duration = base::Time::Now() - request_creation_time;
base::UmaHistogramCustomCounts(
AddHistogramSuffix(client_id, "OfflinePages.Background.TimeToSaved"),
duration.InSeconds(), kMinDurationSeconds, kMaxDurationSeconds,
kDurationBuckets);
duration.InSeconds(), kMinDuration.InSeconds(),
kMaxDuration.InSeconds(), kDurationBuckets);
}
}
......@@ -112,7 +112,7 @@ void RecordCancelTimeUMA(const SavePageRequest& canceled_request) {
base::UmaHistogramCustomCounts(
AddHistogramSuffix(canceled_request.client_id(),
"OfflinePages.Background.TimeToCanceled"),
duration.InSeconds(), kMinDurationSeconds, kMaxDurationSeconds,
duration.InSeconds(), kMinDuration.InSeconds(), kMaxDuration.InSeconds(),
kDurationBuckets);
}
......
......@@ -54,8 +54,8 @@ constexpr uint8_t kMessageHeader[] =
// 5.3. "A single 0 byte which serves as a separator." [spec text]
"HTTP Exchange 1 b2";
constexpr int kFourWeeksInSeconds = base::TimeDelta::FromDays(28).InSeconds();
constexpr int kOneWeekInSeconds = base::TimeDelta::FromDays(7).InSeconds();
constexpr base::TimeDelta kOneWeek = base::TimeDelta::FromDays(7);
constexpr base::TimeDelta kFourWeeks = base::TimeDelta::FromDays(4 * 7);
base::Optional<crypto::SignatureVerifier::SignatureAlgorithm>
GetSignatureAlgorithm(scoped_refptr<net::X509Certificate> cert,
......@@ -206,7 +206,7 @@ bool VerifyTimestamps(const SignedExchangeEnvelope& envelope,
// 3. "If expires is more than 7 days (604800 seconds) after date, return
// "invalid"." [spec text]
if ((expires_time - creation_time).InSeconds() > kOneWeekInSeconds)
if ((expires_time - creation_time).InSeconds() > kOneWeek.InSeconds())
return false;
// 4. "If the current time is before date or after expires, return
......@@ -214,21 +214,21 @@ bool VerifyTimestamps(const SignedExchangeEnvelope& envelope,
if (verification_time < creation_time) {
UMA_HISTOGRAM_CUSTOM_COUNTS(
"SignedExchange.SignatureVerificationError.NotYetValid",
(creation_time - verification_time).InSeconds(), 1, kFourWeeksInSeconds,
50);
(creation_time - verification_time).InSeconds(), 1,
kFourWeeks.InSeconds(), 50);
return false;
}
if (expires_time < verification_time) {
UMA_HISTOGRAM_CUSTOM_COUNTS(
"SignedExchange.SignatureVerificationError.Expired",
(verification_time - expires_time).InSeconds(), 1, kFourWeeksInSeconds,
50);
(verification_time - expires_time).InSeconds(), 1,
kFourWeeks.InSeconds(), 50);
return false;
}
UMA_HISTOGRAM_CUSTOM_COUNTS("SignedExchange.TimeUntilExpiration",
(expires_time - verification_time).InSeconds(), 1,
kOneWeekInSeconds, 50);
kOneWeek.InSeconds(), 50);
return true;
}
......
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