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

Side by Side Diff: base/task/cancelable_task_tracker.h

Issue 2657603004: Clear PostTaskAndReply task on the destination thread (3) (Closed)
Patch Set: rebase Created 3 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // CancelableTaskTracker posts tasks (in the form of a Closure) to a 5 // CancelableTaskTracker posts tasks (in the form of a Closure) to a
6 // TaskRunner, and is able to cancel the task later if it's not needed 6 // TaskRunner, and is able to cancel the task later if it's not needed
7 // anymore. On destruction, CancelableTaskTracker will cancel all 7 // anymore. On destruction, CancelableTaskTracker will cancel all
8 // tracked tasks. 8 // tracked tasks.
9 // 9 //
10 // Each cancelable task can be associated with a reply (also a Closure). After 10 // Each cancelable task can be associated with a reply (also a Closure). After
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 // Cancels all tracked tasks. 68 // Cancels all tracked tasks.
69 ~CancelableTaskTracker(); 69 ~CancelableTaskTracker();
70 70
71 TaskId PostTask(base::TaskRunner* task_runner, 71 TaskId PostTask(base::TaskRunner* task_runner,
72 const tracked_objects::Location& from_here, 72 const tracked_objects::Location& from_here,
73 const base::Closure& task); 73 const base::Closure& task);
74 74
75 TaskId PostTaskAndReply(base::TaskRunner* task_runner, 75 TaskId PostTaskAndReply(base::TaskRunner* task_runner,
76 const tracked_objects::Location& from_here, 76 const tracked_objects::Location& from_here,
77 const base::Closure& task, 77 base::Closure task,
78 const base::Closure& reply); 78 base::Closure reply);
79 79
80 template <typename TaskReturnType, typename ReplyArgType> 80 template <typename TaskReturnType, typename ReplyArgType>
81 TaskId PostTaskAndReplyWithResult( 81 TaskId PostTaskAndReplyWithResult(base::TaskRunner* task_runner,
82 base::TaskRunner* task_runner, 82 const tracked_objects::Location& from_here,
83 const tracked_objects::Location& from_here, 83 base::Callback<TaskReturnType()> task,
84 const base::Callback<TaskReturnType(void)>& task, 84 base::Callback<void(ReplyArgType)> reply) {
85 const base::Callback<void(ReplyArgType)>& reply) {
86 TaskReturnType* result = new TaskReturnType(); 85 TaskReturnType* result = new TaskReturnType();
87 return PostTaskAndReply( 86 return PostTaskAndReply(
88 task_runner, 87 task_runner, from_here,
89 from_here,
90 base::Bind(&base::internal::ReturnAsParamAdapter<TaskReturnType>, 88 base::Bind(&base::internal::ReturnAsParamAdapter<TaskReturnType>,
91 task, 89 std::move(task), base::Unretained(result)),
92 base::Unretained(result)),
93 base::Bind(&base::internal::ReplyAdapter<TaskReturnType, ReplyArgType>, 90 base::Bind(&base::internal::ReplyAdapter<TaskReturnType, ReplyArgType>,
94 reply, 91 std::move(reply), base::Owned(result)));
95 base::Owned(result)));
96 } 92 }
97 93
98 // Creates a tracked TaskId and an associated IsCanceledCallback. Client can 94 // Creates a tracked TaskId and an associated IsCanceledCallback. Client can
99 // later call TryCancel() with the returned TaskId, and run |is_canceled_cb| 95 // later call TryCancel() with the returned TaskId, and run |is_canceled_cb|
100 // from any thread to check whether the TaskId is canceled. 96 // from any thread to check whether the TaskId is canceled.
101 // 97 //
102 // The returned task ID is tracked until the last copy of 98 // The returned task ID is tracked until the last copy of
103 // |is_canceled_cb| is destroyed. 99 // |is_canceled_cb| is destroyed.
104 // 100 //
105 // Note. This function is used to address some special cancelation requirement 101 // Note. This function is used to address some special cancelation requirement
(...skipping 27 matching lines...) Expand all
133 SequenceChecker sequence_checker_; 129 SequenceChecker sequence_checker_;
134 130
135 base::WeakPtrFactory<CancelableTaskTracker> weak_factory_; 131 base::WeakPtrFactory<CancelableTaskTracker> weak_factory_;
136 132
137 DISALLOW_COPY_AND_ASSIGN(CancelableTaskTracker); 133 DISALLOW_COPY_AND_ASSIGN(CancelableTaskTracker);
138 }; 134 };
139 135
140 } // namespace base 136 } // namespace base
141 137
142 #endif // BASE_TASK_CANCELABLE_TASK_TRACKER_H_ 138 #endif // BASE_TASK_CANCELABLE_TASK_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698