Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: base/task.h

Issue 9086002: base::Bind: Remove Task. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style fix. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/message_loop_proxy_impl_unittest.cc ('k') | base/task.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 namespace base { 50 namespace base {
65 51
66 // ScopedClosureRunner is akin to scoped_ptr for Closures. It ensures that the 52 // ScopedClosureRunner is akin to scoped_ptr for Closures. It ensures that the
67 // Closure is executed and deleted no matter how the current scope exits. 53 // Closure is executed and deleted no matter how the current scope exits.
68 class BASE_EXPORT ScopedClosureRunner { 54 class BASE_EXPORT ScopedClosureRunner {
69 public: 55 public:
70 explicit ScopedClosureRunner(const Closure& closure); 56 explicit ScopedClosureRunner(const Closure& closure);
71 ~ScopedClosureRunner(); 57 ~ScopedClosureRunner();
72 58
73 Closure Release(); 59 Closure Release();
74 60
75 private: 61 private:
76 Closure closure_; 62 Closure closure_;
77 63
78 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedClosureRunner); 64 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedClosureRunner);
79 }; 65 };
80 66
81 namespace subtle {
82
83 // This class is meant for use in the implementation of MessageLoop classes
84 // such as MessageLoop, MessageLoopProxy, BrowserThread, and WorkerPool to
85 // implement the compatibility APIs while we are transitioning from Task to
86 // Callback.
87 //
88 // It should NOT be used anywhere else!
89 //
90 // In particular, notice that this is RefCounted instead of
91 // RefCountedThreadSafe. We rely on the fact that users of this class are
92 // careful to ensure that a lock is taken during transfer of ownership for
93 // objects from this class to ensure the refcount is not corrupted.
94 class TaskClosureAdapter : public RefCounted<TaskClosureAdapter> {
95 public:
96 explicit TaskClosureAdapter(Task* task);
97
98 // |should_leak_task| points to a flag variable that can be used to determine
99 // if this class should leak the Task on destruction. This is important
100 // at MessageLoop shutdown since not all tasks can be safely deleted without
101 // running. See MessageLoop::DeletePendingTasks() for the exact behavior
102 // of when a Task should be deleted. It is subtle.
103 TaskClosureAdapter(Task* task, bool* should_leak_task);
104
105 void Run();
106
107 private:
108 friend class base::RefCounted<TaskClosureAdapter>;
109
110 ~TaskClosureAdapter();
111
112 Task* task_;
113 bool* should_leak_task_;
114 static bool kTaskLeakingDefault;
115 };
116
117 } // namespace subtle
118
119 } // namespace base 67 } // namespace base
120 68
121 #endif // BASE_TASK_H_ 69 #endif // BASE_TASK_H_
OLDNEW
« no previous file with comments | « base/message_loop_proxy_impl_unittest.cc ('k') | base/task.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698