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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/debug/alias.h"
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 ~ScopedTaskRunner(); 557 ~ScopedTaskRunner();
558 558
559 Task* Release(); 559 Task* Release();
560 560
561 private: 561 private:
562 Task* task_; 562 Task* task_;
563 563
564 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedTaskRunner); 564 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedTaskRunner);
565 }; 565 };
566 566
567 namespace subtle {
568
569 // This class is meant for use in the implementation of MessageLoop classes
570 // such as MessageLoop, MessageLoopProxy, BrowserThread, and WorkerPool to
571 // implement the compatibiltiy APIs while we are transitioning from Task to
572 // Callback.
573 //
574 // It should NOT be used anywhere else!
575 //
576 // 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.
577 // RefCountedThreadSafe. We rely on the fact that users of this class are
578 // careful to ensure that a lock is taken during transfer of ownership for
579 // objects from this class to ensure the refcount is not corrupted.
580 class TaskClosureAdapter : public RefCounted<TaskClosureAdapter> {
581 public:
582 explicit TaskClosureAdapter(Task* task)
583 : task_(task),
584 should_leak_task_(&kTaskLeakingDefault) {
585 }
586
587 // |should_leak_task| points to a flag variable that can be used to determine
588 // if this class should leak the Task on destruction. This is important
589 // at MessageLoop shutdown since not all tasks can be safely deleted without
590 // running. See MessageLoop::DeletePendingTasks() for the exact behavior
591 // of when a Task should be deleted. It is subtle.
592 TaskClosureAdapter(Task* task, bool* should_leak_task)
593 : task_(task),
594 should_leak_task_(should_leak_task) {
595 }
596
597 void Run() {
598 task_->Run();
599 delete task_;
600 task_ = NULL;
601 }
602
603 private:
604 friend class base::RefCounted<TaskClosureAdapter>;
605
606 ~TaskClosureAdapter() {
607 if (!*should_leak_task_) {
608 delete task_;
609 }
610 }
611
612 Task* task_;
613 bool* should_leak_task_;
614 static bool kTaskLeakingDefault;
615 };
616
617 } // namespace subtle
618
567 } // namespace base 619 } // namespace base
568 620
569 #endif // BASE_TASK_H_ 621 #endif // BASE_TASK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698