Commit 6e9abea2 authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Remove the 'double' methods from blink::TimerBase

Remove the methods in blink::TimerBase that either take or return
a time delta as a double. These methods are mostly unused - a few calls
to StartOneShot and NextFireInterval, and it should be preferable for
new code to use the TimeDelta methods. The non-Delta-suffixed names are
kept - i.e they take on the name of their removed equivalent where
applicable.

The few users of StartOneShot(double, ...) are open-coded instead, and
uses of other methods are adjusted as needed.

The unit tests for Timer is overhauled to use TimeTicks and TimeDelta
throughout.

Bug: 763980
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I47c0449a9ea68e6e984c371e19f03f747bb5b1e0
Reviewed-on: https://chromium-review.googlesource.com/1131131
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574127}
parent 410d3d75
......@@ -190,9 +190,10 @@ void DocumentTimeline::ScheduleNextService() {
}
void DocumentTimeline::DocumentTimelineTiming::WakeAfter(double duration) {
if (timer_.IsActive() && timer_.NextFireInterval() < duration)
TimeDelta duration_delta = TimeDelta::FromSecondsD(duration);
if (timer_.IsActive() && timer_.NextFireInterval() < duration_delta)
return;
timer_.StartOneShot(duration, FROM_HERE);
timer_.StartOneShot(duration_delta, FROM_HERE);
}
void DocumentTimeline::DocumentTimelineTiming::ServiceOnNextFrame() {
......
......@@ -116,7 +116,7 @@ DOMTimer::~DOMTimer() {
}
void DOMTimer::Stop() {
const bool is_interval = !RepeatIntervalDelta().is_zero();
const bool is_interval = !RepeatInterval().is_zero();
probe::AsyncTaskCanceledBreakable(
GetExecutionContext(), is_interval ? "clearInterval" : "clearTimeout",
this);
......@@ -146,17 +146,17 @@ void DOMTimer::Fired() {
TRACE_EVENT1("devtools.timeline", "TimerFire", "data",
InspectorTimerFireEvent::Data(context, timeout_id_));
const bool is_interval = !RepeatIntervalDelta().is_zero();
const bool is_interval = !RepeatInterval().is_zero();
probe::UserCallback probe(context, is_interval ? "setInterval" : "setTimeout",
g_null_atom, true);
probe::AsyncTask async_task(context, this, is_interval ? "fired" : nullptr);
// Simple case for non-one-shot timers.
if (IsActive()) {
if (is_interval && RepeatIntervalDelta() < kMinimumInterval) {
if (is_interval && RepeatInterval() < kMinimumInterval) {
nesting_level_++;
if (nesting_level_ >= kMaxTimerNestingLevel)
AugmentRepeatInterval(kMinimumInterval - RepeatIntervalDelta());
AugmentRepeatInterval(kMinimumInterval - RepeatInterval());
}
// No access to member variables after this point, it can delete the timer.
......
......@@ -59,9 +59,9 @@ void PausableTimer::Pause() {
paused_ = true;
#endif
if (IsActive()) {
next_fire_interval_ = NextFireIntervalDelta();
next_fire_interval_ = NextFireInterval();
DCHECK_GE(next_fire_interval_, TimeDelta());
repeat_interval_ = RepeatIntervalDelta();
repeat_interval_ = RepeatInterval();
TimerBase::Stop();
}
}
......
......@@ -115,9 +115,11 @@ void SearchInputType::StartSearchEventTimer() {
return;
}
// After typing the first key, we wait 0.5 seconds.
// After the second key, 0.4 seconds, then 0.3, then 0.2 from then on.
search_event_timer_.StartOneShot(max(0.2, 0.6 - 0.1 * length), FROM_HERE);
// After typing the first key, we wait 500ms.
// After the second key, 400ms, then 300, then 200 from then on.
unsigned step = std::min(length, 4u) - 1;
TimeDelta timeout = TimeDelta::FromMilliseconds(500 - 100 * step);
search_event_timer_.StartOneShot(timeout, FROM_HERE);
}
void SearchInputType::DispatchSearchEvent() {
......
......@@ -98,7 +98,9 @@ class SecureTextTimer final : public TimerBase {
void RestartWithNewText(unsigned last_typed_character_offset) {
last_typed_character_offset_ = last_typed_character_offset;
if (Settings* settings = layout_text_->GetDocument().GetSettings()) {
StartOneShot(settings->GetPasswordEchoDurationInSeconds(), FROM_HERE);
StartOneShot(
TimeDelta::FromSecondsD(settings->GetPasswordEchoDurationInSeconds()),
FROM_HERE);
}
}
void Invalidate() { last_typed_character_offset_ = -1; }
......
......@@ -120,7 +120,7 @@ bool SMILTimeContainer::HasAnimations() const {
bool SMILTimeContainer::HasPendingSynchronization() const {
return frame_scheduling_state_ == kSynchronizeAnimations &&
wakeup_timer_.IsActive() && !wakeup_timer_.NextFireInterval();
wakeup_timer_.IsActive() && wakeup_timer_.NextFireInterval().is_zero();
}
void SMILTimeContainer::NotifyIntervalsChanged() {
......@@ -267,7 +267,7 @@ void SMILTimeContainer::ScheduleWakeUp(
FrameSchedulingState frame_scheduling_state) {
DCHECK(frame_scheduling_state == kSynchronizeAnimations ||
frame_scheduling_state == kFutureAnimationFrame);
wakeup_timer_.StartOneShot(delay_time, FROM_HERE);
wakeup_timer_.StartOneShot(TimeDelta::FromSecondsD(delay_time), FROM_HERE);
frame_scheduling_state_ = frame_scheduling_state;
}
......
......@@ -115,7 +115,7 @@ TEST_F(SVGImageTest, TimelineSuspendAndResume) {
// true for shouldPauseAnimation, this will result in the timeline being
// suspended.
test::RunDelayedTasks(TimeDelta::FromMilliseconds(1) +
timer->NextFireIntervalDelta());
timer->NextFireInterval());
EXPECT_TRUE(chrome_client.IsSuspended());
EXPECT_FALSE(timer->IsActive());
......@@ -149,7 +149,7 @@ TEST_F(SVGImageTest, ResetAnimation) {
// Fire the timer/trigger a frame update. The timeline will remain
// suspended and no frame will be scheduled.
test::RunDelayedTasks(TimeDelta::FromMillisecondsD(1) +
timer->NextFireIntervalDelta());
timer->NextFireInterval());
EXPECT_TRUE(chrome_client.IsSuspended());
EXPECT_FALSE(timer->IsActive());
......@@ -226,7 +226,7 @@ TEST_F(SVGImagePageVisibilityTest, PageVisibilityHiddenToVisible) {
// Wait for the next animation frame to be triggered, and then trigger a new
// frame. The image animation timeline should be running.
test::RunDelayedTasks(TimeDelta::FromMilliseconds(1) +
timer->NextFireIntervalDelta());
timer->NextFireInterval());
Compositor().BeginFrame();
EXPECT_FALSE(svg_image_chrome_client.IsSuspended());
......@@ -236,7 +236,7 @@ TEST_F(SVGImagePageVisibilityTest, PageVisibilityHiddenToVisible) {
// animation timeline.)
WebView().SetVisibilityState(mojom::PageVisibilityState::kHidden, false);
test::RunDelayedTasks(TimeDelta::FromMilliseconds(1) +
timer->NextFireIntervalDelta());
timer->NextFireInterval());
EXPECT_TRUE(svg_image_chrome_client.IsSuspended());
......@@ -244,7 +244,7 @@ TEST_F(SVGImagePageVisibilityTest, PageVisibilityHiddenToVisible) {
// frame and resume the image animation.
WebView().SetVisibilityState(mojom::PageVisibilityState::kVisible, false);
test::RunDelayedTasks(TimeDelta::FromMilliseconds(1) +
timer->NextFireIntervalDelta());
timer->NextFireInterval());
Compositor().BeginFrame();
EXPECT_FALSE(svg_image_chrome_client.IsSuspended());
......
......@@ -26,15 +26,11 @@
#include "third_party/blink/renderer/platform/timer.h"
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <limits>
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h"
#include "third_party/blink/renderer/platform/wtf/address_sanitizer.h"
#include "third_party/blink/renderer/platform/wtf/hash_set.h"
#include "third_party/blink/renderer/platform/wtf/time.h"
namespace blink {
......@@ -74,7 +70,7 @@ void TimerBase::Stop() {
weak_ptr_factory_.InvalidateWeakPtrs();
}
TimeDelta TimerBase::NextFireIntervalDelta() const {
TimeDelta TimerBase::NextFireInterval() const {
DCHECK(IsActive());
TimeTicks current = TimerCurrentTimeTicks();
if (next_fire_time_ < current)
......
......@@ -52,12 +52,6 @@ class PLATFORM_EXPORT TimerBase {
void Start(TimeDelta next_fire_interval,
TimeDelta repeat_interval,
const base::Location&);
void Start(double next_fire_interval,
double repeat_interval,
const base::Location& from_here) {
Start(TimeDelta::FromSecondsD(next_fire_interval),
TimeDelta::FromSecondsD(repeat_interval), from_here);
}
void StartRepeating(TimeDelta repeat_interval, const base::Location& caller) {
Start(repeat_interval, repeat_interval, caller);
......@@ -66,9 +60,6 @@ class PLATFORM_EXPORT TimerBase {
void StartOneShot(TimeDelta interval, const base::Location& caller) {
Start(interval, TimeDelta(), caller);
}
void StartOneShot(double interval, const base::Location& caller) {
StartOneShot(TimeDelta::FromSecondsD(interval), caller);
}
// Timer cancellation is fast enough that you shouldn't have to worry
// about it unless you're canceling tens of thousands of tasks.
......@@ -76,22 +67,14 @@ class PLATFORM_EXPORT TimerBase {
bool IsActive() const;
const base::Location& GetLocation() const { return location_; }
TimeDelta NextFireIntervalDelta() const;
double NextFireInterval() const {
return NextFireIntervalDelta().InSecondsF();
}
TimeDelta RepeatIntervalDelta() const { return repeat_interval_; }
double RepeatInterval() const { return RepeatIntervalDelta().InSecondsF(); }
TimeDelta NextFireInterval() const;
TimeDelta RepeatInterval() const { return repeat_interval_; }
void AugmentRepeatInterval(TimeDelta delta) {
TimeTicks now = TimerCurrentTimeTicks();
SetNextFireTime(now, std::max(next_fire_time_ - now + delta, TimeDelta()));
repeat_interval_ += delta;
}
void AugmentRepeatInterval(double delta) {
AugmentRepeatInterval(TimeDelta::FromSecondsD(delta));
}
void MoveToNewTaskRunner(scoped_refptr<base::SingleThreadTaskRunner>);
......
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