| Index: chrome/common/cancelable_task_tracker.cc
|
| diff --git a/chrome/common/cancelable_task_tracker.cc b/chrome/common/cancelable_task_tracker.cc
|
| index 3570e0577fab680dea9e372ffaf91c865e91979e..28ee436455276543278edebed89b1c6b00a8326f 100644
|
| --- a/chrome/common/cancelable_task_tracker.cc
|
| +++ b/chrome/common/cancelable_task_tracker.cc
|
| @@ -8,6 +8,7 @@
|
|
|
| #include "base/bind.h"
|
| #include "base/bind_helpers.h"
|
| +#include "base/location.h"
|
| #include "base/memory/ref_counted.h"
|
| #include "base/message_loop_proxy.h"
|
| #include "base/synchronization/cancellation_flag.h"
|
| @@ -33,6 +34,18 @@ void RunIfNotCanceledThenUntrack(const CancellationFlag* flag,
|
| untrack.Run();
|
| }
|
|
|
| +bool IsCanceled(const CancellationFlag* flag,
|
| + base::ScopedClosureRunner* untrack_runner) {
|
| + return flag->IsSet();
|
| +}
|
| +
|
| +void RunOrPostToTaskRunner(TaskRunner* task_runner, const Closure& closure) {
|
| + if (task_runner->RunsTasksOnCurrentThread())
|
| + closure.Run();
|
| + else
|
| + task_runner->PostTask(FROM_HERE, closure);
|
| +}
|
| +
|
| } // namespace
|
|
|
| // static
|
| @@ -84,6 +97,29 @@ CancelableTaskTracker::TaskId CancelableTaskTracker::PostTaskAndReply(
|
| return id;
|
| }
|
|
|
| +CancelableTaskTracker::TaskId CancelableTaskTracker::NewTrackedTaskId(
|
| + IsCanceledCallback* is_canceled_cb) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + DCHECK(base::MessageLoopProxy::current());
|
| +
|
| + TaskId id = next_id_;
|
| + next_id_++; // int64 is big enough that we ignore the potential overflow.
|
| +
|
| + // Both owned by |is_canceled_cb|.
|
| + CancellationFlag* flag = new CancellationFlag();
|
| + base::ScopedClosureRunner* untrack_runner = new base::ScopedClosureRunner(
|
| + Bind(&RunOrPostToTaskRunner,
|
| + base::MessageLoopProxy::current(),
|
| + Bind(&CancelableTaskTracker::Untrack,
|
| + weak_factory_.GetWeakPtr(), id)));
|
| +
|
| + *is_canceled_cb = Bind(&IsCanceled,
|
| + base::Owned(flag),
|
| + base::Owned(untrack_runner));
|
| + Track(id, flag);
|
| + return id;
|
| +}
|
| +
|
| void CancelableTaskTracker::TryCancel(TaskId id) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|