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

Side by Side Diff: base/task/cancelable_task_tracker.cc

Issue 2672753002: Refactor History's CommitLaterTask with CancelableCallback (Closed)
Patch Set: Remove leftover friendship. Created 3 years, 10 months 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 "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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 reply, 97 reply,
98 untrack_closure)); 98 untrack_closure));
99 99
100 if (!success) 100 if (!success)
101 return kBadTaskId; 101 return kBadTaskId;
102 102
103 Track(id, flag); 103 Track(id, flag);
104 return id; 104 return id;
105 } 105 }
106 106
107 CancelableTaskTracker::TaskId CancelableTaskTracker::PostDelayedTask(
Marc Treib 2017/02/02 10:52:21 Hm, I guess this is juuust different enough from P
mastiz 2017/02/02 12:35:53 Acknowledged, I think so.
108 base::TaskRunner* task_runner,
109 const tracked_objects::Location& from_here,
110 const base::Closure& task,
111 base::TimeDelta delay) {
112 DCHECK(sequence_checker_.CalledOnValidSequence());
113
114 // Owned by callback below.
115 CancellationFlag* flag = new CancellationFlag();
116
117 TaskId id = next_id_;
118 next_id_++; // int64_t is big enough that we ignore the potential overflow.
119
120 const Closure& untrack_closure =
121 Bind(&CancelableTaskTracker::Untrack, weak_factory_.GetWeakPtr(), id);
122 bool success = task_runner->PostDelayedTask(
123 from_here, Bind(&RunIfNotCanceledThenUntrack, base::Owned(flag), task,
124 untrack_closure),
125 delay);
126
127 if (!success)
128 return kBadTaskId;
129
130 Track(id, flag);
131 return id;
132 }
133
107 CancelableTaskTracker::TaskId CancelableTaskTracker::NewTrackedTaskId( 134 CancelableTaskTracker::TaskId CancelableTaskTracker::NewTrackedTaskId(
108 IsCanceledCallback* is_canceled_cb) { 135 IsCanceledCallback* is_canceled_cb) {
109 DCHECK(sequence_checker_.CalledOnValidSequence()); 136 DCHECK(sequence_checker_.CalledOnValidSequence());
110 DCHECK(base::SequencedTaskRunnerHandle::IsSet()); 137 DCHECK(base::SequencedTaskRunnerHandle::IsSet());
111 138
112 TaskId id = next_id_; 139 TaskId id = next_id_;
113 next_id_++; // int64_t is big enough that we ignore the potential overflow. 140 next_id_++; // int64_t is big enough that we ignore the potential overflow.
114 141
115 // Will be deleted by |untrack_and_delete_flag| after Untrack(). 142 // Will be deleted by |untrack_and_delete_flag| after Untrack().
116 CancellationFlag* flag = new CancellationFlag(); 143 CancellationFlag* flag = new CancellationFlag();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 DCHECK(success); 200 DCHECK(success);
174 } 201 }
175 202
176 void CancelableTaskTracker::Untrack(TaskId id) { 203 void CancelableTaskTracker::Untrack(TaskId id) {
177 DCHECK(sequence_checker_.CalledOnValidSequence()); 204 DCHECK(sequence_checker_.CalledOnValidSequence());
178 size_t num = task_flags_.erase(id); 205 size_t num = task_flags_.erase(id);
179 DCHECK_EQ(1u, num); 206 DCHECK_EQ(1u, num);
180 } 207 }
181 208
182 } // namespace base 209 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698