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

Side by Side Diff: base/task_runner.h

Issue 2122543002: Replace Closure in TaskRunner::PostTask with OneShotCallback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@07_oneshot
Patch Set: fix Created 4 years, 3 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 | « base/sequenced_task_runner.cc ('k') | base/task_runner.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef BASE_TASK_RUNNER_H_ 5 #ifndef BASE_TASK_RUNNER_H_
6 #define BASE_TASK_RUNNER_H_ 6 #define BASE_TASK_RUNNER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // method Run() that runs each runnable task in random order. 55 // method Run() that runs each runnable task in random order.
56 class BASE_EXPORT TaskRunner 56 class BASE_EXPORT TaskRunner
57 : public RefCountedThreadSafe<TaskRunner, TaskRunnerTraits> { 57 : public RefCountedThreadSafe<TaskRunner, TaskRunnerTraits> {
58 public: 58 public:
59 // Posts the given task to be run. Returns true if the task may be 59 // Posts the given task to be run. Returns true if the task may be
60 // run at some point in the future, and false if the task definitely 60 // run at some point in the future, and false if the task definitely
61 // will not be run. 61 // will not be run.
62 // 62 //
63 // Equivalent to PostDelayedTask(from_here, task, 0). 63 // Equivalent to PostDelayedTask(from_here, task, 0).
64 bool PostTask(const tracked_objects::Location& from_here, 64 bool PostTask(const tracked_objects::Location& from_here,
65 const Closure& task); 65 OnceClosure task);
66 66
67 // Like PostTask, but tries to run the posted task only after 67 // Like PostTask, but tries to run the posted task only after
68 // |delay_ms| has passed. 68 // |delay_ms| has passed.
69 // 69 //
70 // It is valid for an implementation to ignore |delay_ms|; that is, 70 // It is valid for an implementation to ignore |delay_ms|; that is,
71 // to have PostDelayedTask behave the same as PostTask. 71 // to have PostDelayedTask behave the same as PostTask.
72 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, 72 virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
73 const Closure& task, 73 OnceClosure task,
74 base::TimeDelta delay) = 0; 74 base::TimeDelta delay) = 0;
75 75
76 // Returns true if the current thread is a thread on which a task 76 // Returns true if the current thread is a thread on which a task
77 // may be run, and false if no task will be run on the current 77 // may be run, and false if no task will be run on the current
78 // thread. 78 // thread.
79 // 79 //
80 // It is valid for an implementation to always return true, or in 80 // It is valid for an implementation to always return true, or in
81 // general to use 'true' as a default value. 81 // general to use 'true' as a default value.
82 virtual bool RunsTasksOnCurrentThread() const = 0; 82 virtual bool RunsTasksOnCurrentThread() const = 0;
83 83
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // 116 //
117 // 117 //
118 // Things to notice: 118 // Things to notice:
119 // * Results of |task| are shared with |reply| by binding a shared argument 119 // * Results of |task| are shared with |reply| by binding a shared argument
120 // (a DataBuffer instance). 120 // (a DataBuffer instance).
121 // * The DataLoader object has no special thread safety. 121 // * The DataLoader object has no special thread safety.
122 // * The DataLoader object can be deleted while |task| is still running, 122 // * The DataLoader object can be deleted while |task| is still running,
123 // and the reply will cancel itself safely because it is bound to a 123 // and the reply will cancel itself safely because it is bound to a
124 // WeakPtr<>. 124 // WeakPtr<>.
125 bool PostTaskAndReply(const tracked_objects::Location& from_here, 125 bool PostTaskAndReply(const tracked_objects::Location& from_here,
126 const Closure& task, 126 OnceClosure task,
127 const Closure& reply); 127 OnceClosure reply);
128 128
129 protected: 129 protected:
130 friend struct TaskRunnerTraits; 130 friend struct TaskRunnerTraits;
131 131
132 // Only the Windows debug build seems to need this: see 132 // Only the Windows debug build seems to need this: see
133 // http://crbug.com/112250. 133 // http://crbug.com/112250.
134 friend class RefCountedThreadSafe<TaskRunner, TaskRunnerTraits>; 134 friend class RefCountedThreadSafe<TaskRunner, TaskRunnerTraits>;
135 135
136 TaskRunner(); 136 TaskRunner();
137 virtual ~TaskRunner(); 137 virtual ~TaskRunner();
138 138
139 // Called when this object should be destroyed. By default simply 139 // Called when this object should be destroyed. By default simply
140 // deletes |this|, but can be overridden to do something else, like 140 // deletes |this|, but can be overridden to do something else, like
141 // delete on a certain thread. 141 // delete on a certain thread.
142 virtual void OnDestruct() const; 142 virtual void OnDestruct() const;
143 }; 143 };
144 144
145 struct BASE_EXPORT TaskRunnerTraits { 145 struct BASE_EXPORT TaskRunnerTraits {
146 static void Destruct(const TaskRunner* task_runner); 146 static void Destruct(const TaskRunner* task_runner);
147 }; 147 };
148 148
149 } // namespace base 149 } // namespace base
150 150
151 #endif // BASE_TASK_RUNNER_H_ 151 #endif // BASE_TASK_RUNNER_H_
OLDNEW
« no previous file with comments | « base/sequenced_task_runner.cc ('k') | base/task_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698