Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
|
gab
2017/01/31 19:34:59
This need to be callback.h since taking by value.
dcheng
2017/02/07 07:28:44
+1 to this
tzik
2017/02/07 08:05:34
Done in the other CL.
| |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 | 17 |
| 18 struct TaskRunnerTraits; | 18 struct TaskRunnerTraits; |
| 19 | 19 |
| 20 // A TaskRunner is an object that runs posted tasks (in the form of | 20 // A TaskRunner is an object that runs posted tasks (in the form of |
| 21 // Closure objects). The TaskRunner interface provides a way of | 21 // Closure objects). The TaskRunner interface provides a way of |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Closure task, |
| 127 const Closure& reply); | 127 Closure 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_ |
| OLD | NEW |