blob: ce42eedc5061d5e3eb40d8527fa4b18e3e72a59a [file] [log] [blame]
Tibor Goldschwendt5f173cb2018-06-21 22:50:401// Copyright 2018 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#ifndef COMPONENTS_COMPONENT_UPDATER_UPDATE_SCHEDULER_H_
6#define COMPONENTS_COMPONENT_UPDATER_UPDATE_SCHEDULER_H_
7
8#include "base/callback_forward.h"
9#include "base/time/time.h"
10
11namespace component_updater {
12
13// Abstract interface for an update task scheduler.
14class UpdateScheduler {
15 public:
16 using OnFinishedCallback = base::OnceCallback<void()>;
17 // Type of task to be run by the scheduler. The task can start asynchronous
18 // operations and must call |on_finished| when all operations have completed.
19 using UserTask =
20 base::RepeatingCallback<void(OnFinishedCallback on_finished)>;
21 using OnStopTaskCallback = base::RepeatingCallback<void()>;
22
23 virtual ~UpdateScheduler() = default;
24
25 // Schedules |user_task| to be run periodically with at least an interval of
26 // |delay|. The first time |user_task| will be run after at least
27 // |initial_delay|. If the execution of |user_task| must be stopped before it
28 // called its |on_finished| callback, |on_stop| will be called.
29 virtual void Schedule(const base::TimeDelta& initial_delay,
30 const base::TimeDelta& delay,
31 const UserTask& user_task,
32 const OnStopTaskCallback& on_stop) = 0;
33 // Stops to periodically run |user_task| previously scheduled with |Schedule|.
34 virtual void Stop() = 0;
35};
36
37} // namespace component_updater
38
39#endif // COMPONENTS_COMPONENT_UPDATER_UPDATE_SCHEDULER_H_