1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_COMPONENT_UPDATER_UPDATE_SCHEDULER_H_
6 #define COMPONENTS_COMPONENT_UPDATER_UPDATE_SCHEDULER_H_
8 #include "base/functional/callback_forward.h"
9 #include "base/time/time.h"
11 namespace component_updater {
13 // Abstract interface for an update task scheduler.
14 class UpdateScheduler {
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.
20 base::RepeatingCallback<void(OnFinishedCallback on_finished)>;
21 using OnStopTaskCallback = base::RepeatingCallback<void()>;
23 virtual ~UpdateScheduler() = default;
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;
37 } // namespace component_updater
39 #endif // COMPONENTS_COMPONENT_UPDATER_UPDATE_SCHEDULER_H_