Switch //sky/engine to ftl::TaskRunner (flutter/engine#2866)
The ftl::TaskRunner is still based on a base::MessageLoop, but this patch paves the way to replace the message loop on Fuchsia.
This commit is contained in:
@@ -4,7 +4,10 @@
|
||||
|
||||
source_set("glue") {
|
||||
sources = [
|
||||
"trace_event.h"
|
||||
"movable_wrapper.h",
|
||||
"task_runner_adaptor.cc",
|
||||
"task_runner_adaptor.h",
|
||||
"trace_event.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
|
||||
37
engine/src/flutter/glue/movable_wrapper.h
Normal file
37
engine/src/flutter/glue/movable_wrapper.h
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef GLUE_MOVABLE_WRAPPER_H_
|
||||
#define GLUE_MOVABLE_WRAPPER_H_
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace glue {
|
||||
|
||||
template <typename T>
|
||||
class MovableWrapper {
|
||||
public:
|
||||
explicit MovableWrapper(T object) : object_(std::move(object)) {}
|
||||
MovableWrapper(const MovableWrapper& other)
|
||||
: object_(std::move(other.object_)) {}
|
||||
|
||||
MovableWrapper(MovableWrapper&& other) : object_(std::move(other.object_)) {}
|
||||
MovableWrapper& operator=(MovableWrapper&& other) {
|
||||
object_ = std::move(other.object_);
|
||||
}
|
||||
|
||||
T Unwrap() { return std::move(object_); }
|
||||
|
||||
private:
|
||||
mutable T object_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
MovableWrapper<T> WrapMovable(T object) {
|
||||
return MovableWrapper<T>(std::move(object));
|
||||
}
|
||||
|
||||
} // namespace glue
|
||||
|
||||
#endif // GLUE_MOVABLE_WRAPPER_H_
|
||||
38
engine/src/flutter/glue/task_runner_adaptor.cc
Normal file
38
engine/src/flutter/glue/task_runner_adaptor.cc
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "glue/task_runner_adaptor.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/location.h"
|
||||
#include "base/task_runner.h"
|
||||
|
||||
namespace glue {
|
||||
namespace {
|
||||
|
||||
void RunClosure(ftl::Closure task) {
|
||||
task();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TaskRunnerAdaptor::TaskRunnerAdaptor(scoped_refptr<base::TaskRunner> runner)
|
||||
: runner_(std::move(runner)) {}
|
||||
|
||||
TaskRunnerAdaptor::~TaskRunnerAdaptor() {}
|
||||
|
||||
void TaskRunnerAdaptor::PostTask(ftl::Closure task) {
|
||||
runner_->PostTask(FROM_HERE, base::Bind(RunClosure, task));
|
||||
}
|
||||
|
||||
void TaskRunnerAdaptor::PostDelayedTask(ftl::Closure task,
|
||||
ftl::TimeDelta delay) {
|
||||
runner_->PostDelayedTask(
|
||||
FROM_HERE, base::Bind(RunClosure, task),
|
||||
base::TimeDelta::FromMicroseconds(delay.ToMicroseconds()));
|
||||
}
|
||||
|
||||
} // namespace glue
|
||||
33
engine/src/flutter/glue/task_runner_adaptor.h
Normal file
33
engine/src/flutter/glue/task_runner_adaptor.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef GLUE_BASE_TASK_RUNNER_H_
|
||||
#define GLUE_BASE_TASK_RUNNER_H_
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "lib/ftl/tasks/task_runner.h"
|
||||
|
||||
namespace base {
|
||||
class TaskRunner;
|
||||
} // namespace base
|
||||
|
||||
namespace glue {
|
||||
|
||||
class TaskRunnerAdaptor : public ftl::TaskRunner {
|
||||
public:
|
||||
explicit TaskRunnerAdaptor(scoped_refptr<base::TaskRunner> runner);
|
||||
|
||||
void PostTask(ftl::Closure task) override;
|
||||
void PostDelayedTask(ftl::Closure task, ftl::TimeDelta delay) override;
|
||||
|
||||
protected:
|
||||
~TaskRunnerAdaptor() override;
|
||||
|
||||
private:
|
||||
scoped_refptr<base::TaskRunner> runner_;
|
||||
};
|
||||
|
||||
} // namespace glue
|
||||
|
||||
#endif // GLUE_BASE_TASK_RUNNER_H_
|
||||
Reference in New Issue
Block a user