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/raw_scoped_refptr_mismatch_checker.h" | 9 #include "base/memory/raw_scoped_refptr_mismatch_checker.h" |
10 #include "base/memory/weak_ptr.h" | |
10 #include "base/tracked.h" | 11 #include "base/tracked.h" |
11 #include "base/tuple.h" | 12 #include "base/tuple.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(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 template <class Method, class Params> | 142 template <class Method, class Params> |
143 class RunnableMethod : public CancelableTask { | 143 class RunnableMethod : public CancelableTask { |
144 public: | 144 public: |
145 RunnableMethod(const base::WeakPtr<T>& obj, | 145 RunnableMethod(const base::WeakPtr<T>& obj, |
146 Method meth, | 146 Method meth, |
147 const Params& params) | 147 const Params& params) |
148 : obj_(obj), | 148 : obj_(obj), |
149 meth_(meth), | 149 meth_(meth), |
150 params_(params) { | 150 params_(params) { |
151 COMPILE_ASSERT( | 151 COMPILE_ASSERT( |
152 (base::internal::ParamsUseScopedRefptrCorrectly<Params>::value), | 152 (base::internal:: |
brettw
2011/03/24 20:37:30
Revert this, same for the other cases below
| |
153 ParamsUseScopedRefptrCorrectly<Params>::value), | |
153 badscopedrunnablemethodparams); | 154 badscopedrunnablemethodparams); |
154 } | 155 } |
155 | 156 |
156 virtual void Run() { | 157 virtual void Run() { |
157 if (obj_) | 158 if (obj_) |
158 DispatchToMethod(obj_.get(), meth_, params_); | 159 DispatchToMethod(obj_.get(), meth_, params_); |
159 } | 160 } |
160 | 161 |
161 virtual void Cancel() { | 162 virtual void Cancel() { |
162 obj_.reset(); | 163 obj_.reset(); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 | 312 |
312 // RunnableMethod and NewRunnableMethod implementation ------------------------- | 313 // RunnableMethod and NewRunnableMethod implementation ------------------------- |
313 | 314 |
314 template <class T, class Method, class Params> | 315 template <class T, class Method, class Params> |
315 class RunnableMethod : public CancelableTask { | 316 class RunnableMethod : public CancelableTask { |
316 public: | 317 public: |
317 RunnableMethod(T* obj, Method meth, const Params& params) | 318 RunnableMethod(T* obj, Method meth, const Params& params) |
318 : obj_(obj), meth_(meth), params_(params) { | 319 : obj_(obj), meth_(meth), params_(params) { |
319 traits_.RetainCallee(obj_); | 320 traits_.RetainCallee(obj_); |
320 COMPILE_ASSERT( | 321 COMPILE_ASSERT( |
321 (base::internal::ParamsUseScopedRefptrCorrectly<Params>::value), | 322 (base::internal:: |
323 ParamsUseScopedRefptrCorrectly<Params>::value), | |
322 badrunnablemethodparams); | 324 badrunnablemethodparams); |
323 } | 325 } |
324 | 326 |
325 ~RunnableMethod() { | 327 ~RunnableMethod() { |
326 ReleaseCallee(); | 328 ReleaseCallee(); |
327 } | 329 } |
328 | 330 |
329 virtual void Run() { | 331 virtual void Run() { |
330 if (obj_) | 332 if (obj_) |
331 DispatchToMethod(obj_, meth_, params_); | 333 DispatchToMethod(obj_, meth_, params_); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 } | 441 } |
440 | 442 |
441 // RunnableFunction and NewRunnableFunction implementation --------------------- | 443 // RunnableFunction and NewRunnableFunction implementation --------------------- |
442 | 444 |
443 template <class Function, class Params> | 445 template <class Function, class Params> |
444 class RunnableFunction : public CancelableTask { | 446 class RunnableFunction : public CancelableTask { |
445 public: | 447 public: |
446 RunnableFunction(Function function, const Params& params) | 448 RunnableFunction(Function function, const Params& params) |
447 : function_(function), params_(params) { | 449 : function_(function), params_(params) { |
448 COMPILE_ASSERT( | 450 COMPILE_ASSERT( |
449 (base::internal::ParamsUseScopedRefptrCorrectly<Params>::value), | 451 (base::internal:: |
452 ParamsUseScopedRefptrCorrectly<Params>::value), | |
450 badrunnablefunctionparams); | 453 badrunnablefunctionparams); |
451 } | 454 } |
452 | 455 |
453 ~RunnableFunction() { | 456 ~RunnableFunction() { |
454 } | 457 } |
455 | 458 |
456 virtual void Run() { | 459 virtual void Run() { |
457 if (function_) | 460 if (function_) |
458 DispatchToFunction(function_, params_); | 461 DispatchToFunction(function_, params_); |
459 } | 462 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 inline CancelableTask* NewRunnableFunction(Function function, | 540 inline CancelableTask* NewRunnableFunction(Function function, |
538 const A& a, const B& b, | 541 const A& a, const B& b, |
539 const C& c, const D& d, | 542 const C& c, const D& d, |
540 const E& e, const F& f, | 543 const E& e, const F& f, |
541 const G& g, const H& h) { | 544 const G& g, const H& h) { |
542 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> >( |
543 function, MakeTuple(a, b, c, d, e, f, g, h)); | 546 function, MakeTuple(a, b, c, d, e, f, g, h)); |
544 } | 547 } |
545 | 548 |
546 #endif // BASE_TASK_H_ | 549 #endif // BASE_TASK_H_ |
OLD | NEW |