OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/task_scheduler/post_task.h" | 5 #include "base/task_scheduler/post_task.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/task_scheduler/task_scheduler.h" | 10 #include "base/task_scheduler/task_scheduler.h" |
11 #include "base/threading/post_task_and_reply_impl.h" | 11 #include "base/threading/post_task_and_reply_impl.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl { | 17 class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl { |
18 public: | 18 public: |
19 explicit PostTaskAndReplyTaskRunner(const TaskTraits& traits) | 19 explicit PostTaskAndReplyTaskRunner(const TaskTraits& traits) |
20 : traits_(traits) {} | 20 : traits_(traits) {} |
21 | 21 |
22 private: | 22 private: |
23 bool PostTask(const tracked_objects::Location& from_here, | 23 bool PostTask(const tracked_objects::Location& from_here, |
24 Closure task) override { | 24 OnceClosure task) override { |
25 PostTaskWithTraits(from_here, traits_, std::move(task)); | 25 PostTaskWithTraits(from_here, traits_, std::move(task)); |
26 return true; | 26 return true; |
27 } | 27 } |
28 | 28 |
29 const TaskTraits traits_; | 29 const TaskTraits traits_; |
30 }; | 30 }; |
31 | 31 |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 void PostTask(const tracked_objects::Location& from_here, Closure task) { | 35 void PostTask(const tracked_objects::Location& from_here, OnceClosure task) { |
36 PostDelayedTask(from_here, std::move(task), TimeDelta()); | 36 PostDelayedTask(from_here, std::move(task), TimeDelta()); |
37 } | 37 } |
38 | 38 |
39 void PostDelayedTask(const tracked_objects::Location& from_here, | 39 void PostDelayedTask(const tracked_objects::Location& from_here, |
40 Closure task, | 40 OnceClosure task, |
41 TimeDelta delay) { | 41 TimeDelta delay) { |
42 PostDelayedTaskWithTraits(from_here, TaskTraits(), std::move(task), delay); | 42 PostDelayedTaskWithTraits(from_here, TaskTraits(), std::move(task), delay); |
43 } | 43 } |
44 | 44 |
45 void PostTaskAndReply(const tracked_objects::Location& from_here, | 45 void PostTaskAndReply(const tracked_objects::Location& from_here, |
46 Closure task, | 46 OnceClosure task, |
47 Closure reply) { | 47 OnceClosure reply) { |
48 PostTaskWithTraitsAndReply(from_here, TaskTraits(), std::move(task), | 48 PostTaskWithTraitsAndReply(from_here, TaskTraits(), std::move(task), |
49 std::move(reply)); | 49 std::move(reply)); |
50 } | 50 } |
51 | 51 |
52 void PostTaskWithTraits(const tracked_objects::Location& from_here, | 52 void PostTaskWithTraits(const tracked_objects::Location& from_here, |
53 const TaskTraits& traits, | 53 const TaskTraits& traits, |
54 Closure task) { | 54 OnceClosure task) { |
55 PostDelayedTaskWithTraits(from_here, traits, std::move(task), TimeDelta()); | 55 PostDelayedTaskWithTraits(from_here, traits, std::move(task), TimeDelta()); |
56 } | 56 } |
57 | 57 |
58 void PostDelayedTaskWithTraits(const tracked_objects::Location& from_here, | 58 void PostDelayedTaskWithTraits(const tracked_objects::Location& from_here, |
59 const TaskTraits& traits, | 59 const TaskTraits& traits, |
60 Closure task, | 60 OnceClosure task, |
61 TimeDelta delay) { | 61 TimeDelta delay) { |
62 DCHECK(TaskScheduler::GetInstance()) | 62 DCHECK(TaskScheduler::GetInstance()) |
63 << "Ref. Prerequisite section of post_task.h"; | 63 << "Ref. Prerequisite section of post_task.h"; |
64 TaskScheduler::GetInstance()->PostDelayedTaskWithTraits( | 64 TaskScheduler::GetInstance()->PostDelayedTaskWithTraits( |
65 from_here, traits, std::move(task), delay); | 65 from_here, traits, std::move(task), std::move(delay)); |
66 } | 66 } |
67 | 67 |
68 void PostTaskWithTraitsAndReply(const tracked_objects::Location& from_here, | 68 void PostTaskWithTraitsAndReply(const tracked_objects::Location& from_here, |
69 const TaskTraits& traits, | 69 const TaskTraits& traits, |
70 Closure task, | 70 OnceClosure task, |
71 Closure reply) { | 71 OnceClosure reply) { |
72 PostTaskAndReplyTaskRunner(traits).PostTaskAndReply( | 72 PostTaskAndReplyTaskRunner(traits).PostTaskAndReply( |
73 from_here, std::move(task), std::move(reply)); | 73 from_here, std::move(task), std::move(reply)); |
74 } | 74 } |
75 | 75 |
76 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits(const TaskTraits& traits) { | 76 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits(const TaskTraits& traits) { |
77 DCHECK(TaskScheduler::GetInstance()) | 77 DCHECK(TaskScheduler::GetInstance()) |
78 << "Ref. Prerequisite section of post_task.h"; | 78 << "Ref. Prerequisite section of post_task.h"; |
79 return TaskScheduler::GetInstance()->CreateTaskRunnerWithTraits(traits); | 79 return TaskScheduler::GetInstance()->CreateTaskRunnerWithTraits(traits); |
80 } | 80 } |
81 | 81 |
(...skipping 16 matching lines...) Expand all Loading... |
98 #if defined(OS_WIN) | 98 #if defined(OS_WIN) |
99 scoped_refptr<SingleThreadTaskRunner> CreateCOMSTATaskRunnerWithTraits( | 99 scoped_refptr<SingleThreadTaskRunner> CreateCOMSTATaskRunnerWithTraits( |
100 const TaskTraits& traits) { | 100 const TaskTraits& traits) { |
101 DCHECK(TaskScheduler::GetInstance()) | 101 DCHECK(TaskScheduler::GetInstance()) |
102 << "Ref. Prerequisite section of post_task.h"; | 102 << "Ref. Prerequisite section of post_task.h"; |
103 return TaskScheduler::GetInstance()->CreateCOMSTATaskRunnerWithTraits(traits); | 103 return TaskScheduler::GetInstance()->CreateCOMSTATaskRunnerWithTraits(traits); |
104 } | 104 } |
105 #endif // defined(OS_WIN) | 105 #endif // defined(OS_WIN) |
106 | 106 |
107 } // namespace base | 107 } // namespace base |
OLD | NEW |