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 for TaskRunner::PostTaskAndReply. 6 7 #ifndef BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_ 8 #define BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_ 9 10 #include "base/base_export.h" 11 #include "base/callback.h" 12 #include "base/location.h" 13 14 namespace base { 15 namespace internal { 16 17 // Inherit from this in a class that implements PostTask to send a task to a 18 // custom execution context. 19 // 20 // If you're looking for a concrete implementation of PostTaskAndReply, you 21 // probably want base::TaskRunner or base/task_scheduler/post_task.h 22 class BASE_EXPORT PostTaskAndReplyImpl { 23 public: 24 virtual ~PostTaskAndReplyImpl() = default; 25 26 // Posts |task| by calling PostTask(). On completion, posts |reply| to the 27 // origin sequence. Can only be called when 28 // SequencedTaskRunnerHandle::IsSet(). Each callback is deleted synchronously 29 // after running, or scheduled for asynchronous deletion on the origin 30 // sequence if it can't run (e.g. if a TaskRunner skips it on shutdown). See 31 // SequencedTaskRunner::DeleteSoon() for when objects scheduled for 32 // asynchronous deletion can be leaked. Note: All //base task posting APIs 33 // require callbacks to support deletion on the posting sequence if they can't 34 // be scheduled. 35 bool PostTaskAndReply(const Location& from_here, 36 OnceClosure task, 37 OnceClosure reply); 38 39 private: 40 virtual bool PostTask(const Location& from_here, OnceClosure task) = 0; 41 }; 42 43 } // namespace internal 44 } // namespace base 45 46 #endif // BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_ 47