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 // ============================================================================ | 5 // ============================================================================ |
6 // **************************************************************************** | 6 // **************************************************************************** |
7 // * THIS HEADER IS DEPRECATED, SEE base/callback.h FOR NEW IMPLEMENTATION * | 7 // * THIS HEADER IS DEPRECATED, SEE base/callback.h FOR NEW IMPLEMENTATION * |
8 // **************************************************************************** | 8 // **************************************************************************** |
9 // ============================================================================ | 9 // ============================================================================ |
10 // ============================================================================ | 10 // ============================================================================ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 class BASE_EXPORT Task { | 50 class BASE_EXPORT Task { |
51 public: | 51 public: |
52 Task(); | 52 Task(); |
53 virtual ~Task(); | 53 virtual ~Task(); |
54 | 54 |
55 // Tasks are automatically deleted after Run is called. | 55 // Tasks are automatically deleted after Run is called. |
56 virtual void Run() = 0; | 56 virtual void Run() = 0; |
57 }; | 57 }; |
58 | 58 |
59 class BASE_EXPORT CancelableTask : public Task { | |
60 public: | |
61 CancelableTask(); | |
62 virtual ~CancelableTask(); | |
63 | |
64 // Not all tasks support cancellation. | |
65 virtual void Cancel() = 0; | |
66 }; | |
67 | |
68 template<typename T> | 59 template<typename T> |
69 void DeletePointer(T* obj) { | 60 void DeletePointer(T* obj) { |
70 delete obj; | 61 delete obj; |
71 } | 62 } |
72 | 63 |
73 namespace base { | 64 namespace base { |
74 | 65 |
75 // ScopedTaskRunner is akin to scoped_ptr for Tasks. It ensures that the Task | 66 // ScopedClosureRunner is akin to scoped_ptr for Closures. It ensures that the |
76 // is executed and deleted no matter how the current scope exits. | 67 // Closure is executed and deleted no matter how the current scope exits. |
77 class BASE_EXPORT ScopedTaskRunner { | |
78 public: | |
79 // Takes ownership of the task. | |
80 explicit ScopedTaskRunner(Task* task); | |
81 ~ScopedTaskRunner(); | |
82 | |
83 Task* Release(); | |
84 | |
85 private: | |
86 Task* task_; | |
87 | |
88 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedTaskRunner); | |
89 }; | |
90 | |
91 class BASE_EXPORT ScopedClosureRunner { | 68 class BASE_EXPORT ScopedClosureRunner { |
92 public: | 69 public: |
93 explicit ScopedClosureRunner(const Closure& closure); | 70 explicit ScopedClosureRunner(const Closure& closure); |
94 ~ScopedClosureRunner(); | 71 ~ScopedClosureRunner(); |
95 | 72 |
96 Closure Release(); | 73 Closure Release(); |
97 | 74 |
98 private: | 75 private: |
99 Closure closure_; | 76 Closure closure_; |
100 | 77 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 Task* task_; | 112 Task* task_; |
136 bool* should_leak_task_; | 113 bool* should_leak_task_; |
137 static bool kTaskLeakingDefault; | 114 static bool kTaskLeakingDefault; |
138 }; | 115 }; |
139 | 116 |
140 } // namespace subtle | 117 } // namespace subtle |
141 | 118 |
142 } // namespace base | 119 } // namespace base |
143 | 120 |
144 #endif // BASE_TASK_H_ | 121 #endif // BASE_TASK_H_ |
OLD | NEW |