| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 // Owned by reply callback below. | 84 // Owned by reply callback below. |
| 85 CancellationFlag* flag = new CancellationFlag(); | 85 CancellationFlag* flag = new CancellationFlag(); |
| 86 | 86 |
| 87 TaskId id = next_id_; | 87 TaskId id = next_id_; |
| 88 next_id_++; // int64_t is big enough that we ignore the potential overflow. | 88 next_id_++; // int64_t is big enough that we ignore the potential overflow. |
| 89 | 89 |
| 90 Closure untrack_closure = | 90 Closure untrack_closure = |
| 91 Bind(&CancelableTaskTracker::Untrack, weak_factory_.GetWeakPtr(), id); | 91 Bind(&CancelableTaskTracker::Untrack, weak_factory_.GetWeakPtr(), id); |
| 92 bool success = task_runner->PostTaskAndReply( | 92 bool success = task_runner->PostTaskAndReply( |
| 93 from_here, Bind(&RunIfNotCanceled, flag, std::move(task)), | 93 from_here, BindOnce(&RunIfNotCanceled, flag, std::move(task)), |
| 94 Bind(&RunIfNotCanceledThenUntrack, base::Owned(flag), std::move(reply), | 94 BindOnce(&RunIfNotCanceledThenUntrack, base::Owned(flag), |
| 95 std::move(untrack_closure))); | 95 std::move(reply), std::move(untrack_closure))); |
| 96 | 96 |
| 97 if (!success) | 97 if (!success) |
| 98 return kBadTaskId; | 98 return kBadTaskId; |
| 99 | 99 |
| 100 Track(id, flag); | 100 Track(id, flag); |
| 101 return id; | 101 return id; |
| 102 } | 102 } |
| 103 | 103 |
| 104 CancelableTaskTracker::TaskId CancelableTaskTracker::NewTrackedTaskId( | 104 CancelableTaskTracker::TaskId CancelableTaskTracker::NewTrackedTaskId( |
| 105 IsCanceledCallback* is_canceled_cb) { | 105 IsCanceledCallback* is_canceled_cb) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 DCHECK(success); | 170 DCHECK(success); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void CancelableTaskTracker::Untrack(TaskId id) { | 173 void CancelableTaskTracker::Untrack(TaskId id) { |
| 174 DCHECK(sequence_checker_.CalledOnValidSequence()); | 174 DCHECK(sequence_checker_.CalledOnValidSequence()); |
| 175 size_t num = task_flags_.erase(id); | 175 size_t num = task_flags_.erase(id); |
| 176 DCHECK_EQ(1u, num); | 176 DCHECK_EQ(1u, num); |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace base | 179 } // namespace base |
| OLD | NEW |