Commit f97b5870 authored by Alexandr Ilin's avatar Alexandr Ilin Committed by Commit Bot

Reland "Replace WTF::Function with base::OnceCallback."

This reverts commit 844e4a30.

Reason for revert:
The bug that caused a compilation error if DCHECKs is off is fixed.

Original change's description:
> Revert "Replace WTF::Function with base::OnceCallback."
>
> This reverts commit d298a4dd.
>
> Reason for revert:
>
> Findit (https://goo.gl/kROfz5) identified CL at revision 521649 as the
> culprit for failures in the build cycles as shown on:
> https://findit-for-me.appspot.com/waterfall/culprit?key=ag9zfmZpbmRpdC1mb3ItbWVyRAsSDVdmU3VzcGVjdGVkQ0wiMWNocm9taXVtL2QyOThhNGRkNzMyZjA5YzlhMWMzMDZhMjA2NTA3YzEyM2EzNzYxZTIM
>
> Sample Failed Build: https://ci.chromium.org/buildbot/chromium.chrome/Google%20Chrome%20Linux%20x64/24801
>
> Change-Id: I60fec5e188923122bb3b090acc49cfd0f0363df1
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 771087
> Reviewed-on: https://chromium-review.googlesource.com/808224
> Cr-Commit-Position: refs/heads/master@{#521653}

TBR=haraken@chromium.org,tzik@chromium.org

Bug: 771087
Change-Id: I0b74afe02f37d128acfe909fc5027f68afedf773
Reviewed-on: https://chromium-review.googlesource.com/808704
Commit-Queue: Yuta Kitamura <yutak@chromium.org>
Reviewed-by: default avatarTaiju Tsuiki <tzik@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarYuta Kitamura <yutak@chromium.org>
Reviewed-by: default avatarAlexandr Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522377}
parent 26331749
...@@ -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;
...@@ -416,17 +385,17 @@ Function<base::MakeUnboundRunType<FunctionType, BoundParameters...>> Bind( ...@@ -416,17 +385,17 @@ Function<base::MakeUnboundRunType<FunctionType, BoundParameters...>> Bind(
std::index_sequence_for<BoundParameters...>, std::index_sequence_for<BoundParameters...>,
std::decay_t<BoundParameters>...>::ok, std::decay_t<BoundParameters>...>::ok,
"A bound argument uses a bad pattern."); "A bound argument uses a bad pattern.");
auto cb = base::BindOnce(function,
std::forward<BoundParameters>(bound_parameters)...);
#if DCHECK_IS_ON()
using UnboundRunType = using UnboundRunType =
base::MakeUnboundRunType<FunctionType, BoundParameters...>; base::MakeUnboundRunType<FunctionType, BoundParameters...>;
auto cb =
base::Bind(function, std::forward<BoundParameters>(bound_parameters)...);
#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