Chromium Code Reviews| 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 | 7 |
| 8 #include "base/non_thread_safe.h" | 8 #include "base/non_thread_safe.h" |
| 9 #include "base/raw_scoped_refptr_mismatch_checker.h" | 9 #include "base/raw_scoped_refptr_mismatch_checker.h" |
| 10 #include "base/tracked.h" | 10 #include "base/tracked.h" |
| 11 #include "base/tuple.h" | 11 #include "base/tuple.h" |
| 12 #include "base/weak_ptr.h" | 12 #include "base/weak_ptr.h" |
| 13 | 13 |
| 14 // Task ------------------------------------------------------------------------ | 14 // Task ------------------------------------------------------------------------ |
| 15 // | 15 // |
| 16 // A task is a generic runnable thingy, usually used for running code on a | 16 // A task is a generic runnable thingy, usually used for running code on a |
| 17 // different thread or for scheduling future tasks off of the message loop. | 17 // different thread or for scheduling future tasks off of the message loop. |
| 18 | 18 |
| 19 class Task : public tracked_objects::Tracked { | 19 class Task : public tracked_objects::Tracked { |
| 20 public: | 20 public: |
| 21 Task() {} | 21 Task(); |
| 22 virtual ~Task() {} | 22 virtual ~Task(); |
| 23 | 23 |
| 24 // Tasks are automatically deleted after Run is called. | 24 // Tasks are automatically deleted after Run is called. |
| 25 virtual void Run() = 0; | 25 virtual void Run() = 0; |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 class CancelableTask : public Task { | 28 class CancelableTask : public Task { |
| 29 public: | 29 public: |
| 30 CancelableTask(); | |
| 31 ~CancelableTask(); | |
|
Evan Martin
2010/07/15 17:37:33
Why are these needed?
Should this be virtual?
Elliot Glaysher
2010/07/15 18:08:10
Because a copy of the synthesized constructor/dest
| |
| 32 | |
| 30 // Not all tasks support cancellation. | 33 // Not all tasks support cancellation. |
| 31 virtual void Cancel() = 0; | 34 virtual void Cancel() = 0; |
| 32 }; | 35 }; |
| 33 | 36 |
| 34 // Scoped Factories ------------------------------------------------------------ | 37 // Scoped Factories ------------------------------------------------------------ |
| 35 // | 38 // |
| 36 // These scoped factory objects can be used by non-refcounted objects to safely | 39 // These scoped factory objects can be used by non-refcounted objects to safely |
| 37 // place tasks in a message loop. Each factory guarantees that the tasks it | 40 // place tasks in a message loop. Each factory guarantees that the tasks it |
| 38 // produces will not run after the factory is destroyed. Commonly, factories | 41 // produces will not run after the factory is destroyed. Commonly, factories |
| 39 // are declared as class members, so the class' tasks will automatically cancel | 42 // are declared as class members, so the class' tasks will automatically cancel |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 const A& a, const B& b, | 484 const A& a, const B& b, |
| 482 const C& c, const D& d, | 485 const C& c, const D& d, |
| 483 const E& e) { | 486 const E& e) { |
| 484 return new RunnableFunction<Function, Tuple5<A, B, C, D, E> >(function, | 487 return new RunnableFunction<Function, Tuple5<A, B, C, D, E> >(function, |
| 485 MakeTuple(a, b, | 488 MakeTuple(a, b, |
| 486 c, d, | 489 c, d, |
| 487 e)); | 490 e)); |
| 488 } | 491 } |
| 489 | 492 |
| 490 #endif // BASE_TASK_H_ | 493 #endif // BASE_TASK_H_ |
| OLD | NEW |