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_api.h" |
10 #include "base/debug/alias.h" | |
10 #include "base/memory/raw_scoped_refptr_mismatch_checker.h" | 11 #include "base/memory/raw_scoped_refptr_mismatch_checker.h" |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "base/tracked.h" | 13 #include "base/tracked.h" |
13 #include "base/tuple.h" | 14 #include "base/tuple.h" |
14 | 15 |
16 namespace base { | |
17 const size_t kDeadTask = 0xDEAD7A53; | |
18 } | |
19 | |
15 // Task ------------------------------------------------------------------------ | 20 // Task ------------------------------------------------------------------------ |
16 // | 21 // |
17 // 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 |
18 // 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. |
19 | 24 |
20 class BASE_API Task : public tracked_objects::Tracked { | 25 class BASE_API Task : public tracked_objects::Tracked { |
21 public: | 26 public: |
22 Task(); | 27 Task(); |
23 virtual ~Task(); | 28 virtual ~Task(); |
24 | 29 |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 RunnableMethod(T* obj, Method meth, const Params& params) | 323 RunnableMethod(T* obj, Method meth, const Params& params) |
319 : obj_(obj), meth_(meth), params_(params) { | 324 : obj_(obj), meth_(meth), params_(params) { |
320 traits_.RetainCallee(obj_); | 325 traits_.RetainCallee(obj_); |
321 COMPILE_ASSERT( | 326 COMPILE_ASSERT( |
322 (base::internal::ParamsUseScopedRefptrCorrectly<Params>::value), | 327 (base::internal::ParamsUseScopedRefptrCorrectly<Params>::value), |
323 badrunnablemethodparams); | 328 badrunnablemethodparams); |
324 } | 329 } |
325 | 330 |
326 ~RunnableMethod() { | 331 ~RunnableMethod() { |
327 ReleaseCallee(); | 332 ReleaseCallee(); |
333 obj_ = reinterpret_cast<T*>(base::kDeadTask); | |
328 } | 334 } |
329 | 335 |
330 virtual void Run() { | 336 virtual void Run() { |
331 if (obj_) | 337 if (obj_) |
332 DispatchToMethod(obj_, meth_, params_); | 338 DispatchToMethod(obj_, meth_, params_); |
333 } | 339 } |
334 | 340 |
335 virtual void Cancel() { | 341 virtual void Cancel() { |
336 ReleaseCallee(); | 342 ReleaseCallee(); |
337 } | 343 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 class RunnableFunction : public Task { | 451 class RunnableFunction : public Task { |
446 public: | 452 public: |
447 RunnableFunction(Function function, const Params& params) | 453 RunnableFunction(Function function, const Params& params) |
448 : function_(function), params_(params) { | 454 : function_(function), params_(params) { |
449 COMPILE_ASSERT( | 455 COMPILE_ASSERT( |
450 (base::internal::ParamsUseScopedRefptrCorrectly<Params>::value), | 456 (base::internal::ParamsUseScopedRefptrCorrectly<Params>::value), |
451 badrunnablefunctionparams); | 457 badrunnablefunctionparams); |
452 } | 458 } |
453 | 459 |
454 ~RunnableFunction() { | 460 ~RunnableFunction() { |
461 function_ = reinterpret_cast<Function>(base::kDeadTask); | |
455 } | 462 } |
456 | 463 |
457 virtual void Run() { | 464 virtual void Run() { |
465 // TODO(apatrick): Remove this ASAP. This ensures that the function pointer | |
466 // is available in minidumps for the purpose of diagnosing 81449. | |
darin (slow to review)
2011/05/24 04:45:19
nit: prefix bug numbers with "bug" or "crbug.com/"
| |
467 Function function = function_; | |
468 base::debug::Alias(&function); | |
469 Params params = params_; | |
470 base::debug::Alias(¶ms); | |
471 | |
458 if (function_) | 472 if (function_) |
459 DispatchToFunction(function_, params_); | 473 DispatchToFunction(function_, params_); |
460 } | 474 } |
461 | 475 |
462 private: | 476 private: |
463 Function function_; | 477 Function function_; |
464 Params params_; | 478 Params params_; |
465 }; | 479 }; |
466 | 480 |
467 template <class Function> | 481 template <class Function> |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 template <class Function, class A, class B, class C, class D, class E, | 539 template <class Function, class A, class B, class C, class D, class E, |
526 class F, class G, class H> | 540 class F, class G, class H> |
527 inline Task* NewRunnableFunction(Function function, const A& a, const B& b, | 541 inline Task* NewRunnableFunction(Function function, const A& a, const B& b, |
528 const C& c, const D& d, const E& e, const F& f, | 542 const C& c, const D& d, const E& e, const F& f, |
529 const G& g, const H& h) { | 543 const G& g, const H& h) { |
530 return new RunnableFunction<Function, Tuple8<A, B, C, D, E, F, G, H> >( | 544 return new RunnableFunction<Function, Tuple8<A, B, C, D, E, F, G, H> >( |
531 function, MakeTuple(a, b, c, d, e, f, g, h)); | 545 function, MakeTuple(a, b, c, d, e, f, g, h)); |
532 } | 546 } |
533 | 547 |
534 #endif // BASE_TASK_H_ | 548 #endif // BASE_TASK_H_ |
OLD | NEW |