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, ...@@ -137,13 +137,6 @@ void WebTaskRunner::PostTask(const WebTraceLocation& location,
base::TimeDelta()); 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, TaskHandle WebTaskRunner::PostCancellableTask(const WebTraceLocation& location,
WTF::Closure task) { WTF::Closure task) {
DCHECK(RunsTasksInCurrentSequence()); DCHECK(RunsTasksInCurrentSequence());
......
...@@ -78,7 +78,6 @@ class BLINK_PLATFORM_EXPORT WebTaskRunner ...@@ -78,7 +78,6 @@ class BLINK_PLATFORM_EXPORT WebTaskRunner
// For same-thread posting. Must be called from the associated WebThread. // For same-thread posting. Must be called from the associated WebThread.
void PostTask(const WebTraceLocation&, WTF::Closure); 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 // For same-thread cancellable task posting. Returns a TaskHandle object for
// cancellation. // cancellation.
......
...@@ -327,44 +327,13 @@ namespace WTF { ...@@ -327,44 +327,13 @@ namespace WTF {
#endif #endif
template <typename Signature> template <typename Signature>
class Function; using Function = base::OnceCallback<Signature>;
template <typename R, typename... Args> template <typename Signature>
class Function<R(Args...)> { base::OnceCallback<Signature> ConvertToBaseCallback(
USING_FAST_MALLOC(Function); Function<Signature> function) {
return 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> template <typename Signature>
class CrossThreadFunction; class CrossThreadFunction;
...@@ -418,15 +387,15 @@ Function<base::MakeUnboundRunType<FunctionType, BoundParameters...>> Bind( ...@@ -418,15 +387,15 @@ Function<base::MakeUnboundRunType<FunctionType, BoundParameters...>> Bind(
"A bound argument uses a bad pattern."); "A bound argument uses a bad pattern.");
using UnboundRunType = using UnboundRunType =
base::MakeUnboundRunType<FunctionType, BoundParameters...>; base::MakeUnboundRunType<FunctionType, BoundParameters...>;
auto cb = auto cb = base::BindOnce(function,
base::Bind(function, std::forward<BoundParameters>(bound_parameters)...); std::forward<BoundParameters>(bound_parameters)...);
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
using WrapperType = using WrapperType =
ThreadCheckingCallbackWrapper<base::Callback<UnboundRunType>>; ThreadCheckingCallbackWrapper<base::OnceCallback<UnboundRunType>>;
cb = base::Bind(&WrapperType::Run, cb = base::BindOnce(&WrapperType::Run,
std::make_unique<WrapperType>(std::move(cb))); std::make_unique<WrapperType>(std::move(cb)));
#endif #endif
return Function<UnboundRunType>(std::move(cb)); return cb;
} }
template <typename FunctionType, typename... BoundParameters> template <typename FunctionType, typename... BoundParameters>
...@@ -501,4 +470,6 @@ using WTF::Function; ...@@ -501,4 +470,6 @@ using WTF::Function;
using WTF::CrossThreadFunction; using WTF::CrossThreadFunction;
using WTF::CrossThreadClosure; using WTF::CrossThreadClosure;
using WTF::ConvertToBaseCallback;
#endif // WTF_Functional_h #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