1// Copyright 2016 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#ifndef BASE_POST_TASK_AND_REPLY_WITH_RESULT_INTERNAL_H_
6#define BASE_POST_TASK_AND_REPLY_WITH_RESULT_INTERNAL_H_
7
8#include <memory>
9#include <utility>
10
11#include "base/callback.h"
12
13namespace base {
14
15namespace internal {
16
17// Adapts a function that produces a result via a return value to
18// one that returns via an output parameter.
19template <typename ReturnType>
20void ReturnAsParamAdapter(OnceCallback<ReturnType()> func,
21 std::unique_ptr<ReturnType>* result) {
22 result->reset(new ReturnType(std::move(func).Run()));
23}
24
25// Adapts a T* result to a callblack that expects a T.
26template <typename TaskReturnType, typename ReplyArgType>
27void ReplyAdapter(OnceCallback<void(ReplyArgType)> callback,
28 std::unique_ptr<TaskReturnType>* result) {
29 DCHECK(result->get());
30 std::move(callback).Run(std::move(**result));
31}
32
33} // namespace internal
34
35} // namespace base
36
37#endif // BASE_POST_TASK_AND_REPLY_WITH_RESULT_INTERNAL_H_
38