summaryrefslogtreecommitdiffstats
path: root/chrome/browser/policy/delayed_work_scheduler.cc
blob: 35fd049b06f916272eefad52db89e6029570bd4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) 2011 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 "chrome/browser/policy/delayed_work_scheduler.h"

#include <algorithm>

#include "base/logging.h"
#include "base/message_loop.h"

namespace policy {

DelayedWorkScheduler::DelayedWorkScheduler() {
}

DelayedWorkScheduler::~DelayedWorkScheduler() {
  timer_.Stop();
}

void DelayedWorkScheduler::DoDelayedWork() {
  callback_.Run();
}

void DelayedWorkScheduler::CancelDelayedWork() {
  timer_.Stop();
}

void DelayedWorkScheduler::PostDelayedWork(
    const base::Closure& callback,
    int64 delay) {
  callback_ = callback;
  timer_.Start(FROM_HERE,
               base::TimeDelta::FromMilliseconds(delay),
               this,
               &DelayedWorkScheduler::DoDelayedWork);
}

}  // namespace policy