123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- #ifndef BASE_TASK_RUNNER_H_
- #define BASE_TASK_RUNNER_H_
- #include <stddef.h>
- #include "base/base_export.h"
- #include "base/bind.h"
- #include "base/callback.h"
- #include "base/check.h"
- #include "base/location.h"
- #include "base/memory/ref_counted.h"
- #include "base/post_task_and_reply_with_result_internal.h"
- #include "base/time/time.h"
- namespace base {
- struct TaskRunnerTraits;
- class BASE_EXPORT TaskRunner
- : public RefCountedThreadSafe<TaskRunner, TaskRunnerTraits> {
- public:
-
-
-
-
-
- bool PostTask(const Location& from_here, OnceClosure task);
-
-
-
- virtual bool PostDelayedTask(const Location& from_here,
- OnceClosure task,
- base::TimeDelta delay) = 0;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- bool PostTaskAndReply(const Location& from_here,
- OnceClosure task,
- OnceClosure reply);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <typename TaskReturnType, typename ReplyArgType>
- bool PostTaskAndReplyWithResult(const Location& from_here,
- OnceCallback<TaskReturnType()> task,
- OnceCallback<void(ReplyArgType)> reply) {
- DCHECK(task);
- DCHECK(reply);
-
- auto* result = new std::unique_ptr<TaskReturnType>();
- return PostTaskAndReply(
- from_here,
- BindOnce(&internal::ReturnAsParamAdapter<TaskReturnType>,
- std::move(task), result),
- BindOnce(&internal::ReplyAdapter<TaskReturnType, ReplyArgType>,
- std::move(reply), Owned(result)));
- }
- protected:
- friend struct TaskRunnerTraits;
- TaskRunner();
- virtual ~TaskRunner();
-
-
-
- virtual void OnDestruct() const;
- };
- struct BASE_EXPORT TaskRunnerTraits {
- static void Destruct(const TaskRunner* task_runner);
- };
- }
- #endif
|