| Index: base/task/cancelable_task_tracker.cc
|
| diff --git a/base/task/cancelable_task_tracker.cc b/base/task/cancelable_task_tracker.cc
|
| index b6e4b6ac4dedfd80d546deca1fe3798a7106cfc9..697589747bb9c9636b5f465940ddc25a676721a3 100644
|
| --- a/base/task/cancelable_task_tracker.cc
|
| +++ b/base/task/cancelable_task_tracker.cc
|
| @@ -14,6 +14,7 @@
|
| #include "base/message_loop/message_loop_proxy.h"
|
| #include "base/synchronization/cancellation_flag.h"
|
| #include "base/task_runner.h"
|
| +#include "base/thread_task_runner_handle.h"
|
|
|
| using base::Bind;
|
| using base::CancellationFlag;
|
| @@ -72,9 +73,17 @@ CancelableTaskTracker::TaskId CancelableTaskTracker::PostTask(
|
| TaskRunner* task_runner,
|
| const tracked_objects::Location& from_here,
|
| const Closure& task) {
|
| - DCHECK(thread_checker_.CalledOnValidThread());
|
| + return PostDelayedTaskAndReply(task_runner, from_here, task,
|
| + Bind(&base::DoNothing), TimeDelta());
|
| +}
|
|
|
| - return PostTaskAndReply(task_runner, from_here, task, Bind(&base::DoNothing));
|
| +CancelableTaskTracker::TaskId CancelableTaskTracker::PostDelayedTask(
|
| + TaskRunner* task_runner,
|
| + const tracked_objects::Location& from_here,
|
| + const Closure& task,
|
| + const TimeDelta& delay) {
|
| + return PostDelayedTaskAndReply(task_runner, from_here, task,
|
| + Bind(&base::DoNothing), delay);
|
| }
|
|
|
| CancelableTaskTracker::TaskId CancelableTaskTracker::PostTaskAndReply(
|
| @@ -82,32 +91,8 @@ CancelableTaskTracker::TaskId CancelableTaskTracker::PostTaskAndReply(
|
| const tracked_objects::Location& from_here,
|
| const Closure& task,
|
| const Closure& reply) {
|
| - DCHECK(thread_checker_.CalledOnValidThread());
|
| -
|
| - // We need a MessageLoop to run reply.
|
| - DCHECK(base::MessageLoopProxy::current().get());
|
| -
|
| - // Owned by reply callback below.
|
| - CancellationFlag* flag = new CancellationFlag();
|
| -
|
| - TaskId id = next_id_;
|
| - next_id_++; // int64 is big enough that we ignore the potential overflow.
|
| -
|
| - const Closure& untrack_closure =
|
| - Bind(&CancelableTaskTracker::Untrack, weak_factory_.GetWeakPtr(), id);
|
| - bool success =
|
| - task_runner->PostTaskAndReply(from_here,
|
| - Bind(&RunIfNotCanceled, flag, task),
|
| - Bind(&RunIfNotCanceledThenUntrack,
|
| - base::Owned(flag),
|
| - reply,
|
| - untrack_closure));
|
| -
|
| - if (!success)
|
| - return kBadTaskId;
|
| -
|
| - Track(id, flag);
|
| - return id;
|
| + return PostDelayedTaskAndReply(task_runner, from_here, task, reply,
|
| + TimeDelta());
|
| }
|
|
|
| CancelableTaskTracker::TaskId CancelableTaskTracker::NewTrackedTaskId(
|
| @@ -184,4 +169,39 @@ void CancelableTaskTracker::Untrack(TaskId id) {
|
| DCHECK_EQ(1u, num);
|
| }
|
|
|
| +CancelableTaskTracker::TaskId CancelableTaskTracker::PostDelayedTaskAndReply(
|
| + TaskRunner* task_runner,
|
| + const tracked_objects::Location& from_here,
|
| + const Closure& task,
|
| + const Closure& reply,
|
| + const TimeDelta& delay) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| +
|
| + // We need a MessageLoop to run reply.
|
| + DCHECK(ThreadTaskRunnerHandle::Get());
|
| +
|
| + // Owned by reply callback below.
|
| + CancellationFlag* flag = new CancellationFlag();
|
| +
|
| + TaskId id = next_id_;
|
| + next_id_++; // int64 is big enough that we ignore the potential overflow.
|
| +
|
| + const Closure& untrack_closure =
|
| + Bind(&CancelableTaskTracker::Untrack, weak_factory_.GetWeakPtr(), id);
|
| + bool success = task_runner->PostDelayedTaskAndReply(
|
| + from_here,
|
| + Bind(&RunIfNotCanceled, flag, task),
|
| + Bind(&RunIfNotCanceledThenUntrack,
|
| + Owned(flag),
|
| + reply,
|
| + untrack_closure),
|
| + delay);
|
| +
|
| + if (!success)
|
| + return kBadTaskId;
|
| +
|
| + Track(id, flag);
|
| + return id;
|
| +}
|
| +
|
| } // namespace base
|
|
|