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_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 Loading... | |
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 { | |
darin (slow to review)
2011/07/07 21:54:01
nit: new line after namespace
awong
2011/07/08 00:38:40
Done.
| |
568 // This class is meant for use in the implementation of MessageLoop classes | |
569 // such as MessageLoop, MessageLoopProxy, BrowserThread, and WorkerPool to | |
570 // implement the compatibiltiy APIs while we are transitioning from Task to | |
571 // Callback. | |
572 // | |
573 // It should NOT be used anywhere else! | |
574 // | |
575 // In particular, notice that the this is RefCounted instead of | |
576 // RefCountedThreadSafe. We rely on the fact thas users of this class are | |
577 // careful to ensure that a lock is taken during transfer of ownership for | |
578 // objects from this class to ensure the refcount is not corrupted. | |
579 class TaskClosureAdapter : public RefCounted<TaskClosureAdapter> { | |
580 public: | |
581 explicit TaskClosureAdapter(Task* task) | |
582 : task_(task), | |
583 should_leak_task_(&kTaskLeakingDefault) { | |
584 } | |
585 | |
586 // |should_leak_task| points to a flag variable that can be used to determine | |
587 // if this class should leak the Task on destruction. This is important | |
588 // at MessageLoop shutdown since not all tasks can be safely deleted without | |
589 // running. See MessageLoop::DeletePendingTasks() for the exact behavior | |
590 // of when a Task should be deleted. It is subtle. | |
591 TaskClosureAdapter(Task* task, bool* should_leak_task) | |
592 : task_(task), | |
593 should_leak_task_(should_leak_task) { | |
594 } | |
595 | |
596 void Run() { | |
597 task_->Run(); | |
598 delete task_; | |
599 task_ = NULL; | |
600 } | |
601 | |
602 private: | |
603 friend class base::RefCounted<TaskClosureAdapter>; | |
604 | |
605 ~TaskClosureAdapter() { | |
606 if (!*should_leak_task_) { | |
607 delete task_; | |
608 } | |
609 } | |
610 | |
611 Task* task_; | |
612 bool* should_leak_task_; | |
613 static bool kTaskLeakingDefault; | |
614 }; | |
615 | |
616 } // namespace subtle | |
617 | |
567 } // namespace base | 618 } // namespace base |
568 | 619 |
569 #endif // BASE_TASK_H_ | 620 #endif // BASE_TASK_H_ |
OLD | NEW |