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 "base/task/cancelable_task_tracker.h" | 5 #include "base/task/cancelable_task_tracker.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 *is_canceled_cb = | 127 *is_canceled_cb = |
128 Bind(&IsCanceled, flag, Owned(untrack_and_delete_flag_runner)); | 128 Bind(&IsCanceled, flag, Owned(untrack_and_delete_flag_runner)); |
129 | 129 |
130 Track(id, flag); | 130 Track(id, flag); |
131 return id; | 131 return id; |
132 } | 132 } |
133 | 133 |
134 void CancelableTaskTracker::TryCancel(TaskId id) { | 134 void CancelableTaskTracker::TryCancel(TaskId id) { |
135 DCHECK(sequence_checker_.CalledOnValidSequence()); | 135 DCHECK(sequence_checker_.CalledOnValidSequence()); |
136 | 136 |
137 hash_map<TaskId, CancellationFlag*>::const_iterator it = task_flags_.find(id); | 137 const auto it = task_flags_.find(id); |
138 if (it == task_flags_.end()) { | 138 if (it == task_flags_.end()) { |
139 // Two possibilities: | 139 // Two possibilities: |
140 // | 140 // |
141 // 1. The task has already been untracked. | 141 // 1. The task has already been untracked. |
142 // 2. The TaskId is bad or unknown. | 142 // 2. The TaskId is bad or unknown. |
143 // | 143 // |
144 // Since this function is best-effort, it's OK to ignore these. | 144 // Since this function is best-effort, it's OK to ignore these. |
145 return; | 145 return; |
146 } | 146 } |
147 it->second->Set(); | 147 it->second->Set(); |
148 } | 148 } |
149 | 149 |
150 void CancelableTaskTracker::TryCancelAll() { | 150 void CancelableTaskTracker::TryCancelAll() { |
151 DCHECK(sequence_checker_.CalledOnValidSequence()); | 151 DCHECK(sequence_checker_.CalledOnValidSequence()); |
152 | 152 for (const auto it : task_flags_) |
Łukasz Anforowicz
2017/04/24 18:46:10
nit:s/const auto/const auto&/ ?
| |
153 for (hash_map<TaskId, CancellationFlag*>::const_iterator it = | 153 it.second->Set(); |
154 task_flags_.begin(); | |
155 it != task_flags_.end(); | |
156 ++it) { | |
157 it->second->Set(); | |
158 } | |
159 } | 154 } |
160 | 155 |
161 bool CancelableTaskTracker::HasTrackedTasks() const { | 156 bool CancelableTaskTracker::HasTrackedTasks() const { |
162 DCHECK(sequence_checker_.CalledOnValidSequence()); | 157 DCHECK(sequence_checker_.CalledOnValidSequence()); |
163 return !task_flags_.empty(); | 158 return !task_flags_.empty(); |
164 } | 159 } |
165 | 160 |
166 void CancelableTaskTracker::Track(TaskId id, CancellationFlag* flag) { | 161 void CancelableTaskTracker::Track(TaskId id, CancellationFlag* flag) { |
167 DCHECK(sequence_checker_.CalledOnValidSequence()); | 162 DCHECK(sequence_checker_.CalledOnValidSequence()); |
168 | |
169 bool success = task_flags_.insert(std::make_pair(id, flag)).second; | 163 bool success = task_flags_.insert(std::make_pair(id, flag)).second; |
170 DCHECK(success); | 164 DCHECK(success); |
171 } | 165 } |
172 | 166 |
173 void CancelableTaskTracker::Untrack(TaskId id) { | 167 void CancelableTaskTracker::Untrack(TaskId id) { |
174 DCHECK(sequence_checker_.CalledOnValidSequence()); | 168 DCHECK(sequence_checker_.CalledOnValidSequence()); |
175 size_t num = task_flags_.erase(id); | 169 size_t num = task_flags_.erase(id); |
176 DCHECK_EQ(1u, num); | 170 DCHECK_EQ(1u, num); |
177 } | 171 } |
178 | 172 |
179 } // namespace base | 173 } // namespace base |
OLD | NEW |