Commit d298a4dd authored by Yuta Kitamura's avatar Yuta Kitamura Committed by Commit Bot

Replace WTF::Function with base::OnceCallback.

This patch makes WTF::Function an alias of base::OnceCallback. After
this, all the single-threaded callbacks in Blink will become base
callbacks.

This patch doesn't remove the WTF::Funtion type nor ConvertToBase-
Callback() function. The use sites of those names will be removed
individually.

Bug: 771087
Change-Id: I15e7758c29bb9f63b7db7ad7aba6c9cb2d9ae7d1
Reviewed-on: https://chromium-review.googlesource.com/807672Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarTaiju Tsuiki <tzik@chromium.org>
Commit-Queue: Yuta Kitamura <yutak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521649}
parent b3f0207c
......@@ -137,13 +137,6 @@ void WebTaskRunner::PostTask(const WebTraceLocation& location,
base::TimeDelta());
}
void WebTaskRunner::PostDelayedTask(const WebTraceLocation& location,
WTF::Closure task,
TimeDelta delay) {
DCHECK(RunsTasksInCurrentSequence());
PostDelayedTask(location, ConvertToBaseCallback(std::move(task)), delay);
}
TaskHandle WebTaskRunner::PostCancellableTask(const WebTraceLocation& location,
WTF::Closure task) {
DCHECK(RunsTasksInCurrentSequence());
......
......@@ -78,7 +78,6 @@ class BLINK_PLATFORM_EXPORT WebTaskRunner
// For same-thread posting. Must be called from the associated WebThread.
void PostTask(const WebTraceLocation&, WTF::Closure);
void PostDelayedTask(const WebTraceLocation&, WTF::Closure, TimeDelta delay);
// For same-thread cancellable task posting. Returns a TaskHandle object for
// cancellation.
......
......@@ -327,44 +327,13 @@ namespace WTF {
#endif
template <typename Signature>
class Function;
using Function = base::OnceCallback<Signature>;
template <typename R, typename... Args>
class Function<R(Args...)> {
USING_FAST_MALLOC(Function);
public:
Function() {}
Function(base::Callback<R(Args...)> callback)
: callback_(std::move(callback)) {}
~Function() {}
Function(const Function&) = delete;
Function& operator=(const Function&) = delete;
Function(Function&& other) : callback_(std::move(other.callback_)) {}
Function& operator=(Function&& other) {
callback_ = std::move(other.callback_);
return *this;
}
R Run(Args... args) && {
return std::move(callback_).Run(std::forward<Args>(args)...);
}
bool IsCancelled() const { return callback_.IsCancelled(); }
void Reset() { callback_.Reset(); }
explicit operator bool() const { return static_cast<bool>(callback_); }
friend base::OnceCallback<R(Args...)> ConvertToBaseCallback(
Function function) {
return std::move(function.callback_);
}
private:
base::Callback<R(Args...)> callback_;
};
template <typename Signature>
base::OnceCallback<Signature> ConvertToBaseCallback(
Function<Signature> function) {
return function;
}
template <typename Signature>
class CrossThreadFunction;
......@@ -418,15 +387,15 @@ Function<base::MakeUnboundRunType<FunctionType, BoundParameters...>> Bind(
"A bound argument uses a bad pattern.");
using UnboundRunType =
base::MakeUnboundRunType<FunctionType, BoundParameters...>;
auto cb =
base::Bind(function, std::forward<BoundParameters>(bound_parameters)...);
auto cb = base::BindOnce(function,
std::forward<BoundParameters>(bound_parameters)...);
#if DCHECK_IS_ON()
using WrapperType =
ThreadCheckingCallbackWrapper<base::Callback<UnboundRunType>>;
cb = base::Bind(&WrapperType::Run,
std::make_unique<WrapperType>(std::move(cb)));
ThreadCheckingCallbackWrapper<base::OnceCallback<UnboundRunType>>;
cb = base::BindOnce(&WrapperType::Run,
std::make_unique<WrapperType>(std::move(cb)));
#endif
return Function<UnboundRunType>(std::move(cb));
return cb;
}
template <typename FunctionType, typename... BoundParameters>
......@@ -501,4 +470,6 @@ using WTF::Function;
using WTF::CrossThreadFunction;
using WTF::CrossThreadClosure;
using WTF::ConvertToBaseCallback;
#endif // WTF_Functional_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment