| 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_export.h" | 9 #include "base/base_export.h" |
| 10 #include "base/callback.h" |
| 10 #include "base/debug/alias.h" | 11 #include "base/debug/alias.h" |
| 11 #include "base/memory/raw_scoped_refptr_mismatch_checker.h" | 12 #include "base/memory/raw_scoped_refptr_mismatch_checker.h" |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/tracked.h" | 14 #include "base/tracked.h" |
| 14 #include "base/tuple.h" | 15 #include "base/tuple.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 const size_t kDeadTask = 0xDEAD7A53; | 18 const size_t kDeadTask = 0xDEAD7A53; |
| 19 class MessageLoopProxy; |
| 18 } | 20 } |
| 19 | 21 |
| 20 // Task ------------------------------------------------------------------------ | 22 // Task ------------------------------------------------------------------------ |
| 21 // | 23 // |
| 22 // A task is a generic runnable thingy, usually used for running code on a | 24 // 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. | 25 // different thread or for scheduling future tasks off of the message loop. |
| 24 | 26 |
| 25 class BASE_EXPORT Task : public tracked_objects::Tracked { | 27 class BASE_EXPORT Task : public tracked_objects::Tracked { |
| 26 public: | 28 public: |
| 27 Task(); | 29 Task(); |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 | 597 |
| 596 ~TaskClosureAdapter(); | 598 ~TaskClosureAdapter(); |
| 597 | 599 |
| 598 Task* task_; | 600 Task* task_; |
| 599 bool* should_leak_task_; | 601 bool* should_leak_task_; |
| 600 static bool kTaskLeakingDefault; | 602 static bool kTaskLeakingDefault; |
| 601 }; | 603 }; |
| 602 | 604 |
| 603 } // namespace subtle | 605 } // namespace subtle |
| 604 | 606 |
| 607 namespace internal { |
| 608 |
| 609 // This relay class remembers the MessageLoop that it was created on, and |
| 610 // ensures that both the |task| and |reply| Closures are deleted on this same |
| 611 // thread. |
| 612 // |
| 613 // If this is not possible because the originating MessageLoop is no longer |
| 614 // available, the the |task| and |reply| Closures are leaked. Leaking is |
| 615 // considered preferable to having a thread-safetey violations caused by |
| 616 // invoking the Closure destructor on the wrong thread. |
| 617 class PostTaskAndReplyRelay { |
| 618 public: |
| 619 PostTaskAndReplyRelay(const tracked_objects::Location& from_here, |
| 620 const Closure& task, const Closure& reply); |
| 621 |
| 622 ~PostTaskAndReplyRelay(); |
| 623 |
| 624 void Run(); |
| 625 |
| 626 private: |
| 627 void RunReplyAndSelfDestruct(); |
| 628 |
| 629 tracked_objects::Location from_here_; |
| 630 scoped_refptr<MessageLoopProxy> origin_loop_; |
| 631 Closure task_; |
| 632 Closure reply_; |
| 633 }; |
| 634 |
| 635 } // namespace internal |
| 636 |
| 605 } // namespace base | 637 } // namespace base |
| 606 | 638 |
| 607 #endif // BASE_TASK_H_ | 639 #endif // BASE_TASK_H_ |
| OLD | NEW |