blob: c45d74b02e7d0fff48eb8d9917cbf1b2df368337 [file] [log] [blame]
sorin7c717622015-05-26 19:59:091// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "components/component_updater/timer.h"
6
7#include "base/bind.h"
sorin7c717622015-05-26 19:59:098#include "base/location.h"
9
10namespace component_updater {
11
tzik32768d52018-07-10 01:08:3212Timer::Timer() {}
sorin7c717622015-05-26 19:59:0913
14Timer::~Timer() {
15 DCHECK(thread_checker_.CalledOnValidThread());
16 Stop();
17}
18
19void Timer::Start(base::TimeDelta initial_delay,
20 base::TimeDelta delay,
21 const base::Closure& user_task) {
22 DCHECK(thread_checker_.CalledOnValidThread());
23
24 delay_ = delay;
25 user_task_ = user_task;
26
27 timer_.Start(FROM_HERE, initial_delay,
tzik2bcf8e42018-07-31 11:22:1528 base::BindOnce(&Timer::OnDelay, base::Unretained(this)));
sorin7c717622015-05-26 19:59:0929}
30
31void Timer::Stop() {
32 DCHECK(thread_checker_.CalledOnValidThread());
33 timer_.Stop();
34}
35
36void Timer::OnDelay() {
37 DCHECK(thread_checker_.CalledOnValidThread());
38
39 user_task_.Run();
40
41 timer_.Start(FROM_HERE, delay_,
tzik2bcf8e42018-07-31 11:22:1542 base::BindOnce(&Timer::OnDelay, base::Unretained(this)));
sorin7c717622015-05-26 19:59:0943}
44
45} // namespace component_updater