| 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 24 matching lines...) Expand all Loading... |
| 35 #include "base/callback.h" | 35 #include "base/callback.h" |
| 36 #include "base/debug/alias.h" | 36 #include "base/debug/alias.h" |
| 37 #include "base/memory/raw_scoped_refptr_mismatch_checker.h" | 37 #include "base/memory/raw_scoped_refptr_mismatch_checker.h" |
| 38 #include "base/memory/weak_ptr.h" | 38 #include "base/memory/weak_ptr.h" |
| 39 #include "base/tuple.h" | 39 #include "base/tuple.h" |
| 40 | 40 |
| 41 namespace base { | 41 namespace base { |
| 42 const size_t kDeadTask = 0xDEAD7A53; | 42 const size_t kDeadTask = 0xDEAD7A53; |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Task ------------------------------------------------------------------------ | |
| 46 // | |
| 47 // A task is a generic runnable thingy, usually used for running code on a | |
| 48 // different thread or for scheduling future tasks off of the message loop. | |
| 49 | |
| 50 class BASE_EXPORT Task { | |
| 51 public: | |
| 52 Task(); | |
| 53 virtual ~Task(); | |
| 54 | |
| 55 // Tasks are automatically deleted after Run is called. | |
| 56 virtual void Run() = 0; | |
| 57 }; | |
| 58 | |
| 59 template<typename T> | 45 template<typename T> |
| 60 void DeletePointer(T* obj) { | 46 void DeletePointer(T* obj) { |
| 61 delete obj; | 47 delete obj; |
| 62 } | 48 } |
| 63 | 49 |
| 64 template<typename T> | 50 template<typename T> |
| 65 void ReleasePointer(T* obj) { | 51 void ReleasePointer(T* obj) { |
| 66 obj->Release(); | 52 obj->Release(); |
| 67 } | 53 } |
| 68 | 54 |
| 69 namespace base { | 55 namespace base { |
| 70 | 56 |
| 71 // ScopedClosureRunner is akin to scoped_ptr for Closures. It ensures that the | 57 // ScopedClosureRunner is akin to scoped_ptr for Closures. It ensures that the |
| 72 // Closure is executed and deleted no matter how the current scope exits. | 58 // Closure is executed and deleted no matter how the current scope exits. |
| 73 class BASE_EXPORT ScopedClosureRunner { | 59 class BASE_EXPORT ScopedClosureRunner { |
| 74 public: | 60 public: |
| 75 explicit ScopedClosureRunner(const Closure& closure); | 61 explicit ScopedClosureRunner(const Closure& closure); |
| 76 ~ScopedClosureRunner(); | 62 ~ScopedClosureRunner(); |
| 77 | 63 |
| 78 Closure Release(); | 64 Closure Release(); |
| 79 | 65 |
| 80 private: | 66 private: |
| 81 Closure closure_; | 67 Closure closure_; |
| 82 | 68 |
| 83 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedClosureRunner); | 69 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedClosureRunner); |
| 84 }; | 70 }; |
| 85 | 71 |
| 86 namespace subtle { | |
| 87 | |
| 88 // This class is meant for use in the implementation of MessageLoop classes | |
| 89 // such as MessageLoop, MessageLoopProxy, BrowserThread, and WorkerPool to | |
| 90 // implement the compatibility APIs while we are transitioning from Task to | |
| 91 // Callback. | |
| 92 // | |
| 93 // It should NOT be used anywhere else! | |
| 94 // | |
| 95 // In particular, notice that this is RefCounted instead of | |
| 96 // RefCountedThreadSafe. We rely on the fact that users of this class are | |
| 97 // careful to ensure that a lock is taken during transfer of ownership for | |
| 98 // objects from this class to ensure the refcount is not corrupted. | |
| 99 class TaskClosureAdapter : public RefCounted<TaskClosureAdapter> { | |
| 100 public: | |
| 101 explicit TaskClosureAdapter(Task* task); | |
| 102 | |
| 103 // |should_leak_task| points to a flag variable that can be used to determine | |
| 104 // if this class should leak the Task on destruction. This is important | |
| 105 // at MessageLoop shutdown since not all tasks can be safely deleted without | |
| 106 // running. See MessageLoop::DeletePendingTasks() for the exact behavior | |
| 107 // of when a Task should be deleted. It is subtle. | |
| 108 TaskClosureAdapter(Task* task, bool* should_leak_task); | |
| 109 | |
| 110 void Run(); | |
| 111 | |
| 112 private: | |
| 113 friend class base::RefCounted<TaskClosureAdapter>; | |
| 114 | |
| 115 ~TaskClosureAdapter(); | |
| 116 | |
| 117 Task* task_; | |
| 118 bool* should_leak_task_; | |
| 119 static bool kTaskLeakingDefault; | |
| 120 }; | |
| 121 | |
| 122 } // namespace subtle | |
| 123 | |
| 124 } // namespace base | 72 } // namespace base |
| 125 | 73 |
| 126 #endif // BASE_TASK_H_ | 74 #endif // BASE_TASK_H_ |
| OLD | NEW |