Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: base/task_scheduler/post_task.cc

Issue 2726523002: Pass Callback to TaskRunner by value and consume it on invocation (1) (Closed)
Patch Set: erase Closure* Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 const Closure& task) override { 24 Closure task) override {
25 PostTaskWithTraits(from_here, traits_, 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, const Closure& task) { 35 void PostTask(const tracked_objects::Location& from_here, Closure task) {
36 PostDelayedTask(from_here, 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 const Closure& task, 40 Closure task,
41 TimeDelta delay) { 41 TimeDelta delay) {
42 PostDelayedTaskWithTraits(from_here, TaskTraits(), 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 Closure task,
47 Closure reply) { 47 Closure 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 const Closure& task) { 54 Closure task) {
55 PostDelayedTaskWithTraits(from_here, traits, 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 const Closure& task, 60 Closure 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(from_here, traits, 64 TaskScheduler::GetInstance()->PostDelayedTaskWithTraits(
65 task, delay); 65 from_here, traits, std::move(task), 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 Closure task,
71 Closure reply) { 71 Closure 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
(...skipping 13 matching lines...) Expand all
89 89
90 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( 90 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits(
91 const TaskTraits& traits) { 91 const TaskTraits& traits) {
92 DCHECK(TaskScheduler::GetInstance()) 92 DCHECK(TaskScheduler::GetInstance())
93 << "Ref. Prerequisite section of post_task.h"; 93 << "Ref. Prerequisite section of post_task.h";
94 return TaskScheduler::GetInstance()->CreateSingleThreadTaskRunnerWithTraits( 94 return TaskScheduler::GetInstance()->CreateSingleThreadTaskRunnerWithTraits(
95 traits); 95 traits);
96 } 96 }
97 97
98 } // namespace base 98 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/post_task.h ('k') | base/task_scheduler/scheduler_single_thread_task_runner_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698