post_task_and_reply_impl.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // This file contains the implementation for TaskRunner::PostTaskAndReply.
  5. #ifndef BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_
  6. #define BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_
  7. #include "base/base_export.h"
  8. #include "base/callback.h"
  9. #include "base/location.h"
  10. namespace base {
  11. namespace internal {
  12. // Inherit from this in a class that implements PostTask to send a task to a
  13. // custom execution context.
  14. //
  15. // If you're looking for a concrete implementation of PostTaskAndReply, you
  16. // probably want base::TaskRunner or base/task/post_task.h
  17. class BASE_EXPORT PostTaskAndReplyImpl {
  18. public:
  19. virtual ~PostTaskAndReplyImpl() = default;
  20. // Posts |task| by calling PostTask(). On completion, posts |reply| to the
  21. // origin sequence. Can only be called when
  22. // SequencedTaskRunnerHandle::IsSet(). Each callback is deleted synchronously
  23. // after running, or scheduled for asynchronous deletion on the origin
  24. // sequence if it can't run (e.g. if a TaskRunner skips it on shutdown). See
  25. // SequencedTaskRunner::DeleteSoon() for when objects scheduled for
  26. // asynchronous deletion can be leaked. Note: All //base task posting APIs
  27. // require callbacks to support deletion on the posting sequence if they can't
  28. // be scheduled.
  29. bool PostTaskAndReply(const Location& from_here,
  30. OnceClosure task,
  31. OnceClosure reply);
  32. private:
  33. virtual bool PostTask(const Location& from_here, OnceClosure task) = 0;
  34. };
  35. } // namespace internal
  36. } // namespace base
  37. #endif // BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_