post_task_and_reply_impl.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 a base::TaskRunner (typically obtained from
  17. // base/task/thread_pool.h).
  18. class BASE_EXPORT PostTaskAndReplyImpl {
  19. public:
  20. virtual ~PostTaskAndReplyImpl() = default;
  21. // Posts |task| by calling PostTask(). On completion, posts |reply| to the
  22. // origin sequence. Can only be called when
  23. // SequencedTaskRunnerHandle::IsSet(). Each callback is deleted synchronously
  24. // after running, or scheduled for asynchronous deletion on the origin
  25. // sequence if it can't run (e.g. if a TaskRunner skips it on shutdown). See
  26. // SequencedTaskRunner::DeleteSoon() for when objects scheduled for
  27. // asynchronous deletion can be leaked. Note: All //base task posting APIs
  28. // require callbacks to support deletion on the posting sequence if they can't
  29. // be scheduled.
  30. bool PostTaskAndReply(const Location& from_here,
  31. OnceClosure task,
  32. OnceClosure reply);
  33. private:
  34. virtual bool PostTask(const Location& from_here, OnceClosure task) = 0;
  35. };
  36. } // namespace internal
  37. } // namespace base
  38. #endif // BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_