| 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 20 matching lines...) Expand all Loading... |
| 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 tasks whose minimum delay has already passed. |
| 39 void RunEligibleTasks(); | 39 void RunEligibleTasks(); |
| 40 | 40 |
| 41 void RunAllTasksForTesting(); |
| 42 |
| 41 private: | 43 private: |
| 42 struct Task; | 44 struct Task; |
| 43 | 45 |
| 44 // Adds |task| to the set of all tasks, but not the set of eligible tasks. | 46 // Adds |task| to the set of all tasks, but not the set of eligible tasks. |
| 45 void MakeTaskWaiting(Task* task); | 47 void MakeTaskWaiting(Task* task); |
| 46 | 48 |
| 47 // Adds |task| to the set of eligible tasks, and also the set of all tasks | 49 // Adds |task| to the set of eligible tasks, and also the set of all tasks |
| 48 // if not already there. | 50 // if not already there. |
| 49 void MakeTaskEligible(Task* task); | 51 void MakeTaskEligible(Task* task); |
| 50 | 52 |
| 51 // Runs |task|'s callback, removes it from both sets, and deletes it. | 53 // Runs |task|'s callback, removes it from both sets, and deletes it. |
| 52 void RunAndDeleteTask(Task* task); | 54 void RunAndDeleteTask(Task* task); |
| 53 | 55 |
| 54 MockableTime* time_; | 56 MockableTime* time_; |
| 55 std::set<std::unique_ptr<Task>> tasks_; | 57 std::set<std::unique_ptr<Task>> tasks_; |
| 56 std::set<Task*> eligible_tasks_; | 58 std::set<Task*> eligible_tasks_; |
| 57 | 59 |
| 58 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityDispatcher); | 60 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityDispatcher); |
| 59 }; | 61 }; |
| 60 | 62 |
| 61 } // namespace domain_reliability | 63 } // namespace domain_reliability |
| 62 | 64 |
| 63 #endif | 65 #endif |
| OLD | NEW |