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

Unified Diff: base/task.h

Issue 7316015: Support Closure in ALL the loops! (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: I AM NOT A NUMBER TO BE TALLIED (remove all object tracking for right now). Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: base/task.h
diff --git a/base/task.h b/base/task.h
index ae47f32615b1b789db5b8a841b5908e62a9ed57d..182edf57b6645174c69d8b333cf026b714c60bf8 100644
--- a/base/task.h
+++ b/base/task.h
@@ -564,6 +564,58 @@ class BASE_API ScopedTaskRunner {
DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedTaskRunner);
};
+namespace subtle {
+
+// This class is meant for use in the implementation of MessageLoop classes
+// such as MessageLoop, MessageLoopProxy, BrowserThread, and WorkerPool to
+// implement the compatibiltiy APIs while we are transitioning from Task to
+// Callback.
+//
+// It should NOT be used anywhere else!
+//
+// In particular, notice that the this is RefCounted instead of
willchan no longer on Chromium 2011/07/10 16:47:33 "notice that the this is"? s/the //?
awong 2011/07/14 23:03:30 Done.
+// RefCountedThreadSafe. We rely on the fact that users of this class are
+// careful to ensure that a lock is taken during transfer of ownership for
+// objects from this class to ensure the refcount is not corrupted.
+class TaskClosureAdapter : public RefCounted<TaskClosureAdapter> {
+ public:
+ explicit TaskClosureAdapter(Task* task)
+ : task_(task),
+ should_leak_task_(&kTaskLeakingDefault) {
+ }
+
+ // |should_leak_task| points to a flag variable that can be used to determine
+ // if this class should leak the Task on destruction. This is important
+ // at MessageLoop shutdown since not all tasks can be safely deleted without
+ // running. See MessageLoop::DeletePendingTasks() for the exact behavior
+ // of when a Task should be deleted. It is subtle.
+ TaskClosureAdapter(Task* task, bool* should_leak_task)
+ : task_(task),
+ should_leak_task_(should_leak_task) {
+ }
+
+ void Run() {
+ task_->Run();
+ delete task_;
+ task_ = NULL;
+ }
+
+ private:
+ friend class base::RefCounted<TaskClosureAdapter>;
+
+ ~TaskClosureAdapter() {
+ if (!*should_leak_task_) {
+ delete task_;
+ }
+ }
+
+ Task* task_;
+ bool* should_leak_task_;
+ static bool kTaskLeakingDefault;
+};
+
+} // namespace subtle
+
} // namespace base
#endif // BASE_TASK_H_

Powered by Google App Engine
This is Rietveld 408576698