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