OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_H_ | 5 #ifndef BASE_TASK_H_ |
6 #define BASE_TASK_H_ | 6 #define BASE_TASK_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/non_thread_safe.h" | 9 #include "base/non_thread_safe.h" |
10 #include "base/raw_scoped_refptr_mismatch_checker.h" | 10 #include "base/raw_scoped_refptr_mismatch_checker.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 private: | 173 private: |
174 base::WeakPtrFactory<T> weak_factory_; | 174 base::WeakPtrFactory<T> weak_factory_; |
175 }; | 175 }; |
176 | 176 |
177 // General task implementations ------------------------------------------------ | 177 // General task implementations ------------------------------------------------ |
178 | 178 |
179 // Task to delete an object | 179 // Task to delete an object |
180 template<class T> | 180 template<class T> |
181 class DeleteTask : public CancelableTask { | 181 class DeleteTask : public CancelableTask { |
182 public: | 182 public: |
183 explicit DeleteTask(T* obj) : obj_(obj) { | 183 explicit DeleteTask(const T* obj) : obj_(obj) { |
184 } | 184 } |
185 virtual void Run() { | 185 virtual void Run() { |
186 delete obj_; | 186 delete obj_; |
187 } | 187 } |
188 virtual void Cancel() { | 188 virtual void Cancel() { |
189 obj_ = NULL; | 189 obj_ = NULL; |
190 } | 190 } |
191 | 191 |
192 private: | 192 private: |
193 T* obj_; | 193 const T* obj_; |
194 }; | 194 }; |
195 | 195 |
196 // Task to Release() an object | 196 // Task to Release() an object |
197 template<class T> | 197 template<class T> |
198 class ReleaseTask : public CancelableTask { | 198 class ReleaseTask : public CancelableTask { |
199 public: | 199 public: |
200 explicit ReleaseTask(T* obj) : obj_(obj) { | 200 explicit ReleaseTask(const T* obj) : obj_(obj) { |
201 } | 201 } |
202 virtual void Run() { | 202 virtual void Run() { |
203 if (obj_) | 203 if (obj_) |
204 obj_->Release(); | 204 obj_->Release(); |
205 } | 205 } |
206 virtual void Cancel() { | 206 virtual void Cancel() { |
207 obj_ = NULL; | 207 obj_ = NULL; |
208 } | 208 } |
209 | 209 |
210 private: | 210 private: |
211 T* obj_; | 211 const T* obj_; |
212 }; | 212 }; |
213 | 213 |
214 // RunnableMethodTraits -------------------------------------------------------- | 214 // RunnableMethodTraits -------------------------------------------------------- |
215 // | 215 // |
216 // This traits-class is used by RunnableMethod to manage the lifetime of the | 216 // This traits-class is used by RunnableMethod to manage the lifetime of the |
217 // callee object. By default, it is assumed that the callee supports AddRef | 217 // callee object. By default, it is assumed that the callee supports AddRef |
218 // and Release methods. A particular class can specialize this template to | 218 // and Release methods. A particular class can specialize this template to |
219 // define other lifetime management. For example, if the callee is known to | 219 // define other lifetime management. For example, if the callee is known to |
220 // live longer than the RunnableMethod object, then a RunnableMethodTraits | 220 // live longer than the RunnableMethod object, then a RunnableMethodTraits |
221 // struct could be defined with empty RetainCallee and ReleaseCallee methods. | 221 // struct could be defined with empty RetainCallee and ReleaseCallee methods. |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 inline CancelableTask* NewRunnableFunction(Function function, | 520 inline CancelableTask* NewRunnableFunction(Function function, |
521 const A& a, const B& b, | 521 const A& a, const B& b, |
522 const C& c, const D& d, | 522 const C& c, const D& d, |
523 const E& e, const F& f, | 523 const E& e, const F& f, |
524 const G& g, const H& h) { | 524 const G& g, const H& h) { |
525 return new RunnableFunction<Function, Tuple8<A, B, C, D, E, F, G, H> >( | 525 return new RunnableFunction<Function, Tuple8<A, B, C, D, E, F, G, H> >( |
526 function, MakeTuple(a, b, c, d, e, f, g, h)); | 526 function, MakeTuple(a, b, c, d, e, f, g, h)); |
527 } | 527 } |
528 | 528 |
529 #endif // BASE_TASK_H_ | 529 #endif // BASE_TASK_H_ |
OLD | NEW |