This source file includes following definitions.
- Start
- Restart
- Stop
- CheckTimedOut
- IsRunning
#include "content/browser/renderer_host/input/timeout_monitor.h"
using base::Time;
using base::TimeDelta;
namespace content {
TimeoutMonitor::TimeoutMonitor(const TimeoutHandler& timeout_handler)
: timeout_handler_(timeout_handler) {
DCHECK(!timeout_handler_.is_null());
}
TimeoutMonitor::~TimeoutMonitor() {}
void TimeoutMonitor::Start(TimeDelta delay) {
Time requested_end_time = Time::Now() + delay;
if (time_when_considered_timed_out_.is_null() ||
time_when_considered_timed_out_ > requested_end_time)
time_when_considered_timed_out_ = requested_end_time;
if (timeout_timer_.IsRunning() && timeout_timer_.GetCurrentDelay() <= delay) {
return;
}
time_when_considered_timed_out_ = requested_end_time;
timeout_timer_.Stop();
timeout_timer_.Start(FROM_HERE, delay, this, &TimeoutMonitor::CheckTimedOut);
}
void TimeoutMonitor::Restart(TimeDelta delay) {
time_when_considered_timed_out_ = Time();
Start(delay);
}
void TimeoutMonitor::Stop() {
time_when_considered_timed_out_ = Time();
}
void TimeoutMonitor::CheckTimedOut() {
if (time_when_considered_timed_out_.is_null())
return;
Time now = Time::Now();
if (now < time_when_considered_timed_out_) {
Start(time_when_considered_timed_out_ - now);
return;
}
timeout_handler_.Run();
}
bool TimeoutMonitor::IsRunning() const {
return timeout_timer_.IsRunning() &&
!time_when_considered_timed_out_.is_null();
}
}