Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / component_updater / timer.cc
blobe3c79ece2088a7fbaffd8b182b578fa9700cfdba
1 // 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.
5 #include "components/component_updater/timer.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/location.h"
11 namespace component_updater {
13 Timer::Timer() : timer_(false, false) {
16 Timer::~Timer() {
17 DCHECK(thread_checker_.CalledOnValidThread());
18 Stop();
21 void Timer::Start(base::TimeDelta initial_delay,
22 base::TimeDelta delay,
23 const base::Closure& user_task) {
24 DCHECK(thread_checker_.CalledOnValidThread());
26 delay_ = delay;
27 user_task_ = user_task;
29 timer_.Start(FROM_HERE, initial_delay,
30 base::Bind(&Timer::OnDelay, base::Unretained(this)));
33 void Timer::Stop() {
34 DCHECK(thread_checker_.CalledOnValidThread());
35 timer_.Stop();
38 void Timer::OnDelay() {
39 DCHECK(thread_checker_.CalledOnValidThread());
41 user_task_.Run();
43 timer_.Start(FROM_HERE, delay_,
44 base::Bind(&Timer::OnDelay, base::Unretained(this)));
47 } // namespace component_updater