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

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

Issue 1048373003: CancelableTaskTracker::PostDelayedTask() support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove unnecessary base:: Created 5 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
« no previous file with comments | « no previous file | base/task/cancelable_task_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 25 matching lines...) Expand all
36 #ifndef BASE_TASK_CANCELABLE_TASK_TRACKER_H_ 36 #ifndef BASE_TASK_CANCELABLE_TASK_TRACKER_H_
37 #define BASE_TASK_CANCELABLE_TASK_TRACKER_H_ 37 #define BASE_TASK_CANCELABLE_TASK_TRACKER_H_
38 38
39 #include "base/base_export.h" 39 #include "base/base_export.h"
40 #include "base/basictypes.h" 40 #include "base/basictypes.h"
41 #include "base/callback.h" 41 #include "base/callback.h"
42 #include "base/containers/hash_tables.h" 42 #include "base/containers/hash_tables.h"
43 #include "base/memory/weak_ptr.h" 43 #include "base/memory/weak_ptr.h"
44 #include "base/task_runner_util.h" 44 #include "base/task_runner_util.h"
45 #include "base/threading/thread_checker.h" 45 #include "base/threading/thread_checker.h"
46 #include "base/time/time.h"
46 47
47 namespace tracked_objects { 48 namespace tracked_objects {
48 class Location; 49 class Location;
49 } // namespace tracked_objects 50 } // namespace tracked_objects
50 51
51 namespace base { 52 namespace base {
52 53
53 class CancellationFlag; 54 class CancellationFlag;
54 class TaskRunner; 55 class TaskRunner;
55 56
56 class BASE_EXPORT CancelableTaskTracker { 57 class BASE_EXPORT CancelableTaskTracker {
57 public: 58 public:
58 // All values except kBadTaskId are valid. 59 // All values except kBadTaskId are valid.
59 typedef int64 TaskId; 60 typedef int64 TaskId;
60 static const TaskId kBadTaskId; 61 static const TaskId kBadTaskId;
61 62
62 typedef base::Callback<bool()> IsCanceledCallback; 63 typedef base::Callback<bool()> IsCanceledCallback;
63 64
64 CancelableTaskTracker(); 65 CancelableTaskTracker();
65 66
66 // Cancels all tracked tasks. 67 // Cancels all tracked tasks.
67 ~CancelableTaskTracker(); 68 ~CancelableTaskTracker();
68 69
69 TaskId PostTask(base::TaskRunner* task_runner, 70 TaskId PostTask(base::TaskRunner* task_runner,
70 const tracked_objects::Location& from_here, 71 const tracked_objects::Location& from_here,
71 const base::Closure& task); 72 const base::Closure& task);
72 73
74 TaskId PostDelayedTask(base::TaskRunner* task_runner,
75 const tracked_objects::Location& from_here,
76 const base::Closure& task,
77 const TimeDelta& delay);
78
73 TaskId PostTaskAndReply(base::TaskRunner* task_runner, 79 TaskId PostTaskAndReply(base::TaskRunner* task_runner,
74 const tracked_objects::Location& from_here, 80 const tracked_objects::Location& from_here,
75 const base::Closure& task, 81 const base::Closure& task,
76 const base::Closure& reply); 82 const base::Closure& reply);
77 83
78 template <typename TaskReturnType, typename ReplyArgType> 84 template <typename TaskReturnType, typename ReplyArgType>
79 TaskId PostTaskAndReplyWithResult( 85 TaskId PostTaskAndReplyWithResult(
80 base::TaskRunner* task_runner, 86 base::TaskRunner* task_runner,
81 const tracked_objects::Location& from_here, 87 const tracked_objects::Location& from_here,
82 const base::Callback<TaskReturnType(void)>& task, 88 const base::Callback<TaskReturnType(void)>& task,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // noops. 123 // noops.
118 void TryCancelAll(); 124 void TryCancelAll();
119 125
120 // Returns true iff there are in-flight tasks that are still being 126 // Returns true iff there are in-flight tasks that are still being
121 // tracked. 127 // tracked.
122 bool HasTrackedTasks() const; 128 bool HasTrackedTasks() const;
123 129
124 private: 130 private:
125 void Track(TaskId id, base::CancellationFlag* flag); 131 void Track(TaskId id, base::CancellationFlag* flag);
126 void Untrack(TaskId id); 132 void Untrack(TaskId id);
133 TaskId PostDelayedTaskAndReply(base::TaskRunner* task_runner,
134 const tracked_objects::Location& from_here,
135 const base::Closure& task,
136 const base::Closure& reply,
137 const TimeDelta& delay);
127 138
128 base::hash_map<TaskId, base::CancellationFlag*> task_flags_; 139 base::hash_map<TaskId, base::CancellationFlag*> task_flags_;
129 140
130 TaskId next_id_; 141 TaskId next_id_;
131 base::ThreadChecker thread_checker_; 142 base::ThreadChecker thread_checker_;
132 143
133 base::WeakPtrFactory<CancelableTaskTracker> weak_factory_; 144 base::WeakPtrFactory<CancelableTaskTracker> weak_factory_;
134 145
135 DISALLOW_COPY_AND_ASSIGN(CancelableTaskTracker); 146 DISALLOW_COPY_AND_ASSIGN(CancelableTaskTracker);
136 }; 147 };
137 148
138 } // namespace base 149 } // namespace base
139 150
140 #endif // BASE_TASK_CANCELABLE_TASK_TRACKER_H_ 151 #endif // BASE_TASK_CANCELABLE_TASK_TRACKER_H_
OLDNEW
« no previous file with comments | « no previous file | base/task/cancelable_task_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698