Commit 28b4bf79 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Use TimeDelta::operator/() more, components/ edition.

Bug: 1104532
Change-Id: If6affe249332caf832f679e7321e1852c25683d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354915Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Commit-Queue: Jochen Eisinger <jochen@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798567}
parent 03a986b7
...@@ -285,7 +285,7 @@ double UserClassifier::GetHoursSinceLastTime(Event event) const { ...@@ -285,7 +285,7 @@ double UserClassifier::GetHoursSinceLastTime(Event event) const {
base::TimeDelta since_last_time = base::TimeDelta since_last_time =
clock_->Now() - pref_service_->GetTime(GetLastTimeKey(event)); clock_->Now() - pref_service_->GetTime(GetLastTimeKey(event));
return since_last_time.InSecondsF() / 3600; return since_last_time / base::TimeDelta::FromHours(1);
} }
bool UserClassifier::HasLastTime(Event event) const { bool UserClassifier::HasLastTime(Event event) const {
......
...@@ -91,7 +91,7 @@ void MediaControlsProgressView::UpdateProgress( ...@@ -91,7 +91,7 @@ void MediaControlsProgressView::UpdateProgress(
base::TimeDelta current_position = media_position.GetPosition(); base::TimeDelta current_position = media_position.GetPosition();
base::TimeDelta duration = media_position.duration(); base::TimeDelta duration = media_position.duration();
double progress = current_position.InSecondsF() / duration.InSecondsF(); double progress = current_position / duration;
SetBarProgress(progress); SetBarProgress(progress);
// Time formatting can't yet represent durations greater than 24 hours in // Time formatting can't yet represent durations greater than 24 hours in
......
...@@ -361,7 +361,7 @@ double UserClassifier::GetHoursSinceLastTime(Metric metric) const { ...@@ -361,7 +361,7 @@ double UserClassifier::GetHoursSinceLastTime(Metric metric) const {
base::TimeDelta since_last_time = base::TimeDelta since_last_time =
clock_->Now() - DeserializeTime(pref_service_->GetInt64( clock_->Now() - DeserializeTime(pref_service_->GetInt64(
kLastTimeKeys[static_cast<int>(metric)])); kLastTimeKeys[static_cast<int>(metric)]));
return since_last_time.InSecondsF() / 3600; return since_last_time / base::TimeDelta::FromHours(1);
} }
bool UserClassifier::HasLastTime(Metric metric) const { bool UserClassifier::HasLastTime(Metric metric) const {
......
...@@ -386,8 +386,7 @@ int ShortcutsProvider::CalculateScore( ...@@ -386,8 +386,7 @@ int ShortcutsProvider::CalculateScore(
base::TimeDelta time_passed = base::Time::Now() - shortcut.last_access_time; base::TimeDelta time_passed = base::Time::Now() - shortcut.last_access_time;
// Clamp to 0 in case time jumps backwards (e.g. due to DST). // Clamp to 0 in case time jumps backwards (e.g. due to DST).
double decay_exponent = double decay_exponent =
std::max(0.0, kLn2 * static_cast<double>(time_passed.InMicroseconds()) / std::max(0.0, kLn2 * time_passed / base::TimeDelta::FromDays(7));
base::Time::kMicrosecondsPerWeek);
// We modulate the decay factor based on how many times the shortcut has been // We modulate the decay factor based on how many times the shortcut has been
// used. Newly created shortcuts decay at full speed; otherwise, decaying by // used. Newly created shortcuts decay at full speed; otherwise, decaying by
......
...@@ -165,8 +165,7 @@ class TabLoadingFrameNavigationPolicyTest ...@@ -165,8 +165,7 @@ class TabLoadingFrameNavigationPolicyTest
double GetRelativeTime() { double GetRelativeTime() {
base::TimeTicks now = task_environment()->GetMockTickClock()->NowTicks(); base::TimeTicks now = task_environment()->GetMockTickClock()->NowTicks();
base::TimeDelta elapsed = now - start_; base::TimeDelta elapsed = now - start_;
double relative = double relative = elapsed / policy_->GetMaxTimeoutForTesting();
elapsed.InSecondsF() / policy_->GetMaxTimeoutForTesting().InSecondsF();
return relative; return relative;
} }
......
...@@ -1996,7 +1996,7 @@ TEST_F(SyncSchedulerImplTest, PollOnStartUpWithinBoundsAfterLongPause) { ...@@ -1996,7 +1996,7 @@ TEST_F(SyncSchedulerImplTest, PollOnStartUpWithinBoundsAfterLongPause) {
for (int i = 0; i < 10000; ++i) { for (int i = 0; i < 10000; ++i) {
base::Time result = ComputeLastPollOnStart(last_poll, poll_interval, now); base::Time result = ComputeLastPollOnStart(last_poll, poll_interval, now);
base::TimeDelta delay = result + poll_interval - now; base::TimeDelta delay = result + poll_interval - now;
double fraction = delay.InSeconds() * 1.0 / poll_interval.InSeconds(); double fraction = delay / poll_interval;
if (fraction > 0.005) { if (fraction > 0.005) {
found_delay_greater_than_5_permille = true; found_delay_greater_than_5_permille = true;
} else { } else {
......
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