Commit 245aa90e authored by Yuta Kitamura's avatar Yuta Kitamura Committed by Commit Bot

Replace WTF::Function with base::OnceCallback in platform/.

Now WTF::Function is an alias of base::OnceCallback, we can safely
replace all the occurrences of WTF::Function with base::OnceCallback.

Bug: 771087
Change-Id: Ifa51238ab929012e5a39ed7e0c29fc1fdc341f96
Reviewed-on: https://chromium-review.googlesource.com/816635
Commit-Queue: Yuta Kitamura <yutak@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarTaiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522745}
parent f5b15442
...@@ -36,14 +36,14 @@ ...@@ -36,14 +36,14 @@
namespace blink { namespace blink {
std::unique_ptr<ContentSettingCallbacks> ContentSettingCallbacks::Create( std::unique_ptr<ContentSettingCallbacks> ContentSettingCallbacks::Create(
WTF::Closure allowed, base::OnceClosure allowed,
WTF::Closure denied) { base::OnceClosure denied) {
return WTF::WrapUnique( return WTF::WrapUnique(
new ContentSettingCallbacks(std::move(allowed), std::move(denied))); new ContentSettingCallbacks(std::move(allowed), std::move(denied)));
} }
ContentSettingCallbacks::ContentSettingCallbacks(WTF::Closure allowed, ContentSettingCallbacks::ContentSettingCallbacks(base::OnceClosure allowed,
WTF::Closure denied) base::OnceClosure denied)
: allowed_(std::move(allowed)), denied_(std::move(denied)) {} : allowed_(std::move(allowed)), denied_(std::move(denied)) {}
} // namespace blink } // namespace blink
...@@ -18,18 +18,19 @@ class PLATFORM_EXPORT ContentSettingCallbacks { ...@@ -18,18 +18,19 @@ class PLATFORM_EXPORT ContentSettingCallbacks {
WTF_MAKE_NONCOPYABLE(ContentSettingCallbacks); WTF_MAKE_NONCOPYABLE(ContentSettingCallbacks);
public: public:
static std::unique_ptr<ContentSettingCallbacks> Create(WTF::Closure allowed, static std::unique_ptr<ContentSettingCallbacks> Create(
WTF::Closure denied); base::OnceClosure allowed,
base::OnceClosure denied);
virtual ~ContentSettingCallbacks() {} virtual ~ContentSettingCallbacks() {}
void OnAllowed() { std::move(allowed_).Run(); } void OnAllowed() { std::move(allowed_).Run(); }
void OnDenied() { std::move(denied_).Run(); } void OnDenied() { std::move(denied_).Run(); }
private: private:
ContentSettingCallbacks(WTF::Closure allowed, WTF::Closure denied); ContentSettingCallbacks(base::OnceClosure allowed, base::OnceClosure denied);
WTF::Closure allowed_; base::OnceClosure allowed_;
WTF::Closure denied_; base::OnceClosure denied_;
}; };
} // namespace blink } // namespace blink
......
...@@ -39,7 +39,7 @@ void RunCrossThreadClosure(CrossThreadClosure task) { ...@@ -39,7 +39,7 @@ void RunCrossThreadClosure(CrossThreadClosure task) {
class TaskHandle::Runner : public WTF::ThreadSafeRefCounted<Runner> { class TaskHandle::Runner : public WTF::ThreadSafeRefCounted<Runner> {
public: public:
explicit Runner(WTF::Closure task) explicit Runner(base::OnceClosure task)
: task_(std::move(task)), weak_ptr_factory_(this) {} : task_(std::move(task)), weak_ptr_factory_(this) {}
base::WeakPtr<Runner> AsWeakPtr() { return weak_ptr_factory_.GetWeakPtr(); } base::WeakPtr<Runner> AsWeakPtr() { return weak_ptr_factory_.GetWeakPtr(); }
...@@ -47,7 +47,7 @@ class TaskHandle::Runner : public WTF::ThreadSafeRefCounted<Runner> { ...@@ -47,7 +47,7 @@ class TaskHandle::Runner : public WTF::ThreadSafeRefCounted<Runner> {
bool IsActive() const { return task_ && !task_.IsCancelled(); } bool IsActive() const { return task_ && !task_.IsCancelled(); }
void Cancel() { void Cancel() {
WTF::Closure task = std::move(task_); base::OnceClosure task = std::move(task_);
weak_ptr_factory_.InvalidateWeakPtrs(); weak_ptr_factory_.InvalidateWeakPtrs();
} }
...@@ -68,15 +68,15 @@ class TaskHandle::Runner : public WTF::ThreadSafeRefCounted<Runner> { ...@@ -68,15 +68,15 @@ class TaskHandle::Runner : public WTF::ThreadSafeRefCounted<Runner> {
// There is a circular reference in the example above as: // There is a circular reference in the example above as:
// foo -> m_handle -> m_runner -> m_task -> Persistent<Foo> in WTF::bind. // foo -> m_handle -> m_runner -> m_task -> Persistent<Foo> in WTF::bind.
// The TaskHandle parameter on run() is needed to break the circle by clearing // The TaskHandle parameter on run() is needed to break the circle by clearing
// |m_task| when the wrapped WTF::Closure is deleted. // |m_task| when the wrapped base::OnceClosure is deleted.
void Run(const TaskHandle&) { void Run(const TaskHandle&) {
WTF::Closure task = std::move(task_); base::OnceClosure task = std::move(task_);
weak_ptr_factory_.InvalidateWeakPtrs(); weak_ptr_factory_.InvalidateWeakPtrs();
std::move(task).Run(); std::move(task).Run();
} }
private: private:
WTF::Closure task_; base::OnceClosure task_;
base::WeakPtrFactory<Runner> weak_ptr_factory_; base::WeakPtrFactory<Runner> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(Runner); DISALLOW_COPY_AND_ASSIGN(Runner);
...@@ -131,12 +131,12 @@ void WebTaskRunner::PostDelayedTask(const WebTraceLocation& location, ...@@ -131,12 +131,12 @@ void WebTaskRunner::PostDelayedTask(const WebTraceLocation& location,
} }
void WebTaskRunner::PostTask(const WebTraceLocation& location, void WebTaskRunner::PostTask(const WebTraceLocation& location,
WTF::Closure task) { base::OnceClosure task) {
PostDelayedTask(location, std::move(task), base::TimeDelta()); PostDelayedTask(location, std::move(task), base::TimeDelta());
} }
TaskHandle WebTaskRunner::PostCancellableTask(const WebTraceLocation& location, TaskHandle WebTaskRunner::PostCancellableTask(const WebTraceLocation& location,
WTF::Closure task) { base::OnceClosure task) {
DCHECK(RunsTasksInCurrentSequence()); DCHECK(RunsTasksInCurrentSequence());
scoped_refptr<TaskHandle::Runner> runner = scoped_refptr<TaskHandle::Runner> runner =
base::AdoptRef(new TaskHandle::Runner(std::move(task))); base::AdoptRef(new TaskHandle::Runner(std::move(task)));
...@@ -147,7 +147,7 @@ TaskHandle WebTaskRunner::PostCancellableTask(const WebTraceLocation& location, ...@@ -147,7 +147,7 @@ TaskHandle WebTaskRunner::PostCancellableTask(const WebTraceLocation& location,
TaskHandle WebTaskRunner::PostDelayedCancellableTask( TaskHandle WebTaskRunner::PostDelayedCancellableTask(
const WebTraceLocation& location, const WebTraceLocation& location,
WTF::Closure task, base::OnceClosure task,
TimeDelta delay) { TimeDelta delay) {
DCHECK(RunsTasksInCurrentSequence()); DCHECK(RunsTasksInCurrentSequence());
scoped_refptr<TaskHandle::Runner> runner = scoped_refptr<TaskHandle::Runner> runner =
......
...@@ -77,15 +77,15 @@ class BLINK_PLATFORM_EXPORT WebTaskRunner ...@@ -77,15 +77,15 @@ class BLINK_PLATFORM_EXPORT WebTaskRunner
TimeDelta delay); TimeDelta delay);
// 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&, base::OnceClosure);
// For same-thread cancellable task posting. Returns a TaskHandle object for // For same-thread cancellable task posting. Returns a TaskHandle object for
// cancellation. // cancellation.
WARN_UNUSED_RESULT TaskHandle PostCancellableTask(const WebTraceLocation&, WARN_UNUSED_RESULT TaskHandle PostCancellableTask(const WebTraceLocation&,
WTF::Closure); base::OnceClosure);
WARN_UNUSED_RESULT TaskHandle WARN_UNUSED_RESULT TaskHandle
PostDelayedCancellableTask(const WebTraceLocation&, PostDelayedCancellableTask(const WebTraceLocation&,
WTF::Closure, base::OnceClosure,
TimeDelta delay); TimeDelta delay);
protected: protected:
......
...@@ -34,12 +34,12 @@ class PLATFORM_EXPORT WebThreadSupportingGC final { ...@@ -34,12 +34,12 @@ class PLATFORM_EXPORT WebThreadSupportingGC final {
static std::unique_ptr<WebThreadSupportingGC> CreateForThread(WebThread*); static std::unique_ptr<WebThreadSupportingGC> CreateForThread(WebThread*);
~WebThreadSupportingGC(); ~WebThreadSupportingGC();
void PostTask(const WebTraceLocation& location, WTF::Closure task) { void PostTask(const WebTraceLocation& location, base::OnceClosure task) {
thread_->GetWebTaskRunner()->PostTask(location, std::move(task)); thread_->GetWebTaskRunner()->PostTask(location, std::move(task));
} }
void PostDelayedTask(const WebTraceLocation& location, void PostDelayedTask(const WebTraceLocation& location,
WTF::Closure task, base::OnceClosure task,
TimeDelta delay) { TimeDelta delay) {
thread_->GetWebTaskRunner()->PostDelayedTask(location, std::move(task), thread_->GetWebTaskRunner()->PostDelayedTask(location, std::move(task),
delay); delay);
......
...@@ -42,16 +42,16 @@ void Microtask::PerformCheckpoint(v8::Isolate* isolate) { ...@@ -42,16 +42,16 @@ void Microtask::PerformCheckpoint(v8::Isolate* isolate) {
} }
static void MicrotaskFunctionCallback(void* data) { static void MicrotaskFunctionCallback(void* data) {
std::unique_ptr<WTF::Closure> task = std::unique_ptr<base::OnceClosure> task =
WTF::WrapUnique(static_cast<WTF::Closure*>(data)); WTF::WrapUnique(static_cast<base::OnceClosure*>(data));
std::move(*task).Run(); std::move(*task).Run();
} }
void Microtask::EnqueueMicrotask(WTF::Closure callback) { void Microtask::EnqueueMicrotask(base::OnceClosure callback) {
v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Isolate* isolate = v8::Isolate::GetCurrent();
isolate->EnqueueMicrotask( isolate->EnqueueMicrotask(
&MicrotaskFunctionCallback, &MicrotaskFunctionCallback,
static_cast<void*>(new WTF::Closure(std::move(callback)))); static_cast<void*>(new base::OnceClosure(std::move(callback))));
} }
} // namespace blink } // namespace blink
...@@ -70,7 +70,7 @@ class PLATFORM_EXPORT Microtask { ...@@ -70,7 +70,7 @@ class PLATFORM_EXPORT Microtask {
// TODO(jochen): Make all microtasks pass in the ScriptState they want to be // TODO(jochen): Make all microtasks pass in the ScriptState they want to be
// executed in. Until then, all microtasks have to keep track of their // executed in. Until then, all microtasks have to keep track of their
// ScriptState themselves. // ScriptState themselves.
static void EnqueueMicrotask(WTF::Closure); static void EnqueueMicrotask(base::OnceClosure);
}; };
} // namespace blink } // namespace blink
......
...@@ -318,12 +318,12 @@ v8::Local<v8::Object> V8PerIsolateData::FindInstanceInPrototypeChain( ...@@ -318,12 +318,12 @@ v8::Local<v8::Object> V8PerIsolateData::FindInstanceInPrototypeChain(
templ); templ);
} }
void V8PerIsolateData::AddEndOfScopeTask(WTF::Closure task) { void V8PerIsolateData::AddEndOfScopeTask(base::OnceClosure task) {
end_of_scope_tasks_.push_back(std::move(task)); end_of_scope_tasks_.push_back(std::move(task));
} }
void V8PerIsolateData::RunEndOfScopeTasks() { void V8PerIsolateData::RunEndOfScopeTasks() {
Vector<WTF::Closure> tasks; Vector<base::OnceClosure> tasks;
tasks.swap(end_of_scope_tasks_); tasks.swap(end_of_scope_tasks_);
for (auto& task : tasks) for (auto& task : tasks)
std::move(task).Run(); std::move(task).Run();
......
...@@ -185,7 +185,7 @@ class PLATFORM_EXPORT V8PerIsolateData { ...@@ -185,7 +185,7 @@ class PLATFORM_EXPORT V8PerIsolateData {
// to C++ from script, after executing a script task (e.g. callback, // to C++ from script, after executing a script task (e.g. callback,
// event) or microtasks (e.g. promise). This is explicitly needed for // event) or microtasks (e.g. promise). This is explicitly needed for
// Indexed DB transactions per spec, but should in general be avoided. // Indexed DB transactions per spec, but should in general be avoided.
void AddEndOfScopeTask(WTF::Closure); void AddEndOfScopeTask(base::OnceClosure);
void RunEndOfScopeTasks(); void RunEndOfScopeTasks();
void ClearEndOfScopeTasks(); void ClearEndOfScopeTasks();
...@@ -300,7 +300,7 @@ class PLATFORM_EXPORT V8PerIsolateData { ...@@ -300,7 +300,7 @@ class PLATFORM_EXPORT V8PerIsolateData {
bool is_handling_recursion_level_error_; bool is_handling_recursion_level_error_;
bool is_reporting_exception_; bool is_reporting_exception_;
Vector<WTF::Closure> end_of_scope_tasks_; Vector<base::OnceClosure> end_of_scope_tasks_;
std::unique_ptr<Data> thread_debugger_; std::unique_ptr<Data> thread_debugger_;
Persistent<ActiveScriptWrappableSet> active_script_wrappables_; Persistent<ActiveScriptWrappableSet> active_script_wrappables_;
......
...@@ -5072,11 +5072,11 @@ TEST(HeapTest, RegressNullIsStrongified) { ...@@ -5072,11 +5072,11 @@ TEST(HeapTest, RegressNullIsStrongified) {
} }
TEST(HeapTest, Bind) { TEST(HeapTest, Bind) {
WTF::Closure closure = base::OnceClosure closure =
WTF::Bind(static_cast<void (Bar::*)(Visitor*)>(&Bar::Trace), WTF::Bind(static_cast<void (Bar::*)(Visitor*)>(&Bar::Trace),
WrapPersistent(Bar::Create()), nullptr); WrapPersistent(Bar::Create()), nullptr);
// OffHeapInt* should not make Persistent. // OffHeapInt* should not make Persistent.
WTF::Closure closure2 = base::OnceClosure closure2 =
WTF::Bind(&OffHeapInt::VoidFunction, OffHeapInt::Create(1)); WTF::Bind(&OffHeapInt::VoidFunction, OffHeapInt::Create(1));
PreciselyCollectGarbage(); PreciselyCollectGarbage();
// The closure should have a persistent handle to the Bar. // The closure should have a persistent handle to the Bar.
...@@ -5084,7 +5084,7 @@ TEST(HeapTest, Bind) { ...@@ -5084,7 +5084,7 @@ TEST(HeapTest, Bind) {
UseMixin::trace_count_ = 0; UseMixin::trace_count_ = 0;
Mixin* mixin = UseMixin::Create(); Mixin* mixin = UseMixin::Create();
WTF::Closure mixin_closure = base::OnceClosure mixin_closure =
WTF::Bind(static_cast<void (Mixin::*)(Visitor*)>(&Mixin::Trace), WTF::Bind(static_cast<void (Mixin::*)(Visitor*)>(&Mixin::Trace),
WrapPersistent(mixin), nullptr); WrapPersistent(mixin), nullptr);
PreciselyCollectGarbage(); PreciselyCollectGarbage();
......
...@@ -109,7 +109,7 @@ class PLATFORM_EXPORT WebViewScheduler { ...@@ -109,7 +109,7 @@ class PLATFORM_EXPORT WebViewScheduler {
// policy is not affected when the budget expires. // policy is not affected when the budget expires.
virtual void GrantVirtualTimeBudget( virtual void GrantVirtualTimeBudget(
base::TimeDelta budget, base::TimeDelta budget,
WTF::Closure budget_exhausted_callback) = 0; base::OnceClosure budget_exhausted_callback) = 0;
// It's possible for pages to send infinite messages which can arbitrarily // It's possible for pages to send infinite messages which can arbitrarily
// block virtual time. We can prevent this by setting an upper limit on the // block virtual time. We can prevent this by setting an upper limit on the
......
...@@ -191,7 +191,7 @@ bool WebViewSchedulerImpl::VirtualTimeAllowedToAdvance() const { ...@@ -191,7 +191,7 @@ bool WebViewSchedulerImpl::VirtualTimeAllowedToAdvance() const {
void WebViewSchedulerImpl::GrantVirtualTimeBudget( void WebViewSchedulerImpl::GrantVirtualTimeBudget(
base::TimeDelta budget, base::TimeDelta budget,
WTF::Closure budget_exhausted_callback) { base::OnceClosure budget_exhausted_callback) {
renderer_scheduler_->VirtualTimeControlTaskQueue()->PostDelayedTask( renderer_scheduler_->VirtualTimeControlTaskQueue()->PostDelayedTask(
FROM_HERE, std::move(budget_exhausted_callback), budget); FROM_HERE, std::move(budget_exhausted_callback), budget);
} }
......
...@@ -53,8 +53,9 @@ class PLATFORM_EXPORT WebViewSchedulerImpl : public WebViewScheduler { ...@@ -53,8 +53,9 @@ class PLATFORM_EXPORT WebViewSchedulerImpl : public WebViewScheduler {
void DisableVirtualTimeForTesting() override; void DisableVirtualTimeForTesting() override;
bool VirtualTimeAllowedToAdvance() const override; bool VirtualTimeAllowedToAdvance() const override;
void SetVirtualTimePolicy(VirtualTimePolicy virtual_time_policy) override; void SetVirtualTimePolicy(VirtualTimePolicy virtual_time_policy) override;
void GrantVirtualTimeBudget(base::TimeDelta budget, void GrantVirtualTimeBudget(
WTF::Closure budget_exhausted_callback) override; base::TimeDelta budget,
base::OnceClosure budget_exhausted_callback) override;
void SetMaxVirtualTimeTaskStarvationCount( void SetMaxVirtualTimeTaskStarvationCount(
int max_task_starvation_count) override; int max_task_starvation_count) override;
void AudioStateChanged(bool is_audio_playing) override; void AudioStateChanged(bool is_audio_playing) override;
......
...@@ -211,7 +211,7 @@ void RunVirtualTimeRecorderTask(base::SimpleTestTickClock* clock, ...@@ -211,7 +211,7 @@ void RunVirtualTimeRecorderTask(base::SimpleTestTickClock* clock,
task_runner->MonotonicallyIncreasingVirtualTimeSeconds() * 1000.0); task_runner->MonotonicallyIncreasingVirtualTimeSeconds() * 1000.0);
} }
WTF::Closure MakeVirtualTimeRecorderTask( base::OnceClosure MakeVirtualTimeRecorderTask(
base::SimpleTestTickClock* clock, base::SimpleTestTickClock* clock,
scoped_refptr<WebTaskRunner> task_runner, scoped_refptr<WebTaskRunner> task_runner,
std::vector<base::TimeTicks>* out_real_times, std::vector<base::TimeTicks>* out_real_times,
......
...@@ -63,7 +63,7 @@ class FakeWebViewScheduler : public WebViewScheduler { ...@@ -63,7 +63,7 @@ class FakeWebViewScheduler : public WebViewScheduler {
void AddVirtualTimeObserver(VirtualTimeObserver* observer) override {} void AddVirtualTimeObserver(VirtualTimeObserver* observer) override {}
void RemoveVirtualTimeObserver(VirtualTimeObserver* observer) override {} void RemoveVirtualTimeObserver(VirtualTimeObserver* observer) override {}
void GrantVirtualTimeBudget(base::TimeDelta budget, void GrantVirtualTimeBudget(base::TimeDelta budget,
WTF::Closure callback) override {} base::OnceClosure callback) override {}
void SetMaxVirtualTimeTaskStarvationCount(int count) override {} void SetMaxVirtualTimeTaskStarvationCount(int count) override {}
void AudioStateChanged(bool is_audio_playing) override {} void AudioStateChanged(bool is_audio_playing) override {}
bool HasActiveConnectionForTest() const override { return false; } bool HasActiveConnectionForTest() const override { return false; }
......
...@@ -152,13 +152,13 @@ TEST(FunctionalTest, WeakPtr) { ...@@ -152,13 +152,13 @@ TEST(FunctionalTest, WeakPtr) {
EXPECT_EQ(1, counter); EXPECT_EQ(1, counter);
} }
void MakeClosure(Closure** closure_out) { void MakeClosure(base::OnceClosure** closure_out) {
*closure_out = new Closure(WTF::Bind([] {})); *closure_out = new base::OnceClosure(WTF::Bind([] {}));
LEAK_SANITIZER_IGNORE_OBJECT(*closure_out); LEAK_SANITIZER_IGNORE_OBJECT(*closure_out);
} }
TEST(FunctionalTest, ThreadRestriction) { TEST(FunctionalTest, ThreadRestriction) {
Closure* closure = nullptr; base::OnceClosure* closure = nullptr;
base::Thread thread("testing"); base::Thread thread("testing");
thread.Start(); thread.Start();
......
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