Commit 1d33fc6f authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[ppapi] Use base::OnceCallback in RunWhileLocked and CallWhileUnlocked

This change updates ppapi::RunWhileLocked and ppapi::CallWhileUnlocked
to use base::OnceClosure and base::OnceCallback instead of base::Closure
and base::Callback.

Bug: 714018
Change-Id: I7e827ecffe2baca3a681cf3e27982263c89f9f34
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2011927
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarRaymes Khoury <raymes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734397}
parent 7bcec019
......@@ -210,10 +210,9 @@ int32_t FileIOResource::Query(PP_FileInfo* info,
// completion task to write the result.
scoped_refptr<QueryOp> query_op(new QueryOp(file_holder_));
base::PostTaskAndReplyWithResult(
PpapiGlobals::Get()->GetFileTaskRunner(),
FROM_HERE,
Bind(&FileIOResource::QueryOp::DoWork, query_op),
RunWhileLocked(Bind(&TrackedCallback::Run, callback)));
PpapiGlobals::Get()->GetFileTaskRunner(), FROM_HERE,
base::BindOnce(&FileIOResource::QueryOp::DoWork, query_op),
RunWhileLocked(base::BindOnce(&TrackedCallback::Run, callback)));
callback->set_completion_task(
Bind(&FileIOResource::OnQueryComplete, this, query_op, info));
......@@ -478,10 +477,9 @@ int32_t FileIOResource::ReadValidated(int64_t offset,
scoped_refptr<ReadOp> read_op(
new ReadOp(file_holder_, offset, bytes_to_read));
base::PostTaskAndReplyWithResult(
PpapiGlobals::Get()->GetFileTaskRunner(),
FROM_HERE,
Bind(&FileIOResource::ReadOp::DoWork, read_op),
RunWhileLocked(Bind(&TrackedCallback::Run, callback)));
PpapiGlobals::Get()->GetFileTaskRunner(), FROM_HERE,
base::BindOnce(&FileIOResource::ReadOp::DoWork, read_op),
RunWhileLocked(base::BindOnce(&TrackedCallback::Run, callback)));
callback->set_completion_task(
Bind(&FileIOResource::OnReadComplete, this, read_op, array_output));
......@@ -520,10 +518,9 @@ int32_t FileIOResource::WriteValidated(
scoped_refptr<WriteOp> write_op(new WriteOp(
file_holder_, offset, std::move(copy), bytes_to_write, append));
base::PostTaskAndReplyWithResult(
PpapiGlobals::Get()->GetFileTaskRunner(),
FROM_HERE,
Bind(&FileIOResource::WriteOp::DoWork, write_op),
RunWhileLocked(Bind(&TrackedCallback::Run, callback)));
PpapiGlobals::Get()->GetFileTaskRunner(), FROM_HERE,
base::BindOnce(&FileIOResource::WriteOp::DoWork, write_op),
RunWhileLocked(base::BindOnce(&TrackedCallback::Run, callback)));
callback->set_completion_task(Bind(&FileIOResource::OnWriteComplete, this));
return PP_OK_COMPLETIONPENDING;
......@@ -612,10 +609,9 @@ void FileIOResource::OnRequestWriteQuotaComplete(
scoped_refptr<WriteOp> write_op(new WriteOp(
file_holder_, offset, std::move(buffer), bytes_to_write, append));
base::PostTaskAndReplyWithResult(
PpapiGlobals::Get()->GetFileTaskRunner(),
FROM_HERE,
Bind(&FileIOResource::WriteOp::DoWork, write_op),
RunWhileLocked(Bind(&TrackedCallback::Run, callback)));
PpapiGlobals::Get()->GetFileTaskRunner(), FROM_HERE,
base::BindOnce(&FileIOResource::WriteOp::DoWork, write_op),
RunWhileLocked(base::BindOnce(&TrackedCallback::Run, callback)));
callback->set_completion_task(Bind(&FileIOResource::OnWriteComplete, this));
}
}
......
......@@ -109,7 +109,7 @@ bool MessageHandler::LoopIsValid() const {
void MessageHandler::HandleMessage(ScopedPPVar var) {
message_loop_->task_runner()->PostTask(
FROM_HERE, RunWhileLocked(base::Bind(&HandleMessageWrapper,
FROM_HERE, RunWhileLocked(base::BindOnce(&HandleMessageWrapper,
handler_if_->HandleMessage,
instance_, user_data_, var)));
}
......@@ -119,7 +119,7 @@ void MessageHandler::HandleBlockingMessage(
std::unique_ptr<IPC::Message> reply_msg) {
message_loop_->task_runner()->PostTask(
FROM_HERE,
RunWhileLocked(base::Bind(
RunWhileLocked(base::BindOnce(
&HandleBlockingMessageWrapper, handler_if_->HandleBlockingMessage,
instance_, user_data_, var, base::Passed(std::move(reply_msg)))));
}
......
......@@ -74,7 +74,7 @@ void CallOnMainThread(int delay_in_ms,
PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostDelayedTask(
FROM_HERE,
RunWhileLocked(base::Bind(&CallbackWrapper, callback, result)),
RunWhileLocked(base::BindOnce(&CallbackWrapper, callback, result)),
base::TimeDelta::FromMilliseconds(delay_in_ms));
}
......
......@@ -284,7 +284,7 @@ void ImageDataCache::Add(ImageData* image_data) {
// Schedule a timer to invalidate this entry.
PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostDelayedTask(
FROM_HERE,
RunWhileLocked(base::Bind(&ImageDataCache::OnTimer,
RunWhileLocked(base::BindOnce(&ImageDataCache::OnTimer,
weak_factory_.GetWeakPtr(),
image_data->pp_instance())),
base::TimeDelta::FromSeconds(kMaxAgeSeconds));
......
......@@ -636,7 +636,7 @@ void PPB_Instance_Proxy::SelectionChanged(PP_Instance instance) {
if (!data->is_request_surrounding_text_pending) {
PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
FROM_HERE,
RunWhileLocked(base::Bind(&RequestSurroundingText, instance)));
RunWhileLocked(base::BindOnce(&RequestSurroundingText, instance)));
data->is_request_surrounding_text_pending = true;
}
}
......
......@@ -95,9 +95,8 @@ int32_t MessageLoopResource::AttachToCurrentThread() {
task_runner_ = base::ThreadTaskRunnerHandle::Get();
// Post all pending work to the task executor.
for (size_t i = 0; i < pending_tasks_.size(); i++) {
const TaskInfo& info = pending_tasks_[i];
PostClosure(info.from_here, info.closure, info.delay_ms);
for (auto& info : pending_tasks_) {
PostClosure(info.from_here, std::move(info.closure), info.delay_ms);
}
pending_tasks_.clear();
......@@ -116,7 +115,7 @@ int32_t MessageLoopResource::Run() {
nested_invocations_++;
CallWhileUnlocked(
base::Bind(&base::RunLoop::Run, base::Unretained(run_loop_)));
base::BindOnce(&base::RunLoop::Run, base::Unretained(run_loop_)));
nested_invocations_--;
run_loop_ = previous_run_loop;
......@@ -188,17 +187,17 @@ bool MessageLoopResource::IsCurrent() const {
}
void MessageLoopResource::PostClosure(const base::Location& from_here,
const base::Closure& closure,
base::OnceClosure closure,
int64_t delay_ms) {
if (task_runner_.get()) {
task_runner_->PostDelayedTask(from_here, closure,
task_runner_->PostDelayedTask(from_here, std::move(closure),
base::TimeDelta::FromMilliseconds(delay_ms));
} else {
TaskInfo info;
info.from_here = FROM_HERE;
info.closure = closure;
info.closure = std::move(closure);
info.delay_ms = delay_ms;
pending_tasks_.push_back(info);
pending_tasks_.push_back(std::move(info));
}
}
......
......@@ -59,7 +59,7 @@ class PPAPI_PROXY_EXPORT MessageLoopResource : public MessageLoopShared {
private:
struct TaskInfo {
base::Location from_here;
base::Closure closure;
base::OnceClosure closure;
int64_t delay_ms;
};
......@@ -74,7 +74,7 @@ class PPAPI_PROXY_EXPORT MessageLoopResource : public MessageLoopShared {
// This only makes sense for user code and completely thread-safe
// proxy operations (e.g., MessageLoop::QuitClosure).
void PostClosure(const base::Location& from_here,
const base::Closure& closure,
base::OnceClosure closure,
int64_t delay_ms) override;
base::SingleThreadTaskRunner* GetTaskRunner() override;
bool CurrentlyHandlingBlockingMessage() override;
......
......@@ -380,9 +380,8 @@ void PPB_Var_Deprecated_Proxy::OnMsgReleaseObject(int64_t object_id) {
// then remove this.
PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostNonNestableTask(
FROM_HERE,
RunWhileLocked(base::Bind(&PPB_Var_Deprecated_Proxy::DoReleaseObject,
task_factory_.GetWeakPtr(),
object_id)));
RunWhileLocked(base::BindOnce(&PPB_Var_Deprecated_Proxy::DoReleaseObject,
task_factory_.GetWeakPtr(), object_id)));
}
void PPB_Var_Deprecated_Proxy::OnMsgHasProperty(
......
......@@ -245,7 +245,7 @@ class CallbackMockResource : public Resource {
// |thread_checker_| will bind to the background thread.
thread_checker_.DetachFromThread();
loop_resource->task_runner()->PostTask(
FROM_HERE, RunWhileLocked(base::Bind(
FROM_HERE, RunWhileLocked(base::BindOnce(
&CallbackMockResource::CreateCallbacks, this)));
}
......
......@@ -190,8 +190,7 @@ void UDPSocketFilter::RecvQueue::DataReceivedOnIOThread(
base::Unretained(recvfrom_addr_resource_)));
last_recvfrom_addr_ = addr;
PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
FROM_HERE,
RunWhileLocked(slot_available_callback_));
FROM_HERE, RunWhileLocked(base::BindOnce(slot_available_callback_)));
}
read_buffer_ = NULL;
......
......@@ -181,7 +181,8 @@ void PPB_Audio_Shared::StopThread() {
} else {
if (audio_thread_.get()) {
auto local_audio_thread(std::move(audio_thread_));
CallWhileUnlocked(base::Bind(&base::DelegateSimpleThread::Join,
CallWhileUnlocked(
base::BindOnce(&base::DelegateSimpleThread::Join,
base::Unretained(local_audio_thread.get())));
}
}
......
......@@ -44,7 +44,7 @@ class PPAPI_SHARED_EXPORT MessageLoopShared
// This only makes sense for user code and completely thread-safe
// proxy operations (e.g., MessageLoop::QuitClosure).
virtual void PostClosure(const base::Location& from_here,
const base::Closure& closure,
base::OnceClosure closure,
int64_t delay_ms) = 0;
virtual base::SingleThreadTaskRunner* GetTaskRunner() = 0;
......
......@@ -89,9 +89,9 @@ ProxyLock::LockingDisablerForTest::~LockingDisablerForTest() {
g_disable_locking_for_thread.Get().Set(false);
}
void CallWhileUnlocked(const base::Closure& closure) {
void CallWhileUnlocked(base::OnceClosure closure) {
ProxyAutoUnlock lock;
closure.Run();
std::move(closure).Run();
}
} // namespace ppapi
......@@ -164,7 +164,7 @@ ReturnType CallWhileUnlocked(ReturnType (*function)(A1, A2, A3, A4, A5),
ProxyAutoUnlock unlock;
return function(p1, p2, p3, p4, p5);
}
void PPAPI_SHARED_EXPORT CallWhileUnlocked(const base::Closure& closure);
void PPAPI_SHARED_EXPORT CallWhileUnlocked(base::OnceClosure closure);
namespace internal {
......@@ -178,9 +178,9 @@ class RunWhileLockedHelper;
template <>
class RunWhileLockedHelper<void()> {
public:
typedef base::Callback<void()> CallbackType;
explicit RunWhileLockedHelper(const CallbackType& callback)
: callback_(new CallbackType(callback)) {
typedef base::OnceCallback<void()> CallbackType;
explicit RunWhileLockedHelper(CallbackType callback)
: callback_(std::move(callback)) {
// CallWhileLocked and destruction might happen on a different thread from
// creation.
thread_checker_.DetachFromThread();
......@@ -201,8 +201,8 @@ class RunWhileLockedHelper<void()> {
// Use a scope and local Callback to ensure that the callback is cleared
// before the lock is released, even in the unlikely event that Run()
// throws an exception.
std::unique_ptr<CallbackType> temp_callback(std::move(ptr->callback_));
temp_callback->Run();
CallbackType temp_callback = std::move(ptr->callback_);
std::move(temp_callback).Run();
}
}
......@@ -234,13 +234,13 @@ class RunWhileLockedHelper<void()> {
base::ScopedAllowCrossThreadRefCountAccess
allow_cross_thread_ref_count_access;
callback_.reset();
callback_.Reset();
}
}
private:
DISALLOW_COPY_AND_ASSIGN(RunWhileLockedHelper);
std::unique_ptr<CallbackType> callback_;
CallbackType callback_;
// Used to ensure that the Callback is run and deleted on the same thread.
base::ThreadChecker thread_checker_;
......@@ -249,9 +249,9 @@ class RunWhileLockedHelper<void()> {
template <typename P1>
class RunWhileLockedHelper<void(P1)> {
public:
typedef base::Callback<void(P1)> CallbackType;
explicit RunWhileLockedHelper(const CallbackType& callback)
: callback_(new CallbackType(callback)) {
typedef base::OnceCallback<void(P1)> CallbackType;
explicit RunWhileLockedHelper(CallbackType callback)
: callback_(std::move(callback)) {
thread_checker_.DetachFromThread();
}
static void CallWhileLocked(std::unique_ptr<RunWhileLockedHelper> ptr,
......@@ -263,8 +263,8 @@ class RunWhileLockedHelper<void(P1)> {
base::ScopedAllowCrossThreadRefCountAccess
allow_cross_thread_ref_count_access;
{
std::unique_ptr<CallbackType> temp_callback(std::move(ptr->callback_));
temp_callback->Run(p1);
CallbackType temp_callback = std::move(ptr->callback_);
std::move(temp_callback).Run(p1);
}
}
~RunWhileLockedHelper() {
......@@ -275,22 +275,22 @@ class RunWhileLockedHelper<void(P1)> {
// |lock| above protects the access to Resource instances.
base::ScopedAllowCrossThreadRefCountAccess
allow_cross_thread_ref_count_access;
callback_.reset();
callback_.Reset();
}
}
private:
DISALLOW_COPY_AND_ASSIGN(RunWhileLockedHelper);
std::unique_ptr<CallbackType> callback_;
CallbackType callback_;
base::ThreadChecker thread_checker_;
};
template <typename P1, typename P2>
class RunWhileLockedHelper<void(P1, P2)> {
public:
typedef base::Callback<void(P1, P2)> CallbackType;
explicit RunWhileLockedHelper(const CallbackType& callback)
: callback_(new CallbackType(callback)) {
typedef base::OnceCallback<void(P1, P2)> CallbackType;
explicit RunWhileLockedHelper(CallbackType callback)
: callback_(std::move(callback)) {
thread_checker_.DetachFromThread();
}
static void CallWhileLocked(std::unique_ptr<RunWhileLockedHelper> ptr,
......@@ -303,8 +303,8 @@ class RunWhileLockedHelper<void(P1, P2)> {
base::ScopedAllowCrossThreadRefCountAccess
allow_cross_thread_ref_count_access;
{
std::unique_ptr<CallbackType> temp_callback(std::move(ptr->callback_));
temp_callback->Run(p1, p2);
CallbackType temp_callback = std::move(ptr->callback_);
std::move(temp_callback).Run(p1, p2);
}
}
~RunWhileLockedHelper() {
......@@ -315,22 +315,22 @@ class RunWhileLockedHelper<void(P1, P2)> {
// |lock| above protects the access to Resource instances.
base::ScopedAllowCrossThreadRefCountAccess
allow_cross_thread_ref_count_access;
callback_.reset();
callback_.Reset();
}
}
private:
DISALLOW_COPY_AND_ASSIGN(RunWhileLockedHelper);
std::unique_ptr<CallbackType> callback_;
CallbackType callback_;
base::ThreadChecker thread_checker_;
};
template <typename P1, typename P2, typename P3>
class RunWhileLockedHelper<void(P1, P2, P3)> {
public:
typedef base::Callback<void(P1, P2, P3)> CallbackType;
explicit RunWhileLockedHelper(const CallbackType& callback)
: callback_(new CallbackType(callback)) {
typedef base::OnceCallback<void(P1, P2, P3)> CallbackType;
explicit RunWhileLockedHelper(CallbackType callback)
: callback_(std::move(callback)) {
thread_checker_.DetachFromThread();
}
static void CallWhileLocked(std::unique_ptr<RunWhileLockedHelper> ptr,
......@@ -344,8 +344,8 @@ class RunWhileLockedHelper<void(P1, P2, P3)> {
base::ScopedAllowCrossThreadRefCountAccess
allow_cross_thread_ref_count_access;
{
std::unique_ptr<CallbackType> temp_callback(std::move(ptr->callback_));
temp_callback->Run(p1, p2, p3);
CallbackType temp_callback = std::move(ptr->callback_);
std::move(temp_callback).Run(p1, p2, p3);
}
}
~RunWhileLockedHelper() {
......@@ -356,13 +356,13 @@ class RunWhileLockedHelper<void(P1, P2, P3)> {
// |lock| above protects the access to Resource instances.
base::ScopedAllowCrossThreadRefCountAccess
allow_cross_thread_ref_count_access;
callback_.reset();
callback_.Reset();
}
}
private:
DISALLOW_COPY_AND_ASSIGN(RunWhileLockedHelper);
std::unique_ptr<CallbackType> callback_;
CallbackType callback_;
base::ThreadChecker thread_checker_;
};
......@@ -383,7 +383,8 @@ class RunWhileLockedHelper<void(P1, P2, P3)> {
// EXAMPLE USAGE:
// GetMainThreadMessageLoop()->PostDelayedTask(
// FROM_HERE,
// RunWhileLocked(base::Bind(&CallbackWrapper, callback, result)),
// RunWhileLocked(
// base::BindOnce(&CallbackWrapper, std::move(callback), result)),
// delay_in_ms);
//
// In normal usage like the above, this all should "just work". However, if you
......@@ -397,14 +398,15 @@ class RunWhileLockedHelper<void(P1, P2, P3)> {
// was run (but can be destroyed with or without the proxy lock acquired). Or
// (3) destroyed without the proxy lock acquired.
template <class FunctionType>
inline base::Callback<FunctionType> RunWhileLocked(
const base::Callback<FunctionType>& callback) {
inline base::OnceCallback<FunctionType> RunWhileLocked(
base::OnceCallback<FunctionType> callback) {
// NOTE: the reason we use "scoped_ptr" here instead of letting the callback
// own it via base::Owned is kind of subtle. Imagine for the moment that we
// call RunWhileLocked without the ProxyLock:
// {
// base::Callback<void ()> local_callback = base::Bind(&Foo);
// some_task_runner.PostTask(FROM_HERE, RunWhileLocked(local_callback));
// base::OnceCallback<void ()> local_callback = base::BinOnced(&Foo);
// some_task_runner.PostTask(FROM_HERE,
// RunWhileLocked(std::move(local_callback)));
// }
// In this case, since we don't have a lock synchronizing us, it's possible
// for the callback to run on the other thread before we return and destroy
......@@ -415,8 +417,8 @@ inline base::Callback<FunctionType> RunWhileLocked(
// on this thread, which will violate the RunWhileLockedHelper's assumption
// that it is destroyed on the same thread where it is run.
std::unique_ptr<internal::RunWhileLockedHelper<FunctionType>> helper(
new internal::RunWhileLockedHelper<FunctionType>(callback));
return base::Bind(
new internal::RunWhileLockedHelper<FunctionType>(std::move(callback)));
return base::BindOnce(
&internal::RunWhileLockedHelper<FunctionType>::CallWhileLocked,
base::Passed(std::move(helper)));
}
......
......@@ -76,20 +76,20 @@ TEST_F(PpapiProxyLockTest, Locking) {
TestGlobals globals;
expect_to_be_locked = true;
base::Callback<void()> cb0;
base::OnceCallback<void()> cb0;
{
ProxyAutoLock lock;
cb0 = RunWhileLocked(base::Bind(TestCallback_0));
cb0 = RunWhileLocked(base::BindOnce(TestCallback_0));
}
cb0.Run();
std::move(cb0).Run();
ASSERT_EQ(1, called_num);
called_num = 0;
{
ProxyAutoLock lock;
cb0 = RunWhileLocked(base::Bind(TestCallback_1, 123));
cb0 = RunWhileLocked(base::BindOnce(TestCallback_1, 123));
}
cb0.Run();
std::move(cb0).Run();
ASSERT_EQ(1, called_num);
called_num = 0;
......@@ -97,55 +97,56 @@ TEST_F(PpapiProxyLockTest, Locking) {
ProxyAutoLock lock;
scoped_refptr<CheckLockStateInDestructor> object =
new CheckLockStateInDestructor();
cb0 =
RunWhileLocked(base::Bind(&CheckLockStateInDestructor::Method, object));
cb0 = RunWhileLocked(
base::BindOnce(&CheckLockStateInDestructor::Method, object));
// Note after this scope, the Callback owns the only reference.
}
cb0.Run();
std::move(cb0).Run();
ASSERT_EQ(1, called_num);
called_num = 0;
base::Callback<void(int)> cb1;
base::OnceCallback<void(int)> cb1;
{
ProxyAutoLock lock;
cb1 = RunWhileLocked(base::Bind(TestCallback_1));
cb1 = RunWhileLocked(base::BindOnce(TestCallback_1));
}
cb1.Run(123);
std::move(cb1).Run(123);
ASSERT_EQ(1, called_num);
called_num = 0;
base::Callback<void(int, const std::string&)> cb2;
base::OnceCallback<void(int, const std::string&)> cb2;
{
ProxyAutoLock lock;
cb2 = RunWhileLocked(base::Bind(TestCallback_2));
cb2 = RunWhileLocked(base::BindOnce(TestCallback_2));
}
cb2.Run(123, std::string("yo"));
std::move(cb2).Run(123, std::string("yo"));
ASSERT_EQ(1, called_num);
called_num = 0;
base::Callback<void(int, const std::string&, Param)> cb3;
base::OnceCallback<void(int, const std::string&, Param)> cb3;
{
ProxyAutoLock lock;
cb3 = RunWhileLocked(base::Bind(TestCallback_3));
cb3 = RunWhileLocked(base::BindOnce(TestCallback_3));
}
cb3.Run(123, std::string("yo"), Param());
std::move(cb3).Run(123, std::string("yo"), Param());
ASSERT_EQ(1, called_num);
called_num = 0;
base::Callback<void(const std::string&)> cb1_string;
base::OnceCallback<void(const std::string&)> cb1_string;
{
ProxyAutoLock lock;
cb1_string = RunWhileLocked(base::Bind(TestCallback_2, 123));
cb1_string = RunWhileLocked(base::BindOnce(TestCallback_2, 123));
}
cb1_string.Run(std::string("yo"));
std::move(cb1_string).Run(std::string("yo"));
ASSERT_EQ(1, called_num);
called_num = 0;
{
ProxyAutoLock lock;
cb0 = RunWhileLocked(base::Bind(TestCallback_2, 123, std::string("yo")));
cb0 =
RunWhileLocked(base::BindOnce(TestCallback_2, 123, std::string("yo")));
}
cb0.Run();
std::move(cb0).Run();
ASSERT_EQ(1, called_num);
called_num = 0;
}
......@@ -168,16 +169,13 @@ TEST_F(PpapiProxyLockTest, Unlocking) {
called_num = 0;
}
{
// TODO(dmichael): Make const-ref arguments work properly with type
// deduction.
CallWhileUnlocked<void, int, const std::string&>(
TestCallback_2, 123, std::string("yo"));
CallWhileUnlocked(TestCallback_2, 123, std::string("yo"));
ASSERT_EQ(1, called_num);
called_num = 0;
}
{
base::Callback<void()> callback(base::Bind(TestCallback_0));
CallWhileUnlocked(callback);
base::OnceCallback<void()> callback(base::BindOnce(TestCallback_0));
CallWhileUnlocked(std::move(callback));
ASSERT_EQ(1, called_num);
called_num = 0;
}
......
......@@ -18,9 +18,9 @@ class ThreadAwareCallbackBase::Core : public base::RefCountedThreadSafe<Core> {
void MarkAsAborted() { aborted_ = true; }
void RunIfNotAborted(const base::Closure& closure) {
void RunIfNotAborted(base::OnceClosure closure) {
if (!aborted_)
CallWhileUnlocked(closure);
CallWhileUnlocked(std::move(closure));
}
private:
......@@ -44,14 +44,15 @@ bool ThreadAwareCallbackBase::HasTargetLoop() {
}
void ThreadAwareCallbackBase::InternalRunOnTargetThread(
const base::Closure& closure) {
base::OnceClosure closure) {
if (target_loop_.get() != PpapiGlobals::Get()->GetCurrentMessageLoop()) {
target_loop_->PostClosure(
FROM_HERE,
RunWhileLocked(base::Bind(&Core::RunIfNotAborted, core_, closure)),
RunWhileLocked(
base::BindOnce(&Core::RunIfNotAborted, core_, std::move(closure))),
0);
} else {
CallWhileUnlocked(closure);
CallWhileUnlocked(std::move(closure));
}
}
......
......@@ -24,7 +24,7 @@ class PPAPI_SHARED_EXPORT ThreadAwareCallbackBase {
static bool HasTargetLoop();
void InternalRunOnTargetThread(const base::Closure& closure);
void InternalRunOnTargetThread(base::OnceClosure closure);
private:
class Core;
......
......@@ -256,17 +256,17 @@ void TrackedCallback::PostRunWithLock(int32_t result) {
// directly.
SignalBlockingCallback(result);
} else {
base::Closure callback_closure(
RunWhileLocked(base::Bind(&TrackedCallback::Run, this, result)));
base::OnceClosure callback_closure(
RunWhileLocked(base::BindOnce(&TrackedCallback::Run, this, result)));
if (target_loop_) {
target_loop_->PostClosure(FROM_HERE, callback_closure, 0);
target_loop_->PostClosure(FROM_HERE, std::move(callback_closure), 0);
} else {
// We must be running in-process and on the main thread (the Enter
// classes protect against having a null target_loop_ otherwise).
DCHECK(IsMainThread());
DCHECK(PpapiGlobals::Get()->IsHostGlobals());
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
callback_closure);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, std::move(callback_closure));
}
}
is_scheduled_ = true;
......
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