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

Unified Diff: base/task/cancelable_task_tracker.cc

Issue 2672753002: Refactor History's CommitLaterTask with CancelableCallback (Closed)
Patch Set: Remove leftover friendship. Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: base/task/cancelable_task_tracker.cc
diff --git a/base/task/cancelable_task_tracker.cc b/base/task/cancelable_task_tracker.cc
index 92d82cc9eaee49a18e9630f7230f7956dc36564d..b2b745f5fab534c5702813ffc2acaa5dbb985eae 100644
--- a/base/task/cancelable_task_tracker.cc
+++ b/base/task/cancelable_task_tracker.cc
@@ -104,6 +104,33 @@ CancelableTaskTracker::TaskId CancelableTaskTracker::PostTaskAndReply(
return id;
}
+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.
+ base::TaskRunner* task_runner,
+ const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ base::TimeDelta delay) {
+ DCHECK(sequence_checker_.CalledOnValidSequence());
+
+ // Owned by callback below.
+ CancellationFlag* flag = new CancellationFlag();
+
+ TaskId id = next_id_;
+ next_id_++; // int64_t is big enough that we ignore the potential overflow.
+
+ const Closure& untrack_closure =
+ Bind(&CancelableTaskTracker::Untrack, weak_factory_.GetWeakPtr(), id);
+ bool success = task_runner->PostDelayedTask(
+ from_here, Bind(&RunIfNotCanceledThenUntrack, base::Owned(flag), task,
+ untrack_closure),
+ delay);
+
+ if (!success)
+ return kBadTaskId;
+
+ Track(id, flag);
+ return id;
+}
+
CancelableTaskTracker::TaskId CancelableTaskTracker::NewTrackedTaskId(
IsCanceledCallback* is_canceled_cb) {
DCHECK(sequence_checker_.CalledOnValidSequence());

Powered by Google App Engine
This is Rietveld 408576698