1 // Copyright 2014 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 #ifndef COMPONENTS_DOMAIN_RELIABILITY_DISPATCHER_H_
6 #define COMPONENTS_DOMAIN_RELIABILITY_DISPATCHER_H_
10 #include "base/callback_forward.h"
11 #include "base/time/time.h"
12 #include "components/domain_reliability/domain_reliability_export.h"
14 namespace tracked_objects
{
16 } // namespace tracked_objects
18 namespace domain_reliability
{
22 // Runs tasks during a specified interval. Calling |RunEligibleTasks| gives any
23 // task a chance to run early (if the minimum delay has already passed); tasks
24 // that aren't run early will be run once their maximum delay has passed.
26 // (See scheduler.h for an explanation of how the intervals are chosen.)
27 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityDispatcher
{
29 explicit DomainReliabilityDispatcher(MockableTime
* time
);
30 ~DomainReliabilityDispatcher();
32 // Schedules |task| to be executed between |min_delay| and |max_delay| from
33 // now. The task will be run at most |max_delay| from now; once |min_delay|
34 // has passed, any call to |RunEligibleTasks| will run the task earlier than
36 void ScheduleTask(const base::Closure
& task
,
37 base::TimeDelta min_delay
,
38 base::TimeDelta max_delay
);
40 // Runs all tasks whose minimum delay has already passed.
41 void RunEligibleTasks();
46 // Adds |task| to the set of all tasks, but not the set of eligible tasks.
47 void MakeTaskWaiting(Task
* task
);
49 // Adds |task| to the set of eligible tasks, and also the set of all tasks
50 // if not already there.
51 void MakeTaskEligible(Task
* task
);
53 // Runs |task|'s callback, removes it from both sets, and deletes it.
54 void RunAndDeleteTask(Task
* task
);
57 std::set
<Task
*> tasks_
;
58 std::set
<Task
*> eligible_tasks_
;
61 } // namespace domain_reliability