| 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 #include "components/domain_reliability/dispatcher.h" | 5 #include "components/domain_reliability/dispatcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 69 } |
| 70 | 70 |
| 71 void DomainReliabilityDispatcher::RunEligibleTasks() { | 71 void DomainReliabilityDispatcher::RunEligibleTasks() { |
| 72 // Move all eligible tasks to a separate set so that eligible_tasks_.erase in | 72 // Move all eligible tasks to a separate set so that eligible_tasks_.erase in |
| 73 // RunAndDeleteTask won't erase elements out from under the iterator. (Also | 73 // RunAndDeleteTask won't erase elements out from under the iterator. (Also |
| 74 // keeps RunEligibleTasks from running forever if a task adds a new, already- | 74 // keeps RunEligibleTasks from running forever if a task adds a new, already- |
| 75 // eligible task that does the same, and so on.) | 75 // eligible task that does the same, and so on.) |
| 76 std::set<Task*> tasks; | 76 std::set<Task*> tasks; |
| 77 tasks.swap(eligible_tasks_); | 77 tasks.swap(eligible_tasks_); |
| 78 | 78 |
| 79 for (auto& task : tasks) { | 79 for (auto* task : tasks) { |
| 80 DCHECK(task); | 80 DCHECK(task); |
| 81 DCHECK(task->eligible); | 81 DCHECK(task->eligible); |
| 82 RunAndDeleteTask(task); | 82 RunAndDeleteTask(task); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 void DomainReliabilityDispatcher::MakeTaskWaiting(Task* task) { | 86 void DomainReliabilityDispatcher::MakeTaskWaiting(Task* task) { |
| 87 DCHECK(task); | 87 DCHECK(task); |
| 88 DCHECK(!task->eligible); | 88 DCHECK(!task->eligible); |
| 89 DCHECK(!task->timer->IsRunning()); | 89 DCHECK(!task->timer->IsRunning()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 111 DCHECK(task); | 111 DCHECK(task); |
| 112 DCHECK(!task->closure.is_null()); | 112 DCHECK(!task->closure.is_null()); |
| 113 task->closure.Run(); | 113 task->closure.Run(); |
| 114 if (task->eligible) | 114 if (task->eligible) |
| 115 eligible_tasks_.erase(task); | 115 eligible_tasks_.erase(task); |
| 116 tasks_.erase(task); | 116 tasks_.erase(task); |
| 117 delete task; | 117 delete task; |
| 118 } | 118 } |
| 119 | 119 |
| 120 } // namespace domain_reliability | 120 } // namespace domain_reliability |
| OLD | NEW |