• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 // This file contains the implementation shared by
6 // TaskRunner::PostTaskAndReply and WorkerPool::PostTaskAndReply.
7 
8 #ifndef BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_
9 #define BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_
10 
11 #include "base/base_export.h"
12 #include "base/callback.h"
13 #include "base/location.h"
14 
15 namespace base {
16 namespace internal {
17 
18 // Inherit from this in a class that implements PostTask to send a task to a
19 // custom execution context.
20 //
21 // If you're looking for a concrete implementation of PostTaskAndReply, you
22 // probably want base::TaskRunner, or you may want base::WorkerPool.
23 class BASE_EXPORT PostTaskAndReplyImpl {
24  public:
25   virtual ~PostTaskAndReplyImpl() = default;
26 
27   // Posts |task| by calling PostTask(). On completion, |reply| is posted to the
28   // sequence or thread that called this. Can only be called when
29   // SequencedTaskRunnerHandle::IsSet(). Both |task| and |reply| are guaranteed
30   // to be deleted on the sequence or thread that called this.
31   bool PostTaskAndReply(const tracked_objects::Location& from_here,
32                         OnceClosure task,
33                         OnceClosure reply);
34 
35  private:
36   virtual bool PostTask(const tracked_objects::Location& from_here,
37                         OnceClosure task) = 0;
38 };
39 
40 }  // namespace internal
41 }  // namespace base
42 
43 #endif  // BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_
44