Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: components/domain_reliability/dispatcher.cc

Issue 2336043007: Domain Reliability: Don't crash on shutdown with uploads pending (Closed)
Patch Set: No, really. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::RunAllTasksForTesting() {
87 std::set<Task*> tasks;
88 for (auto& task : tasks_)
89 tasks.insert(task.get());
mmenke 2016/12/14 19:12:17 std::set<Task*> tasks = tasks_;?
Julia Tuttle 2016/12/15 21:53:00 Doesn't work; tasks_ contains unique_ptr<Task> whi
90
91 for (auto* task : tasks) {
92 DCHECK(task);
93 RunAndDeleteTask(task);
94 }
mmenke 2016/12/14 19:12:17 I assume we can't just do: while(!tasks.empty())
Julia Tuttle 2016/12/15 21:53:00 Yeah, same contract as RunEligibleTasks -- it runs
95 }
96
86 void DomainReliabilityDispatcher::MakeTaskWaiting(Task* task) { 97 void DomainReliabilityDispatcher::MakeTaskWaiting(Task* task) {
87 DCHECK(task); 98 DCHECK(task);
88 DCHECK(!task->eligible); 99 DCHECK(!task->eligible);
89 DCHECK(!task->timer->IsRunning()); 100 DCHECK(!task->timer->IsRunning());
90 task->timer->Start(FROM_HERE, 101 task->timer->Start(FROM_HERE,
91 task->min_delay, 102 task->min_delay,
92 base::Bind(&DomainReliabilityDispatcher::MakeTaskEligible, 103 base::Bind(&DomainReliabilityDispatcher::MakeTaskEligible,
93 base::Unretained(this), 104 base::Unretained(this),
94 task)); 105 task));
95 } 106 }
(...skipping 21 matching lines...) Expand all
117 auto it = std::find_if(tasks_.begin(), tasks_.end(), 128 auto it = std::find_if(tasks_.begin(), tasks_.end(),
118 [task](const std::unique_ptr<Task>& task_ptr) { 129 [task](const std::unique_ptr<Task>& task_ptr) {
119 return task_ptr.get() == task; 130 return task_ptr.get() == task;
120 }); 131 });
121 132
122 DCHECK(it != tasks_.end()); 133 DCHECK(it != tasks_.end());
123 tasks_.erase(it); 134 tasks_.erase(it);
124 } 135 }
125 136
126 } // namespace domain_reliability 137 } // namespace domain_reliability
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698