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

Unified Diff: base/threading/thread_unittest.cc

Issue 8653006: Remove custom Task implementations in base. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month 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 | « base/threading/thread.cc ('k') | base/threading/worker_pool_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/thread_unittest.cc
diff --git a/base/threading/thread_unittest.cc b/base/threading/thread_unittest.cc
index 68a24cf444a3ceb2b40a09bc5a1882546f43f33a..a1a237f23c67c1d0c396a2294ed807cac695408e 100644
--- a/base/threading/thread_unittest.cc
+++ b/base/threading/thread_unittest.cc
@@ -6,6 +6,7 @@
#include <vector>
+#include "base/bind.h"
#include "base/message_loop.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -17,29 +18,11 @@ typedef PlatformTest ThreadTest;
namespace {
-class ToggleValue : public Task {
- public:
- explicit ToggleValue(bool* value) : value_(value) {
- ANNOTATE_BENIGN_RACE(value, "Test-only data race on boolean "
- "in base/thread_unittest");
- }
- virtual void Run() {
- *value_ = !*value_;
- }
- private:
- bool* value_;
-};
-
-class SleepSome : public Task {
- public:
- explicit SleepSome(int msec) : msec_(msec) {
- }
- virtual void Run() {
- base::PlatformThread::Sleep(msec_);
- }
- private:
- int msec_;
-};
+void ToggleValue(bool* value) {
+ ANNOTATE_BENIGN_RACE(value, "Test-only data race on boolean "
+ "in base/thread_unittest");
+ *value = !*value;
+}
class SleepInsideInitThread : public Thread {
public:
@@ -173,7 +156,7 @@ TEST_F(ThreadTest, StartWithOptions_StackSize) {
EXPECT_TRUE(a.IsRunning());
bool was_invoked = false;
- a.message_loop()->PostTask(FROM_HERE, new ToggleValue(&was_invoked));
+ a.message_loop()->PostTask(FROM_HERE, base::Bind(&ToggleValue, &was_invoked));
// wait for the task to run (we could use a kernel event here
// instead to avoid busy waiting, but this is sufficient for
@@ -194,8 +177,10 @@ TEST_F(ThreadTest, TwoTasks) {
// Test that all events are dispatched before the Thread object is
// destroyed. We do this by dispatching a sleep event before the
// event that will toggle our sentinel value.
- a.message_loop()->PostTask(FROM_HERE, new SleepSome(20));
- a.message_loop()->PostTask(FROM_HERE, new ToggleValue(&was_invoked));
+ a.message_loop()->PostTask(FROM_HERE,
+ base::Bind(&base::PlatformThread::Sleep, 20));
+ a.message_loop()->PostTask(FROM_HERE, base::Bind(&ToggleValue,
+ &was_invoked));
}
EXPECT_TRUE(was_invoked);
}
« no previous file with comments | « base/threading/thread.cc ('k') | base/threading/worker_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698