Ignore title parameter for navigator.registerProtocolHandler
[chromium-blink-merge.git] / components / domain_reliability / dispatcher.h
blob58c2b2702356caa0119a509610dafed5ec7fe5cd
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_
8 #include <set>
10 #include "base/callback.h"
11 #include "base/time/time.h"
12 #include "components/domain_reliability/domain_reliability_export.h"
13 #include "components/domain_reliability/util.h"
15 namespace tracked_objects {
16 class Location;
17 } // namespace tracked_objects
19 namespace domain_reliability {
21 // Runs tasks during a specified interval. Calling |RunEligibleTasks| gives any
22 // task a chance to run early (if the minimum delay has already passed); tasks
23 // that aren't run early will be run once their maximum delay has passed.
25 // (See scheduler.h for an explanation of how the intervals are chosen.)
26 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityDispatcher {
27 public:
28 explicit DomainReliabilityDispatcher(MockableTime* time);
29 ~DomainReliabilityDispatcher();
31 // Schedules |task| to be executed between |min_delay| and |max_delay| from
32 // now. The task will be run at most |max_delay| from now; once |min_delay|
33 // has passed, any call to |RunEligibleTasks| will run the task earlier than
34 // that.
35 void ScheduleTask(const base::Closure& task,
36 base::TimeDelta min_delay,
37 base::TimeDelta max_delay);
39 // Runs all tasks whose minimum delay has already passed.
40 void RunEligibleTasks();
42 private:
43 struct Task;
45 // Adds |task| to the set of all tasks, but not the set of eligible tasks.
46 void MakeTaskWaiting(Task* task);
48 // Adds |task| to the set of eligible tasks, and also the set of all tasks
49 // if not already there.
50 void MakeTaskEligible(Task* task);
52 // Runs |task|'s callback, removes it from both sets, and deletes it.
53 void RunAndDeleteTask(Task* task);
55 MockableTime* time_;
56 std::set<Task*> tasks_;
57 std::set<Task*> eligible_tasks_;
60 } // namespace domain_reliability
62 #endif