OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/cancelable_task_tracker.h" | 5 #include "chrome/common/cancelable_task_tracker.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } // namespace | 54 } // namespace |
55 | 55 |
56 // static | 56 // static |
57 const CancelableTaskTracker::TaskId CancelableTaskTracker::kBadTaskId = 0; | 57 const CancelableTaskTracker::TaskId CancelableTaskTracker::kBadTaskId = 0; |
58 | 58 |
59 CancelableTaskTracker::CancelableTaskTracker() | 59 CancelableTaskTracker::CancelableTaskTracker() |
60 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 60 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
61 next_id_(1) {} | 61 next_id_(1) {} |
62 | 62 |
63 CancelableTaskTracker::~CancelableTaskTracker() { | 63 CancelableTaskTracker::~CancelableTaskTracker() { |
| 64 DCHECK(thread_checker_.CalledOnValidThread()); |
| 65 |
64 TryCancelAll(); | 66 TryCancelAll(); |
65 } | 67 } |
66 | 68 |
67 CancelableTaskTracker::TaskId CancelableTaskTracker::PostTask( | 69 CancelableTaskTracker::TaskId CancelableTaskTracker::PostTask( |
68 TaskRunner* task_runner, | 70 TaskRunner* task_runner, |
69 const tracked_objects::Location& from_here, | 71 const tracked_objects::Location& from_here, |
70 const Closure& task) { | 72 const Closure& task) { |
| 73 DCHECK(thread_checker_.CalledOnValidThread()); |
| 74 |
71 return PostTaskAndReply(task_runner, from_here, task, Bind(&base::DoNothing)); | 75 return PostTaskAndReply(task_runner, from_here, task, Bind(&base::DoNothing)); |
72 } | 76 } |
73 | 77 |
74 CancelableTaskTracker::TaskId CancelableTaskTracker::PostTaskAndReply( | 78 CancelableTaskTracker::TaskId CancelableTaskTracker::PostTaskAndReply( |
75 TaskRunner* task_runner, | 79 TaskRunner* task_runner, |
76 const tracked_objects::Location& from_here, | 80 const tracked_objects::Location& from_here, |
77 const Closure& task, | 81 const Closure& task, |
78 const Closure& reply) { | 82 const Closure& reply) { |
79 DCHECK(thread_checker_.CalledOnValidThread()); | 83 DCHECK(thread_checker_.CalledOnValidThread()); |
80 | 84 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 156 |
153 for (hash_map<TaskId, CancellationFlag*>::const_iterator it = | 157 for (hash_map<TaskId, CancellationFlag*>::const_iterator it = |
154 task_flags_.begin(); | 158 task_flags_.begin(); |
155 it != task_flags_.end(); | 159 it != task_flags_.end(); |
156 ++it) { | 160 ++it) { |
157 it->second->Set(); | 161 it->second->Set(); |
158 } | 162 } |
159 } | 163 } |
160 | 164 |
161 void CancelableTaskTracker::Track(TaskId id, CancellationFlag* flag) { | 165 void CancelableTaskTracker::Track(TaskId id, CancellationFlag* flag) { |
| 166 DCHECK(thread_checker_.CalledOnValidThread()); |
| 167 |
162 bool success = task_flags_.insert(std::make_pair(id, flag)).second; | 168 bool success = task_flags_.insert(std::make_pair(id, flag)).second; |
163 DCHECK(success); | 169 DCHECK(success); |
164 } | 170 } |
165 | 171 |
166 void CancelableTaskTracker::Untrack(TaskId id) { | 172 void CancelableTaskTracker::Untrack(TaskId id) { |
167 DCHECK(thread_checker_.CalledOnValidThread()); | 173 DCHECK(thread_checker_.CalledOnValidThread()); |
168 | 174 |
169 size_t num = task_flags_.erase(id); | 175 size_t num = task_flags_.erase(id); |
170 DCHECK_EQ(1u, num); | 176 DCHECK_EQ(1u, num); |
171 } | 177 } |
OLD | NEW |