forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pepper_main_thread_task_runner.cc
61 lines (48 loc) · 1.72 KB
/
pepper_main_thread_task_runner.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2015 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 "remoting/client/plugin/pepper_main_thread_task_runner.h"
#include <memory>
#include <utility>
#include "base/bind.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/core.h"
#include "ppapi/cpp/module.h"
namespace remoting {
namespace {
void RunAndDestroy(void* task_ptr, int32_t) {
std::unique_ptr<base::OnceClosure> task(
static_cast<base::OnceClosure*>(task_ptr));
std::move(*task).Run();
}
} // namespace
PepperMainThreadTaskRunner::PepperMainThreadTaskRunner()
: core_(pp::Module::Get()->core()), weak_ptr_factory_(this) {
DCHECK(core_->IsMainThread());
weak_ptr_ = weak_ptr_factory_.GetWeakPtr();
}
bool PepperMainThreadTaskRunner::PostDelayedTask(
const base::Location& from_here,
base::OnceClosure task,
base::TimeDelta delay) {
auto task_ptr = std::make_unique<base::OnceClosure>(base::Bind(
&PepperMainThreadTaskRunner::RunTask, weak_ptr_, base::Passed(&task)));
core_->CallOnMainThread(
delay.InMillisecondsRoundedUp(),
pp::CompletionCallback(&RunAndDestroy, task_ptr.release()));
return true;
}
bool PepperMainThreadTaskRunner::PostNonNestableDelayedTask(
const base::Location& from_here,
base::OnceClosure task,
base::TimeDelta delay) {
return PostDelayedTask(from_here, std::move(task), delay);
}
bool PepperMainThreadTaskRunner::RunsTasksInCurrentSequence() const {
return core_->IsMainThread();
}
PepperMainThreadTaskRunner::~PepperMainThreadTaskRunner() {}
void PepperMainThreadTaskRunner::RunTask(base::OnceClosure task) {
std::move(task).Run();
}
} // namespace remoting