| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_DOMAIN_RELIABILITY_DISPATCHER_H_ | 5 #ifndef COMPONENTS_DOMAIN_RELIABILITY_DISPATCHER_H_ |
| 6 #define COMPONENTS_DOMAIN_RELIABILITY_DISPATCHER_H_ | 6 #define COMPONENTS_DOMAIN_RELIABILITY_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 ~DomainReliabilityDispatcher(); | 28 ~DomainReliabilityDispatcher(); |
| 29 | 29 |
| 30 // Schedules |task| to be executed between |min_delay| and |max_delay| from | 30 // Schedules |task| to be executed between |min_delay| and |max_delay| from |
| 31 // now. The task will be run at most |max_delay| from now; once |min_delay| | 31 // now. The task will be run at most |max_delay| from now; once |min_delay| |
| 32 // has passed, any call to |RunEligibleTasks| will run the task earlier than | 32 // has passed, any call to |RunEligibleTasks| will run the task earlier than |
| 33 // that. | 33 // that. |
| 34 void ScheduleTask(const base::Closure& task, | 34 void ScheduleTask(const base::Closure& task, |
| 35 base::TimeDelta min_delay, | 35 base::TimeDelta min_delay, |
| 36 base::TimeDelta max_delay); | 36 base::TimeDelta max_delay); |
| 37 | 37 |
| 38 // Runs all tasks whose minimum delay has already passed. | 38 // Runs all existing tasks whose minimum delay has already passed. Does not |
| 39 // run tasks added by those existing tasks, even if their minimum delay has |
| 40 // already passed. |
| 39 void RunEligibleTasks(); | 41 void RunEligibleTasks(); |
| 40 | 42 |
| 43 // Runs all waiting or eligible tasks, regardless of whether their minimum |
| 44 // delay has passed. |
| 45 void RunAllTasksForTesting(); |
| 46 |
| 41 private: | 47 private: |
| 42 struct Task; | 48 struct Task; |
| 43 | 49 |
| 44 // Adds |task| to the set of all tasks, but not the set of eligible tasks. | 50 // Adds |task| to the set of all tasks, but not the set of eligible tasks. |
| 45 void MakeTaskWaiting(Task* task); | 51 void MakeTaskWaiting(Task* task); |
| 46 | 52 |
| 47 // Adds |task| to the set of eligible tasks, and also the set of all tasks | 53 // Adds |task| to the set of eligible tasks, and also the set of all tasks |
| 48 // if not already there. | 54 // if not already there. |
| 49 void MakeTaskEligible(Task* task); | 55 void MakeTaskEligible(Task* task); |
| 50 | 56 |
| 51 // Runs |task|'s callback, removes it from both sets, and deletes it. | 57 // Runs |task|'s callback, removes it from both sets, and deletes it. |
| 52 void RunAndDeleteTask(Task* task); | 58 void RunAndDeleteTask(Task* task); |
| 53 | 59 |
| 54 MockableTime* time_; | 60 MockableTime* time_; |
| 55 std::set<std::unique_ptr<Task>> tasks_; | 61 std::set<std::unique_ptr<Task>> tasks_; |
| 56 std::set<Task*> eligible_tasks_; | 62 std::set<Task*> eligible_tasks_; |
| 57 | 63 |
| 58 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityDispatcher); | 64 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityDispatcher); |
| 59 }; | 65 }; |
| 60 | 66 |
| 61 } // namespace domain_reliability | 67 } // namespace domain_reliability |
| 62 | 68 |
| 63 #endif | 69 #endif |
| OLD | NEW |