mirror of
https://github.com/klzgrad/naiveproxy.git
synced 2024-11-24 14:26:09 +03:00
60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
// Copyright 2014 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "base/timer/mock_timer.h"
|
|
|
|
namespace base {
|
|
|
|
MockTimer::MockTimer(bool retain_user_task, bool is_repeating)
|
|
: Timer(retain_user_task, is_repeating),
|
|
is_running_(false) {
|
|
}
|
|
|
|
MockTimer::MockTimer(const Location& posted_from,
|
|
TimeDelta delay,
|
|
const base::Closure& user_task,
|
|
bool is_repeating)
|
|
: Timer(true, is_repeating), delay_(delay), is_running_(false) {}
|
|
|
|
MockTimer::~MockTimer() = default;
|
|
|
|
bool MockTimer::IsRunning() const {
|
|
return is_running_;
|
|
}
|
|
|
|
base::TimeDelta MockTimer::GetCurrentDelay() const {
|
|
return delay_;
|
|
}
|
|
|
|
void MockTimer::Start(const Location& posted_from,
|
|
TimeDelta delay,
|
|
const base::Closure& user_task) {
|
|
delay_ = delay;
|
|
user_task_ = user_task;
|
|
Reset();
|
|
}
|
|
|
|
void MockTimer::Stop() {
|
|
is_running_ = false;
|
|
if (!retain_user_task())
|
|
user_task_.Reset();
|
|
}
|
|
|
|
void MockTimer::Reset() {
|
|
DCHECK(!user_task_.is_null());
|
|
is_running_ = true;
|
|
}
|
|
|
|
void MockTimer::Fire() {
|
|
DCHECK(is_running_);
|
|
base::Closure old_task = user_task_;
|
|
if (is_repeating())
|
|
Reset();
|
|
else
|
|
Stop();
|
|
old_task.Run();
|
|
}
|
|
|
|
} // namespace base
|