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 { | |
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/08 12:04:21
Your comment is totally off. This is RefCountedThr
awong
2011/07/08 18:36:51
Sorry...it's actually supposed to just be RefCount
| |
577 // RefCountedThreadSafe. We rely on the fact thas users of this class are | |
willchan no longer on Chromium
2011/07/08 12:04:21
s/thas/that/
awong
2011/07/08 18:36:51
Done.
| |
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 RefCountedThreadSafe<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::RefCountedThreadSafe<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_ |
OLD | NEW |