OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/client/plugin/pepper_main_thread_task_runner.h" | 5 #include "remoting/client/plugin/pepper_main_thread_task_runner.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" |
| 12 #include "base/callback_helpers.h" |
10 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
11 #include "ppapi/cpp/completion_callback.h" | 14 #include "ppapi/cpp/completion_callback.h" |
12 #include "ppapi/cpp/core.h" | 15 #include "ppapi/cpp/core.h" |
13 #include "ppapi/cpp/module.h" | 16 #include "ppapi/cpp/module.h" |
14 | 17 |
15 namespace remoting { | 18 namespace remoting { |
16 namespace { | 19 namespace { |
17 | 20 |
18 void RunAndDestroy(void* task_ptr, int32_t) { | 21 void RunAndDestroy(void* task_ptr, int32_t) { |
19 std::unique_ptr<base::Closure> task(static_cast<base::Closure*>(task_ptr)); | 22 std::unique_ptr<base::Closure> task(static_cast<base::Closure*>(task_ptr)); |
20 task->Run(); | 23 task->Run(); |
21 } | 24 } |
22 | 25 |
23 } // namespace | 26 } // namespace |
24 | 27 |
25 PepperMainThreadTaskRunner::PepperMainThreadTaskRunner() | 28 PepperMainThreadTaskRunner::PepperMainThreadTaskRunner() |
26 : core_(pp::Module::Get()->core()), weak_ptr_factory_(this) { | 29 : core_(pp::Module::Get()->core()), weak_ptr_factory_(this) { |
27 DCHECK(core_->IsMainThread()); | 30 DCHECK(core_->IsMainThread()); |
28 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); | 31 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); |
29 } | 32 } |
30 | 33 |
31 bool PepperMainThreadTaskRunner::PostDelayedTask( | 34 bool PepperMainThreadTaskRunner::PostDelayedTask( |
32 const tracked_objects::Location& from_here, | 35 const tracked_objects::Location& from_here, |
33 const base::Closure& task, | 36 base::Closure task, |
34 base::TimeDelta delay) { | 37 base::TimeDelta delay) { |
35 auto task_ptr = base::MakeUnique<base::Closure>( | 38 auto task_ptr = base::MakeUnique<base::Closure>(base::Bind( |
36 base::Bind(&PepperMainThreadTaskRunner::RunTask, weak_ptr_, task)); | 39 &PepperMainThreadTaskRunner::RunTask, weak_ptr_, base::Passed(&task))); |
37 core_->CallOnMainThread( | 40 core_->CallOnMainThread( |
38 delay.InMillisecondsRoundedUp(), | 41 delay.InMillisecondsRoundedUp(), |
39 pp::CompletionCallback(&RunAndDestroy, task_ptr.release())); | 42 pp::CompletionCallback(&RunAndDestroy, task_ptr.release())); |
40 return true; | 43 return true; |
41 } | 44 } |
42 | 45 |
43 bool PepperMainThreadTaskRunner::PostNonNestableDelayedTask( | 46 bool PepperMainThreadTaskRunner::PostNonNestableDelayedTask( |
44 const tracked_objects::Location& from_here, | 47 const tracked_objects::Location& from_here, |
45 const base::Closure& task, | 48 base::Closure task, |
46 base::TimeDelta delay) { | 49 base::TimeDelta delay) { |
47 return PostDelayedTask(from_here, task, delay); | 50 return PostDelayedTask(from_here, std::move(task), delay); |
48 } | 51 } |
49 | 52 |
50 bool PepperMainThreadTaskRunner::RunsTasksOnCurrentThread() const { | 53 bool PepperMainThreadTaskRunner::RunsTasksOnCurrentThread() const { |
51 return core_->IsMainThread(); | 54 return core_->IsMainThread(); |
52 } | 55 } |
53 | 56 |
54 PepperMainThreadTaskRunner::~PepperMainThreadTaskRunner() {} | 57 PepperMainThreadTaskRunner::~PepperMainThreadTaskRunner() {} |
55 | 58 |
56 void PepperMainThreadTaskRunner::RunTask(const base::Closure& task) { | 59 void PepperMainThreadTaskRunner::RunTask(base::Closure task) { |
57 task.Run(); | 60 std::move(task).Run(); |
58 } | 61 } |
59 | 62 |
60 } // namespace remoting | 63 } // namespace remoting |
OLD | NEW |