OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base_api.h" | 9 #include "base/base_export.h" |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
11 #include "base/memory/raw_scoped_refptr_mismatch_checker.h" | 11 #include "base/memory/raw_scoped_refptr_mismatch_checker.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/tracked.h" | 13 #include "base/tracked.h" |
14 #include "base/tuple.h" | 14 #include "base/tuple.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 const size_t kDeadTask = 0xDEAD7A53; | 17 const size_t kDeadTask = 0xDEAD7A53; |
18 } | 18 } |
19 | 19 |
20 // Task ------------------------------------------------------------------------ | 20 // Task ------------------------------------------------------------------------ |
21 // | 21 // |
22 // A task is a generic runnable thingy, usually used for running code on a | 22 // A task is a generic runnable thingy, usually used for running code on a |
23 // different thread or for scheduling future tasks off of the message loop. | 23 // different thread or for scheduling future tasks off of the message loop. |
24 | 24 |
25 class BASE_API Task : public tracked_objects::Tracked { | 25 class BASE_EXPORT Task : public tracked_objects::Tracked { |
26 public: | 26 public: |
27 Task(); | 27 Task(); |
28 virtual ~Task(); | 28 virtual ~Task(); |
29 | 29 |
30 // Tasks are automatically deleted after Run is called. | 30 // Tasks are automatically deleted after Run is called. |
31 virtual void Run() = 0; | 31 virtual void Run() = 0; |
32 }; | 32 }; |
33 | 33 |
34 class BASE_API CancelableTask : public Task { | 34 class BASE_EXPORT CancelableTask : public Task { |
35 public: | 35 public: |
36 CancelableTask(); | 36 CancelableTask(); |
37 virtual ~CancelableTask(); | 37 virtual ~CancelableTask(); |
38 | 38 |
39 // Not all tasks support cancellation. | 39 // Not all tasks support cancellation. |
40 virtual void Cancel() = 0; | 40 virtual void Cancel() = 0; |
41 }; | 41 }; |
42 | 42 |
43 // Scoped Factories ------------------------------------------------------------ | 43 // Scoped Factories ------------------------------------------------------------ |
44 // | 44 // |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 const C& c, const D& d, const E& e, const F& f, | 543 const C& c, const D& d, const E& e, const F& f, |
544 const G& g, const H& h) { | 544 const G& g, const H& h) { |
545 return new RunnableFunction<Function, Tuple8<A, B, C, D, E, F, G, H> >( | 545 return new RunnableFunction<Function, Tuple8<A, B, C, D, E, F, G, H> >( |
546 function, MakeTuple(a, b, c, d, e, f, g, h)); | 546 function, MakeTuple(a, b, c, d, e, f, g, h)); |
547 } | 547 } |
548 | 548 |
549 namespace base { | 549 namespace base { |
550 | 550 |
551 // ScopedTaskRunner is akin to scoped_ptr for Tasks. It ensures that the Task | 551 // ScopedTaskRunner is akin to scoped_ptr for Tasks. It ensures that the Task |
552 // is executed and deleted no matter how the current scope exits. | 552 // is executed and deleted no matter how the current scope exits. |
553 class BASE_API ScopedTaskRunner { | 553 class BASE_EXPORT ScopedTaskRunner { |
554 public: | 554 public: |
555 // Takes ownership of the task. | 555 // Takes ownership of the task. |
556 explicit ScopedTaskRunner(Task* task); | 556 explicit ScopedTaskRunner(Task* task); |
557 ~ScopedTaskRunner(); | 557 ~ScopedTaskRunner(); |
558 | 558 |
559 Task* Release(); | 559 Task* Release(); |
560 | 560 |
561 private: | 561 private: |
562 Task* task_; | 562 Task* task_; |
563 | 563 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 Task* task_; | 598 Task* task_; |
599 bool* should_leak_task_; | 599 bool* should_leak_task_; |
600 static bool kTaskLeakingDefault; | 600 static bool kTaskLeakingDefault; |
601 }; | 601 }; |
602 | 602 |
603 } // namespace subtle | 603 } // namespace subtle |
604 | 604 |
605 } // namespace base | 605 } // namespace base |
606 | 606 |
607 #endif // BASE_TASK_H_ | 607 #endif // BASE_TASK_H_ |
OLD | NEW |