summaryrefslogtreecommitdiff
path: root/base/task/cancelable_task_tracker.h
diff options
context:
space:
mode:
Diffstat (limited to 'base/task/cancelable_task_tracker.h')
-rw-r--r--base/task/cancelable_task_tracker.h52
1 files changed, 27 insertions, 25 deletions
diff --git a/base/task/cancelable_task_tracker.h b/base/task/cancelable_task_tracker.h
index 4f64a24060..86b5a45845 100644
--- a/base/task/cancelable_task_tracker.h
+++ b/base/task/cancelable_task_tracker.h
@@ -15,38 +15,36 @@
//
// CancelableCallback (base/cancelable_callback.h) and WeakPtr binding are
// preferred solutions for canceling a task. However, they don't support
-// cancelation from another sequence. This is sometimes a performance critical
+// cancelation from another thread. This is sometimes a performance critical
// requirement. E.g. We need to cancel database lookup task on DB thread when
// user changes inputed text. If it is performance critical to do a best effort
-// cancelation of a task, then CancelableTaskTracker is appropriate, otherwise
-// use one of the other mechanisms.
+// cancelation of a task, then CancelableTaskTracker is appropriate,
+// otherwise use one of the other mechanisms.
//
// THREAD-SAFETY:
//
-// 1. A CancelableTaskTracker object must be created, used, and destroyed on a
-// single sequence.
+// 1. CancelableTaskTracker objects are not thread safe. They must
+// be created, used, and destroyed on the originating thread that posts the
+// task. It's safe to destroy a CancelableTaskTracker while there
+// are outstanding tasks. This is commonly used to cancel all outstanding
+// tasks.
//
-// 2. It's safe to destroy a CancelableTaskTracker while there are outstanding
-// tasks. This is commonly used to cancel all outstanding tasks.
+// 2. Both task and reply are deleted on the originating thread.
//
-// 3. Both task and reply are deleted on the originating sequence.
-//
-// 4. IsCanceledCallback can be run or deleted on any sequence.
+// 3. IsCanceledCallback is thread safe and can be run or deleted on any
+// thread.
#ifndef BASE_TASK_CANCELABLE_TASK_TRACKER_H_
#define BASE_TASK_CANCELABLE_TASK_TRACKER_H_
#include <stdint.h>
-#include <utility>
-
#include "base/base_export.h"
-#include "base/bind.h"
#include "base/callback.h"
#include "base/containers/hash_tables.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
-#include "base/post_task_and_reply_with_result_internal.h"
-#include "base/sequence_checker.h"
+#include "base/task_runner_util.h"
+#include "base/threading/thread_checker.h"
namespace tracked_objects {
class Location;
@@ -76,21 +74,25 @@ class BASE_EXPORT CancelableTaskTracker {
TaskId PostTaskAndReply(base::TaskRunner* task_runner,
const tracked_objects::Location& from_here,
- base::Closure task,
- base::Closure reply);
+ const base::Closure& task,
+ const base::Closure& reply);
template <typename TaskReturnType, typename ReplyArgType>
- TaskId PostTaskAndReplyWithResult(base::TaskRunner* task_runner,
- const tracked_objects::Location& from_here,
- base::Callback<TaskReturnType()> task,
- base::Callback<void(ReplyArgType)> reply) {
+ TaskId PostTaskAndReplyWithResult(
+ base::TaskRunner* task_runner,
+ const tracked_objects::Location& from_here,
+ const base::Callback<TaskReturnType(void)>& task,
+ const base::Callback<void(ReplyArgType)>& reply) {
TaskReturnType* result = new TaskReturnType();
return PostTaskAndReply(
- task_runner, from_here,
+ task_runner,
+ from_here,
base::Bind(&base::internal::ReturnAsParamAdapter<TaskReturnType>,
- std::move(task), base::Unretained(result)),
+ task,
+ base::Unretained(result)),
base::Bind(&base::internal::ReplyAdapter<TaskReturnType, ReplyArgType>,
- std::move(reply), base::Owned(result)));
+ reply,
+ base::Owned(result)));
}
// Creates a tracked TaskId and an associated IsCanceledCallback. Client can
@@ -128,7 +130,7 @@ class BASE_EXPORT CancelableTaskTracker {
base::hash_map<TaskId, base::CancellationFlag*> task_flags_;
TaskId next_id_;
- SequenceChecker sequence_checker_;
+ base::ThreadChecker thread_checker_;
base::WeakPtrFactory<CancelableTaskTracker> weak_factory_;