summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-05 02:18:18 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-05 02:18:18 +0000
commite7b3a61984f86ccb238664542699c3b8a75b54c6 (patch)
treea75e7830c5fa93c5af7bcebf0c60485513ce6a1e /base
parent9c66adca4f62f3b85593068aea30cf1568690987 (diff)
downloadchromium_src-e7b3a61984f86ccb238664542699c3b8a75b54c6.zip
chromium_src-e7b3a61984f86ccb238664542699c3b8a75b54c6.tar.gz
chromium_src-e7b3a61984f86ccb238664542699c3b8a75b54c6.tar.bz2
base::Bind: Remove Task.
BUG=none TEST=none R=awong Review URL: http://codereview.chromium.org/9086002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116439 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/files/file_path_watcher_linux.cc113
-rw-r--r--base/message_loop.cc64
-rw-r--r--base/message_loop.h32
-rw-r--r--base/message_loop_proxy.h25
-rw-r--r--base/message_loop_proxy_impl.cc46
-rw-r--r--base/message_loop_proxy_impl.h18
-rw-r--r--base/message_loop_proxy_impl_unittest.cc46
-rw-r--r--base/task.cc37
-rw-r--r--base/task.h52
-rw-r--r--base/threading/thread_unittest.cc24
-rw-r--r--base/threading/worker_pool.h7
-rw-r--r--base/threading/worker_pool_posix.cc30
-rw-r--r--base/threading/worker_pool_posix.h9
-rw-r--r--base/threading/worker_pool_win.cc11
14 files changed, 69 insertions, 445 deletions
diff --git a/base/files/file_path_watcher_linux.cc b/base/files/file_path_watcher_linux.cc
index 86c963c..9711766 100644
--- a/base/files/file_path_watcher_linux.cc
+++ b/base/files/file_path_watcher_linux.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -152,76 +152,62 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate,
DISALLOW_COPY_AND_ASSIGN(FilePathWatcherImpl);
};
-class InotifyReaderTask : public Task {
- public:
- InotifyReaderTask(InotifyReader* reader, int inotify_fd, int shutdown_fd)
- : reader_(reader),
- inotify_fd_(inotify_fd),
- shutdown_fd_(shutdown_fd) {
- // Make sure the file descriptors are good for use with select().
- CHECK_LE(0, inotify_fd_);
- CHECK_GT(FD_SETSIZE, inotify_fd_);
- CHECK_LE(0, shutdown_fd_);
- CHECK_GT(FD_SETSIZE, shutdown_fd_);
- }
-
- virtual void Run() {
- while (true) {
- fd_set rfds;
- FD_ZERO(&rfds);
- FD_SET(inotify_fd_, &rfds);
- FD_SET(shutdown_fd_, &rfds);
-
- // Wait until some inotify events are available.
- int select_result =
- HANDLE_EINTR(select(std::max(inotify_fd_, shutdown_fd_) + 1,
- &rfds, NULL, NULL, NULL));
- if (select_result < 0) {
- DPLOG(WARNING) << "select failed";
- return;
- }
+void InotifyReaderCallback(InotifyReader* reader, int inotify_fd,
+ int shutdown_fd) {
+ // Make sure the file descriptors are good for use with select().
+ CHECK_LE(0, inotify_fd);
+ CHECK_GT(FD_SETSIZE, inotify_fd);
+ CHECK_LE(0, shutdown_fd);
+ CHECK_GT(FD_SETSIZE, shutdown_fd);
+
+ while (true) {
+ fd_set rfds;
+ FD_ZERO(&rfds);
+ FD_SET(inotify_fd, &rfds);
+ FD_SET(shutdown_fd, &rfds);
+
+ // Wait until some inotify events are available.
+ int select_result =
+ HANDLE_EINTR(select(std::max(inotify_fd, shutdown_fd) + 1,
+ &rfds, NULL, NULL, NULL));
+ if (select_result < 0) {
+ DPLOG(WARNING) << "select failed";
+ return;
+ }
- if (FD_ISSET(shutdown_fd_, &rfds))
- return;
+ if (FD_ISSET(shutdown_fd, &rfds))
+ return;
- // Adjust buffer size to current event queue size.
- int buffer_size;
- int ioctl_result = HANDLE_EINTR(ioctl(inotify_fd_, FIONREAD,
- &buffer_size));
+ // Adjust buffer size to current event queue size.
+ int buffer_size;
+ int ioctl_result = HANDLE_EINTR(ioctl(inotify_fd, FIONREAD,
+ &buffer_size));
- if (ioctl_result != 0) {
- DPLOG(WARNING) << "ioctl failed";
- return;
- }
+ if (ioctl_result != 0) {
+ DPLOG(WARNING) << "ioctl failed";
+ return;
+ }
- std::vector<char> buffer(buffer_size);
+ std::vector<char> buffer(buffer_size);
- ssize_t bytes_read = HANDLE_EINTR(read(inotify_fd_, &buffer[0],
- buffer_size));
+ ssize_t bytes_read = HANDLE_EINTR(read(inotify_fd, &buffer[0],
+ buffer_size));
- if (bytes_read < 0) {
- DPLOG(WARNING) << "read from inotify fd failed";
- return;
- }
+ if (bytes_read < 0) {
+ DPLOG(WARNING) << "read from inotify fd failed";
+ return;
+ }
- ssize_t i = 0;
- while (i < bytes_read) {
- inotify_event* event = reinterpret_cast<inotify_event*>(&buffer[i]);
- size_t event_size = sizeof(inotify_event) + event->len;
- DCHECK(i + event_size <= static_cast<size_t>(bytes_read));
- reader_->OnInotifyEvent(event);
- i += event_size;
- }
+ ssize_t i = 0;
+ while (i < bytes_read) {
+ inotify_event* event = reinterpret_cast<inotify_event*>(&buffer[i]);
+ size_t event_size = sizeof(inotify_event) + event->len;
+ DCHECK(i + event_size <= static_cast<size_t>(bytes_read));
+ reader->OnInotifyEvent(event);
+ i += event_size;
}
}
-
- private:
- InotifyReader* reader_;
- int inotify_fd_;
- int shutdown_fd_;
-
- DISALLOW_COPY_AND_ASSIGN(InotifyReaderTask);
-};
+}
static base::LazyInstance<InotifyReader> g_inotify_reader =
LAZY_INSTANCE_INITIALIZER;
@@ -234,7 +220,8 @@ InotifyReader::InotifyReader()
shutdown_pipe_[1] = -1;
if (inotify_fd_ >= 0 && pipe(shutdown_pipe_) == 0 && thread_.Start()) {
thread_.message_loop()->PostTask(
- FROM_HERE, new InotifyReaderTask(this, inotify_fd_, shutdown_pipe_[0]));
+ FROM_HERE, base::Bind(&InotifyReaderCallback, this, inotify_fd_,
+ shutdown_pipe_[0]));
valid_ = true;
}
}
diff --git a/base/message_loop.cc b/base/message_loop.cc
index 6da3b6b..aa04f45 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -249,68 +249,6 @@ void MessageLoop::RemoveDestructionObserver(
}
void MessageLoop::PostTask(
- const tracked_objects::Location& from_here, Task* task) {
- DCHECK(task);
- PendingTask pending_task(
- from_here,
- base::Bind(
- &base::subtle::TaskClosureAdapter::Run,
- new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)),
- CalculateDelayedRuntime(0), true);
- AddToIncomingQueue(&pending_task);
-}
-
-void MessageLoop::PostDelayedTask(
- const tracked_objects::Location& from_here, Task* task, int64 delay_ms) {
- DCHECK(task);
- PendingTask pending_task(
- from_here,
- base::Bind(
- &base::subtle::TaskClosureAdapter::Run,
- new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)),
- CalculateDelayedRuntime(delay_ms), true);
- AddToIncomingQueue(&pending_task);
-}
-
-void MessageLoop::PostDelayedTask(
- const tracked_objects::Location& from_here,
- Task* task,
- base::TimeDelta delay) {
- PostDelayedTask(from_here, task, delay.InMillisecondsRoundedUp());
-}
-
-void MessageLoop::PostNonNestableTask(
- const tracked_objects::Location& from_here, Task* task) {
- DCHECK(task);
- PendingTask pending_task(
- from_here,
- base::Bind(
- &base::subtle::TaskClosureAdapter::Run,
- new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)),
- CalculateDelayedRuntime(0), false);
- AddToIncomingQueue(&pending_task);
-}
-
-void MessageLoop::PostNonNestableDelayedTask(
- const tracked_objects::Location& from_here, Task* task, int64 delay_ms) {
- DCHECK(task);
- PendingTask pending_task(
- from_here,
- base::Bind(
- &base::subtle::TaskClosureAdapter::Run,
- new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)),
- CalculateDelayedRuntime(delay_ms), false);
- AddToIncomingQueue(&pending_task);
-}
-
-void MessageLoop::PostNonNestableDelayedTask(
- const tracked_objects::Location& from_here,
- Task* task,
- base::TimeDelta delay) {
- PostNonNestableDelayedTask(from_here, task, delay.InMillisecondsRoundedUp());
-}
-
-void MessageLoop::PostTask(
const tracked_objects::Location& from_here, const base::Closure& task) {
DCHECK(!task.is_null()) << from_here.ToString();
PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), true);
diff --git a/base/message_loop.h b/base/message_loop.h
index 2f66d26..edaa71a 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -162,36 +162,6 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
//
// NOTE: These methods may be called on any thread. The Task will be invoked
// on the thread that executes MessageLoop::Run().
-
- void PostTask(
- const tracked_objects::Location& from_here, Task* task);
-
- void PostDelayedTask(
- const tracked_objects::Location& from_here, Task* task, int64 delay_ms);
-
- void PostDelayedTask(
- const tracked_objects::Location& from_here,
- Task* task,
- base::TimeDelta delay);
-
- void PostNonNestableTask(
- const tracked_objects::Location& from_here, Task* task);
-
- void PostNonNestableDelayedTask(
- const tracked_objects::Location& from_here, Task* task, int64 delay_ms);
-
- void PostNonNestableDelayedTask(
- const tracked_objects::Location& from_here,
- Task* task,
- base::TimeDelta delay);
-
- // TODO(ajwong): Remove the functions above once the Task -> Closure migration
- // is complete.
- //
- // There are 2 sets of Post*Task functions, one which takes the older Task*
- // function object representation, and one that takes the newer base::Closure.
- // We have this overload to allow a staged transition between the two systems.
- // Once the transition is done, the functions above should be deleted.
void PostTask(
const tracked_objects::Location& from_here,
const base::Closure& task);
diff --git a/base/message_loop_proxy.h b/base/message_loop_proxy.h
index b6da5e4..ef1f658 100644
--- a/base/message_loop_proxy.h
+++ b/base/message_loop_proxy.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -33,33 +33,14 @@ class BASE_EXPORT MessageLoopProxy
MessageLoopProxyTraits> {
public:
// These methods are the same as in message_loop.h, but are guaranteed to
- // either post the Task to the MessageLoop (if it's still alive), or to
- // delete the Task otherwise.
+ // either post the Task to the MessageLoop (if it's still alive), or the task
+ // is discarded.
// They return true iff the thread existed and the task was posted. Note that
// even if the task is posted, there's no guarantee that it will run; for
// example the target loop may already be quitting, or in the case of a
// delayed task a Quit message may preempt it in the message loop queue.
// Conversely, a return value of false is a guarantee the task will not run.
virtual bool PostTask(const tracked_objects::Location& from_here,
- Task* task) = 0;
- virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
- Task* task,
- int64 delay_ms) = 0;
- virtual bool PostNonNestableTask(const tracked_objects::Location& from_here,
- Task* task) = 0;
- virtual bool PostNonNestableDelayedTask(
- const tracked_objects::Location& from_here,
- Task* task,
- int64 delay_ms) = 0;
-
- // TODO(ajwong): Remove the functions above once the Task -> Closure migration
- // is complete.
- //
- // There are 2 sets of Post*Task functions, one which takes the older Task*
- // function object representation, and one that takes the newer base::Closure.
- // We have this overload to allow a staged transition between the two systems.
- // Once the transition is done, the functions above should be deleted.
- virtual bool PostTask(const tracked_objects::Location& from_here,
const base::Closure& task) = 0;
virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
const base::Closure& task,
diff --git a/base/message_loop_proxy_impl.cc b/base/message_loop_proxy_impl.cc
index b826916..e0ecd89 100644
--- a/base/message_loop_proxy_impl.cc
+++ b/base/message_loop_proxy_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -12,29 +12,6 @@ namespace base {
MessageLoopProxyImpl::~MessageLoopProxyImpl() {
}
- // MessageLoopProxy implementation
-bool MessageLoopProxyImpl::PostTask(const tracked_objects::Location& from_here,
- Task* task) {
- return PostTaskHelper(from_here, task, 0, true);
-}
-
-bool MessageLoopProxyImpl::PostDelayedTask(
- const tracked_objects::Location& from_here, Task* task, int64 delay_ms) {
- return PostTaskHelper(from_here, task, delay_ms, true);
-}
-
-bool MessageLoopProxyImpl::PostNonNestableTask(
- const tracked_objects::Location& from_here, Task* task) {
- return PostTaskHelper(from_here, task, 0, false);
-}
-
-bool MessageLoopProxyImpl::PostNonNestableDelayedTask(
- const tracked_objects::Location& from_here,
- Task* task,
- int64 delay_ms) {
- return PostTaskHelper(from_here, task, delay_ms, false);
-}
-
bool MessageLoopProxyImpl::PostTask(const tracked_objects::Location& from_here,
const base::Closure& task) {
return PostTaskHelper(from_here, task, 0, true);
@@ -100,27 +77,6 @@ MessageLoopProxyImpl::MessageLoopProxyImpl()
}
bool MessageLoopProxyImpl::PostTaskHelper(
- const tracked_objects::Location& from_here, Task* task, int64 delay_ms,
- bool nestable) {
- bool ret = false;
- {
- AutoLock lock(message_loop_lock_);
- if (target_message_loop_) {
- if (nestable) {
- target_message_loop_->PostDelayedTask(from_here, task, delay_ms);
- } else {
- target_message_loop_->PostNonNestableDelayedTask(from_here, task,
- delay_ms);
- }
- ret = true;
- }
- }
- if (!ret)
- delete task;
- return ret;
-}
-
-bool MessageLoopProxyImpl::PostTaskHelper(
const tracked_objects::Location& from_here, const base::Closure& task,
int64 delay_ms, bool nestable) {
AutoLock lock(message_loop_lock_);
diff --git a/base/message_loop_proxy_impl.h b/base/message_loop_proxy_impl.h
index 0c44c82..bb1fc0b 100644
--- a/base/message_loop_proxy_impl.h
+++ b/base/message_loop_proxy_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -23,17 +23,6 @@ class BASE_EXPORT MessageLoopProxyImpl
// MessageLoopProxy implementation
virtual bool PostTask(const tracked_objects::Location& from_here,
- Task* task) OVERRIDE;
- virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
- Task* task,
- int64 delay_ms) OVERRIDE;
- virtual bool PostNonNestableTask(const tracked_objects::Location& from_here,
- Task* task) OVERRIDE;
- virtual bool PostNonNestableDelayedTask(
- const tracked_objects::Location& from_here,
- Task* task,
- int64 delay_ms) OVERRIDE;
- virtual bool PostTask(const tracked_objects::Location& from_here,
const base::Closure& task) OVERRIDE;
virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
const base::Closure& task,
@@ -58,11 +47,6 @@ class BASE_EXPORT MessageLoopProxyImpl
virtual void WillDestroyCurrentMessageLoop();
- // TODO(ajwong): Remove this after we've fully migrated to base::Closure.
- bool PostTaskHelper(const tracked_objects::Location& from_here,
- Task* task,
- int64 delay_ms,
- bool nestable);
bool PostTaskHelper(const tracked_objects::Location& from_here,
const base::Closure& task,
int64 delay_ms,
diff --git a/base/message_loop_proxy_impl_unittest.cc b/base/message_loop_proxy_impl_unittest.cc
index 2935911..612312a 100644
--- a/base/message_loop_proxy_impl_unittest.cc
+++ b/base/message_loop_proxy_impl_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -58,21 +58,6 @@ class MessageLoopProxyImplTest : public testing::Test {
FAIL() << "Callback Should not get executed.";
}
- class DummyTask : public Task {
- public:
- explicit DummyTask(bool* deleted) : deleted_(deleted) { }
- ~DummyTask() {
- *deleted_ = true;
- }
-
- void Run() {
- FAIL();
- }
-
- private:
- bool* deleted_;
- };
-
class DeletedOnFile {
public:
explicit DeletedOnFile(MessageLoopProxyImplTest* test) : test_(test) {}
@@ -105,35 +90,6 @@ TEST_F(MessageLoopProxyImplTest, Delete) {
MessageLoop::current()->Run();
}
-TEST_F(MessageLoopProxyImplTest, LegacyPostTaskAfterThreadExits) {
- scoped_ptr<base::Thread> test_thread(
- new base::Thread("MessageLoopProxyImplTest_Dummy"));
- test_thread->Start();
- scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
- test_thread->message_loop_proxy();
- test_thread->Stop();
-
- bool deleted = false;
- bool ret = message_loop_proxy->PostTask(
- FROM_HERE, new DummyTask(&deleted));
- EXPECT_FALSE(ret);
- EXPECT_TRUE(deleted);
-}
-
-TEST_F(MessageLoopProxyImplTest, LegacyPostTaskAfterThreadIsDeleted) {
- scoped_refptr<base::MessageLoopProxy> message_loop_proxy;
- {
- scoped_ptr<base::Thread> test_thread(
- new base::Thread("MessageLoopProxyImplTest_Dummy"));
- test_thread->Start();
- message_loop_proxy = test_thread->message_loop_proxy();
- }
- bool deleted = false;
- bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted));
- EXPECT_FALSE(ret);
- EXPECT_TRUE(deleted);
-}
-
TEST_F(MessageLoopProxyImplTest, PostTask) {
EXPECT_TRUE(file_thread_->message_loop_proxy()->PostTask(
FROM_HERE, base::Bind(&MessageLoopProxyImplTest::BasicFunction,
diff --git a/base/task.cc b/base/task.cc
index 38ac086..baf4e0f6 100644
--- a/base/task.cc
+++ b/base/task.cc
@@ -1,15 +1,9 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/task.h"
-Task::Task() {
-}
-
-Task::~Task() {
-}
-
namespace base {
ScopedClosureRunner::ScopedClosureRunner(const Closure& closure)
@@ -27,33 +21,4 @@ Closure ScopedClosureRunner::Release() {
return result;
}
-namespace subtle {
-
-TaskClosureAdapter::TaskClosureAdapter(Task* task)
- : task_(task),
- should_leak_task_(&kTaskLeakingDefault) {
-}
-
-TaskClosureAdapter::TaskClosureAdapter(Task* task, bool* should_leak_task)
- : task_(task),
- should_leak_task_(should_leak_task) {
-}
-
-TaskClosureAdapter::~TaskClosureAdapter() {
- if (!*should_leak_task_) {
- delete task_;
- }
-}
-
-void TaskClosureAdapter::Run() {
- task_->Run();
- delete task_;
- task_ = NULL;
-}
-
-// Don't leak tasks by default.
-bool TaskClosureAdapter::kTaskLeakingDefault = false;
-
-} // namespace subtle
-
} // namespace base
diff --git a/base/task.h b/base/task.h
index a310e0d..dbef70b 100644
--- a/base/task.h
+++ b/base/task.h
@@ -42,20 +42,6 @@ namespace base {
const size_t kDeadTask = 0xDEAD7A53;
}
-// Task ------------------------------------------------------------------------
-//
-// A task is a generic runnable thingy, usually used for running code on a
-// different thread or for scheduling future tasks off of the message loop.
-
-class BASE_EXPORT Task {
- public:
- Task();
- virtual ~Task();
-
- // Tasks are automatically deleted after Run is called.
- virtual void Run() = 0;
-};
-
template<typename T>
void DeletePointer(T* obj) {
delete obj;
@@ -78,44 +64,6 @@ class BASE_EXPORT ScopedClosureRunner {
DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedClosureRunner);
};
-namespace subtle {
-
-// This class is meant for use in the implementation of MessageLoop classes
-// such as MessageLoop, MessageLoopProxy, BrowserThread, and WorkerPool to
-// implement the compatibility APIs while we are transitioning from Task to
-// Callback.
-//
-// It should NOT be used anywhere else!
-//
-// In particular, notice that this is RefCounted instead of
-// 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);
-
- // |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);
-
- void Run();
-
- private:
- friend class base::RefCounted<TaskClosureAdapter>;
-
- ~TaskClosureAdapter();
-
- Task* task_;
- bool* should_leak_task_;
- static bool kTaskLeakingDefault;
-};
-
-} // namespace subtle
-
} // namespace base
#endif // BASE_TASK_H_
diff --git a/base/threading/thread_unittest.cc b/base/threading/thread_unittest.cc
index 0444947..87df252 100644
--- a/base/threading/thread_unittest.cc
+++ b/base/threading/thread_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -105,21 +105,9 @@ class CapturingDestructionObserver : public MessageLoop::DestructionObserver {
};
// Task that adds a destruction observer to the current message loop.
-class RegisterDestructionObserver : public Task {
- public:
- explicit RegisterDestructionObserver(
- MessageLoop::DestructionObserver* observer)
- : observer_(observer) {
- }
-
- virtual void Run() {
- MessageLoop::current()->AddDestructionObserver(observer_);
- observer_ = NULL;
- }
-
- private:
- MessageLoop::DestructionObserver* observer_;
-};
+void RegisterDestructionObserver(MessageLoop::DestructionObserver* observer) {
+ MessageLoop::current()->AddDestructionObserver(observer);
+}
} // namespace
@@ -234,8 +222,8 @@ TEST_F(ThreadTest, CleanUp) {
// Register an observer that writes into |captured_events| once the
// thread's message loop is destroyed.
t.message_loop()->PostTask(
- FROM_HERE,
- new RegisterDestructionObserver(&loop_destruction_observer));
+ FROM_HERE, base::Bind(&RegisterDestructionObserver,
+ base::Unretained(&loop_destruction_observer)));
// Upon leaving this scope, the thread is deleted.
}
diff --git a/base/threading/worker_pool.h b/base/threading/worker_pool.h
index 0db6122..6694830 100644
--- a/base/threading/worker_pool.h
+++ b/base/threading/worker_pool.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -31,11 +31,6 @@ class BASE_EXPORT WorkerPool {
// should be used for tasks that will take a long time to execute. Returns
// false if |task| could not be posted to a worker thread. Regardless of
// return value, ownership of |task| is transferred to the worker pool.
- //
- // TODO(ajwong): Remove the Task* based overload once we've finished the
- // Task -> Closure migration.
- static bool PostTask(const tracked_objects::Location& from_here,
- Task* task, bool task_is_slow);
static bool PostTask(const tracked_objects::Location& from_here,
const base::Closure& task, bool task_is_slow);
diff --git a/base/threading/worker_pool_posix.cc b/base/threading/worker_pool_posix.cc
index f93c447..2655b85c 100644
--- a/base/threading/worker_pool_posix.cc
+++ b/base/threading/worker_pool_posix.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -31,8 +31,6 @@ class WorkerPoolImpl {
WorkerPoolImpl();
~WorkerPoolImpl();
- void PostTask(const tracked_objects::Location& from_here, Task* task,
- bool task_is_slow);
void PostTask(const tracked_objects::Location& from_here,
const base::Closure& task, bool task_is_slow);
@@ -50,11 +48,6 @@ WorkerPoolImpl::~WorkerPoolImpl() {
}
void WorkerPoolImpl::PostTask(const tracked_objects::Location& from_here,
- Task* task, bool task_is_slow) {
- pool_->PostTask(from_here, task);
-}
-
-void WorkerPoolImpl::PostTask(const tracked_objects::Location& from_here,
const base::Closure& task, bool task_is_slow) {
pool_->PostTask(from_here, task);
}
@@ -109,12 +102,6 @@ void WorkerThread::ThreadMain() {
} // namespace
bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
- Task* task, bool task_is_slow) {
- g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow);
- return true;
-}
-
-bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
const base::Closure& task, bool task_is_slow) {
g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow);
return true;
@@ -146,21 +133,6 @@ void PosixDynamicThreadPool::Terminate() {
void PosixDynamicThreadPool::PostTask(
const tracked_objects::Location& from_here,
- Task* task) {
- PendingTask pending_task(from_here,
- base::Bind(&subtle::TaskClosureAdapter::Run,
- new subtle::TaskClosureAdapter(task)));
- // |pending_task| and AddTask() work in conjunction here to ensure that after
- // a successful AddTask(), the TaskClosureAdapter object is deleted on the
- // worker thread. In AddTask(), the reference |pending_task.task| is handed
- // off in a destructive manner to ensure that the local copy of
- // |pending_task| doesn't keep a ref on the Closure causing the
- // TaskClosureAdapter to be deleted on the wrong thread.
- AddTask(&pending_task);
-}
-
-void PosixDynamicThreadPool::PostTask(
- const tracked_objects::Location& from_here,
const base::Closure& task) {
PendingTask pending_task(from_here, task);
AddTask(&pending_task);
diff --git a/base/threading/worker_pool_posix.h b/base/threading/worker_pool_posix.h
index 491dbbb..f56582d 100644
--- a/base/threading/worker_pool_posix.h
+++ b/base/threading/worker_pool_posix.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -59,13 +59,6 @@ class BASE_EXPORT PosixDynamicThreadPool
// worker threads. Wakes up all the idle threads to let them exit.
void Terminate();
- // Adds |task| to the thread pool. PosixDynamicThreadPool assumes ownership
- // of |task|.
- //
- // TODO(ajwong): Remove this compatibility API once the Task -> Closure
- // migration is finished.
- void PostTask(const tracked_objects::Location& from_here, Task* task);
-
// Adds |task| to the thread pool.
void PostTask(const tracked_objects::Location& from_here,
const Closure& task);
diff --git a/base/threading/worker_pool_win.cc b/base/threading/worker_pool_win.cc
index 188c4a9..d4249ea 100644
--- a/base/threading/worker_pool_win.cc
+++ b/base/threading/worker_pool_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -53,15 +53,6 @@ bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) {
} // namespace
bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
- Task* task, bool task_is_slow) {
- PendingTask* pending_task =
- new PendingTask(from_here,
- base::Bind(&subtle::TaskClosureAdapter::Run,
- new subtle::TaskClosureAdapter(task)));
- return PostTaskInternal(pending_task, task_is_slow);
-}
-
-bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
const base::Closure& task, bool task_is_slow) {
PendingTask* pending_task = new PendingTask(from_here, task);
return PostTaskInternal(pending_task, task_is_slow);