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

Unified Diff: base/message_loop.cc

Issue 7316015: Support Closure in ALL the loops! (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed nit and rebased. 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
« no previous file with comments | « no previous file | base/message_loop_proxy.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop.cc
diff --git a/base/message_loop.cc b/base/message_loop.cc
index 08985a4c0061833df1dbc4bb9e7e7c5599fd1f50..e3f6ea3440251bfcb43901ed4a32826381aa5171 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -85,40 +85,6 @@ const base::LinearHistogram::DescriptionPair event_descriptions_[] = {
bool enable_histogrammer_ = false;
-// TODO(ajwong): This is one use case for having a Owned() tag that behaves
-// like a "Unique" pointer. If we had that, and Tasks were always safe to
-// delete on MessageLoop shutdown, this class could just be a function.
-class TaskClosureAdapter : public base::RefCounted<TaskClosureAdapter> {
- public:
- // |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_;
-};
-
} // namespace
//------------------------------------------------------------------------------
@@ -271,8 +237,9 @@ void MessageLoop::PostTask(
const tracked_objects::Location& from_here, Task* task) {
CHECK(task);
PendingTask pending_task(
- base::Bind(&TaskClosureAdapter::Run,
- new TaskClosureAdapter(task, &should_leak_tasks_)),
+ base::Bind(
+ &base::subtle::TaskClosureAdapter::Run,
+ new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)),
from_here,
CalculateDelayedRuntime(0), true);
AddToIncomingQueue(&pending_task);
@@ -282,8 +249,9 @@ void MessageLoop::PostDelayedTask(
const tracked_objects::Location& from_here, Task* task, int64 delay_ms) {
CHECK(task);
PendingTask pending_task(
- base::Bind(&TaskClosureAdapter::Run,
- new TaskClosureAdapter(task, &should_leak_tasks_)),
+ base::Bind(
+ &base::subtle::TaskClosureAdapter::Run,
+ new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)),
from_here,
CalculateDelayedRuntime(delay_ms), true);
AddToIncomingQueue(&pending_task);
@@ -293,8 +261,9 @@ void MessageLoop::PostNonNestableTask(
const tracked_objects::Location& from_here, Task* task) {
CHECK(task);
PendingTask pending_task(
- base::Bind(&TaskClosureAdapter::Run,
- new TaskClosureAdapter(task, &should_leak_tasks_)),
+ base::Bind(
+ &base::subtle::TaskClosureAdapter::Run,
+ new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)),
from_here,
CalculateDelayedRuntime(0), false);
AddToIncomingQueue(&pending_task);
@@ -304,8 +273,9 @@ void MessageLoop::PostNonNestableDelayedTask(
const tracked_objects::Location& from_here, Task* task, int64 delay_ms) {
CHECK(task);
PendingTask pending_task(
- base::Bind(&TaskClosureAdapter::Run,
- new TaskClosureAdapter(task, &should_leak_tasks_)),
+ base::Bind(
+ &base::subtle::TaskClosureAdapter::Run,
+ new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)),
from_here,
CalculateDelayedRuntime(delay_ms), false);
AddToIncomingQueue(&pending_task);
@@ -486,11 +456,9 @@ void MessageLoop::RunTask(const PendingTask& pending_task) {
DidProcessTask(pending_task.time_posted));
#if defined(TRACK_ALL_TASK_OBJECTS)
- if (tracked_objects::ThreadData::IsActive() && pending_task.post_births) {
- tracked_objects::ThreadData::current()->TallyADeath(
- *pending_task.post_births,
- TimeTicks::Now() - pending_task.time_posted);
- }
+ tracked_objects::ThreadData::TallyADeathIfActive(
+ pending_task.post_births,
+ TimeTicks::Now() - pending_task.time_posted);
#endif // defined(TRACK_ALL_TASK_OBJECTS)
nestable_tasks_allowed_ = true;
@@ -780,14 +748,7 @@ MessageLoop::PendingTask::PendingTask(
nestable(nestable),
birth_program_counter(posted_from.program_counter()) {
#if defined(TRACK_ALL_TASK_OBJECTS)
- post_births = NULL;
- if (tracked_objects::ThreadData::IsActive()) {
- tracked_objects::ThreadData* current_thread_data =
- tracked_objects::ThreadData::current();
- if (current_thread_data) {
- post_births = current_thread_data->TallyABirth(posted_from);
- }
- }
+ post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from);
#endif // defined(TRACK_ALL_TASK_OBJECTS)
}
« no previous file with comments | « no previous file | base/message_loop_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698